LC constant rename
This commit is contained in:
parent
b9d85a0bd5
commit
159f57f27e
|
@ -255,7 +255,7 @@ proc initLightClientBootstrapForPeriod(
|
|||
forkyBlck.toLightClientHeader(lcDataFork))
|
||||
dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
|
||||
bid.slot, forkyState.data.build_proof(
|
||||
lcDataFork.CURRENT_SYNC_COMMITTEE_GINDEX).get)
|
||||
lcDataFork.current_sync_committee_gindex).get)
|
||||
else: raiseAssert "Unreachable"
|
||||
res
|
||||
|
||||
|
@ -403,10 +403,10 @@ proc initLightClientUpdateForPeriod(
|
|||
attested_header: forkyBlck.toLightClientHeader(lcDataFork),
|
||||
next_sync_committee: forkyState.data.next_sync_committee,
|
||||
next_sync_committee_branch: forkyState.data.build_proof(
|
||||
lcDataFork.NEXT_SYNC_COMMITTEE_GINDEX).get,
|
||||
lcDataFork.next_sync_committee_gindex).get,
|
||||
finality_branch:
|
||||
if finalizedBid.slot != FAR_FUTURE_SLOT:
|
||||
forkyState.data.build_proof(lcDataFork.FINALIZED_ROOT_GINDEX).get
|
||||
forkyState.data.build_proof(lcDataFork.finalized_root_gindex).get
|
||||
else:
|
||||
default(lcDataFork.FinalityBranch)))
|
||||
else: raiseAssert "Unreachable"
|
||||
|
@ -478,16 +478,16 @@ proc cacheLightClientData(
|
|||
bid = blck.toBlockId()
|
||||
cachedData = CachedLightClientData(
|
||||
current_sync_committee_branch: normalize_merkle_branch(
|
||||
state.data.build_proof(lcDataFork.CURRENT_SYNC_COMMITTEE_GINDEX).get,
|
||||
LightClientDataFork.high.CURRENT_SYNC_COMMITTEE_GINDEX),
|
||||
state.data.build_proof(lcDataFork.current_sync_committee_gindex).get,
|
||||
LightClientDataFork.high.current_sync_committee_gindex),
|
||||
next_sync_committee_branch: normalize_merkle_branch(
|
||||
state.data.build_proof(lcDataFork.NEXT_SYNC_COMMITTEE_GINDEX).get,
|
||||
LightClientDataFork.high.NEXT_SYNC_COMMITTEE_GINDEX),
|
||||
state.data.build_proof(lcDataFork.next_sync_committee_gindex).get,
|
||||
LightClientDataFork.high.next_sync_committee_gindex),
|
||||
finalized_slot:
|
||||
state.data.finalized_checkpoint.epoch.start_slot,
|
||||
finality_branch: normalize_merkle_branch(
|
||||
state.data.build_proof(lcDataFork.FINALIZED_ROOT_GINDEX).get,
|
||||
LightClientDataFork.high.FINALIZED_ROOT_GINDEX),
|
||||
state.data.build_proof(lcDataFork.finalized_root_gindex).get,
|
||||
LightClientDataFork.high.finalized_root_gindex),
|
||||
current_period_best_update:
|
||||
current_period_best_update,
|
||||
latest_signature_slot:
|
||||
|
@ -553,7 +553,7 @@ proc assignLightClientData(
|
|||
next_sync_committee.get
|
||||
forkyObject.next_sync_committee_branch = normalize_merkle_branch(
|
||||
attested_data.next_sync_committee_branch,
|
||||
lcDataFork.NEXT_SYNC_COMMITTEE_GINDEX)
|
||||
lcDataFork.next_sync_committee_gindex)
|
||||
else:
|
||||
doAssert next_sync_committee.isNone
|
||||
var finalized_slot = attested_data.finalized_slot
|
||||
|
@ -562,7 +562,7 @@ proc assignLightClientData(
|
|||
if finalized_slot == forkyObject.finalized_header.beacon.slot:
|
||||
forkyObject.finality_branch = normalize_merkle_branch(
|
||||
attested_data.finality_branch,
|
||||
lcDataFork.FINALIZED_ROOT_GINDEX)
|
||||
lcDataFork.finalized_root_gindex)
|
||||
elif finalized_slot < max(dag.tail.slot, dag.backfill.slot):
|
||||
forkyObject.finalized_header.reset()
|
||||
forkyObject.finality_branch.reset()
|
||||
|
@ -582,12 +582,12 @@ proc assignLightClientData(
|
|||
if finalized_slot == forkyObject.finalized_header.beacon.slot:
|
||||
forkyObject.finality_branch = normalize_merkle_branch(
|
||||
attested_data.finality_branch,
|
||||
lcDataFork.FINALIZED_ROOT_GINDEX)
|
||||
lcDataFork.finalized_root_gindex)
|
||||
elif finalized_slot == GENESIS_SLOT:
|
||||
forkyObject.finalized_header.reset()
|
||||
forkyObject.finality_branch = normalize_merkle_branch(
|
||||
attested_data.finality_branch,
|
||||
lcDataFork.FINALIZED_ROOT_GINDEX)
|
||||
lcDataFork.finalized_root_gindex)
|
||||
else:
|
||||
var fin_header = dag.getExistingLightClientHeader(finalized_bid)
|
||||
if fin_header.kind == LightClientDataFork.None:
|
||||
|
@ -599,7 +599,7 @@ proc assignLightClientData(
|
|||
forkyObject.finalized_header = fin_header.forky(lcDataFork)
|
||||
forkyObject.finality_branch = normalize_merkle_branch(
|
||||
attested_data.finality_branch,
|
||||
lcDataFork.FINALIZED_ROOT_GINDEX)
|
||||
lcDataFork.finalized_root_gindex)
|
||||
withForkyObject(obj):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
forkyObject.sync_aggregate = sync_aggregate
|
||||
|
@ -726,7 +726,7 @@ proc createLightClientBootstrap(
|
|||
dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
|
||||
bid.slot, normalize_merkle_branch(
|
||||
dag.getLightClientData(bid).current_sync_committee_branch,
|
||||
lcDataFork.CURRENT_SYNC_COMMITTEE_GINDEX))
|
||||
lcDataFork.current_sync_committee_gindex))
|
||||
else: raiseAssert "Unreachable"
|
||||
ok()
|
||||
|
||||
|
@ -1053,7 +1053,7 @@ proc getLightClientBootstrap(
|
|||
dag.lcDataStore.db.putHeader(header)
|
||||
dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
|
||||
slot, forkyState.data.build_proof(
|
||||
lcDataFork.CURRENT_SYNC_COMMITTEE_GINDEX).get)
|
||||
lcDataFork.current_sync_committee_gindex).get)
|
||||
else: raiseAssert "Unreachable"
|
||||
do: return default(ForkedLightClientBootstrap)
|
||||
|
||||
|
|
|
@ -61,9 +61,12 @@ const
|
|||
# If there are ever more than 32 members in `BeaconState`, indices change!
|
||||
# `FINALIZED_ROOT_GINDEX` is one layer deeper, i.e., `52 * 2 + 1`.
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/ssz/merkle-proofs.md
|
||||
FINALIZED_ROOT_GINDEX* = 105.GeneralizedIndex # finalized_checkpoint > root
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX* = 54.GeneralizedIndex # current_sync_committee
|
||||
NEXT_SYNC_COMMITTEE_GINDEX* = 55.GeneralizedIndex # next_sync_committee
|
||||
# finalized_checkpoint > root
|
||||
FINALIZED_ROOT_GINDEX* = 105.GeneralizedIndex
|
||||
# current_sync_committee
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX* = 54.GeneralizedIndex
|
||||
# next_sync_committee
|
||||
NEXT_SYNC_COMMITTEE_GINDEX* = 55.GeneralizedIndex
|
||||
|
||||
SYNC_SUBCOMMITTEE_SIZE* = SYNC_COMMITTEE_SIZE div SYNC_COMMITTEE_SUBNET_COUNT
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ const
|
|||
# The first member (`randao_reveal`) is 16, subsequent members +1 each.
|
||||
# If there are ever more than 16 members in `BeaconBlockBody`, indices change!
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/ssz/merkle-proofs.md
|
||||
EXECUTION_PAYLOAD_GINDEX* = 25.GeneralizedIndex # execution_payload
|
||||
# execution_payload
|
||||
EXECUTION_PAYLOAD_GINDEX* = 25.GeneralizedIndex
|
||||
|
||||
type
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#executionpayload
|
||||
|
|
|
@ -45,9 +45,12 @@ const
|
|||
# If there are ever more than 64 members in `BeaconState`, indices change!
|
||||
# `FINALIZED_ROOT_GINDEX` is one layer deeper, i.e., `84 * 2 + 1`.
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/ssz/merkle-proofs.md
|
||||
FINALIZED_ROOT_GINDEX* = 169.GeneralizedIndex # finalized_checkpoint > root
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX* = 86.GeneralizedIndex # current_sync_committee
|
||||
NEXT_SYNC_COMMITTEE_GINDEX* = 87.GeneralizedIndex # next_sync_committee
|
||||
# finalized_checkpoint > root
|
||||
FINALIZED_ROOT_GINDEX_ELECTRA* = 169.GeneralizedIndex
|
||||
# current_sync_committee
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA* = 86.GeneralizedIndex
|
||||
# next_sync_committee
|
||||
NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA* = 87.GeneralizedIndex
|
||||
|
||||
type
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/beacon-chain.md#indexedattestation
|
||||
|
@ -161,13 +164,13 @@ type
|
|||
signature*: ValidatorSig
|
||||
|
||||
FinalityBranch* =
|
||||
array[log2trunc(FINALIZED_ROOT_GINDEX), Eth2Digest]
|
||||
array[log2trunc(FINALIZED_ROOT_GINDEX_ELECTRA), Eth2Digest]
|
||||
|
||||
CurrentSyncCommitteeBranch* =
|
||||
array[log2trunc(CURRENT_SYNC_COMMITTEE_GINDEX), Eth2Digest]
|
||||
array[log2trunc(CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA), Eth2Digest]
|
||||
|
||||
NextSyncCommitteeBranch* =
|
||||
array[log2trunc(NEXT_SYNC_COMMITTEE_GINDEX), Eth2Digest]
|
||||
array[log2trunc(NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA), Eth2Digest]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/light-client/sync-protocol.md#modified-lightclientheader
|
||||
LightClientHeader* = object
|
||||
|
@ -773,7 +776,7 @@ func upgrade_lc_bootstrap_to_electra*(
|
|||
header: upgrade_lc_header_to_electra(pre.header),
|
||||
current_sync_committee: pre.current_sync_committee,
|
||||
current_sync_committee_branch: normalize_merkle_branch(
|
||||
pre.current_sync_committee_branch, CURRENT_SYNC_COMMITTEE_GINDEX))
|
||||
pre.current_sync_committee_branch, CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/fork.md#upgrading-light-client-data
|
||||
func upgrade_lc_update_to_electra*(
|
||||
|
@ -782,10 +785,10 @@ func upgrade_lc_update_to_electra*(
|
|||
attested_header: upgrade_lc_header_to_electra(pre.attested_header),
|
||||
next_sync_committee: pre.next_sync_committee,
|
||||
next_sync_committee_branch: normalize_merkle_branch(
|
||||
pre.next_sync_committee_branch, NEXT_SYNC_COMMITTEE_GINDEX),
|
||||
pre.next_sync_committee_branch, NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA),
|
||||
finalized_header: upgrade_lc_header_to_electra(pre.finalized_header),
|
||||
finality_branch: normalize_merkle_branch(
|
||||
pre.finality_branch, FINALIZED_ROOT_GINDEX),
|
||||
pre.finality_branch, FINALIZED_ROOT_GINDEX_ELECTRA),
|
||||
sync_aggregate: pre.sync_aggregate,
|
||||
signature_slot: pre.signature_slot)
|
||||
|
||||
|
@ -796,7 +799,7 @@ func upgrade_lc_finality_update_to_electra*(
|
|||
attested_header: upgrade_lc_header_to_electra(pre.attested_header),
|
||||
finalized_header: upgrade_lc_header_to_electra(pre.finalized_header),
|
||||
finality_branch: normalize_merkle_branch(
|
||||
pre.finality_branch, FINALIZED_ROOT_GINDEX),
|
||||
pre.finality_branch, FINALIZED_ROOT_GINDEX_ELECTRA),
|
||||
sync_aggregate: pre.sync_aggregate,
|
||||
signature_slot: pre.signature_slot)
|
||||
|
||||
|
|
|
@ -223,12 +223,12 @@ template kind*(
|
|||
electra.LightClientStore]): LightClientDataFork =
|
||||
LightClientDataFork.Electra
|
||||
|
||||
template FINALIZED_ROOT_GINDEX*(
|
||||
template finalized_root_gindex*(
|
||||
kind: static LightClientDataFork): GeneralizedIndex =
|
||||
when kind >= LightClientDataFork.Electra:
|
||||
electra.FINALIZED_ROOT_GINDEX
|
||||
FINALIZED_ROOT_GINDEX_ELECTRA
|
||||
elif kind >= LightClientDataFork.Altair:
|
||||
altair.FINALIZED_ROOT_GINDEX
|
||||
FINALIZED_ROOT_GINDEX
|
||||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
|
@ -240,12 +240,12 @@ template FinalityBranch*(kind: static LightClientDataFork): auto =
|
|||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
template CURRENT_SYNC_COMMITTEE_GINDEX*(
|
||||
template current_sync_committee_gindex*(
|
||||
kind: static LightClientDataFork): GeneralizedIndex =
|
||||
when kind >= LightClientDataFork.Electra:
|
||||
electra.CURRENT_SYNC_COMMITTEE_GINDEX
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA
|
||||
elif kind >= LightClientDataFork.Altair:
|
||||
altair.CURRENT_SYNC_COMMITTEE_GINDEX
|
||||
CURRENT_SYNC_COMMITTEE_GINDEX
|
||||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
|
@ -257,12 +257,12 @@ template CurrentSyncCommitteeBranch*(kind: static LightClientDataFork): auto =
|
|||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
template NEXT_SYNC_COMMITTEE_GINDEX*(
|
||||
template next_sync_committee_gindex*(
|
||||
kind: static LightClientDataFork): GeneralizedIndex =
|
||||
when kind >= LightClientDataFork.Electra:
|
||||
electra.NEXT_SYNC_COMMITTEE_GINDEX
|
||||
NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA
|
||||
elif kind >= LightClientDataFork.Altair:
|
||||
altair.NEXT_SYNC_COMMITTEE_GINDEX
|
||||
NEXT_SYNC_COMMITTEE_GINDEX
|
||||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
|
@ -1062,8 +1062,8 @@ func toCapellaLightClientHeader(
|
|||
block_hash: payload.block_hash,
|
||||
transactions_root: hash_tree_root(payload.transactions),
|
||||
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch:
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX).get)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.0/specs/deneb/light-client/full-node.md#modified-block_to_light_client_header
|
||||
func toDenebLightClientHeader(
|
||||
|
@ -1104,8 +1104,8 @@ func toDenebLightClientHeader(
|
|||
block_hash: payload.block_hash,
|
||||
transactions_root: hash_tree_root(payload.transactions),
|
||||
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch:
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX).get)
|
||||
|
||||
func toDenebLightClientHeader(
|
||||
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
||||
|
@ -1132,8 +1132,8 @@ func toDenebLightClientHeader(
|
|||
withdrawals_root: hash_tree_root(payload.withdrawals),
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch:
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX).get)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/full-node.md#modified-block_to_light_client_header
|
||||
func toElectraLightClientHeader(
|
||||
|
@ -1174,8 +1174,9 @@ func toElectraLightClientHeader(
|
|||
block_hash: payload.block_hash,
|
||||
transactions_root: hash_tree_root(payload.transactions),
|
||||
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch: normalize_merkle_branch(
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX).get,
|
||||
EXECUTION_PAYLOAD_GINDEX_ELECTRA))
|
||||
|
||||
func toElectraLightClientHeader(
|
||||
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
||||
|
@ -1202,8 +1203,9 @@ func toElectraLightClientHeader(
|
|||
withdrawals_root: hash_tree_root(payload.withdrawals),
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch: normalize_merkle_branch(
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX).get,
|
||||
EXECUTION_PAYLOAD_GINDEX_ELECTRA))
|
||||
|
||||
func toElectraLightClientHeader(
|
||||
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
||||
|
@ -1234,8 +1236,8 @@ func toElectraLightClientHeader(
|
|||
withdrawal_requests_root: hash_tree_root(payload.withdrawal_requests),
|
||||
consolidation_requests_root:
|
||||
hash_tree_root(payload.consolidation_requests)),
|
||||
execution_branch: blck.message.body.build_proof(
|
||||
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
||||
execution_branch:
|
||||
blck.message.body.build_proof(EXECUTION_PAYLOAD_GINDEX_ELECTRA).get)
|
||||
|
||||
func toLightClientHeader*(
|
||||
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
||||
|
|
|
@ -50,7 +50,7 @@ func initialize_light_client_store*(
|
|||
if not is_valid_normalized_merkle_branch(
|
||||
hash_tree_root(bootstrap.current_sync_committee),
|
||||
bootstrap.current_sync_committee_branch,
|
||||
lcDataFork.CURRENT_SYNC_COMMITTEE_GINDEX,
|
||||
lcDataFork.current_sync_committee_gindex,
|
||||
bootstrap.header.beacon.state_root):
|
||||
return ResultType.err(VerifierError.Invalid)
|
||||
|
||||
|
@ -132,7 +132,7 @@ proc validate_light_client_update*(
|
|||
if not is_valid_normalized_merkle_branch(
|
||||
finalized_root,
|
||||
update.finality_branch,
|
||||
lcDataFork.FINALIZED_ROOT_GINDEX,
|
||||
lcDataFork.finalized_root_gindex,
|
||||
update.attested_header.beacon.state_root):
|
||||
return err(VerifierError.Invalid)
|
||||
|
||||
|
@ -153,7 +153,7 @@ proc validate_light_client_update*(
|
|||
if not is_valid_normalized_merkle_branch(
|
||||
hash_tree_root(update.next_sync_committee),
|
||||
update.next_sync_committee_branch,
|
||||
lcDataFork.NEXT_SYNC_COMMITTEE_GINDEX,
|
||||
lcDataFork.next_sync_committee_gindex,
|
||||
update.attested_header.beacon.state_root):
|
||||
return err(VerifierError.Invalid)
|
||||
|
||||
|
|
|
@ -286,8 +286,8 @@ proc runTest(storeDataFork: static LightClientDataFork) =
|
|||
template next_sync_committee(): auto = state.next_sync_committee
|
||||
let
|
||||
next_sync_committee_branch = normalize_merkle_branch(
|
||||
state.build_proof(altair.NEXT_SYNC_COMMITTEE_GINDEX).get,
|
||||
storeDataFork.NEXT_SYNC_COMMITTEE_GINDEX)
|
||||
state.build_proof(NEXT_SYNC_COMMITTEE_GINDEX).get,
|
||||
storeDataFork.next_sync_committee_gindex)
|
||||
|
||||
# Finality is unchanged
|
||||
finality_header = default(storeDataFork.LightClientHeader)
|
||||
|
@ -359,8 +359,8 @@ proc runTest(storeDataFork: static LightClientDataFork) =
|
|||
state.finalized_checkpoint.root
|
||||
let
|
||||
finality_branch = normalize_merkle_branch(
|
||||
state.build_proof(altair.FINALIZED_ROOT_GINDEX).get,
|
||||
storeDataFork.FINALIZED_ROOT_GINDEX)
|
||||
state.build_proof(FINALIZED_ROOT_GINDEX).get,
|
||||
storeDataFork.finalized_root_gindex)
|
||||
|
||||
update = storeDataFork.LightClientUpdate(
|
||||
attested_header: attested_header,
|
||||
|
|
Loading…
Reference in New Issue