Example #1
0
    mempools[parent_shard].insert(position, {'opcode': 'switch', 'child_to_become_parent': child_to_become_parent, 'child_to_move_down': child_to_move_down})

# Setup
GENESIS_BLOCKS = {}
GENESIS_MESSAGES = []
for ID in SHARD_IDS:
    GENESIS_BLOCKS[ID] = Block(ID, sources={}) # temporarily set sources to {}, since genesis blocks are not known yet
    GENESIS_MESSAGES.append(ConsensusMessage(GENESIS_BLOCKS[ID], 0, []))  # The watcher is the sender of the genesis blocks

for ID in SHARD_IDS:
    GENESIS_BLOCKS[ID].sources = {ID : GENESIS_BLOCKS[ID] for ID in SHARD_IDS}
    GENESIS_BLOCKS[ID].parent_ID = None
    for _ in SHARD_IDS:
        if ID in INITIAL_TOPOLOGY[_]:
            GENESIS_BLOCKS[ID].parent_ID = _
    GENESIS_BLOCKS[ID].child_IDs = INITIAL_TOPOLOGY[ID]

for ID in SHARD_IDS:
    GENESIS_BLOCKS[ID].compute_routing_table()

validators = {}
for name in VALIDATOR_NAMES:
    validators[name] = Validator(name)

#  Watcher lives at validator name 0 and receives all the messages
watcher = validators[0]

for v in VALIDATOR_NAMES:
    for genesis_message in GENESIS_MESSAGES:
        validators[v].receive_consensus_message(genesis_message)
Example #2
0
GENESIS_BLOCKS = {}
GENESIS_MESSAGES = []
for ID in SHARD_IDS:
    GENESIS_BLOCKS[ID] = Block(
        ID, sources={}
    )  # temporarily set sources to {}, since genesis blocks are not known yet
    GENESIS_MESSAGES.append(ConsensusMessage(
        GENESIS_BLOCKS[ID], 0,
        []))  # The watcher is the sender of the genesis blocks

for ID in SHARD_IDS:
    GENESIS_BLOCKS[ID].sources = {ID: GENESIS_BLOCKS[ID] for ID in SHARD_IDS}
    # TODO: this is where the tree structure is hardcoded. somewhere better?
    if ID == 0:
        GENESIS_BLOCKS[ID].parent_ID = None
        GENESIS_BLOCKS[ID].child_IDs = [1, 2]
    elif ID == 1:
        GENESIS_BLOCKS[ID].parent_ID = 0
        GENESIS_BLOCKS[ID].child_IDs = [3, 4]
    elif ID == 2:
        GENESIS_BLOCKS[ID].parent_ID = 0
        GENESIS_BLOCKS[ID].child_IDs = [5]
    elif ID in [3, 4]:
        GENESIS_BLOCKS[ID].parent_ID = 1
        GENESIS_BLOCKS[ID].child_IDs = []
    elif ID == 5:
        GENESIS_BLOCKS[ID].parent_ID = 2
        GENESIS_BLOCKS[ID].child_IDs = []
    else:
        assert False