Merge branch 'fixes' into develop
This commit is contained in:
commit
791aaa5879
@ -156,6 +156,9 @@ class Bitcoin(Coin):
|
||||
WIF_BYTE = 0x80
|
||||
GENESIS_HASH=(b'000000000019d6689c085ae165831e93'
|
||||
b'4ff763ae46a2a6c172b3f1b60a8ce26f')
|
||||
TX_COUNT = 109611638
|
||||
TX_COUNT_HEIGHT = 398055
|
||||
TX_PER_BLOCK = 2000
|
||||
|
||||
class BitcoinTestnet(Coin):
|
||||
NAME = "Bitcoin"
|
||||
|
||||
21
server/db.py
21
server/db.py
@ -379,7 +379,7 @@ class DB(object):
|
||||
last_flush = self.last_flush
|
||||
tx_diff = self.tx_count - self.db_tx_count
|
||||
height_diff = self.height - self.db_height
|
||||
self.logger.info('starting flush {:,d} txs and {:,d} blocks'
|
||||
self.logger.info('flushing cache: {:,d} transactions and {:,d} blocks'
|
||||
.format(tx_diff, height_diff))
|
||||
|
||||
# Write out the files to the FS before flushing to the DB. If
|
||||
@ -406,16 +406,21 @@ class DB(object):
|
||||
self.logger.info('flush #{:,d} to height {:,d} took {:,d}s'
|
||||
.format(self.flush_count, self.height, flush_time))
|
||||
|
||||
# Roughly 2500 tx/block at end
|
||||
# Log handy stats
|
||||
txs_per_sec = int(self.tx_count / self.wall_time)
|
||||
this_txs_per_sec = int(tx_diff / (self.last_flush - last_flush))
|
||||
eta = (daemon_height - self.height) * 2500 / (this_txs_per_sec + 0.01)
|
||||
this_txs_per_sec = 1 + int(tx_diff / (self.last_flush - last_flush))
|
||||
if self.height > self.coin.TX_COUNT_HEIGHT:
|
||||
tx_est = (daemon_height - self.height) * self.coin.TX_PER_BLOCK
|
||||
else:
|
||||
tx_est = ((daemon_height - self.coin.TX_COUNT_HEIGHT)
|
||||
* self.coin.TX_PER_BLOCK + self.coin.TX_COUNT)
|
||||
|
||||
self.logger.info('txs: {:,d} tx/sec since genesis: {:,d}, '
|
||||
'since last flush: {:,d}'
|
||||
.format(self.tx_count, txs_per_sec, this_txs_per_sec))
|
||||
self.logger.info('sync time: {} ETA: {}'
|
||||
.format(formatted_time(self.wall_time),
|
||||
formatted_time(eta)))
|
||||
formatted_time(tx_est / this_txs_per_sec)))
|
||||
|
||||
def flush_to_fs(self):
|
||||
'''Flush the things stored on the filesystem.'''
|
||||
@ -479,7 +484,7 @@ class DB(object):
|
||||
while cursor < len(hashes):
|
||||
file_num, offset = divmod(file_pos, self.tx_hash_file_size)
|
||||
size = min(len(hashes) - cursor, self.tx_hash_file_size - offset)
|
||||
filename = 'hashes{:05d}'.format(file_num)
|
||||
filename = 'hashes{:04d}'.format(file_num)
|
||||
with self.open_file(filename, create=True) as f:
|
||||
f.seek(offset)
|
||||
f.write(hashes[cursor:cursor + size])
|
||||
@ -487,7 +492,7 @@ class DB(object):
|
||||
file_pos += size
|
||||
self.tx_hashes = []
|
||||
|
||||
def cache_MB(self, daemon_height):
|
||||
def cache_size(self, daemon_height):
|
||||
'''Returns the approximate size of the cache, in MB.'''
|
||||
# Good average estimates
|
||||
utxo_cache_size = len(self.utxo_cache.cache) * 187
|
||||
@ -529,7 +534,7 @@ class DB(object):
|
||||
now = time.time()
|
||||
if now > self.next_cache_check:
|
||||
self.next_cache_check = now + 60
|
||||
if self.cache_MB(daemon_height) > self.flush_MB:
|
||||
if self.cache_size(daemon_height) > self.flush_MB:
|
||||
self.flush_all(daemon_height)
|
||||
|
||||
def process_tx(self, tx_hash, tx):
|
||||
|
||||
@ -80,6 +80,7 @@ class BlockCache(object):
|
||||
if not self.stop:
|
||||
self.logger.info('caught up to height {:d}'
|
||||
.format(self.daemon_height))
|
||||
self.db.flush_all(self.daemon_height)
|
||||
|
||||
def cache_used(self):
|
||||
return sum(len(block) for block in self.blocks)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user