def initialization_complete(self, journal): """Processes all invocations that arrived while the ledger was being initialized. """ # propagate the maximum blocks to keep journal.maximum_blocks_to_keep = max( journal.maximum_blocks_to_keep, WaitTimer.certificate_sample_length) # initialize stats specifically for the block chain journal journal.JournalStats.add_metric(stats.Value('LocalMeanTime', 0)) journal.JournalStats.add_metric(stats.Value('AggregateLocalMean', 0)) journal.JournalStats.add_metric(stats.Value('PopulationEstimate', 0)) journal.JournalStats.add_metric(stats.Value('ExpectedExpirationTime', 0)) journal.JournalStats.add_metric(stats.Value('Duration', 0)) # initialize the block handlers poet_transaction_block.register_message_handlers(journal) # Load our validator statistics. If they exist, we are going to be # optimistic and assume they are in sync with block chain. If they # don't exist, we are going to walk the block chain and initialize # them. self._validator_statistics = \ journal.local_store.get('validator_statistics') if self._validator_statistics is None: self._validator_statistics = {} # If the journal is restored from local store, we want to know so # that we can build up or stats from the restored blocks journal.on_restored += self._on_journal_restored # We want to know when the journal has completed initialization. This # turns out to be very important - up until that point, we are not # able to send out any transactions (such as validator registry # transactions), which is really important because that will keep us # from ever joining a validator network for the first time. journal.on_initialization_complete += \ self._on_journal_initialization_complete # We want the ability to test a block before it gets claimed so that # we can enforce PoET 1 policies journal.on_block_test += self._on_block_test # We want to know when a block is committed or decommitted so that # we can keep track of validator statistics journal.on_commit_block += self._on_commit_block journal.on_decommit_block += self._on_decommit_block
def initialization_complete(self, journal): """Processes all invocations that arrived while the ledger was being initialized. """ # propagate the maximum blocks to keep journal.maximum_blocks_to_keep = max( journal.maximum_blocks_to_keep, WaitTimer.certificate_sample_length) # initialize stats specifically for the block chain journal journal.JournalStats.add_metric(stats.Value('LocalMeanTime', 0)) journal.JournalStats.add_metric(stats.Value('AggregateLocalMean', 0)) journal.JournalStats.add_metric(stats.Value('PopulationEstimate', 0)) journal.JournalStats.add_metric( stats.Value('ExpectedExpirationTime', 0)) journal.JournalStats.add_metric(stats.Value('Duration', 0)) # initialize the block handlers poet_transaction_block.register_message_handlers(journal) # Load our validator statistics. If they exist, we are going to be # optimistic and assume they are in sync with block chain. If they # don't exist, we are going to walk the block chain and initialize # them. self._validator_statistics = \ journal.local_store.get('validator_statistics') if self._validator_statistics is None: self._validator_statistics = {} # If the journal is restored from local store, we want to know so # that we can build up or stats from the restored blocks journal.on_restored += self._on_journal_restored # We want to know when the journal has completed initialization. This # turns out to be very important - up until that point, we are not # able to send out any transactions (such as validator registry # transactions), which is really important because that will keep us # from ever joining a validator network for the first time. journal.on_initialization_complete += \ self._on_journal_initialization_complete # We want the ability to test a block before it gets claimed so that # we can enforce PoET 1 policies journal.on_block_test += self._on_block_test # We want to know when a block is committed or decommitted so that # we can keep track of validator statistics journal.on_commit_block += self._on_commit_block journal.on_decommit_block += self._on_decommit_block
def initialization_complete(self, journal): """Processes all invocations that arrived while the ledger was being initialized. """ # Before we allow the base journal to do anything that might result # in a wait timer or wait certificate being created, we have to ensure # the PoET enclave has been initialized. This can be done in one of # two ways: # 1. If we have sealed signup data (meaning that we have previously # created signup info), we can request that the enclave unseal it, # in the process restoring the enclave to its previous state. # 2. Create new signup information. signup_info = None sealed_signup_data = journal.local_store.get('sealed_signup_data') if sealed_signup_data is not None: self.poet_public_key = SignupInfo.unseal_signup_data( sealed_signup_data=sealed_signup_data) else: wait_certificate_id = journal.most_recent_committed_block_id public_key_hash = \ hashlib.sha256( pybitcointools.encode_pubkey( journal.local_node.public_key(), 'hex')).hexdigest() signup_info = \ SignupInfo.create_signup_info( originator_public_key_hash=public_key_hash, most_recent_wait_certificate_id=wait_certificate_id) # Save off the sealed signup data journal.local_store.set('sealed_signup_data', signup_info.sealed_signup_data) journal.local_store.sync() self.poet_public_key = signup_info.poet_public_key # propagate the maximum blocks to keep journal.maximum_blocks_to_keep = max( journal.maximum_blocks_to_keep, WaitTimer.certificate_sample_length) # initialize stats specifically for the block chain journal journal.JournalStats.add_metric(stats.Value('LocalMeanTime', 0)) journal.JournalStats.add_metric(stats.Value('AggregateLocalMean', 0)) journal.JournalStats.add_metric(stats.Value('PopulationEstimate', 0)) journal.JournalStats.add_metric( stats.Value('ExpectedExpirationTime', 0)) journal.JournalStats.add_metric(stats.Value('Duration', 0)) # initialize the block handlers poet_transaction_block.register_message_handlers(journal) # If we created signup information, then advertise self to network if signup_info is not None: # Create a validator register transaction and sign it. Wrap # the transaction in a message. Broadcast it to out. transaction = \ val_reg.ValidatorRegistryTransaction.register_validator( journal.local_node.Name, journal.local_node.Identifier, signup_info) transaction.sign_from_node(journal.local_node) message = \ val_reg.ValidatorRegistryTransactionMessage() message.Transaction = transaction LOGGER.info('Advertise PoET 1 validator with name %s', journal.local_node.Name) journal.gossip.broadcast_message(message)