Created
July 11, 2018 18:02
-
-
Save tommling/71f80a0eba29349fd26f3121ee5fb17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2017 Intel Corporation | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# ------------------------------------------------------------------------------ | |
# pylint: disable=too-many-lines | |
import math | |
import logging | |
import collections | |
import itertools | |
import threading | |
import cbor | |
from sawtooth_poet.poet_consensus import utils | |
from sawtooth_poet.poet_consensus.poet_settings_view import PoetSettingsView | |
from sawtooth_poet.poet_consensus.signup_info import SignupInfo | |
from sawtooth_poet.poet_consensus.stake_view import StakeView | |
from sawtooth_poet_common.validator_registry_view.validator_registry_view \ | |
import ValidatorRegistryView | |
LOGGER = logging.getLogger(__name__) | |
ValidatorState = \ | |
collections.namedtuple( | |
'ValidatorState', | |
['key_block_claim_count', | |
'poet_public_key', | |
'total_block_claim_count' | |
]) | |
""" Instead of creating a full-fledged class, let's use a named tuple for | |
the validator state. The validator state represents the state for a single | |
validator at a point in time. A validator state object contains: | |
key_block_claim_count (int): The number of blocks that the validator has | |
claimed using the current PoET public key | |
poet_public_key (str): The current PoET public key for the validator | |
total_block_claim_count (int): The total number of the blocks that the | |
validator has claimed | |
""" | |
class ConsensusState(object): | |
"""Represents the consensus state at a particular point in time (i.e., | |
when the block that this consensus state corresponds to was committed to | |
the block chain). | |
Attributes: | |
aggregate_local_mean (float): The sum of the local means for the PoET | |
blocks since the last non-PoET block | |
total_block_claim_count (int): The number of blocks that have been | |
claimed by all validators | |
""" | |
# MINIMUM_WAIT_TIME must match the constants in the enclaves | |
MINIMUM_WAIT_TIME = 1.0 | |
_BlockInfo = \ | |
collections.namedtuple( | |
'_BlockInfo', | |
['wait_certificate', 'validator_info', 'poet_settings_view', 'stake_view']) | |
""" Instead of creating a full-fledged class, let's use a named tuple for | |
the block info. The block info represents the information we need to | |
create consensus state. A block info object contains: | |
wait_certificate (WaitCertificate): The PoET wait certificate object for | |
the block | |
validator_info (ValidatorInfo): The validator registry information for the | |
validator that claimed the block | |
poet_settings_view (PoetSettingsView): The PoET settings view associated | |
with the block | |
""" | |
_PopulationSample = \ | |
collections.namedtuple( | |
'_PopulationSample', ['duration', 'local_mean']) | |
""" Instead of creating a full-fledged class, let's use a named tuple for | |
the population sample. The population sample represents the information | |
we need to create the population estimate, which in turn is used to compute | |
the local mean. A population sample object contains: | |
duration (float): The duration from a wait certificate/timer | |
local_mean (float): The local mean from a wait certificate/timer | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment