Ejemplo n.º 1
0
    def __init__(self):
        """
        Class to interact with and do basic operations on a data
        structure that stores information about what parts of a merkle
        tree a peer has or does not have. The structure is itself a binary
        tree implemented as nested lists, where a node is a list
        with one or three elements: Either [int nodestate], or
        [int nodestate, [list child1], [list child2]]. Whether the node has
        children can be inferred from the value of nodestate.

        nodestate can have one of four values:

        0 (MISSING): The peer does not have any information about the corresponding
        node in the merkle tree or its descendants. This node will be a leaf
        in the TreeState structure, but not necessarily a leaf in the actual
        merkle tree.

        1 (HASH): The peer has the hash for the corresponding merkle node. The peer
        may or may not have any children's hashes. This tree node will have children.

        2 (ALLHASH): The peer has the hash for the corresponding merkle node, and
        the hashes for all descendants of this node, up to the transaction
        hashes themselves. The peer is not known to have the actual
        transactions.

        3 (ALLTX): The peer has the hash for this node and all descendants, and has
        the transactions themselves for all descendants.

        If nodestate == 1, then the node entry must include children.
        If nodestate != 1, then the node entry must not include children.
        """
        self.state = [TreeState.MISSING]
        self.changes = 0  # the number of nodes added since initialization; used for deciding when to re-send to peers
        self.rwlock = rwlock.ReadWriteLock()
Ejemplo n.º 2
0
 def __init__(self, root):
     if type(root) == long:
         root = util.ser_uint256(root)
     self.valid = [root, [], []]
     self.state = TreeState()
     # A dict for purgatory is a bit of a hack, and should probably be fixed before switching to C++.
     self.purgatory = {}  # key = (level, index); value = [candidate hashes]
     self.peerorigins = {}  # key = hash, value = peer
     self.levels = 0
     self.txcount = 0
     self.runs = 0  # number of runs added; used to help decide when to send a new state to peers
     self.rwlock = rwlock.ReadWriteLock()
Ejemplo n.º 3
0
 def __init__(self):
     self.pods = {}
     self.lock = rwlock.ReadWriteLock()
     self.hp_pods = 0
     self.be_pods = 0