Various improvements (#233)

* Fix formatting

* Refactor daemons

Replaced FujiDaemon with FakeEstimateFeeDaemon that simulates estimate
fee calls and provide the same functionality.
Removed the parameter False for LegacyRPCDaemon's getblock RPC call as
it is not needed.

* Fix Crown coin P2SH_VERBYTES and add REORG_LIMIT
This commit is contained in:
John L. Jegutanis 2017-08-26 06:33:20 +03:00 committed by Neil
parent 3d4d382178
commit 885872f0b5
4 changed files with 28 additions and 21 deletions

View File

@ -42,7 +42,8 @@ from lib.script import ScriptPubKey
from lib.tx import Deserializer, DeserializerSegWit, DeserializerAuxPow, \ from lib.tx import Deserializer, DeserializerSegWit, DeserializerAuxPow, \
DeserializerZcash, DeserializerTxTime, DeserializerReddcoin DeserializerZcash, DeserializerTxTime, DeserializerReddcoin
from server.block_processor import BlockProcessor from server.block_processor import BlockProcessor
from server.daemon import Daemon, DashDaemon, LegacyRPCDaemon, FujiDaemon from server.daemon import Daemon, DashDaemon, LegacyRPCDaemon,\
FakeEstimateFeeDaemon
from server.session import ElectrumX, DashElectrumX from server.session import ElectrumX, DashElectrumX
@ -917,6 +918,7 @@ class Monacoin(Coin):
'electrumx2.movsign.info t', 'electrumx2.movsign.info t',
] ]
class Crown(AuxPowMixin, Coin): class Crown(AuxPowMixin, Coin):
NAME = "Crown" NAME = "Crown"
SHORTNAME = "CRW" SHORTNAME = "CRW"
@ -924,7 +926,7 @@ class Crown(AuxPowMixin, Coin):
XPUB_VERBYTES = bytes.fromhex("0488b21e") XPUB_VERBYTES = bytes.fromhex("0488b21e")
XPRV_VERBYTES = bytes.fromhex("0488ade4") XPRV_VERBYTES = bytes.fromhex("0488ade4")
P2PKH_VERBYTE = bytes.fromhex("00") P2PKH_VERBYTE = bytes.fromhex("00")
P2SH_VERBYTES = [bytes.fromhex("05")] P2SH_VERBYTES = [bytes.fromhex("1c")]
WIF_BYTE = bytes.fromhex("80") WIF_BYTE = bytes.fromhex("80")
GENESIS_HASH = ('0000000085370d5e122f64f4ab19c686' GENESIS_HASH = ('0000000085370d5e122f64f4ab19c686'
'14ff3df78c8d13cb814fd7e69a1dc6da') '14ff3df78c8d13cb814fd7e69a1dc6da')
@ -932,6 +934,8 @@ class Crown(AuxPowMixin, Coin):
TX_COUNT_HEIGHT = 1268206 TX_COUNT_HEIGHT = 1268206
TX_PER_BLOCK = 10 TX_PER_BLOCK = 10
RPC_PORT = 9341 RPC_PORT = 9341
REORG_LIMIT = 1000
class Fujicoin(Coin): class Fujicoin(Coin):
NAME = "Fujicoin" NAME = "Fujicoin"
@ -944,10 +948,11 @@ class Fujicoin(Coin):
WIF_BYTE = bytes.fromhex("a4") WIF_BYTE = bytes.fromhex("a4")
GENESIS_HASH = ('adb6d9cfd74075e7f91608add4bd2a2e' GENESIS_HASH = ('adb6d9cfd74075e7f91608add4bd2a2e'
'a636f70856183086842667a1597714a0') 'a636f70856183086842667a1597714a0')
# DESERIALIZER = DeserializerSegWit ESTIMATE_FEE = 0.001
DAEMON = FujiDaemon RELAY_FEE = 0.001
DAEMON = FakeEstimateFeeDaemon
TX_COUNT = 170478 TX_COUNT = 170478
TX_COUNT_HEIGHT = 1521676 TX_COUNT_HEIGHT = 1521676
TX_PER_BLOCK = 1 TX_PER_BLOCK = 1
RPC_PORT = 3776 RPC_PORT = 3776
# REORG_LIMIT = 1000 REORG_LIMIT = 1000

View File

@ -47,7 +47,8 @@ class Controller(util.LoggedClass):
self.loop.set_default_executor(self.executor) self.loop.set_default_executor(self.executor)
self.start_time = time.time() self.start_time = time.time()
self.coin = env.coin self.coin = env.coin
self.daemon = self.coin.DAEMON(env.coin.daemon_urls(env.daemon_url)) self.daemon = self.coin.DAEMON(self.coin,
env.coin.daemon_urls(env.daemon_url))
self.bp = self.coin.BLOCK_PROCESSOR(env, self, self.daemon) self.bp = self.coin.BLOCK_PROCESSOR(env, self, self.daemon)
self.mempool = MemPool(self.bp, self) self.mempool = MemPool(self.bp, self)
self.peer_mgr = PeerManager(env, self) self.peer_mgr = PeerManager(env, self)

