Skip to content

Commit b45bdd0

Browse files
committed
feat: add envelope table
1 parent 44b938a commit b45bdd0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

beacon_chain/beacon_chain_db.nim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ type
121121

122122
stateRoots: KvStoreRef # (Slot, BlockRoot) -> StateRoot
123123

124+
envelopes: KvStoreRef # (BlockRoot -> SignedExecutionPayloadEnvelope)
125+
124126
statesNoVal: array[ConsensusFork, KvStoreRef] # StateRoot -> ForkBeaconStateNoImmutableValidators
125127

126128
stateDiffs: KvStoreRef ##\
@@ -604,6 +606,10 @@ proc new*(T: type BeaconChainDB,
604606
if cfg.FULU_FORK_EPOCH != FAR_FUTURE_EPOCH:
605607
columns = kvStore db.openKvStore("fulu_columns").expectDb()
606608

609+
var envelopes: KvStoreRef
610+
if cfg.GLOAS_FORK_EPOCH != FAR_FUTURE_EPOCH:
611+
envelopes = kvStore db.openKvStore("gloas_envelopes").expectDb()
612+
607613
let quarantine = db.initQuarantineDB().expectDb()
608614

609615
# Versions prior to 1.4.0 (altair) stored validators in `immutable_validators`
@@ -642,6 +648,7 @@ proc new*(T: type BeaconChainDB,
642648
blocks: blocks,
643649
blobs: blobs,
644650
columns: columns,
651+
envelopes: envelopes,
645652
stateRoots: stateRoots,
646653
statesNoVal: statesNoVal,
647654
stateDiffs: stateDiffs,
@@ -866,6 +873,14 @@ proc delDataColumnSidecar*(
866873
root: Eth2Digest, index: ColumnIndex): bool =
867874
db.columns.del(columnkey(root, index)).expectDb()
868875

876+
proc putExecutionPayloadEnvelope*(
877+
db: BeaconChainDB, value: SignedExecutionPayloadEnvelope) =
878+
template key: untyped = value.message.beacon_block_root
879+
db.envelopes.putSZSSZ(key.data, value)
880+
881+
proc delExecutionPayloadEnvelope*(db: BeaconChainDB, root: Eth2Digest): bool =
882+
db.envelopes.del(root.data).expectDb()
883+
869884
proc updateImmutableValidators*(
870885
db: BeaconChainDB, validators: openArray[Validator]) =
871886
# Must be called before storing a state that references the new validators
@@ -1078,6 +1093,13 @@ proc getDataColumnSidecar*(db: BeaconChainDB, root: Eth2Digest, index: ColumnInd
10781093
return false
10791094
db.columns.getSZSSZ(columnkey(root, index), value) == GetResult.found
10801095

1096+
proc getExecutionPayloadEnvelope*(
1097+
db: BeaconChainDB, root: Eth2Digest,
1098+
value: var TrustedSignedExecutionPayloadEnvelope): bool =
1099+
if db.envelopes == nil:
1100+
return false
1101+
db.envelopes.getSZSSZ(root.data, value) == GetResult.found
1102+
10811103
proc getBlockSZ*[X: ForkyTrustedSignedBeaconBlock](
10821104
db: BeaconChainDB, key: Eth2Digest,
10831105
data: var seq[byte], T: typedesc[X]): bool =

beacon_chain/spec/datatypes/gloas.nim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,24 @@ type
9595
blob_kzg_commitments*: KzgCommitments
9696
state_root*: Eth2Digest
9797

98+
TrustedExecutionPayloadEnvelope* = object
99+
payload*: deneb.ExecutionPayload
100+
execution_requests*: ExecutionRequests
101+
builder_index*: uint64
102+
beacon_block_root*: Eth2Digest
103+
slot*: Slot
104+
blob_kzg_commitments*: KzgCommitments
105+
state_root*: Eth2Digest
106+
98107
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.6/specs/gloas/beacon-chain.md#signedexecutionpayloadenvelope
99108
SignedExecutionPayloadEnvelope* = object
100109
message*: ExecutionPayloadEnvelope
101110
signature*: ValidatorSig
102111

112+
TrustedSignedExecutionPayloadEnvelope* = object
113+
message*: TrustedExecutionPayloadEnvelope
114+
signature*: ValidatorSig
115+
103116
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.6/specs/gloas/beacon-chain.md#payloadattestationdata
104117
PayloadAttestationData* = object
105118
beacon_block_root*: Eth2Digest
@@ -608,11 +621,23 @@ func shortLog*(v: ExecutionPayloadBid): auto =
608621
blob_kzg_commitments_root: shortLog(v.blob_kzg_commitments_root),
609622
)
610623

624+
func shortLog*(v: ExecutionPayloadEnvelope): auto =
625+
(
626+
beacon_block_root: shortLog(v.beacon_block_root),
627+
slot: v.slot,
628+
builder_index: v.builder_index,
629+
state_root: shortLog(v.state_root)
630+
)
631+
611632
template asSigned*(
612633
x: SigVerifiedSignedBeaconBlock |
613634
TrustedSignedBeaconBlock): SignedBeaconBlock =
614635
isomorphicCast[SignedBeaconBlock](x)
615636

637+
template asSigned*(
638+
x: TrustedSignedExecutionPayloadEnvelope): SignedExecutionPayloadEnvelope =
639+
isomorphicCast[SignedExecutionPayloadEnvelope](x)
640+
616641
template asSigVerified*(
617642
x: SignedBeaconBlock |
618643
TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =

0 commit comments

Comments
 (0)