本文整理汇总了Python中sawtooth_validator.state.merkle.MerkleDatabase.create_index_configuration方法的典型用法代码示例。如果您正苦于以下问题:Python MerkleDatabase.create_index_configuration方法的具体用法?Python MerkleDatabase.create_index_configuration怎么用?Python MerkleDatabase.create_index_configuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sawtooth_validator.state.merkle.MerkleDatabase
的用法示例。
在下文中一共展示了MerkleDatabase.create_index_configuration方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_state_verifier
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def test_state_verifier(self):
blockstore = BlockStore(DictDatabase(
indexes=BlockStore.create_index_configuration()))
global_state_db = NativeLmdbDatabase(
os.path.join(self._temp_dir, 'test_state_verifier.lmdb'),
indexes=MerkleDatabase.create_index_configuration())
precalculated_state_roots = [
"e35490eac6f77453675c3399da7efe451e791272bbc8cf1b032c75030fb455c3",
"3a369eb951171895c00ba2ffd04bfa1ef98d6ee651f96a65ae3280cf8d67d5e7",
"797e70e29915c9129f950b2084ed0e3c09246bd1e6c232571456f51ca85df340",
]
signer = get_signer()
populate_blockstore(blockstore, signer, precalculated_state_roots)
verify_state(
global_state_db,
blockstore,
"tcp://eth0:4004",
"serial")
# There is a bug in the shutdown code for some component this depends
# on, which causes it to occassionally hang during shutdown. Just kill
# the process for now.
# pylint: disable=protected-access
os._exit(0)
示例2: setUp
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def setUp(self):
self._temp_dir = tempfile.mkdtemp()
self.database = NativeLmdbDatabase(
os.path.join(self._temp_dir, 'test_state_view.lmdb'),
indexes=MerkleDatabase.create_index_configuration(),
_size=10 * 1024 * 1024)
示例3: test_empty_batch_file_should_produce_block
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def test_empty_batch_file_should_produce_block(
self, mock_scheduler_complete
):
"""
In this case, the genesis batch, even with an empty list of batches,
should produce a genesis block.
Also:
- the genesis.batch file should be deleted
- the block_chain_id file should be created and populated
"""
genesis_file = self._with_empty_batch_file()
block_store = self.make_block_store()
block_manager = BlockManager()
block_manager.add_commit_store(block_store)
state_database = NativeLmdbDatabase(
os.path.join(self._temp_dir, 'test_genesis.lmdb'),
indexes=MerkleDatabase.create_index_configuration(),
_size=10 * 1024 * 1024)
merkle_db = MerkleDatabase(state_database)
ctx_mgr = Mock(name='ContextManager')
ctx_mgr.get_squash_handler.return_value = Mock()
ctx_mgr.get_first_root.return_value = merkle_db.get_merkle_root()
txn_executor = Mock(name='txn_executor')
completer = Mock('completer')
completer.add_block = Mock('add_block')
genesis_ctrl = GenesisController(
context_manager=ctx_mgr,
transaction_executor=txn_executor,
completer=completer,
block_store=block_store,
state_view_factory=StateViewFactory(state_database),
identity_signer=self._signer,
block_manager=block_manager,
data_dir=self._temp_dir,
config_dir=self._temp_dir,
chain_id_manager=ChainIdManager(self._temp_dir),
batch_sender=Mock('batch_sender'))
on_done_fn = Mock(return_value='')
genesis_ctrl.start(on_done_fn)
self.assertEqual(False, os.path.exists(genesis_file))
self.assertEqual(True, block_store.chain_head is not None)
self.assertEqual(1, on_done_fn.call_count)
self.assertEqual(1, completer.add_block.call_count)
self.assertEqual(block_store.chain_head.identifier,
self._read_block_chain_id())
示例4: __init__
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def __init__(self, with_genesis=True):
self.block_sender = MockBlockSender()
self.batch_sender = MockBatchSender()
self.dir = tempfile.mkdtemp()
self.block_db = NativeLmdbDatabase(
os.path.join(self.dir, 'block.lmdb'),
BlockStore.create_index_configuration())
self.block_store = BlockStore(self.block_db)
self.block_cache = BlockCache(self.block_store)
self.state_db = NativeLmdbDatabase(
os.path.join(self.dir, "merkle.lmdb"),
MerkleDatabase.create_index_configuration())
self.state_view_factory = NativeStateViewFactory(self.state_db)
self.block_manager = BlockManager()
self.block_manager.add_commit_store(self.block_store)
context = create_context('secp256k1')
private_key = context.new_random_private_key()
crypto_factory = CryptoFactory(context)
self.signer = crypto_factory.new_signer(private_key)
identity_private_key = context.new_random_private_key()
self.identity_signer = crypto_factory.new_signer(identity_private_key)
chain_head = None
if with_genesis:
self.genesis_block = self.generate_genesis_block()
chain_head = self.genesis_block
self.block_manager.put([chain_head.block])
self.block_manager.persist(
chain_head.block.header_signature,
"commit_store")
self.block_publisher = BlockPublisher(
block_manager=self.block_manager,
transaction_executor=MockTransactionExecutor(),
transaction_committed=self.block_store.has_transaction,
batch_committed=self.block_store.has_batch,
state_view_factory=self.state_view_factory,
block_sender=self.block_sender,
batch_sender=self.block_sender,
chain_head=chain_head.block,
identity_signer=self.identity_signer,
data_dir=None,
config_dir=None,
permission_verifier=MockPermissionVerifier(),
batch_observers=[])
示例5: compute_state_hashes_wo_scheduler
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def compute_state_hashes_wo_scheduler(self, base_dir):
"""Creates a state hash from the state updates from each txn in a
valid batch.
Returns state_hashes (list of str): The merkle roots from state
changes in 1 or more blocks in the yaml file.
"""
database = NativeLmdbDatabase(
os.path.join(base_dir, 'compute_state_hashes_wo_scheduler.lmdb'),
indexes=MerkleDatabase.create_index_configuration(),
_size=10 * 1024 * 1024)
tree = MerkleDatabase(database=database)
state_hashes = []
updates = {}
for batch in self._batches:
b_id = batch.header_signature
result = self._batch_results[b_id]
if result.is_valid:
for txn in batch.transactions:
txn_id = txn.header_signature
_, address_values, deletes = self._txn_execution[txn_id]
batch_updates = {}
for pair in address_values:
batch_updates.update({a: pair[a] for a in pair.keys()})
# since this is entirely serial, any overwrite
# of an address is expected and desirable.
updates.update(batch_updates)
for address in deletes:
if address in updates:
del updates[address]
# This handles yaml files that have state roots in them
if result.state_hash is not None:
s_h = tree.update(set_items=updates, virtual=False)
tree.set_merkle_root(merkle_root=s_h)
state_hashes.append(s_h)
if not state_hashes:
state_hashes.append(tree.update(set_items=updates))
return state_hashes
示例6: get_databases
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def get_databases(bind_network, data_dir):
# Get the global state database to operate on
global_state_db_filename = os.path.join(
data_dir, 'merkle-{}.lmdb'.format(bind_network[-2:]))
LOGGER.debug(
'verifying state in %s', global_state_db_filename)
global_state_db = NativeLmdbDatabase(
global_state_db_filename,
indexes=MerkleDatabase.create_index_configuration())
# Get the blockstore
block_db_filename = os.path.join(
data_dir, 'block-{}.lmdb'.format(bind_network[-2:]))
LOGGER.debug('block store file is %s', block_db_filename)
block_db = NativeLmdbDatabase(
block_db_filename,
indexes=BlockStore.create_index_configuration())
blockstore = BlockStore(block_db)
return global_state_db, blockstore
示例7: make_db_and_store
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def make_db_and_store(base_dir, size=3):
"""
Creates and returns three related objects for testing:
* database - dict database with evolving state
* store - blocks with root hashes corresponding to that state
* roots - list of root hashes used in order
With defaults, the values at the three roots look like this:
* 0 - {'000...1': b'1'}
* 1 - {'000...1': b'2', '000...2': b'4'}
* 2 - {'000...1': b'3', '000...2': b'5', '000...3': b'7'}
* 3 - {'000...1': b'4', '000...2': b'6',
'000...3': b'8', '000...4': b'10'}
"""
database = NativeLmdbDatabase(
os.path.join(base_dir, 'client_handlers_mock_db.lmdb'),
indexes=MerkleDatabase.create_index_configuration(),
_size=10 * 1024 * 1024)
store = MockBlockStore(size=0)
roots = []
merkle = MerkleDatabase(database)
data = {}
# Create all the keys that will be used. Keys are zero-padded hex strings
# starting with '1'.
keys = [format(i, 'x').zfill(70) for i in range(1, size + 1)]
for i in range(1, size + 1):
# Construct the state for this root
data = {}
for key_idx in range(i):
key = keys[key_idx]
# Calculate unique values based on the key and root
val = i + (2 * key_idx)
data[key] = str(val).encode()
root = merkle.update(data, virtual=False)
roots.append(root)
store.add_block(str(i), root)
return database, store, roots
示例8: __init__
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import create_index_configuration [as 别名]
def __init__(self,
bind_network,
bind_component,
bind_consensus,
endpoint,
peering,
seeds_list,
peer_list,
data_dir,
config_dir,
identity_signer,
scheduler_type,
permissions,
minimum_peer_connectivity,
maximum_peer_connectivity,
state_pruning_block_depth,
fork_cache_keep_time,
network_public_key=None,
network_private_key=None,
roles=None,
component_thread_pool_workers=10,
network_thread_pool_workers=10,
signature_thread_pool_workers=3):
"""Constructs a validator instance.
Args:
bind_network (str): the network endpoint
bind_component (str): the component endpoint
endpoint (str): the zmq-style URI of this validator's
publically reachable endpoint
peering (str): The type of peering approach. Either 'static'
or 'dynamic'. In 'static' mode, no attempted topology
buildout occurs -- the validator only attempts to initiate
peering connections with endpoints specified in the
peer_list. In 'dynamic' mode, the validator will first
attempt to initiate peering connections with endpoints
specified in the peer_list and then attempt to do a
topology buildout starting with peer lists obtained from
endpoints in the seeds_list. In either mode, the validator
will accept incoming peer requests up to max_peers.
seeds_list (list of str): a list of addresses to connect
to in order to perform the initial topology buildout
peer_list (list of str): a list of peer addresses
data_dir (str): path to the data directory
config_dir (str): path to the config directory
identity_signer (str): cryptographic signer the validator uses for
signing
component_thread_pool_workers (int): number of workers in the
component thread pool; defaults to 10.
network_thread_pool_workers (int): number of workers in the network
thread pool; defaults to 10.
signature_thread_pool_workers (int): number of workers in the
signature thread pool; defaults to 3.
"""
# -- Setup Global State Database and Factory -- #
global_state_db_filename = os.path.join(
data_dir, 'merkle-{}.lmdb'.format(bind_network[-2:]))
LOGGER.debug(
'global state database file is %s', global_state_db_filename)
global_state_db = NativeLmdbDatabase(
global_state_db_filename,
indexes=MerkleDatabase.create_index_configuration())
state_view_factory = StateViewFactory(global_state_db)
native_state_view_factory = NativeStateViewFactory(global_state_db)
# -- Setup Receipt Store -- #
receipt_db_filename = os.path.join(
data_dir, 'txn_receipts-{}.lmdb'.format(bind_network[-2:]))
LOGGER.debug('txn receipt store file is %s', receipt_db_filename)
receipt_db = LMDBNoLockDatabase(receipt_db_filename, 'c')
receipt_store = TransactionReceiptStore(receipt_db)
# -- Setup Block Store -- #
block_db_filename = os.path.join(
data_dir, 'block-{}.lmdb'.format(bind_network[-2:]))
LOGGER.debug('block store file is %s', block_db_filename)
block_db = NativeLmdbDatabase(
block_db_filename,
indexes=BlockStore.create_index_configuration())
block_store = BlockStore(block_db)
# The cache keep time for the journal's block cache must be greater
# than the cache keep time used by the completer.
base_keep_time = 1200
block_manager = BlockManager()
block_manager.add_commit_store(block_store)
block_status_store = BlockValidationResultStore()
# -- Setup Thread Pools -- #
component_thread_pool = InstrumentedThreadPoolExecutor(
max_workers=component_thread_pool_workers,
name='Component')
network_thread_pool = InstrumentedThreadPoolExecutor(
max_workers=network_thread_pool_workers,
name='Network')
client_thread_pool = InstrumentedThreadPoolExecutor(
max_workers=5,
name='Client')
sig_pool = InstrumentedThreadPoolExecutor(
#.........这里部分代码省略.........