diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index cc1e9b0a2..7db452718 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -229,7 +229,7 @@ def process_delta(state: BeaconState, shard_state: ShardState, index: ValidatorI ### `get_genesis_shard_state` ```python -def get_genesis_shard_state(state: BeaconState, shard: Shard) -> ShardState: +def get_genesis_shard_state(shard: Shard) -> ShardState: return ShardState( shard=shard, slot=ShardSlot(SHARD_GENESIS_EPOCH * SHARD_SLOTS_PER_EPOCH), @@ -295,8 +295,8 @@ def process_shard_slot(state: BeaconState, shard_state: ShardState) -> None: ```python def process_shard_period(state: BeaconState, shard_state: ShardState) -> None: # Rotate rewards and fees - state.older_committee_deltas = state.newer_committee_deltas - state.newer_committee_deltas = [GweiDelta(0) for _ in range(MAX_PERIOD_COMMITTEE_SIZE)] + shard_state.older_committee_deltas = shard_state.newer_committee_deltas + shard_state.newer_committee_deltas = [GweiDelta(0) for _ in range(MAX_PERIOD_COMMITTEE_SIZE)] ``` ### Block processing @@ -313,16 +313,16 @@ def process_shard_block(state: BeaconState, shard_state: ShardState, block: Shar ```python def process_shard_block_header(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None: # Verify the shard number - assert block.shard == state.shard + assert block.shard == shard_state.shard # Verify the slot number - assert block.slot == state.slot + assert block.slot == shard_state.slot # Verify the beacon chain root - parent_epoch = compute_epoch_of_shard_slot(state.latest_block_header.slot) + parent_epoch = compute_epoch_of_shard_slot(shard_state.latest_block_header.slot) assert block.beacon_block_root == get_block_root(state, parent_epoch) # Verify the parent root - assert block.parent_root == hash_tree_root(state.latest_block_header) + assert block.parent_root == hash_tree_root(shard_state.latest_block_header) # Save current block as the new latest block - state.latest_block_header = ShardBlockHeader( + shard_state.latest_block_header = ShardBlockHeader( shard=block.shard, slot=block.slot, beacon_block_root=block.beacon_block_root, @@ -335,10 +335,10 @@ def process_shard_block_header(state: BeaconState, shard_state: ShardState, bloc # `signature` is zeroed ) # Verify the sum of the block sizes since genesis - state.block_size_sum += SHARD_HEADER_SIZE + len(block.body) + shard_state.block_size_sum += SHARD_HEADER_SIZE + len(block.body) assert block.block_size_sum == state.block_size_sum # Verify proposer signature - proposer_index = get_shard_proposer_index(state, state.shard, block.slot) + proposer_index = get_shard_proposer_index(state, shard_state.shard, block.slot) pubkey = state.validators[proposer_index].pubkey domain = get_domain(state, DOMAIN_SHARD_PROPOSER, compute_epoch_of_shard_slot(block.slot)) assert bls_verify(pubkey, hash_tree_root(block.block), block.proposer, domain) @@ -350,7 +350,7 @@ def process_shard_block_header(state: BeaconState, shard_state: ShardState, bloc def process_shard_attestations(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None: pubkeys = [] attestation_count = 0 - shard_committee = get_shard_committee(state, state.shard, block.slot) + shard_committee = get_shard_committee(state, shard_state.shard, block.slot) for i, validator_index in enumerate(shard_committee): if block.aggregation_bits[i]: pubkeys.append(state.validators[validator_index].pubkey) @@ -364,7 +364,7 @@ def process_shard_attestations(state: BeaconState, shard_state: ShardState, bloc message = hash_tree_root(ShardCheckpoint(shard_state.slot, block.parent_root)) assert bls_verify(bls_aggregate_pubkeys(pubkeys), message, block.attestations, domain) # Proposer micro-reward - proposer_index = get_shard_proposer_index(state, state.shard, block.slot) + proposer_index = get_shard_proposer_index(state, shard_state.shard, block.slot) reward = attestation_count * get_base_reward(state, proposer_index) // PROPOSER_REWARD_QUOTIENT process_delta(state, shard_state, proposer_index, reward) ``` @@ -376,20 +376,20 @@ def process_shard_block_body(state: BeaconState, shard_state: ShardState, block: # Verify block body size is a multiple of the header size assert len(block.body) % SHARD_HEADER_SIZE == 0 # Apply proposer block body fee - proposer_index = get_shard_proposer_index(state, state.shard, block.slot) + proposer_index = get_shard_proposer_index(state, shard_state.shard, block.slot) block_body_fee = state.block_body_price * len(block.body) // MAX_SHARD_BLOCK_SIZE process_delta(state, shard_state, proposer_index, -block_body_fee) # Burn process_delta(state, shard_state, proposer_index, block_body_fee // PROPOSER_REWARD_QUOTIENT) # Reward # Calculate new block body price block_size = SHARD_HEADER_SIZE + len(block.body) QUOTIENT = MAX_SHARD_BLOCK_SIZE * BLOCK_BODY_PRICE_QUOTIENT - price_delta = GweiDelta(state.block_body_price * (block_size - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT) + price_delta = GweiDelta(shard_state.block_body_price * (block_size - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT) if price_delta > 0: # The maximum block body price caps the amount burnt on fees within a period MAX_BLOCK_BODY_PRICE = MAX_EFFECTIVE_BALANCE // EPOCHS_PER_SHARD_PERIOD // SHARD_SLOTS_PER_EPOCH - state.block_body_price = Gwei(min(MAX_BLOCK_BODY_PRICE, state.block_body_price + price_delta)) + shard_state.block_body_price = Gwei(min(MAX_BLOCK_BODY_PRICE, shard_state.block_body_price + price_delta)) else: - state.block_body_price = Gwei(max(MIN_BLOCK_BODY_PRICE, state.block_body_price + price_delta)) + shard_state.block_body_price = Gwei(max(MIN_BLOCK_BODY_PRICE, shard_state.block_body_price + price_delta)) ``` ## Shard fork choice rule