Skip to content
Draft
Show file tree
Hide file tree
Changes from 222 commits
Commits
Show all changes
223 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
54fbed4
e2e test forking working hardcoded
Mar 29, 2025
c9c57ff
fix slot times and remove debug
Mar 29, 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
7364efe
Cleanup with chain spec
Apr 1, 2025
469af14
Merge branch 'main' of github.com:berachain/beacon-kit into timestamp…
Apr 1, 2025
94dfdf8
nit for_slot
Apr 1, 2025
219209d
Merge branch 'timestamp-based-forking' into timestamp-based-forking-d…
Apr 1, 2025
9d8e5d8
Rename test case
Apr 1, 2025
d2d2c8f
better finalize block comment
Apr 1, 2025
7ed78eb
Remove extraneous file
Apr 1, 2025
81da681
Merge branch 'timestamp-based-forking' into timestamp-based-forking-d…
Apr 1, 2025
d030f65
fix devnet spec
Apr 1, 2025
49b7759
Merge branch 'timestamp-based-forking-dynamic-e2e' of github.com:bera…
Apr 1, 2025
c7accc0
Better timestamp setting
Apr 1, 2025
86c91bd
lint
Apr 1, 2025
8448d0a
fix devnet equality check
Apr 1, 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
23 changes: 16 additions & 7 deletions beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"time"

"github.com/berachain/beacon-kit/config/spec"
"github.com/berachain/beacon-kit/consensus/cometbft/service/encoding"
"github.com/berachain/beacon-kit/consensus/types"
"github.com/berachain/beacon-kit/primitives/math"
Expand All @@ -38,12 +39,23 @@ func (s *Service) FinalizeBlock(
ctx sdk.Context,
req *cmtabci.FinalizeBlockRequest,
) (transition.ValidatorUpdates, error) {
cometTime := math.U64(req.GetTime().Unix()) //#nosec: G115
if s.chainSpec.DepositEth1ChainID() != spec.DevnetEth1ChainID {
state := s.storageBackend.StateFromContext(ctx)
lph, err := state.GetLatestExecutionPayloadHeader()
if err != nil {
return nil, err
}
cometTime = lph.GetTimestamp() + math.U64(s.chainSpec.TargetSecondsPerEth1Block())
}
// STEP 1: Decode block and blobs.
signedBlk, blobs, err := encoding.ExtractBlobsAndBlockFromRequest(
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(cometTime))
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 @@ -88,7 +100,7 @@ func (s *Service) FinalizeBlock(
}

// STEP 3: Finalize the block.
consensusBlk := types.NewConsensusBlock(blk, req.GetProposerAddress(), req.GetTime())
consensusBlk := types.NewConsensusBlock(blk, req.GetProposerAddress(), cometTime)
st := s.storageBackend.StateFromContext(ctx)
valUpdates, err := s.finalizeBeaconBlock(ctx, st, consensusBlk)
if err != nil {
Expand All @@ -98,14 +110,12 @@ func (s *Service) FinalizeBlock(
return nil, err
}

// STEP 4: Post Finalizations cleanups.

// STEP 4: Post Finalization cleanups.
// Fetch and store the deposit for the block.
blockNum := blk.GetBody().GetExecutionPayload().GetNumber()
s.depositFetcher(ctx, blockNum)

// Store the finalized block in the KVStore.
//
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete some empty lines to appease funlen

// TODO: Store full SignedBeaconBlock with all data in storage
slot := blk.GetSlot()
if err = s.storageBackend.BlockStore().Set(blk); err != nil {
Expand All @@ -121,10 +131,9 @@ 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)
}

return valUpdates, nil
}

Expand Down
8 changes: 5 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,7 @@ type PruningChainSpec interface {
type ServiceChainSpec interface {
PruningChainSpec
chain.BlobSpec
ActiveForkVersionForSlot(slot math.Slot) common.Version
ActiveForkVersionForTimestamp(timestamp math.U64) common.Version
DepositEth1ChainID() uint64
TargetSecondsPerEth1Block() uint64
}
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
48 changes: 39 additions & 9 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

payloadtime "github.com/berachain/beacon-kit/beacon/payload-time"
"github.com/berachain/beacon-kit/config/spec"
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/consensus/cometbft/service/encoding"
"github.com/berachain/beacon-kit/consensus/types"
Expand All @@ -37,6 +38,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 +69,23 @@ func (s *Service) ProcessProposal(
)
}

cometTime := math.U64(req.GetTime().Unix()) //#nosec: G115
if s.chainSpec.DepositEth1ChainID() != spec.DevnetEth1ChainID {
state := s.storageBackend.StateFromContext(ctx)
lph, err := state.GetLatestExecutionPayloadHeader()
if err != nil {
return err
}
cometTime = lph.GetTimestamp() + math.U64(s.chainSpec.TargetSecondsPerEth1Block())
}
forkVersion := s.chainSpec.ActiveForkVersionForTimestamp(cometTime)
// 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 +103,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,11 +170,11 @@ func (s *Service) ProcessProposal(
}
}

// Process the block
// Process the block.
consensusBlk := types.NewConsensusBlock(
blk,
req.GetProposerAddress(),
req.GetTime(),
cometTime,
)
err = s.VerifyIncomingBlock(
ctx,
Expand Down
Loading
Loading