Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: predictable block times #1

Closed
wants to merge 12 commits into from
Closed
6 changes: 3 additions & 3 deletions beacon/blockchain/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
const defaultRetryInterval = 20 * time.Second

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) depositFetcher(
ctx context.Context,
blockNum math.U64,
Expand All @@ -52,7 +52,7 @@ func (s *Service[
}

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) fetchAndStoreDeposits(
ctx context.Context,
blockNum math.U64,
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *Service[
}

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) depositCatchupFetcher(ctx context.Context) {
ticker := time.NewTicker(defaultRetryInterval)
defer ticker.Stop()
Expand Down
6 changes: 3 additions & 3 deletions beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// sendPostBlockFCU sends a forkchoice update to the execution client.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) sendPostBlockFCU(
ctx context.Context,
st BeaconStateT,
Expand All @@ -57,7 +57,7 @@ func (s *Service[
// client with attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _,
_, _, ExecutionPayloadHeaderT, _, _, _, _,
_, ExecutionPayloadHeaderT, _, _, _, _,
]) sendNextFCUWithAttributes(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *Service[
// sendNextFCUWithoutAttributes sends a forkchoice update to the
// execution client without attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _,
ExecutionPayloadHeaderT, _, _, _, PayloadAttributesT,
]) sendNextFCUWithoutAttributes(
ctx context.Context,
Expand Down
6 changes: 3 additions & 3 deletions beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _,
_, _, _, GenesisT, ConsensusSidecarsT, BlobSidecarsT, _,
]) FinalizeBlock(
ctx sdk.Context,
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *Service[
// finalizeBeaconBlock receives an incoming beacon block, it first validates
// and then processes the block.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) finalizeBeaconBlock(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *Service[

// executeStateTransition runs the stf.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) executeStateTransition(
ctx context.Context,
st BeaconStateT,
Expand Down
2 changes: 1 addition & 1 deletion beacon/blockchain/init_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// ProcessGenesisData processes the genesis state and initializes the beacon
// state.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, GenesisT, _, _, _,
_, _, _, _, _, _, _, _, _, GenesisT, _, _, _,
]) ProcessGenesisData(
ctx context.Context,
bytes []byte,
Expand Down
10 changes: 5 additions & 5 deletions beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// forceStartupHead sends a force head FCU to the execution client.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) forceStartupHead(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s *Service[
// handleRebuildPayloadForRejectedBlock handles the case where the incoming
// block was rejected and we need to rebuild the payload for the current slot.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) handleRebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
Expand All @@ -82,7 +82,7 @@ func (s *Service[
// rejected the incoming block and it would be unsafe to use any
// information from it.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, ExecutionPayloadHeaderT,
_, _, _, _, _, BeaconStateT, _, _, ExecutionPayloadHeaderT,
_, _, _, _,
]) rebuildPayloadForRejectedBlock(
ctx context.Context,
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *Service[
// handleOptimisticPayloadBuild handles optimistically
// building for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _,
]) handleOptimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand All @@ -164,7 +164,7 @@ func (s *Service[

// optimisticPayloadBuild builds a payload for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _,
]) optimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand Down
8 changes: 4 additions & 4 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _,
_, _, _, GenesisT, ConsensusSidecarsT, BlobSidecarsT, _,
]) ProcessProposal(
ctx sdk.Context,
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *Service[
// VerifyIncomingBlock verifies the state root of an incoming block
// and logs the process.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _,
ExecutionPayloadHeaderT, _, _, _, _,
]) VerifyIncomingBlock(
ctx context.Context,
Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *Service[
// verifyStateRoot verifies the state root of an incoming block.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, BeaconStateT,
_, _, _, _, _, _, _, _,
_, _, _, _, _, _, _,
]) verifyStateRoot(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -272,7 +272,7 @@ func (s *Service[
// shouldBuildOptimisticPayloads returns true if optimistic
// payload builds are enabled.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _,
]) shouldBuildOptimisticPayloads() bool {
return s.optimisticPayloadBuilds && s.localBuilder.Enabled()
}
Expand Down
8 changes: 3 additions & 5 deletions beacon/blockchain/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
package blockchain

import (
"github.com/berachain/beacon-kit/execution/deposit"
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/math"
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _,
]) processPruning(beaconBlk BeaconBlockT) error {
// prune availability store
start, end := availabilityPruneRangeFn(
Expand All @@ -49,9 +49,7 @@ func (s *Service[
return nil
}

func depositPruneRangeFn[
DepositT deposit.Deposit[DepositT],
](deposits []DepositT, cs common.ChainSpec) (uint64, uint64) {
func depositPruneRangeFn(deposits []*ctypes.Deposit, cs common.ChainSpec) (uint64, uint64) {
if len(deposits) == 0 || cs.MaxDepositsPerBlock() == 0 {
return 0, 0
}
Expand Down
35 changes: 16 additions & 19 deletions beacon/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"sync"

ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/da/da"
"github.com/berachain/beacon-kit/execution/deposit"
"github.com/berachain/beacon-kit/log"
Expand All @@ -38,22 +39,21 @@ import (
// Service is the blockchain service.
type Service[
AvailabilityStoreT AvailabilityStore[BeaconBlockBodyT],
DepositStoreT backend.DepositStore[DepositT],
DepositStoreT backend.DepositStore,
ConsensusBlockT ConsensusBlock[BeaconBlockT],
BeaconBlockT BeaconBlock[BeaconBlockT, BeaconBlockBodyT],
BeaconBlockBodyT interface {
BeaconBlockBody[ExecutionPayloadT]
GetBlobKzgCommitments() eip4844.KZGCommitments[common.ExecutionHash]
GetDeposits() []DepositT
GetDeposits() []*ctypes.Deposit
},
BeaconStateT ReadOnlyBeaconState[
BeaconStateT, ExecutionPayloadHeaderT,
],
BlockStoreT blockstore.BlockStore[BeaconBlockT],
DepositT deposit.Deposit[DepositT],
ExecutionPayloadT ExecutionPayload,
ExecutionPayloadHeaderT ExecutionPayloadHeader,
GenesisT Genesis[DepositT, ExecutionPayloadHeaderT],
GenesisT Genesis[ExecutionPayloadHeaderT],
ConsensusSidecarsT da.ConsensusSidecars[BlobSidecarsT],
BlobSidecarsT BlobSidecars[BlobSidecarsT],

Expand All @@ -76,10 +76,10 @@ type Service[
// TODO: Remove this and use the block store from the storage backend.
blockStore BlockStoreT
// depositStore is the deposit store that stores deposits.
depositStore deposit.Store[DepositT]
depositStore deposit.Store
// depositContract is the contract interface for interacting with the
// deposit contract.
depositContract deposit.Contract[DepositT]
depositContract deposit.Contract
// eth1FollowDistance is the follow distance for Ethereum 1.0 blocks.
eth1FollowDistance math.U64
// failedBlocksMu protects failedBlocks for concurrent access.
Expand All @@ -102,7 +102,6 @@ type Service[
BeaconBlockT,
BeaconStateT,
*transition.Context,
DepositT,
ExecutionPayloadHeaderT,
]
// metrics is the metrics for the service.
Expand All @@ -117,22 +116,21 @@ type Service[
// NewService creates a new validator service.
func NewService[
AvailabilityStoreT AvailabilityStore[BeaconBlockBodyT],
DepositStoreT backend.DepositStore[DepositT],
DepositStoreT backend.DepositStore,
ConsensusBlockT ConsensusBlock[BeaconBlockT],
BeaconBlockT BeaconBlock[BeaconBlockT, BeaconBlockBodyT],
BeaconBlockBodyT interface {
BeaconBlockBody[ExecutionPayloadT]
GetBlobKzgCommitments() eip4844.KZGCommitments[common.ExecutionHash]
GetDeposits() []DepositT
GetDeposits() []*ctypes.Deposit
},
BeaconStateT ReadOnlyBeaconState[
BeaconStateT, ExecutionPayloadHeaderT,
],
BlockStoreT blockstore.BlockStore[BeaconBlockT],
DepositT deposit.Deposit[DepositT],
ExecutionPayloadT ExecutionPayload,
ExecutionPayloadHeaderT ExecutionPayloadHeader,
GenesisT Genesis[DepositT, ExecutionPayloadHeaderT],
GenesisT Genesis[ExecutionPayloadHeaderT],
PayloadAttributesT PayloadAttributes,
ConsensusSidecarsT da.ConsensusSidecars[BlobSidecarsT],
BlobSidecarsT BlobSidecars[BlobSidecarsT],
Expand All @@ -148,8 +146,8 @@ func NewService[
ConsensusSidecarsT, BlobSidecarsT,
],
blockStore BlockStoreT,
depositStore deposit.Store[DepositT],
depositContract deposit.Contract[DepositT],
depositStore deposit.Store,
depositContract deposit.Contract,
eth1FollowDistance math.U64,
logger log.Logger,
chainSpec common.ChainSpec,
Expand All @@ -159,22 +157,21 @@ func NewService[
BeaconBlockT,
BeaconStateT,
*transition.Context,
DepositT,
ExecutionPayloadHeaderT,
],
telemetrySink TelemetrySink,
optimisticPayloadBuilds bool,
) *Service[
AvailabilityStoreT, DepositStoreT,
ConsensusBlockT, BeaconBlockT, BeaconBlockBodyT,
BeaconStateT, BlockStoreT, DepositT,
BeaconStateT, BlockStoreT,
ExecutionPayloadT, ExecutionPayloadHeaderT, GenesisT,
ConsensusSidecarsT, BlobSidecarsT, PayloadAttributesT,
] {
return &Service[
AvailabilityStoreT, DepositStoreT,
ConsensusBlockT, BeaconBlockT, BeaconBlockBodyT,
BeaconStateT, BlockStoreT, DepositT,
BeaconStateT, BlockStoreT,
ExecutionPayloadT, ExecutionPayloadHeaderT,
GenesisT, ConsensusSidecarsT, BlobSidecarsT, PayloadAttributesT,
]{
Expand All @@ -199,13 +196,13 @@ func NewService[

// Name returns the name of the service.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _,
]) Name() string {
return "blockchain"
}

func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _,
]) Start(ctx context.Context) error {
// Catchup deposits for failed blocks.
go s.depositCatchupFetcher(ctx)
Expand All @@ -214,7 +211,7 @@ func (s *Service[
}

func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _,
]) Stop() error {
return nil
}
7 changes: 3 additions & 4 deletions beacon/blockchain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ type ExecutionPayloadHeader interface {
}

// Genesis is the interface for the genesis.
type Genesis[DepositT any, ExecutionPayloadHeaderT any] interface {
type Genesis[ExecutionPayloadHeaderT any] interface {
// GetForkVersion returns the fork version.
GetForkVersion() common.Version
// GetDeposits returns the deposits.
GetDeposits() []DepositT
GetDeposits() []*ctypes.Deposit
// GetExecutionPayloadHeader returns the execution payload header.
GetExecutionPayloadHeader() ExecutionPayloadHeaderT
}
Expand Down Expand Up @@ -188,15 +188,14 @@ type StateProcessor[
BeaconBlockT,
BeaconStateT,
ContextT,
DepositT,
ExecutionPayloadHeaderT any,
] interface {
// InitializePreminedBeaconStateFromEth1 initializes the premined beacon
// state
// from the eth1 deposits.
InitializePreminedBeaconStateFromEth1(
BeaconStateT,
[]DepositT,
[]*ctypes.Deposit,
ExecutionPayloadHeaderT,
common.Version,
) (transition.ValidatorUpdates, error)
Expand Down
Loading