View File

@ -34,8 +34,9 @@ class Daemon(util.LoggedClass):
class DaemonWarmingUpError(Exception): class DaemonWarmingUpError(Exception):
'''Raised when the daemon returns an error in its results.''' '''Raised when the daemon returns an error in its results.'''
def __init__(self, urls): def __init__(self, coin, urls):
super().__init__() super().__init__()
self.coin = coin
self.set_urls(urls) self.set_urls(urls)
self._height = None self._height = None
self._mempool_hashes = set() self._mempool_hashes = set()
@ -272,18 +273,17 @@ class DashDaemon(Daemon):
'''Return the masternode status.''' '''Return the masternode status.'''
return await self._send_single('masternodelist', params) return await self._send_single('masternodelist', params)
class FujiDaemon(Daemon): class FakeEstimateFeeDaemon(Daemon):
'''This is a measure against coin daemon which does not have the 'estimatefee' command. '''Daemon that simulates estimatefee and relayfee RPC calls. Coin that
When the electrum is in 'Use dynamic fees' mode, the estimatefee does not return from electrum-X, so the user can not remit money. wants to use this daemon must define ESTIMATE_FEE & RELAY_FEE'''
See class Fujicoin() in lib/coins.py for usage.'''
async def estimatefee(self, params): async def estimatefee(self, params):
'''Return the fee estimate for the given parameters.''' '''Return the fee estimate for the given parameters.'''
return 0.001 return self.coin.ESTIMATE_FEE
async def relayfee(self): async def relayfee(self):
'''The minimum fee a low-priority tx must pay in order to be accepted '''The minimum fee a low-priority tx must pay in order to be accepted
to the daemon's memory pool.''' to the daemon's memory pool.'''
return 0.001 return self.coin.RELAY_FEE
class LegacyRPCDaemon(Daemon): class LegacyRPCDaemon(Daemon):
'''Handles connections to a daemon at the given URL. '''Handles connections to a daemon at the given URL.
@ -297,7 +297,7 @@ class LegacyRPCDaemon(Daemon):
async def raw_blocks(self, hex_hashes): async def raw_blocks(self, hex_hashes):
'''Return the raw binary blocks with the given hex hashes.''' '''Return the raw binary blocks with the given hex hashes.'''
params_iterable = ((h, False) for h in hex_hashes) params_iterable = ((h, ) for h in hex_hashes)
block_info = await self._send_vector('getblock', params_iterable) block_info = await self._send_vector('getblock', params_iterable)
blocks = [] blocks = []

View File

@ -394,13 +394,14 @@ class DashElectrumX(ElectrumX):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.electrumx_handlers['masternode.announce.broadcast'] = self.masternode_announce_broadcast self.electrumx_handlers['masternode.announce.broadcast'] =\
self.electrumx_handlers['masternode.subscribe'] = self.masternode_subscribe self.masternode_announce_broadcast
self.electrumx_handlers['masternode.subscribe'] =\
self.masternode_subscribe
self.mns = set() self.mns = set()
async def notify(self, height, touched): async def notify(self, height, touched):
'''Notify the client about changes in masternode list.''' '''Notify the client about changes in masternode list.'''
await super().notify(height, touched) await super().notify(height, touched)
for masternode in self.mns: for masternode in self.mns:
@ -418,7 +419,6 @@ class DashElectrumX(ElectrumX):
Force version string response for Electrum-Dash 2.6.4 client caused by Force version string response for Electrum-Dash 2.6.4 client caused by
https://github.com/dashpay/electrum-dash/commit/638cf6c0aeb7be14a85ad98f873791cb7b49ee29 https://github.com/dashpay/electrum-dash/commit/638cf6c0aeb7be14a85ad98f873791cb7b49ee29
''' '''
default_return = super().server_version(client_name, protocol_version) default_return = super().server_version(client_name, protocol_version)
if self.client == '2.6.4': if self.client == '2.6.4':
return '1.0' return '1.0'
@ -426,10 +426,11 @@ class DashElectrumX(ElectrumX):
# Masternode command handlers # Masternode command handlers
async def masternode_announce_broadcast(self, signmnb): async def masternode_announce_broadcast(self, signmnb):
'''Pass through the masternode announce message to be broadcast by the daemon.''' '''Pass through the masternode announce message to be broadcast
by the daemon.'''
try: try:
mnb_info = await self.daemon.masternode_broadcast(['relay', signmnb]) mnb_info = await self.daemon.masternode_broadcast(
['relay', signmnb])
return mnb_info return mnb_info
except DaemonError as e: except DaemonError as e:
error = e.args[0] error = e.args[0]