Skip to content

Commit

Permalink
bet
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Jun 22, 2024
1 parent 33229bf commit d0ab95a
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 30 deletions.
4 changes: 4 additions & 0 deletions mod/beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) sendPostBlockFCU(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -75,6 +76,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) sendNextFCUWithAttributes(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -130,6 +132,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) sendNextFCUWithoutAttributes(
ctx context.Context,
blk BeaconBlockT,
Expand Down Expand Up @@ -171,6 +174,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) calculateNextTimestamp(blk BeaconBlockT) uint64 {
//#nosec:G701 // not an issue in practice.
return max(
Expand Down
5 changes: 5 additions & 0 deletions mod/beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) forceStartupHead(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -79,6 +80,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) handleRebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -112,6 +114,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) rebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -199,6 +202,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) handleOptimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -226,6 +230,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) optimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand Down
4 changes: 4 additions & 0 deletions mod/beacon/blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) ProcessGenesisData(
ctx context.Context,
genesisData GenesisT,
Expand All @@ -71,6 +72,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) ProcessBlockAndBlobs(
ctx context.Context,
blk BeaconBlockT,
Expand Down Expand Up @@ -146,6 +148,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) processBeaconBlock(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -191,6 +194,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) processBlobSidecars(
ctx context.Context,
slot math.Slot,
Expand Down
5 changes: 5 additions & 0 deletions mod/beacon/blockchain/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) ReceiveBlockAndBlobs(
ctx context.Context,
blk BeaconBlockT,
Expand Down Expand Up @@ -84,6 +85,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) VerifyIncomingBlock(
ctx context.Context,
blk BeaconBlockT,
Expand Down Expand Up @@ -161,6 +163,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) verifyStateRoot(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -206,6 +209,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) VerifyIncomingBlobs(
_ context.Context,
blk BeaconBlockT,
Expand Down Expand Up @@ -259,6 +263,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) shouldBuildOptimisticPayloads() bool {
return s.optimisticPayloadBuilds && s.lb.Enabled()
}
8 changes: 6 additions & 2 deletions mod/beacon/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Service[
Version() uint32
GetSuggestedFeeRecipient() common.ExecutionAddress
},
WithdrawalT any,
] struct {
// sb represents the backend storage for beacon states and associated
// sidecars.
Expand Down Expand Up @@ -111,6 +112,7 @@ func NewService[
Version() uint32
GetSuggestedFeeRecipient() common.ExecutionAddress
},
WithdrawalT any,
](
sb StorageBackend[
AvailabilityStoreT,
Expand Down Expand Up @@ -140,12 +142,12 @@ func NewService[
) *Service[
AvailabilityStoreT, BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
BeaconStateT, BlobSidecarsT, DepositT, ExecutionPayloadT,
ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT,
ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, WithdrawalT,
] {
return &Service[
AvailabilityStoreT, BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
BeaconStateT, BlobSidecarsT, DepositT, ExecutionPayloadT,
ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT,
ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, WithdrawalT,
]{
sb: sb,
logger: logger,
Expand Down Expand Up @@ -174,6 +176,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) Name() string {
return "blockchain"
}
Expand All @@ -190,6 +193,7 @@ func (s *Service[
ExecutionPayloadHeaderT,
GenesisT,
PayloadAttributesT,
_,
]) Start(
context.Context,
) error {
Expand Down
23 changes: 12 additions & 11 deletions mod/execution/pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ import (
// from the Ethereum 2.0 Specification.
type Engine[
ExecutionPayloadT ExecutionPayload[
ExecutionPayloadT, *engineprimitives.Withdrawal,
ExecutionPayloadT, WithdrawalT,
],
PayloadAttributesT engineprimitives.PayloadAttributer,
PayloadIDT ~[8]byte,
WithdrawalT Withdrawal[WithdrawalT],
] struct {
// ec is the engine client that the engine will use to
// interact with the execution layer.
Expand All @@ -61,10 +62,11 @@ type Engine[
// New creates a new Engine.
func New[
ExecutionPayloadT ExecutionPayload[
ExecutionPayloadT, *engineprimitives.Withdrawal,
ExecutionPayloadT, WithdrawalT,
],
PayloadAttributesT engineprimitives.PayloadAttributer,
PayloadIDT ~[8]byte,
WithdrawalT Withdrawal[WithdrawalT],
](
ec *client.EngineClient[ExecutionPayloadT, PayloadAttributesT],
logger log.Logger[any],
Expand All @@ -74,9 +76,9 @@ func New[
],
telemtrySink TelemetrySink,
) *Engine[
ExecutionPayloadT, PayloadAttributesT, PayloadIDT,
ExecutionPayloadT, PayloadAttributesT, PayloadIDT, WithdrawalT,
] {
return &Engine[ExecutionPayloadT, PayloadAttributesT, PayloadIDT]{
return &Engine[ExecutionPayloadT, PayloadAttributesT, PayloadIDT, WithdrawalT]{
ec: ec,
logger: logger,
metrics: newEngineMetrics(telemtrySink, logger),
Expand All @@ -85,9 +87,7 @@ func New[
}

// Start spawns any goroutines required by the service.
func (ee *Engine[
ExecutionPayloadT, PayloadAttributesT, PayloadIDT,
]) Start(
func (ee *Engine[_, _, _, _]) Start(
ctx context.Context,
) error {
go func() {
Expand All @@ -101,7 +101,7 @@ func (ee *Engine[

// GetPayload returns the payload and blobs bundle for the given slot.
func (ee *Engine[
ExecutionPayloadT, _, _,
ExecutionPayloadT, _, _, _,
]) GetPayload(
ctx context.Context,
req *engineprimitives.GetPayloadRequest[engineprimitives.PayloadID],
Expand All @@ -114,7 +114,7 @@ func (ee *Engine[

// NotifyForkchoiceUpdate notifies the execution client of a forkchoice update.
func (ee *Engine[
_, PayloadAttributesT, _,
_, PayloadAttributesT, _, _,
]) NotifyForkchoiceUpdate(
ctx context.Context,
req *engineprimitives.ForkchoiceUpdateRequest[PayloadAttributesT],
Expand Down Expand Up @@ -186,11 +186,12 @@ func (ee *Engine[
// VerifyAndNotifyNewPayload verifies the new payload and notifies the
// execution client.
func (ee *Engine[
ExecutionPayloadT, _, _,
ExecutionPayloadT, _, _, WithdrawalT,
]) VerifyAndNotifyNewPayload(
ctx context.Context,
req *engineprimitives.NewPayloadRequest[
ExecutionPayloadT, *engineprimitives.Withdrawal],
ExecutionPayloadT, WithdrawalT,
],
) error {
// Log the new payload attempt.
ee.metrics.markNewPayloadCalled(
Expand Down
14 changes: 14 additions & 0 deletions mod/execution/pkg/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,17 @@ type TelemetrySink interface {
// provided keys.
SetGauge(key string, value int64, args ...string)
}

// Withdrawal is the interface for a withdrawal.
type Withdrawal[WithdrawalT any] interface {
// Equals returns true if the withdrawal is equal to the other.
Equals(WithdrawalT) bool
// GetAmount returns the amount of the withdrawal.
GetAmount() math.Gwei
// GetIndex returns the public key of the validator.
GetIndex() math.U64
// GetValidatorIndex returns the index of the validator.
GetValidatorIndex() math.ValidatorIndex
// GetAddress returns the address of the withdrawal.
GetAddress() common.ExecutionAddress
}
3 changes: 3 additions & 0 deletions mod/node-core/pkg/components/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"cosmossdk.io/depinject"
"github.com/berachain/beacon-kit/mod/beacon/blockchain"
"github.com/berachain/beacon-kit/mod/config"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
Expand Down Expand Up @@ -63,6 +64,8 @@ func ProvideChainService(
*ExecutionPayload,
*ExecutionPayloadHeader,
*Genesis,
*engineprimitives.PayloadAttributes[*Withdrawal],
*Withdrawal,
](
in.StorageBackend,
in.Logger.With("service", "blockchain"),
Expand Down
6 changes: 5 additions & 1 deletion mod/node-core/pkg/components/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func DefaultComponentsWithStandardTypes() []any {
*engineprimitives.PayloadAttributes[*Withdrawal],
],
ProvideExecutionEngine[
*ExecutionPayload, *Withdrawal],
*ExecutionPayload,
*engineprimitives.PayloadAttributes[*Withdrawal],
engineprimitives.PayloadID,
*Withdrawal,
],
ProvideJWTSecret,
ProvideLocalBuilder,
ProvideServiceRegistry,
Expand Down
Loading

0 comments on commit d0ab95a

Please sign in to comment.