rename sync_{committee_,}aggregate and execute_payload -> notify_new_payload (#3347)
This commit is contained in:
parent
336403d18b
commit
0c814f49ee
|
@ -212,7 +212,7 @@ template validateBeaconBlockBellatrix(
|
||||||
of BeaconBlockFork.Altair:
|
of BeaconBlockFork.Altair:
|
||||||
false
|
false
|
||||||
of BeaconBlockFork.Bellatrix:
|
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
|
# shows how this gets folded into the state each block; checking this
|
||||||
# is equivalent, without ever requiring state replay or any similarly
|
# is equivalent, without ever requiring state replay or any similarly
|
||||||
# expensive computation.
|
# expensive computation.
|
||||||
|
|
|
@ -64,7 +64,7 @@ const
|
||||||
INACTIVITY_SCORE_BIAS* = 4
|
INACTIVITY_SCORE_BIAS* = 4
|
||||||
INACTIVITY_SCORE_RECOVERY_RATE* = 16
|
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
|
# MIN_SYNC_COMMITTEE_PARTICIPANTS defined in presets
|
||||||
UPDATE_TIMEOUT* = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
UPDATE_TIMEOUT* = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ type
|
||||||
|
|
||||||
### Modified/overloaded
|
### 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
|
LightClientUpdate* = object
|
||||||
attested_header*: BeaconBlockHeader ##\
|
attested_header*: BeaconBlockHeader ##\
|
||||||
## The beacon block header that is attested to by the sync committee
|
## The beacon block header that is attested to by the sync committee
|
||||||
|
@ -167,12 +167,12 @@ type
|
||||||
finality_branch*: array[log2trunc(FINALIZED_ROOT_INDEX), Eth2Digest]
|
finality_branch*: array[log2trunc(FINALIZED_ROOT_INDEX), Eth2Digest]
|
||||||
|
|
||||||
# Sync committee aggregate signature
|
# Sync committee aggregate signature
|
||||||
sync_committee_aggregate*: SyncAggregate
|
sync_aggregate*: SyncAggregate
|
||||||
|
|
||||||
fork_version*: Version ##\
|
fork_version*: Version ##\
|
||||||
## Fork version for the aggregate signature
|
## 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
|
LightClientStore* = object
|
||||||
finalized_header*: BeaconBlockHeader ##\
|
finalized_header*: BeaconBlockHeader ##\
|
||||||
## Beacon block header that is finalized
|
## Beacon block header that is finalized
|
||||||
|
|
|
@ -3,7 +3,7 @@ import
|
||||||
datatypes/altair,
|
datatypes/altair,
|
||||||
helpers
|
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 =
|
func get_active_header(update: LightClientUpdate): BeaconBlockHeader =
|
||||||
# The "active header" is the header that the update is trying to convince
|
# 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
|
# us to accept. If a finalized header is present, it's the finalized
|
||||||
|
@ -13,7 +13,7 @@ func get_active_header(update: LightClientUpdate): BeaconBlockHeader =
|
||||||
else:
|
else:
|
||||||
update.attested_header
|
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,
|
proc validate_light_client_update*(store: LightClientStore,
|
||||||
update: LightClientUpdate,
|
update: LightClientUpdate,
|
||||||
current_slot: Slot,
|
current_slot: Slot,
|
||||||
|
@ -60,7 +60,7 @@ proc validate_light_client_update*(store: LightClientStore,
|
||||||
return false
|
return false
|
||||||
unsafeAddr store.next_sync_committee
|
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)
|
let sync_committee_participants_count = countOnes(sync_aggregate.sync_committee_bits)
|
||||||
|
|
||||||
# Verify sync committee has sufficient participants
|
# Verify sync committee has sufficient participants
|
||||||
|
@ -81,7 +81,7 @@ proc validate_light_client_update*(store: LightClientStore,
|
||||||
blsFastAggregateVerify(
|
blsFastAggregateVerify(
|
||||||
participant_pubkeys, signing_root.data, sync_aggregate.sync_committee_signature)
|
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(
|
func apply_light_client_update(
|
||||||
store: var LightClientStore, update: LightClientUpdate) =
|
store: var LightClientStore, update: LightClientUpdate) =
|
||||||
let
|
let
|
||||||
|
@ -93,14 +93,14 @@ func apply_light_client_update(
|
||||||
store.next_sync_committee = update.next_sync_committee
|
store.next_sync_committee = update.next_sync_committee
|
||||||
store.finalized_header = active_header
|
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 =
|
func get_safety_threshold(store: LightClientStore): uint64 =
|
||||||
max(
|
max(
|
||||||
store.previous_max_active_participants,
|
store.previous_max_active_participants,
|
||||||
store.current_max_active_participants
|
store.current_max_active_participants
|
||||||
) div 2
|
) 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,
|
proc process_light_client_update*(store: var LightClientStore,
|
||||||
update: LightClientUpdate,
|
update: LightClientUpdate,
|
||||||
current_slot: Slot,
|
current_slot: Slot,
|
||||||
|
@ -110,14 +110,14 @@ proc process_light_client_update*(store: var LightClientStore,
|
||||||
return false
|
return false
|
||||||
|
|
||||||
let
|
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)
|
sum_sync_committee_bits = countOnes(sync_committee_bits)
|
||||||
|
|
||||||
# Update the best update in case we have to force-update to it if the
|
# Update the best update in case we have to force-update to it if the
|
||||||
# timeout elapses
|
# timeout elapses
|
||||||
if store.best_valid_update.isNone or
|
if store.best_valid_update.isNone or
|
||||||
sum_sync_committee_bits > countOnes(
|
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)
|
store.best_valid_update = some(update)
|
||||||
|
|
||||||
# Track the maximum number of active participants in the committee signatures
|
# Track the maximum number of active participants in the committee signatures
|
||||||
|
|
|
@ -27,7 +27,7 @@ const
|
||||||
TTFB_TIMEOUT* = 5.seconds
|
TTFB_TIMEOUT* = 5.seconds
|
||||||
RESP_TIMEOUT* = 10.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
|
GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
|
||||||
MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
|
MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
|
||||||
|
|
||||||
|
|
|
@ -496,10 +496,10 @@ proc process_sync_aggregate*(
|
||||||
|
|
||||||
ok()
|
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*(
|
proc process_execution_payload*(
|
||||||
state: var bellatrix.BeaconState, payload: ExecutionPayload,
|
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
|
## Verify consistency of the parent hash with respect to the previous
|
||||||
## execution payload header
|
## execution payload header
|
||||||
if is_merge_transition_complete(state):
|
if is_merge_transition_complete(state):
|
||||||
|
@ -516,7 +516,7 @@ proc process_execution_payload*(
|
||||||
return err("process_execution_payload: invalid timestamp")
|
return err("process_execution_payload: invalid timestamp")
|
||||||
|
|
||||||
# Verify the execution payload is valid
|
# 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")
|
return err("process_execution_payload: execution payload invalid")
|
||||||
|
|
||||||
# Cache execution payload header
|
# Cache execution payload header
|
||||||
|
|
|
@ -92,7 +92,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
res
|
res
|
||||||
genesisState = newClone(initGenesisState(cfg = cfg))
|
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":
|
test "test_process_light_client_update_not_timeout":
|
||||||
var forked = assignClone(genesisState[])
|
var forked = assignClone(genesisState[])
|
||||||
template state: untyped {.inject.} = forked[].altairData.data
|
template state: untyped {.inject.} = forked[].altairData.data
|
||||||
|
@ -116,7 +116,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
sync_committee_bits = full_sync_committee_bits
|
sync_committee_bits = full_sync_committee_bits
|
||||||
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
||||||
forked[], committee)
|
forked[], committee)
|
||||||
sync_committee_aggregate = SyncAggregate(
|
sync_aggregate = SyncAggregate(
|
||||||
sync_committee_bits: sync_committee_bits,
|
sync_committee_bits: sync_committee_bits,
|
||||||
sync_committee_signature: sync_committee_signature)
|
sync_committee_signature: sync_committee_signature)
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
next_sync_committee_branch: next_sync_committee_branch,
|
next_sync_committee_branch: next_sync_committee_branch,
|
||||||
finalized_header: finality_header,
|
finalized_header: finality_header,
|
||||||
finality_branch: finality_branch,
|
finality_branch: finality_branch,
|
||||||
sync_committee_aggregate: sync_committee_aggregate,
|
sync_aggregate: sync_aggregate,
|
||||||
fork_version: state.fork.current_version)
|
fork_version: state.fork.current_version)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
@ -149,7 +149,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
store.finalized_header == pre_store_finalized_header
|
store.finalized_header == pre_store_finalized_header
|
||||||
store.best_valid_update.get == update
|
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":
|
test "process_light_client_update_timeout":
|
||||||
var forked = assignClone(genesisState[])
|
var forked = assignClone(genesisState[])
|
||||||
template state: untyped {.inject.} = forked[].altairData.data
|
template state: untyped {.inject.} = forked[].altairData.data
|
||||||
|
@ -182,7 +182,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
sync_committee_bits = full_sync_committee_bits
|
sync_committee_bits = full_sync_committee_bits
|
||||||
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
||||||
forked[], committee, block_root = block_header.hash_tree_root())
|
forked[], committee, block_root = block_header.hash_tree_root())
|
||||||
sync_committee_aggregate = SyncAggregate(
|
sync_aggregate = SyncAggregate(
|
||||||
sync_committee_bits: sync_committee_bits,
|
sync_committee_bits: sync_committee_bits,
|
||||||
sync_committee_signature: sync_committee_signature)
|
sync_committee_signature: sync_committee_signature)
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
next_sync_committee_branch: next_sync_committee_branch,
|
next_sync_committee_branch: next_sync_committee_branch,
|
||||||
finalized_header: finality_header,
|
finalized_header: finality_header,
|
||||||
finality_branch: finality_branch,
|
finality_branch: finality_branch,
|
||||||
sync_committee_aggregate: sync_committee_aggregate,
|
sync_aggregate: sync_aggregate,
|
||||||
fork_version: state.fork.current_version)
|
fork_version: state.fork.current_version)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
@ -215,7 +215,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
store.best_valid_update.get == update
|
store.best_valid_update.get == update
|
||||||
store.finalized_header == pre_store_finalized_header
|
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":
|
test "process_light_client_update_finality_updated":
|
||||||
var forked = assignClone(genesisState[])
|
var forked = assignClone(genesisState[])
|
||||||
template state: untyped {.inject.} = forked[].altairData.data
|
template state: untyped {.inject.} = forked[].altairData.data
|
||||||
|
@ -277,7 +277,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
sync_committee_bits = full_sync_committee_bits
|
sync_committee_bits = full_sync_committee_bits
|
||||||
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
||||||
forked[], committee, block_root = block_header.hash_tree_root())
|
forked[], committee, block_root = block_header.hash_tree_root())
|
||||||
sync_committee_aggregate = SyncAggregate(
|
sync_aggregate = SyncAggregate(
|
||||||
sync_committee_bits: sync_committee_bits,
|
sync_committee_bits: sync_committee_bits,
|
||||||
sync_committee_signature: sync_committee_signature)
|
sync_committee_signature: sync_committee_signature)
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ suite "EF - Altair - Unittests - Sync protocol" & preset():
|
||||||
next_sync_committee_branch: next_sync_committee_branch,
|
next_sync_committee_branch: next_sync_committee_branch,
|
||||||
finalized_header: finalized_block_header,
|
finalized_header: finalized_block_header,
|
||||||
finality_branch: finality_branch,
|
finality_branch: finality_branch,
|
||||||
sync_committee_aggregate: sync_committee_aggregate,
|
sync_aggregate: sync_aggregate,
|
||||||
fork_version: state.fork.current_version)
|
fork_version: state.fork.current_version)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
|
|
@ -43,7 +43,7 @@ func sign_block(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
|
||||||
blck.root,
|
blck.root,
|
||||||
privkey).toValidatorSig()
|
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 =
|
func build_empty_execution_payload(state: bellatrix.BeaconState): ExecutionPayload =
|
||||||
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
|
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
|
||||||
## without any transactions.
|
## without any transactions.
|
||||||
|
|
Loading…
Reference in New Issue