Exemplo n.º 1
0
    def test_verify_unsealing_data(self):
        signup_info = \
            SignupInfo.create_signup_info(
                originator_public_key_hash=self._originator_public_key_hash,
                most_recent_wait_certificate_id=NullIdentifier)
        poet_public_key = \
            SignupInfo.unseal_signup_data(signup_info.sealed_signup_data)

        self.assertEqual(
            signup_info.poet_public_key,
            poet_public_key,
            msg="PoET public key in signup info and sealed data don't match")
Exemplo n.º 2
0
    def test_verify_unsealing_data(self):
        signup_info = \
            SignupInfo.create_signup_info(
                validator_address='1660 Pennsylvania Avenue NW',
                originator_public_key_hash=self._originator_public_key_hash,
                most_recent_wait_certificate_id=NullIdentifier)
        poet_public_key = \
            SignupInfo.unseal_signup_data(
                validator_address='1660 Pennsylvania Avenue NW',
                sealed_signup_data=signup_info.sealed_signup_data)

        self.assertEqual(
            signup_info.poet_public_key,
            poet_public_key,
            msg="PoET public key in signup info and sealed data don't match")
Exemplo n.º 3
0
    def _on_journal_initialization_complete(self, journal):
        """
        Callback journal makes after the journal has completed initialization

        Args:
            journal (Journal): The journal object that has completed
                initialization.

        Returns:
            True
        """
        # 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.  If
        # we don't have sealed signup data, we need to create and register it.
        #
        # Note - this MUST be done AFTER the journal has completed
        # initialization so that there is at least one peer node to which
        # we can send the validator registry transaction to.  Otherwise,
        # we will never, ever be able to be added to the validator registry
        # and, to paraphrase Martha Stewart, that is a bad thing.

        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(
                    validator_address=journal.local_node.signing_address(),
                    sealed_signup_data=sealed_signup_data)

            LOGGER.info(
                'Restore signup info for %s (ID = %s, PoET public key = %s)',
                journal.local_node.Name,
                journal.local_node.Identifier,
                self.poet_public_key)
        else:
            self.register_signup_information(journal)

        return True
Exemplo n.º 4
0
    def _on_journal_initialization_complete(self, journal):
        """
        Callback journal makes after the journal has completed initialization

        Args:
            journal (Journal): The journal object that has completed
                initialization.

        Returns:
            True
        """
        # 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.  If
        # we don't have sealed signup data.  If we don't have sealed signup
        # data, we need to create and register it.
        #
        # Note - this MUST be done AFTER the journal has completed
        # initialization so that there is at least one peer node to which
        # we can send the validator registry transaction to.  Otherwise,
        # we will never, ever be able to be added to the validator registry
        # and, to paraphrase Martha Stewart, that is a bad thing.

        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(
                    validator_address=journal.local_node.signing_address(),
                    sealed_signup_data=sealed_signup_data)

            LOGGER.info(
                'Restore signup info for %s (ID = %s, PoET public key = %s)',
                journal.local_node.Name, journal.local_node.Identifier,
                self.poet_public_key)
        else:
            self.register_signup_information(journal)

        return True
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def test_create_wait_timer(self):
        # Need to create signup information first
        signup_info = \
            SignupInfo.create_signup_info(
                validator_address='1060 W Addison Street',
                originator_public_key_hash=self._originator_public_key_hash,
                most_recent_wait_certificate_id=NullIdentifier)

        stake_in_the_sand = time.time()

        # An empty certificate list should result in a local mean that is
        # the target wait time
        wt = wait_timer.WaitTimer.create_wait_timer(
            validator_address='1060 W Addison Street', certificates=[])

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(wt.duration,
                                wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        wt = wait_timer.WaitTimer.create_wait_timer(
            validator_address='1060 W Addison Street', certificates=tuple())

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(wt.duration,
                                wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        # Ensure that the enclave is set back to initial state
        SignupInfo.poet_enclave = reload(poet_enclave)
        wait_timer.WaitTimer.poet_enclave = SignupInfo.poet_enclave

        # Make sure that trying to create a wait timer before signup
        # information is provided causes an error
        with self.assertRaises(ValueError):
            wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street', certificates=[])

        with self.assertRaises(ValueError):
            wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=tuple())

        # Initialize the enclave with sealed signup data
        SignupInfo.unseal_signup_data(
            validator_address='1660 Pennsylvania Avenue NW',
            sealed_signup_data=signup_info.sealed_signup_data)

        stake_in_the_sand = time.time()

        # An empty certificate list should result in a local mean that is
        # the target wait time
        wt = wait_timer.WaitTimer.create_wait_timer(
            validator_address='1060 W Addison Street', certificates=[])

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(wt.duration,
                                wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        wt = wait_timer.WaitTimer.create_wait_timer(
            validator_address='1600 Pennsylvania Avenue NW',
            certificates=tuple())

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(wt.duration,
                                wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1600 Pennsylvania Avenue NW')
Exemplo n.º 7
0
    def test_create_wait_timer(self):
        # Need to create signup information first
        signup_info = \
            SignupInfo.create_signup_info(
                validator_address='1060 W Addison Street',
                originator_public_key_hash=self._originator_public_key_hash,
                most_recent_wait_certificate_id=NullIdentifier)

        stake_in_the_sand = time.time()

        # An empty certificate list should result in a local mean that is
        # the target wait time
        wt = wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=[])

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(
            wt.duration,
            wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        wt = wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=tuple())

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(
            wt.duration,
            wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        # Ensure that the enclave is set back to initial state
        SignupInfo.poet_enclave = reload(poet_enclave)
        wait_timer.WaitTimer.poet_enclave = SignupInfo.poet_enclave

        # Make sure that trying to create a wait timer before signup
        # information is provided causes an error
        with self.assertRaises(ValueError):
            wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=[])

        with self.assertRaises(ValueError):
            wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=tuple())

        # Initialize the enclave with sealed signup data
        SignupInfo.unseal_signup_data(
            validator_address='1660 Pennsylvania Avenue NW',
            sealed_signup_data=signup_info.sealed_signup_data)

        stake_in_the_sand = time.time()

        # An empty certificate list should result in a local mean that is
        # the target wait time
        wt = wait_timer.WaitTimer.create_wait_timer(
                validator_address='1060 W Addison Street',
                certificates=[])

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(
            wt.duration,
            wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1060 W Addison Street')

        wt = wait_timer.WaitTimer.create_wait_timer(
                validator_address='1600 Pennsylvania Avenue NW',
                certificates=tuple())

        self.assertIsNotNone(wt)
        self.assertEqual(wt.local_mean, wait_timer.WaitTimer.target_wait_time)
        self.assertEqual(wt.previous_certificate_id, NullIdentifier)
        self.assertGreaterEqual(wt.request_time, stake_in_the_sand)
        self.assertLessEqual(wt.request_time, time.time())
        self.assertGreaterEqual(
            wt.duration,
            wait_timer.WaitTimer.minimum_wait_time)
        self.assertEqual(wt.validator_address, '1600 Pennsylvania Avenue NW')