mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-17 12:14:33 +08:00
api tweak: pass the server state to the virtualchain hooks (including the atlas state)
This commit is contained in:
@@ -2233,7 +2233,7 @@ def index_blockchain(server_state, expected_snapshots=GENESIS_SNAPSHOT):
|
||||
# NOTE: at each block, the atlas db will be synchronized by virtualchain_hooks
|
||||
log.debug("Begin indexing (up to %s)" % current_block)
|
||||
set_indexing( working_dir, True )
|
||||
rc = virtualchain_hooks.sync_blockchain(working_dir, bt_opts, current_block, subdomain_index=server_state['subdomains'], expected_snapshots=expected_snapshots, tx_filter=blockstack_tx_filter)
|
||||
rc = virtualchain_hooks.sync_blockchain(working_dir, bt_opts, current_block, server_state, expected_snapshots=expected_snapshots, tx_filter=blockstack_tx_filter)
|
||||
set_indexing( working_dir, False )
|
||||
|
||||
db.close()
|
||||
|
||||
@@ -492,6 +492,11 @@ def db_save( block_height, consensus_hash, ops_hash, accepted_ops, virtualchain_
|
||||
os.abort()
|
||||
|
||||
try:
|
||||
atlas_state = None
|
||||
if hasattr(db_state, 'atlas_state') and db_state.atlas_state is not None:
|
||||
# normal course of action
|
||||
atlas_state = db_state.atlas_state
|
||||
|
||||
# sync block data to atlas, if enabled
|
||||
if is_atlas_enabled(blockstack_opts):
|
||||
log.debug("Synchronize Atlas DB for {}".format(block_height))
|
||||
@@ -500,7 +505,7 @@ def db_save( block_height, consensus_hash, ops_hash, accepted_ops, virtualchain_
|
||||
|
||||
# NOTE: set end_block explicitly since db_state.lastblock still points to the previous block height
|
||||
gc.collect()
|
||||
new_zonefile_infos = atlasdb_sync_zonefiles(db_state, block_height, zonefile_dir, path=atlasdb_path, end_block=block_height+1)
|
||||
new_zonefile_infos = atlasdb_sync_zonefiles(db_state, block_height, zonefile_dir, atlas_state, path=atlasdb_path, end_block=block_height+1)
|
||||
gc.collect()
|
||||
|
||||
except Exception as e:
|
||||
@@ -523,7 +528,7 @@ def db_save( block_height, consensus_hash, ops_hash, accepted_ops, virtualchain_
|
||||
log.warning("Instantiating subdomain index")
|
||||
subdomain_index = SubdomainIndex(blockstack_opts['subdomaindb_path'], blockstack_opts=blockstack_opts)
|
||||
instantiated = True
|
||||
|
||||
|
||||
log.debug("Synchronize subdomain index for {}".format(block_height))
|
||||
|
||||
gc.collect()
|
||||
@@ -564,7 +569,7 @@ def db_continue( block_id, consensus_hash ):
|
||||
return is_running() or os.environ.get("BLOCKSTACK_TEST") == "1"
|
||||
|
||||
|
||||
def sync_blockchain( working_dir, bt_opts, last_block, subdomain_index=None, expected_snapshots={}, **virtualchain_args ):
|
||||
def sync_blockchain( working_dir, bt_opts, last_block, server_state, expected_snapshots={}, **virtualchain_args ):
|
||||
"""
|
||||
synchronize state with the blockchain.
|
||||
Return True on success
|
||||
@@ -572,6 +577,9 @@ def sync_blockchain( working_dir, bt_opts, last_block, subdomain_index=None, exp
|
||||
Abort on error
|
||||
"""
|
||||
|
||||
subdomain_index = server_state['subdomains']
|
||||
atlas_state = server_state['atlas']
|
||||
|
||||
# make this usable even if we haven't explicitly configured virtualchain
|
||||
impl = sys.modules[__name__]
|
||||
log.info("Synchronizing database {} up to block {}".format(working_dir, last_block))
|
||||
@@ -579,7 +587,10 @@ def sync_blockchain( working_dir, bt_opts, last_block, subdomain_index=None, exp
|
||||
# NOTE: this is the only place where a read-write handle should be created,
|
||||
# since this is the only place where the db should be modified.
|
||||
new_db = BlockstackDB.borrow_readwrite_instance(working_dir, last_block, expected_snapshots=expected_snapshots)
|
||||
|
||||
# propagate runtime state to virtualchain callbacks
|
||||
new_db.subdomain_index = subdomain_index
|
||||
new_db.atlas_state = atlas_state
|
||||
|
||||
rc = virtualchain.sync_virtualchain(bt_opts, last_block, new_db, expected_snapshots=expected_snapshots, **virtualchain_args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user