Skip to content
Merged
Show file tree
Hide file tree
Changes from 236 commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
5aab014
rampage
rezzmah Mar 11, 2025
fca383b
cleanup inprogress
rezzmah Mar 11, 2025
3172a64
Rename
rezzmah Mar 11, 2025
8f246b9
Deleted unused pruner
rezzmah Mar 11, 2025
6162470
fix gomock issues
rezzmah Mar 11, 2025
831580d
more cleanup
rezzmah Mar 11, 2025
6927ffa
cleanup
rezzmah Mar 11, 2025
3ace3a8
Cleanup
rezzmah Mar 11, 2025
0349136
cleanup
rezzmah Mar 11, 2025
340367c
cleanup
rezzmah Mar 11, 2025
90c0edd
donezo
rezzmah Mar 11, 2025
da94127
Update interfaces.go
rezzmah Mar 12, 2025
6d34318
Update interfaces.go
rezzmah Mar 12, 2025
f63ad68
Update chain_spec.mock.go
rezzmah Mar 12, 2025
4cc4276
x
rezzmah Mar 10, 2025
f91925c
ssz
rezzmah Mar 11, 2025
b3b18a0
Update body_test.go
rezzmah Mar 11, 2025
0c0cac4
Update body.go
rezzmah Mar 11, 2025
a7f31ca
Update execution_requests.go
rezzmah Mar 11, 2025
45a64aa
Update body.go
rezzmah Mar 11, 2025
14f68e4
Fixed tests
rezzmah Mar 11, 2025
e19855b
Update execution_requests.go
rezzmah Mar 11, 2025
e250124
Update execution_requests.go
rezzmah Mar 11, 2025
bef0d9b
Small test refactor
rezzmah Mar 11, 2025
739c508
Update body.go
rezzmah Mar 12, 2025
06a28d4
fix tests and change unmarshalling
rezzmah Mar 12, 2025
4a7230f
make executionRequests private
rezzmah Mar 12, 2025
432fe90
cleanup
rezzmah Mar 12, 2025
7aaa22e
making stuff private
rezzmah Mar 12, 2025
8a5e5a1
fix
rezzmah Mar 12, 2025
3bab234
Update attributes.go
rezzmah Mar 12, 2025
800e881
Update attributes.go
rezzmah Mar 12, 2025
e82b9f8
Update payload.go
rezzmah Mar 12, 2025
c2861a9
chore(types): remove unused chain spec from da/blob (#2595)
calbera Mar 12, 2025
9f184e3
remove pectra types for now
rezzmah Mar 12, 2025
486203d
fixes
rezzmah Mar 12, 2025
9ed548d
remove unused
rezzmah Mar 12, 2025
fa9404f
Delete temp-test-unit-cover.txt
rezzmah Mar 12, 2025
1071ade
Removed hardcoded deneb from types
rezzmah Mar 12, 2025
fedbc6f
Merge branch 'cleanup-excessive-types' into pectra-types-rez-poc
rezzmah Mar 12, 2025
f28032b
chore(types): remove unused chain spec from da/store (#2596)
Mar 12, 2025
cadf2fa
Add RunForAll
rezzmah Mar 12, 2025
2d61ed3
Merge branch 'cleanup-excessive-types' into pectra-types-rez-poc
rezzmah Mar 12, 2025
6eaf397
clean
rezzmah Mar 12, 2025
959e628
Merge branch 'main' into pectra-types-rez-poc
rezzmah Mar 12, 2025
b3190d9
Update interfaces.go
rezzmah Mar 12, 2025
db13791
Update block_test.go
rezzmah Mar 12, 2025
9a50a51
Update transformers.go
rezzmah Mar 12, 2025
47a09f8
Fix quick test
rezzmah Mar 12, 2025
31ed961
fails
rezzmah Mar 13, 2025
5f89e80
Update withdrawals_test.go
rezzmah Mar 13, 2025
37edbb6
fixed
rezzmah Mar 13, 2025
d21c091
cleanup
rezzmah Mar 13, 2025
e7debe9
Update compare_test.go
rezzmah Mar 13, 2025
4193d10
bring back types
rezzmah Mar 13, 2025
15dabfc
started and todo
rezzmah Mar 13, 2025
8e98064
Adding TODOs
rezzmah Mar 13, 2025
1f9119d
Added test cases
rezzmah Mar 13, 2025
81f304e
add
rezzmah Mar 13, 2025
510dc1e
Tests and fixes
rezzmah Mar 13, 2025
ea142c6
Update execution_requests.go
rezzmah Mar 13, 2025
9735fc1
Update prysm to fix consolidations amount
rezzmah Mar 14, 2025
dc86015
Update execution_requests_test.go
rezzmah Mar 14, 2025
6b500e0
Update execution_requests_test.go
rezzmah Mar 14, 2025
08a0d64
Merge branch 'main' into pectra-types-rez-poc
rezzmah Mar 17, 2025
12fd20e
Merge branch 'pectra-types-rez-poc' into pectra-types-for-real
rezzmah Mar 17, 2025
9fc1297
lint
rezzmah Mar 17, 2025
d41a1d3
wip - race condition
rezzmah Mar 17, 2025
8355af2
chore(types): standardize interfaces and convention (#2602)
calbera Mar 17, 2025
d0a8674
Merge branch 'main' into pectra-types-rez-poc
calbera Mar 17, 2025
7cc9b86
Merge branch 'pectra-types-rez-poc' into pectra-types-for-real
rezzmah Mar 18, 2025
322d688
merge conflict issues
rezzmah Mar 18, 2025
9f93530
Update signed_beacon_block_test.go
rezzmah Mar 18, 2025
0e6738f
Update body.go
rezzmah Mar 18, 2025
335d60d
Fixes
rezzmah Mar 18, 2025
298d39d
Update core_test.go
rezzmah Mar 18, 2025
9647923
Merge branch 'pectra-types-rez-poc' into pectra-types-for-real
calbera Mar 18, 2025
36afbed
progressing
rezzmah Mar 18, 2025
31aab0b
fixes
rezzmah Mar 18, 2025
3922c5b
Merge branch 'pectra-types-fix-ssz' into pectra-types-for-real
rezzmah Mar 18, 2025
c0ce942
Update body_test.go
rezzmah Mar 18, 2025
5f46be9
Merge branch 'pectra-types-fix-ssz' into pectra-types-for-real
rezzmah Mar 18, 2025
f419c32
Update body_test.go
rezzmah Mar 18, 2025
1bebe0d
Merge branch 'pectra-types-for-real' of github.com:berachain/beacon-k…
rezzmah Mar 18, 2025
6f9325c
try this
calbera Mar 18, 2025
839d26f
Update body_test.go
rezzmah Mar 18, 2025
6cfcbbd
tests
calbera Mar 18, 2025
90c274e
fix tests
rezzmah Mar 18, 2025
7955ce7
Merge branch 'signed-blk' into pectra-types-for-real
rezzmah Mar 18, 2025
85df076
fixing merge conflicts
rezzmah Mar 18, 2025
552a761
linter
rezzmah Mar 18, 2025
028f13a
Merge branch 'signed-blk' into pectra-types-for-real
rezzmah Mar 18, 2025
6fa5f52
fix tests
rezzmah Mar 18, 2025
d66f05f
Update execution_requests_test.go
rezzmah Mar 18, 2025
9a07173
Fix SSZ Unmarshalling for SignedBlock (#2610)
calbera Mar 18, 2025
e7fe78c
Merge branch 'pectra-types-rez-poc' into pectra-types-for-real
rezzmah Mar 18, 2025
75b09c3
Merge branch 'main' into pectra-types-rez-poc
calbera Mar 18, 2025
aded626
Merge branch 'pectra-types-rez-poc' of github.com:berachain/beacon-ki…
calbera Mar 18, 2025
6a11388
todo added
calbera Mar 18, 2025
544466c
Update execution_requests_test.go
rezzmah Mar 18, 2025
237a085
Update go.sum
rezzmah Mar 18, 2025
42d269f
Update execution_requests_test.go
rezzmah Mar 18, 2025
312806f
hacking
rezzmah Mar 18, 2025
d40ddf9
refactor chainspec component
rezzmah Mar 18, 2025
2df3e73
hacking
rezzmah Mar 19, 2025
8d86772
Update payload_requests.go
rezzmah Mar 19, 2025
40d0d60
Update signed_beacon_block.go
rezzmah Mar 19, 2025
a123b59
Update pectra_test.go
rezzmah Mar 19, 2025
94597d1
Update signed_beacon_block.go
rezzmah Mar 19, 2025
d42c62c
Update signed_beacon_block.go
rezzmah Mar 19, 2025
94d70ab
Update utils.go
rezzmah Mar 19, 2025
d4c6e44
Correctly distinguish JSON/SSZ marshaling and misc cleanup (#2611)
calbera Mar 19, 2025
ed6b6b2
some minor nits
calbera Mar 19, 2025
f3109f7
wip: created single constructor
abi87 Mar 19, 2025
e63e90f
unlocked compilation
abi87 Mar 19, 2025
b5d8d52
fixing UTs
abi87 Mar 19, 2025
09cebb1
fixed BlobSidecar syntax
abi87 Mar 19, 2025
b14cb9e
nit
abi87 Mar 19, 2025
cb68791
appease linter
abi87 Mar 19, 2025
ae1797f
nit
abi87 Mar 19, 2025
e26127c
appease nilaway
abi87 Mar 19, 2025
d6ad0ab
nit: make interfaces private for those that can be
calbera Mar 19, 2025
85e2edd
darned patterns..
calbera Mar 19, 2025
d3f11ce
Merge branch 'pectra-types-rez-poc' into pectra-types-for-real
rezzmah Mar 19, 2025
c07d927
Merge branch 'pectra-types-for-real' into pectra-handling
rezzmah Mar 19, 2025
5dcb8fd
fixed UTs
abi87 Mar 20, 2025
f48704e
some more cleanup
abi87 Mar 20, 2025
5d91a14
nits
abi87 Mar 20, 2025
c220613
Merge branch 'pectra-types-rez-poc' into pectra-types-ctor-cleanup-v2
abi87 Mar 20, 2025
5ec10c8
wip: dropping use of sszVersionedUnmarshaler.NewFromSSZ
abi87 Mar 20, 2025
fca8985
cleaned up interface
abi87 Mar 20, 2025
b573aac
fixed UTs
abi87 Mar 20, 2025
af80c26
Merge branch 'main' into pectra-types-ctor-cleanup-v2
abi87 Mar 20, 2025
7bd5a5f
Merge branch 'pectra-types-ctor-cleanup-v2' into pectra-types-cleanup…
abi87 Mar 20, 2025
63422ec
Fixed EnsureSyntaxFromSSZ
abi87 Mar 20, 2025
71c549b
cleanup imports to prevent import cycles
rezzmah Mar 20, 2025
97e4143
reintroducing types
rezzmah Mar 20, 2025
a7e9e40
cleanup and moving across
rezzmah Mar 20, 2025
e791b2d
Update body.go
rezzmah Mar 20, 2025
7f238c7
Update consolidation_request.go
rezzmah Mar 20, 2025
692026a
cleanup
rezzmah Mar 20, 2025
6f13371
Update pectra_test.go
rezzmah Mar 20, 2025
47b8a4d
fix licenses
rezzmah Mar 20, 2025
155354a
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 20, 2025
831e967
remove comments from merge conflicts
rezzmah Mar 20, 2025
eb4242c
Update state_processor_payload.go
rezzmah Mar 20, 2025
8482c0f
fix bug in test
rezzmah Mar 20, 2025
2224be5
fix bug in test
rezzmah Mar 21, 2025
7d43422
Fix tests
rezzmah Mar 21, 2025
522b7ac
Update supported.go
rezzmah Mar 21, 2025
748b4a1
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 21, 2025
3f1f729
Renamed EnsureSyntaxFromSSZ
abi87 Mar 21, 2025
4599d74
nit
abi87 Mar 21, 2025
3c4a875
ValidateAfterDecodingSSZ minor change
abi87 Mar 21, 2025
f7c7b02
Merge branch 'pectra-types-ctor-cleanup-v2' into pectra-types-cleanup…
abi87 Mar 21, 2025
9dcf6df
fix merge
abi87 Mar 21, 2025
3ff91c6
drop ExecutionPayloadHeader empty
abi87 Mar 21, 2025
c5b82ce
Merge branch 'pectra-types-cleanup-ctors-v3' into pectra-type-cleanup-v4
abi87 Mar 21, 2025
39c3cce
Merge branch 'pectra-type-cleanup-v4' into pectra-types-v5
rezzmah Mar 21, 2025
50613dd
merge fixes
rezzmah Mar 21, 2025
d1a7a31
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 21, 2025
98944cb
Merge branch 'pectra-handling' of github.com:berachain/beacon-kit int…
rezzmah Mar 21, 2025
672aec4
Merge branch 'main' into pectra-type-cleanup-v4
abi87 Mar 21, 2025
d5e2c37
Merge branch 'pectra-type-cleanup-v4' into pectra-types-v5
rezzmah Mar 21, 2025
b4322e4
Merge branch 'main' into pectra-types-v5
rezzmah Mar 21, 2025
ceac516
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 21, 2025
069b66e
Fix comment
rezzmah Mar 22, 2025
40d2cac
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 22, 2025
54f88d1
Merge branch 'main' into pectra-types-v5
rezzmah Mar 23, 2025
89ad669
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 23, 2025
cb60f48
Merge branch 'main' into pectra-types-v5
rezzmah Mar 24, 2025
0f04ff9
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 24, 2025
fa3c849
timestamp based forking
Mar 25, 2025
3c34720
disable pectra fork in devnet
Mar 25, 2025
bee44a9
Fix inflation test
Mar 25, 2025
e46a0e3
cleanup
Mar 25, 2025
89d61d5
Add time to finalize Block
Mar 25, 2025
03dba92
Merge branch 'main' into pectra-types-v5
rezzmah Mar 25, 2025
9fd93ee
Merge branch 'pectra-types-v5' into pectra-handling
rezzmah Mar 25, 2025
9e56892
Fix consensusTime vs blkTime and give up on tests
Mar 26, 2025
5da16a0
Merge branch 'main' into timestamp-based-forking
Mar 26, 2025
73ff8f5
Fix e2e tests and nits
Mar 26, 2025
1a68db1
Merge branch 'timestamp-based-forking' of github.com:berachain/beacon…
Mar 26, 2025
36dec02
Merge branch 'main' into pectra-handling
rezzmah Mar 26, 2025
a4a3712
Merge branch 'main' into timestamp-based-forking
calbera Mar 26, 2025
ee840c3
Merge branch 'pectra-handling' of github.com:berachain/beacon-kit int…
Mar 26, 2025
0ef5f7d
Set timestamps in simulated tests
Mar 26, 2025
7ca7c75
Merge branch 'main' of github.com:berachain/beacon-kit into timestamp…
Mar 26, 2025
197cbf2
nits and lint
Mar 26, 2025
acb4e5a
Add real deneb1 fork time to chainspecs
Mar 26, 2025
649daf2
fix inflation value in e2e test
Mar 26, 2025
88971e5
comment nit
Mar 26, 2025
2a95bba
Merge branch 'main' of github.com:berachain/beacon-kit into timestamp…
Mar 27, 2025
88be46d
address comments:
Mar 27, 2025
4c242db
Update config/spec/defaults.go
Mar 27, 2025
9f0ae7e
nits and better comments
Mar 27, 2025
6c9fd52
Merge branch 'timestamp-based-forking' of github.com:berachain/beacon…
Mar 27, 2025
a39e545
fork
rezzmah Mar 27, 2025
b9090ba
hcking
rezzmah Mar 27, 2025
396c262
Update payload.go
rezzmah Mar 27, 2025
639ceb2
Merge branch 'fix-bug-in-force-sync-upon-finalize' into timestamp-bas…
rezzmah Mar 27, 2025
60c9fe3
Refactor
rezzmah Mar 28, 2025
4857ee9
refactor
rezzmah Mar 28, 2025
6ef8978
Merge branch 'fix-bug-in-force-sync-upon-finalize' into timestamp-bas…
rezzmah Mar 29, 2025
c7fa6d7
tidy
rezzmah Mar 29, 2025
efc45b7
x
rezzmah Mar 29, 2025
65c1d5a
working fork
rezzmah Mar 30, 2025
0ec070b
Update finalize_block.go
rezzmah Mar 30, 2025
04d5f7c
Cleanup
rezzmah Mar 30, 2025
ec75a22
fix
rezzmah Mar 30, 2025
f45b536
reth persistance
rezzmah Mar 30, 2025
9c122b3
Update testing.mk
rezzmah Mar 30, 2025
ae094d7
Update devnet.go
rezzmah Mar 30, 2025
2d153fb
Update testing.mk
rezzmah Mar 30, 2025
4bf635f
Update version.go
rezzmah Mar 30, 2025
250d9cb
working
rezzmah Mar 30, 2025
cb79f12
delete chainspec depinject
rezzmah Mar 30, 2025
66830ad
Delete configurable.go
rezzmah Mar 30, 2025
2d92b19
working
rezzmah Mar 30, 2025
d4ade29
Update chainspec.go
rezzmah Mar 30, 2025
520fa65
Added make start-configurable
rezzmah Mar 30, 2025
deb275f
Update chainspec_test.go
rezzmah Mar 30, 2025
a1f99bb
Update chainspec_test.go
rezzmah Mar 30, 2025
b784edd
Update chainspec.go
rezzmah Mar 30, 2025
e2e1752
Update chainspec.go
rezzmah Mar 30, 2025
890aa40
Merge branch 'chain-spec-config-file' of github.com:berachain/beacon-…
Mar 31, 2025
469af14
Merge branch 'main' of github.com:berachain/beacon-kit into timestamp…
Apr 1, 2025
94dfdf8
nit for_slot
Apr 1, 2025
b0d874e
Merge branch 'timestamp-based-forking' into timestamp-based-forking-d…
rezzmah Apr 1, 2025
222edd6
logging fix
rezzmah Apr 1, 2025
a677e52
Update finalize_block.go
rezzmah Apr 1, 2025
9d4ee02
Update devnet.go
rezzmah Apr 1, 2025
d3600f5
Update version.go
rezzmah Apr 1, 2025
9d8e5d8
Rename test case
Apr 1, 2025
d2d2c8f
better finalize block comment
Apr 1, 2025
981f3d6
Merge branch 'timestamp-based-forking' into timestamp-based-forking-d…
rezzmah Apr 1, 2025
a131052
Merge branch 'main' into timestamp-based-forking-devnet-chainspec-1
Apr 3, 2025
9b82c28
remove extra line from conflict resolution
Apr 3, 2025
adb542d
Merge branch 'main' into timestamp-based-forking-devnet-chainspec-1
rezzmah Apr 3, 2025
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
3 changes: 3 additions & 0 deletions beacon/blockchain/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var (
ErrNilBlk = errors.New("nil beacon block")
// ErrNilBlob is an error for when the BlobSidecars is nil.
ErrNilBlob = errors.New("nil blob")
// ErrVersionMismatch is an error for when the fork for the block timestamp does not match the fork
// for the ABCI timestamp.
ErrVersionMismatch = errors.New("ABCI fork version mismatch")
// ErrDataNotAvailable indicates that the required data is not available.
ErrDataNotAvailable = errors.New("data not available")
// ErrSidecarCommitmentMismatch indicates that the BeaconBlockBody commitments do not match the sidecars.
Expand Down
5 changes: 1 addition & 4 deletions beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"

ctypes "github.com/berachain/beacon-kit/consensus-types/types"
contypes "github.com/berachain/beacon-kit/consensus/types"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
)
Expand All @@ -38,7 +37,6 @@ import (
func (s *Service) sendPostBlockFCU(
ctx context.Context,
st *statedb.StateDB,
blk *contypes.ConsensusBlock,
) error {
lph, err := st.GetLatestExecutionPayloadHeader()
if err != nil {
Expand All @@ -47,15 +45,14 @@ func (s *Service) sendPostBlockFCU(

// Send a forkchoice update without payload attributes to notify
// EL of the new head.
beaconBlk := blk.GetBeaconBlock()
// TODO: Switch to New().
req := ctypes.BuildForkchoiceUpdateRequestNoAttrs(
&engineprimitives.ForkchoiceStateV1{
HeadBlockHash: lph.GetBlockHash(),
SafeBlockHash: lph.GetParentHash(),
FinalizedBlockHash: lph.GetParentHash(),
},
s.chainSpec.ActiveForkVersionForSlot(beaconBlk.GetSlot()),
lph.GetForkVersion(),
)
if _, err = s.executionEngine.NotifyForkchoiceUpdate(ctx, req); err != nil {
return fmt.Errorf("failed forkchoice update, head %s: %w",
Expand Down
6 changes: 4 additions & 2 deletions beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (s *Service) FinalizeBlock(
req,
BeaconBlockTxIndex,
BlobSidecarsTxIndex,
s.chainSpec.ActiveForkVersionForSlot(math.Slot(req.Height))) // #nosec G115
// While req.GetTime() and blk.GetTimestamp() may be different, they are guaranteed
// to map to the same forkVersion due to checks during ProcessProposal.
s.chainSpec.ActiveForkVersionForTimestamp(math.U64(req.GetTime().Unix()))) //#nosec: G115
if err != nil {
s.logger.Error("Failed to decode block and blobs", "error", err)
return nil, fmt.Errorf("failed to decode block and blobs: %w", err)
Expand Down Expand Up @@ -121,7 +123,7 @@ func (s *Service) FinalizeBlock(
s.logger.Error("failed to processPruning", "error", err)
}

if err = s.sendPostBlockFCU(ctx, st, consensusBlk); err != nil {
if err = s.sendPostBlockFCU(ctx, st); err != nil {
return nil, fmt.Errorf("sendPostBlockFCU failed: %w", err)
}

Expand Down
6 changes: 3 additions & 3 deletions beacon/blockchain/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ type LocalBuilder interface {
ctx context.Context,
st *statedb.StateDB,
slot math.Slot,
timestamp uint64,
timestamp math.U64,
parentBlockRoot common.Root,
headEth1BlockHash common.ExecutionHash,
finalEth1BlockHash common.ExecutionHash,
) (*engineprimitives.PayloadID, error)
) (*engineprimitives.PayloadID, common.Version, error)
}

// StateProcessor defines the interface for processing various state transitions
Expand Down Expand Up @@ -167,5 +167,5 @@ type PruningChainSpec interface {
type ServiceChainSpec interface {
PruningChainSpec
chain.BlobSpec
ActiveForkVersionForSlot(slot math.Slot) common.Version
ActiveForkVersionForTimestamp(timestamp math.U64) common.Version
}
27 changes: 7 additions & 20 deletions beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ func (s *Service) forceSyncUponProcess(
ctx context.Context,
st *statedb.StateDB,
) {
slot, err := st.GetSlot()
if err != nil {
s.logger.Error(
"failed to get slot for force startup head",
"error", err,
)
return
}

// TODO: Verify if the slot number is correct here, I believe in current
// form it should be +1'd. Not a big deal until hardforks are in play though.
slot++

lph, err := st.GetLatestExecutionPayloadHeader()
if err != nil {
s.logger.Error(
Expand All @@ -64,7 +51,7 @@ func (s *Service) forceSyncUponProcess(
"head_eth1_hash", lph.GetBlockHash(),
"safe_eth1_hash", lph.GetParentHash(),
"finalized_eth1_hash", lph.GetParentHash(),
"for_slot", slot.Base10(),
"for_slot", lph.GetNumber(),
)

// Submit the forkchoice update to the execution client.
Expand All @@ -74,7 +61,7 @@ func (s *Service) forceSyncUponProcess(
SafeBlockHash: lph.GetParentHash(),
FinalizedBlockHash: lph.GetParentHash(),
},
s.chainSpec.ActiveForkVersionForSlot(slot),
s.chainSpec.ActiveForkVersionForTimestamp(lph.GetTimestamp()),
)
if _, err = s.executionEngine.NotifyForkchoiceUpdate(ctx, req); err != nil {
s.logger.Error(
Expand Down Expand Up @@ -117,7 +104,7 @@ func (s *Service) forceSyncUponFinalize(
SafeBlockHash: executionPayload.GetParentHash(),
FinalizedBlockHash: executionPayload.GetParentHash(),
},
s.chainSpec.ActiveForkVersionForSlot(beaconBlock.GetSlot()),
s.chainSpec.ActiveForkVersionForTimestamp(executionPayload.GetTimestamp()),
)

switch _, err = s.executionEngine.NotifyForkchoiceUpdate(ctx, req); {
Expand Down Expand Up @@ -196,12 +183,12 @@ func (s *Service) rebuildPayloadForRejectedBlock(
}

// Submit a request for a new payload.
if _, err = s.localBuilder.RequestPayloadAsync(
if _, _, err = s.localBuilder.RequestPayloadAsync(
ctx,
st,
// We are rebuilding for the current slot.
stateSlot,
nextPayloadTimestamp.Unwrap(),
nextPayloadTimestamp,
// We set the parent root to the previous block root. The HashTreeRoot
// of the header is the same as the HashTreeRoot of the block.
latestHeader.HashTreeRoot(),
Expand Down Expand Up @@ -264,10 +251,10 @@ func (s *Service) optimisticPayloadBuild(

// We then trigger a request for the next payload.
payload := blk.GetBody().GetExecutionPayload()
if _, err := s.localBuilder.RequestPayloadAsync(
if _, _, err := s.localBuilder.RequestPayloadAsync(
ctx, st,
slot,
nextPayloadTimestamp.Unwrap(),
nextPayloadTimestamp,
// The previous block root is simply the root of the block we just
// processed.
blk.HashTreeRoot(),
Expand Down
36 changes: 28 additions & 8 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/berachain/beacon-kit/primitives/eip4844"
"github.com/berachain/beacon-kit/primitives/math"
"github.com/berachain/beacon-kit/primitives/transition"
"github.com/berachain/beacon-kit/primitives/version"
"github.com/berachain/beacon-kit/state-transition/core"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
cmtabci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -67,12 +68,14 @@ func (s *Service) ProcessProposal(
)
}

forkVersion := s.chainSpec.ActiveForkVersionForTimestamp(math.U64(req.GetTime().Unix())) //#nosec: G115
// Decode signed block and sidecars.
signedBlk, sidecars, err := encoding.ExtractBlobsAndBlockFromRequest(
req,
BeaconBlockTxIndex,
BlobSidecarsTxIndex,
s.chainSpec.ActiveForkVersionForSlot(math.Slot(req.Height))) // #nosec G115
forkVersion,
)
if err != nil {
return err
}
Expand All @@ -90,24 +93,41 @@ func (s *Service) ProcessProposal(
}

blk := signedBlk.GetBeaconBlock()

// There are two different timestamps:
// - The "consensus time" is determined by CometBFT consensus and can be retrieved with `req.GetTime()`
// - The "block time" is determined by beacon-kit consensus and can be retrieved with `blk.GetTimestamp()`
// The "consensus time" is what the network agrees the current time is based on CometBFT PBTS.
// This "consensus time" is used to constrain the timestamp set as the "block time" by the
// beacon-kit app, but they are not always equal in value. The "block time" is used by the
// beacon-kit consensus and execution layers to determine the active fork version.
//
// When unmarshaling the BeaconBlock, we do not yet have access to the "block time", so we
// must rely on the "consensus time" as our best estimation of the "block time" needed to
// determine the current fork version. Since the two timestamps could be different, we need to
// ensure that the fork version for these timestamps are the same. This may result in a failed
// proposal or two at the start of the fork.
blkVersion := s.chainSpec.ActiveForkVersionForTimestamp(blk.GetTimestamp())
if !version.Equals(blkVersion, forkVersion) {
return fmt.Errorf("CometBFT version %v, BeaconBlock version %v: %w",
forkVersion, blkVersion,
ErrVersionMismatch,
)
}
// Make sure we have the right number of BlobSidecars
blobKzgCommitments := blk.GetBody().GetBlobKzgCommitments()
numCommitments := len(blobKzgCommitments)
if numCommitments != len(sidecars) {
err = fmt.Errorf("expected %d sidecars, got %d: %w",
return fmt.Errorf("expected %d sidecars, got %d: %w",
numCommitments, len(sidecars),
ErrSidecarCommitmentMismatch,
)
s.logger.Warn(err.Error())
return err
}
if uint64(numCommitments) > s.chainSpec.MaxBlobsPerBlock() {
err = fmt.Errorf("expected less than %d sidecars, got %d: %w",
return fmt.Errorf("expected less than %d sidecars, got %d: %w",
s.chainSpec.MaxBlobsPerBlock(), numCommitments,
core.ErrExceedsBlockBlobLimit,
)
s.logger.Warn(err.Error())
return err
}

// Verify the block and sidecar signatures. We can simply verify the block
Expand Down Expand Up @@ -140,7 +160,7 @@ func (s *Service) ProcessProposal(
}
}

// Process the block
// Process the block.
consensusBlk := types.NewConsensusBlock(
blk,
req.GetProposerAddress(),
Expand Down
68 changes: 37 additions & 31 deletions beacon/validator/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ func (s *Service) BuildBlockAndSidecars(
// and safe block hashes to the execution client.
st := s.sb.StateFromContext(ctx)

// we introduce hard forks with the expectation that the height set for the
// hard fork is the first height at which new rules apply. So we need to make
// sure that when building blocks, we pick the right height. blkSlots is the
// height for the next block, which consensus is requesting BeaconKit to build.
// blkSlot is the height for the next block, which consensus is requesting BeaconKit to build.
blkSlot := slotData.GetSlot()

// Prepare the state such that it is ready to build a block for
Expand All @@ -74,29 +71,44 @@ func (s *Service) BuildBlockAndSidecars(
return nil, nil, err
}

// Build forkdata used for the signing root of the reveal and the sidecars
forkData, err := s.buildForkData(st, blkSlot)
// Grab parent block root for payload request.
parentBlockRoot, err := st.GetBlockRootAtIndex(
(blkSlot.Unwrap() - 1) % s.chainSpec.SlotsPerHistoricalRoot(),
)
if err != nil {
return nil, nil, err
}

// Build the reveal for the current slot.
// TODO: We can optimize to pre-compute this in parallel?
reveal, err := s.buildRandaoReveal(forkData, blkSlot)
// Get the payload for the block.
envelope, err := s.retrieveExecutionPayload(ctx, st, parentBlockRoot, slotData)
if err != nil {
return nil, nil, fmt.Errorf("failed retrieving execution payload: %w", err)
}

// We introduce hard forks with the expectation that the first block proposed after the
// hard fork timestamp is when new rules apply. When building blocks, we provide the Execution
// Layer client with a timestamp, and it will create its payload based on that timestamp. We
// must use this same timestamp from the payload to build the beacon block. This ensures that
// we are building on the same fork version as the Execution Layer.
timestamp := envelope.GetExecutionPayload().GetTimestamp()

// Build forkdata used for the signing root of the reveal and the sidecars
forkData, err := s.buildForkData(st, timestamp)
if err != nil {
return nil, nil, err
}

// Create a new empty block from the current state.
blk, err := s.getEmptyBeaconBlockForSlot(st, blkSlot)
blk, err := s.getEmptyBeaconBlockForSlot(st, blkSlot, forkData.CurrentVersion, parentBlockRoot)
if err != nil {
return nil, nil, err
}

// Get the payload for the block.
envelope, err := s.retrieveExecutionPayload(ctx, st, blk, slotData)
// Build the reveal for the current slot.
// TODO: We can optimize to pre-compute this in parallel?
reveal, err := s.buildRandaoReveal(forkData, blkSlot)
if err != nil {
return nil, nil, fmt.Errorf("failed retrieving execution payload: %w", err)
return nil, nil, err
}

// We have to assemble the block body prior to producing the sidecars
Expand Down Expand Up @@ -150,15 +162,8 @@ func (s *Service) BuildBlockAndSidecars(
// getEmptyBeaconBlockForSlot creates a new empty block.
func (s *Service) getEmptyBeaconBlockForSlot(
st *statedb.StateDB, requestedSlot math.Slot,
forkVersion common.Version, parentBlockRoot common.Root,
) (*ctypes.BeaconBlock, error) {
// Create a new block.
parentBlockRoot, err := st.GetBlockRootAtIndex(
(requestedSlot.Unwrap() - 1) % s.chainSpec.SlotsPerHistoricalRoot(),
)
if err != nil {
return nil, err
}

// Get the proposer index for the slot.
proposerIndex, err := st.ValidatorIndexByPubkey(
s.signer.PublicKey(),
Expand All @@ -167,22 +172,23 @@ func (s *Service) getEmptyBeaconBlockForSlot(
return nil, err
}

// Create a new block.
return ctypes.NewBeaconBlockWithVersion(
requestedSlot,
proposerIndex,
parentBlockRoot,
s.chainSpec.ActiveForkVersionForSlot(requestedSlot),
forkVersion,
)
}

func (s *Service) buildForkData(st *statedb.StateDB, slot math.Slot) (*ctypes.ForkData, error) {
func (s *Service) buildForkData(st *statedb.StateDB, timestamp math.U64) (*ctypes.ForkData, error) {
genesisValidatorsRoot, err := st.GetGenesisValidatorsRoot()
if err != nil {
return nil, err
}

return ctypes.NewForkData(
s.chainSpec.ActiveForkVersionForSlot(slot),
s.chainSpec.ActiveForkVersionForTimestamp(timestamp),
genesisValidatorsRoot,
), nil
}
Expand All @@ -206,7 +212,7 @@ func (s *Service) buildRandaoReveal(
func (s *Service) retrieveExecutionPayload(
ctx context.Context,
st *statedb.StateDB,
blk *ctypes.BeaconBlock,
parentBlockRoot common.Root,
slotData *types.SlotData,
) (ctypes.BuiltExecutionPayloadEnv, error) {
//
Expand All @@ -215,8 +221,8 @@ func (s *Service) retrieveExecutionPayload(
// Get the payload for the block.
envelope, err := s.localPayloadBuilder.RetrievePayload(
ctx,
blk.GetSlot(),
blk.GetParentBlockRoot(),
slotData.GetSlot(),
parentBlockRoot,
)
if err == nil {
return envelope, nil
Expand All @@ -232,7 +238,7 @@ func (s *Service) retrieveExecutionPayload(
// this less confusing.

s.metrics.failedToRetrievePayload(
blk.GetSlot(),
slotData.GetSlot(),
err,
)

Expand All @@ -246,13 +252,13 @@ func (s *Service) retrieveExecutionPayload(
return s.localPayloadBuilder.RequestPayloadSync(
ctx,
st,
blk.GetSlot(),
slotData.GetSlot(),
payloadtime.Next(
slotData.GetConsensusTime(),
lph.GetTimestamp(),
false, // buildOptimistically
).Unwrap(),
blk.GetParentBlockRoot(),
),
parentBlockRoot,
lph.GetBlockHash(),
lph.GetParentHash(),
)
Expand Down
Loading
Loading