コード例 #1
0
 def all_fork_choices(self):
     blocks = self.get_blocks_from_consensus_messages()
     weighted_blocks = self.get_weighted_blocks()
     genesis_blocks = self.genesis_blocks()
     return {
         shard_ID: fork_choice(genesis_blocks[shard_ID], blocks,
                               weighted_blocks)
         for shard_ID in genesis_blocks
     }
コード例 #2
0
    def make_fork_choice(self, shard_ID, genesis_blocks):
        # the blocks in the view are the genesis blocks and blocks from consensus messages
        blocks = self.get_blocks_from_consensus_messages()
        weighted_blocks = self.get_weighted_blocks()

        next_fork_choice = fork_choice(shard_ID, genesis_blocks[shard_ID],
                                       blocks, weighted_blocks, genesis_blocks)

        assert next_fork_choice.shard_ID == shard_ID, "expected fork choice to be on requested shard"

        return next_fork_choice
コード例 #3
0
    def fork_choice(self, shard_ID):
        # the blocks in the view are the genesis blocks and blocks from consensus messages
        blocks = self.get_blocks_from_consensus_messages()
        weighted_blocks = self.get_weighted_blocks()
        genesis_blocks = self.genesis_blocks()

        ret = {}
        ret[shard_ID] = fork_choice(genesis_blocks[shard_ID], blocks, weighted_blocks)

        # get parent fork choice
        parent_ID = ret[shard_ID].parent_ID
        if parent_ID is not None:
            ret[parent_ID] = fork_choice(genesis_blocks[parent_ID], blocks, weighted_blocks)

        # get children fork choices
        children = sharded_fork_choice(genesis_blocks, blocks, weighted_blocks, ret[shard_ID], ret[shard_ID].child_IDs)
        for c in children:
            ret[c] = children[c]

        return ret
コード例 #4
0
    def make_fork_choice(self, shard_ID):
        # the blocks in the view are the genesis blocks and blocks from consensus messages
        blocks = self.get_blocks_from_consensus_messages()
        weighted_blocks = self.get_weighted_blocks()
        genesis_blocks = self.genesis_blocks()

        # The root shard doesn't have filtered blocks
        for g in genesis_blocks.values():
            if g.parent_ID is None:
                root_choice = fork_choice(genesis_blocks[g.shard_ID], blocks,
                                          weighted_blocks)
                break

        # If we're just asking for the root shard, then we're done
        if root_choice.shard_ID == shard_ID:
            return root_choice

        # Getting sequence of shards from shard_ID to root shard
        backwards_shard_sequence = []
        this_ID = shard_ID
        while (this_ID != root_choice.shard_ID):
            backwards_shard_sequence.append(this_ID)
            this_ID = genesis_blocks[this_ID].parent_ID

        shard_sequence = []
        for i in range(len(backwards_shard_sequence)):
            shard_sequence.append(
                backwards_shard_sequence[len(backwards_shard_sequence) - 1 -
                                         i])

        for i in range(len(backwards_shard_sequence) - 1):
            assert shard_sequence[i] == genesis_blocks[shard_sequence[
                i + 1]].parent_ID, "expected chain of parents!"

        # FORK CHOICE HAPPENS HERE:
        next_fork_choice = root_choice
        for i in range(len(backwards_shard_sequence)):
            next_fork_choice = sharded_fork_choice(shard_sequence[i],
                                                   genesis_blocks, blocks,
                                                   weighted_blocks,
                                                   next_fork_choice)

        print("shard_sequence", shard_sequence)
        print("shard_ID", next_fork_choice.shard_ID, shard_ID)
        assert next_fork_choice.shard_ID == shard_ID, "expected fork choice to be on requested shard"

        return next_fork_choice