Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename sync_{committee_,}aggregate and execute_payload -> notify_new_payload #3347

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ template validateBeaconBlockBellatrix(
of BeaconBlockFork.Altair:
false
of BeaconBlockFork.Bellatrix:
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#process_execution_payload
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#process_execution_payload
# shows how this gets folded into the state each block; checking this
# is equivalent, without ever requiring state replay or any similarly
# expensive computation.
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/spec/datatypes/altair.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const
INACTIVITY_SCORE_BIAS* = 4
INACTIVITY_SCORE_RECOVERY_RATE* = 16

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#misc
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#misc
# MIN_SYNC_COMMITTEE_PARTICIPANTS defined in presets
UPDATE_TIMEOUT* = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD

Expand Down Expand Up @@ -152,7 +152,7 @@ type

### Modified/overloaded

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#lightclientupdate
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#lightclientupdate
LightClientUpdate* = object
attested_header*: BeaconBlockHeader ##\
## The beacon block header that is attested to by the sync committee
Expand All @@ -167,12 +167,12 @@ type
finality_branch*: array[log2trunc(FINALIZED_ROOT_INDEX), Eth2Digest]

# Sync committee aggregate signature
sync_committee_aggregate*: SyncAggregate
sync_aggregate*: SyncAggregate

fork_version*: Version ##\
## Fork version for the aggregate signature

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#lightclientstore
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#lightclientstore
LightClientStore* = object
finalized_header*: BeaconBlockHeader ##\
## Beacon block header that is finalized
Expand Down
16 changes: 8 additions & 8 deletions beacon_chain/spec/light_client_sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import
datatypes/altair,
helpers

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#get_active_header
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#get_active_header
func get_active_header(update: LightClientUpdate): BeaconBlockHeader =
# The "active header" is the header that the update is trying to convince
# us to accept. If a finalized header is present, it's the finalized
Expand All @@ -13,7 +13,7 @@ func get_active_header(update: LightClientUpdate): BeaconBlockHeader =
else:
update.attested_header

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#validate_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#validate_light_client_update
proc validate_light_client_update*(store: LightClientStore,
update: LightClientUpdate,
current_slot: Slot,
Expand Down Expand Up @@ -60,7 +60,7 @@ proc validate_light_client_update*(store: LightClientStore,
return false
unsafeAddr store.next_sync_committee

template sync_aggregate(): auto = update.sync_committee_aggregate
template sync_aggregate(): auto = update.sync_aggregate
let sync_committee_participants_count = countOnes(sync_aggregate.sync_committee_bits)

# Verify sync committee has sufficient participants
Expand All @@ -81,7 +81,7 @@ proc validate_light_client_update*(store: LightClientStore,
blsFastAggregateVerify(
participant_pubkeys, signing_root.data, sync_aggregate.sync_committee_signature)

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#apply_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#apply_light_client_update
func apply_light_client_update(
store: var LightClientStore, update: LightClientUpdate) =
let
Expand All @@ -93,14 +93,14 @@ func apply_light_client_update(
store.next_sync_committee = update.next_sync_committee
store.finalized_header = active_header

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#get_safety_threshold
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#get_safety_threshold
func get_safety_threshold(store: LightClientStore): uint64 =
max(
store.previous_max_active_participants,
store.current_max_active_participants
) div 2

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#process_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/sync-protocol.md#process_light_client_update
proc process_light_client_update*(store: var LightClientStore,
update: LightClientUpdate,
current_slot: Slot,
Expand All @@ -110,14 +110,14 @@ proc process_light_client_update*(store: var LightClientStore,
return false

let
sync_committee_bits = update.sync_committee_aggregate.sync_committee_bits
sync_committee_bits = update.sync_aggregate.sync_committee_bits
sum_sync_committee_bits = countOnes(sync_committee_bits)

# Update the best update in case we have to force-update to it if the
# timeout elapses
if store.best_valid_update.isNone or
sum_sync_committee_bits > countOnes(
store.best_valid_update.get.sync_committee_aggregate.sync_committee_bits):
store.best_valid_update.get.sync_aggregate.sync_committee_bits):
store.best_valid_update = some(update)

# Track the maximum number of active participants in the committee signatures
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const
TTFB_TIMEOUT* = 5.seconds
RESP_TIMEOUT* = 10.seconds

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/p2p-interface.md#configuration
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/p2p-interface.md#configuration
GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes

Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ proc process_sync_aggregate*(

ok()

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#process_execution_payload
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#process_execution_payload
proc process_execution_payload*(
state: var bellatrix.BeaconState, payload: ExecutionPayload,
execute_payload: ExecutePayload): Result[void, cstring] =
notify_new_payload: ExecutePayload): Result[void, cstring] =
## Verify consistency of the parent hash with respect to the previous
## execution payload header
if is_merge_transition_complete(state):
Expand All @@ -516,7 +516,7 @@ proc process_execution_payload*(
return err("process_execution_payload: invalid timestamp")

# Verify the execution payload is valid
if not execute_payload(payload):
if not notify_new_payload(payload):
return err("process_execution_payload: execution payload invalid")

# Cache execution payload header
Expand Down
18 changes: 9 additions & 9 deletions tests/consensus_spec/altair/test_fixture_sync_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
res
genesisState = newClone(initGenesisState(cfg = cfg))

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L36-L90
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L36-L90
test "test_process_light_client_update_not_timeout":
var forked = assignClone(genesisState[])
template state: untyped {.inject.} = forked[].altairData.data
Expand All @@ -116,7 +116,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
sync_committee_bits = full_sync_committee_bits
sync_committee_signature = compute_aggregate_sync_committee_signature(
forked[], committee)
sync_committee_aggregate = SyncAggregate(
sync_aggregate = SyncAggregate(
sync_committee_bits: sync_committee_bits,
sync_committee_signature: sync_committee_signature)

Expand All @@ -137,7 +137,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
next_sync_committee_branch: next_sync_committee_branch,
finalized_header: finality_header,
finality_branch: finality_branch,
sync_committee_aggregate: sync_committee_aggregate,
sync_aggregate: sync_aggregate,
fork_version: state.fork.current_version)

check:
Expand All @@ -149,7 +149,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
store.finalized_header == pre_store_finalized_header
store.best_valid_update.get == update

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L93-L154
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L93-L154
test "process_light_client_update_timeout":
var forked = assignClone(genesisState[])
template state: untyped {.inject.} = forked[].altairData.data
Expand Down Expand Up @@ -182,7 +182,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
sync_committee_bits = full_sync_committee_bits
sync_committee_signature = compute_aggregate_sync_committee_signature(
forked[], committee, block_root = block_header.hash_tree_root())
sync_committee_aggregate = SyncAggregate(
sync_aggregate = SyncAggregate(
sync_committee_bits: sync_committee_bits,
sync_committee_signature: sync_committee_signature)

Expand All @@ -202,7 +202,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
next_sync_committee_branch: next_sync_committee_branch,
finalized_header: finality_header,
finality_branch: finality_branch,
sync_committee_aggregate: sync_committee_aggregate,
sync_aggregate: sync_aggregate,
fork_version: state.fork.current_version)

check:
Expand All @@ -215,7 +215,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
store.best_valid_update.get == update
store.finalized_header == pre_store_finalized_header

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L157-L224
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L157-L224
test "process_light_client_update_finality_updated":
var forked = assignClone(genesisState[])
template state: untyped {.inject.} = forked[].altairData.data
Expand Down Expand Up @@ -277,7 +277,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
sync_committee_bits = full_sync_committee_bits
sync_committee_signature = compute_aggregate_sync_committee_signature(
forked[], committee, block_root = block_header.hash_tree_root())
sync_committee_aggregate = SyncAggregate(
sync_aggregate = SyncAggregate(
sync_committee_bits: sync_committee_bits,
sync_committee_signature: sync_committee_signature)

Expand All @@ -287,7 +287,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
next_sync_committee_branch: next_sync_committee_branch,
finalized_header: finalized_block_header,
finality_branch: finality_branch,
sync_committee_aggregate: sync_committee_aggregate,
sync_aggregate: sync_aggregate,
fork_version: state.fork.current_version)

check:
Expand Down
2 changes: 1 addition & 1 deletion tests/mocking/mock_blocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func sign_block(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
blck.root,
privkey).toValidatorSig()

# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py#L1-L31
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py#L1-L31
func build_empty_execution_payload(state: bellatrix.BeaconState): ExecutionPayload =
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
## without any transactions.
Expand Down