diff --git a/beacond/cmd/defaults.go b/beacond/cmd/defaults.go index e4ede16b88..148fc79972 100644 --- a/beacond/cmd/defaults.go +++ b/beacond/cmd/defaults.go @@ -42,7 +42,8 @@ func DefaultComponents() []any { *BeaconBlockHeader, *BlobSidecars, *Logger, ], components.ProvideBeaconDepositContract[ - *Deposit, *ExecutionPayload, *ExecutionPayloadHeader, + *Deposit, *ExecutionPayload, *ExecutionPayloadHeader, Log, + *Withdrawal, Withdrawals, WithdrawalCredentials, ], components.ProvideBlockStore[ *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader, *Logger, @@ -64,7 +65,7 @@ func DefaultComponents() []any { *AvailabilityStore, *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader, *BeaconState, *BeaconStateMarshallable, *BlobSidecars, *BlockStore, *Deposit, *DepositStore, - *ExecutionPayload, *ExecutionPayloadHeader, *Genesis, + *ExecutionPayload, *ExecutionPayloadHeader, Log, *Genesis, *KVStore, *Logger, *StorageBackend, ], components.ProvideNode, @@ -82,27 +83,28 @@ func DefaultComponents() []any { components.ProvideDBManager[*AvailabilityStore, *DepositStore, *Logger], components.ProvideDepositPruner[ *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader, - *Deposit, *DepositStore, *Logger, + *Deposit, *DepositStore, Log, *Logger, ], components.ProvideDepositService[ *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader, *Deposit, *DepositContract, *DepositStore, *ExecutionPayload, - *ExecutionPayloadHeader, *Logger, + *ExecutionPayloadHeader, Log, *Logger, + *Withdrawal, Withdrawals, WithdrawalCredentials, ], components.ProvideDepositStore[*Deposit], components.ProvideDispatcher[ *BeaconBlock, *BlobSidecars, *Genesis, *Logger, ], components.ProvideEngineClient[ - *ExecutionPayload, *ExecutionPayloadHeader, *Logger, + *ExecutionPayload, *ExecutionPayloadHeader, Log, *Logger, ], components.ProvideExecutionEngine[ - *ExecutionPayload, *ExecutionPayloadHeader, *Logger, + *ExecutionPayload, *ExecutionPayloadHeader, Log, *Logger, ], components.ProvideJWTSecret, components.ProvideLocalBuilder[ *BeaconBlockHeader, *BeaconState, *BeaconStateMarshallable, - *ExecutionPayload, *ExecutionPayloadHeader, *KVStore, *Logger, + *ExecutionPayload, *ExecutionPayloadHeader, Log, *KVStore, *Logger, ], components.ProvideReportingService[*Logger], components.ProvideCometBFTService[*Logger], @@ -111,7 +113,7 @@ func DefaultComponents() []any { *BeaconBlockHeader, *BlockStore, *BeaconState, *BeaconStateMarshallable, *BlobSidecar, *BlobSidecars, *Deposit, *DepositStore, *ExecutionPayload, *ExecutionPayloadHeader, - *Genesis, *KVStore, *Logger, + Log, *Genesis, *KVStore, *Logger, NodeAPIContext, ], components.ProvideSidecarFactory[ @@ -120,7 +122,7 @@ func DefaultComponents() []any { components.ProvideStateProcessor[ *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader, *BeaconState, *BeaconStateMarshallable, *Deposit, *ExecutionPayload, - *ExecutionPayloadHeader, *KVStore, + *ExecutionPayloadHeader, Log, *KVStore, ], components.ProvideKVStore[*BeaconBlockHeader, *ExecutionPayloadHeader], components.ProvideStorageBackend[ diff --git a/beacond/cmd/types.go b/beacond/cmd/types.go index 32f851a73e..a0066600b6 100644 --- a/beacond/cmd/types.go +++ b/beacond/cmd/types.go @@ -129,18 +129,21 @@ type ( *BeaconBlockBody, *Deposit, *ExecutionPayload, + Log, WithdrawalCredentials, ] // EngineClient is a type alias for the engine client. EngineClient = engineclient.EngineClient[ *ExecutionPayload, + Log, *PayloadAttributes, ] // EngineClient is a type alias for the engine client. ExecutionEngine = execution.Engine[ *ExecutionPayload, + Log, *PayloadAttributes, PayloadID, engineprimitives.Withdrawals, @@ -246,7 +249,7 @@ type ( // BeaconBlock type aliases. BeaconBlock = types.BeaconBlock - BeaconBlockBody = types.BeaconBlockBody + BeaconBlockBody = types.BeaconBlockBody[Log] BeaconBlockHeader = types.BeaconBlockHeader // BeaconState is a type alias for the BeaconState. @@ -290,11 +293,12 @@ type ( Context = transition.Context // Deposit is a type alias for the deposit. - Deposit = types.Deposit + Deposit = types.Deposit[Log] // DepositContract is a type alias for the deposit contract. DepositContract = deposit.WrappedBeaconDepositContract[ *Deposit, + Log, WithdrawalCredentials, ] @@ -320,6 +324,9 @@ type ( *ExecutionPayloadHeader, ] + // Log is a type alias for the log. + Log = engineprimitives.Log + // Logger is a type alias for the logger. Logger = phuslu.Logger diff --git a/mod/cli/pkg/commands/genesis/collect.go b/mod/cli/pkg/commands/genesis/collect.go index d11b4b13ae..79b3f9bafc 100644 --- a/mod/cli/pkg/commands/genesis/collect.go +++ b/mod/cli/pkg/commands/genesis/collect.go @@ -27,6 +27,7 @@ import ( "github.com/berachain/beacon-kit/mod/cli/pkg/context" "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/errors" "github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -59,7 +60,7 @@ func CollectGenesisDepositsCmd() *cobra.Command { return err } - var deposits []*types.Deposit + var deposits []*types.Deposit[engineprimitives.Log] if deposits, err = CollectValidatorJSONFiles( filepath.Join(config.RootDir, "config", "premined-deposits"), appGenesis, @@ -71,7 +72,7 @@ func CollectGenesisDepositsCmd() *cobra.Command { } genesisInfo := &types.Genesis[ - *types.Deposit, + *types.Deposit[engineprimitives.Log], *types.ExecutionPayloadHeader, ]{} @@ -110,7 +111,7 @@ func CollectGenesisDepositsCmd() *cobra.Command { func CollectValidatorJSONFiles( genTxsDir string, genesis *genutiltypes.AppGenesis, -) ([]*types.Deposit, error) { +) ([]*types.Deposit[engineprimitives.Log], error) { // prepare a map of all balances in genesis state to then validate // against the validators addresses var appState map[string]json.RawMessage @@ -125,7 +126,7 @@ func CollectValidatorJSONFiles( } // prepare the list of validators - deposits := make([]*types.Deposit, 0) + deposits := make([]*types.Deposit[engineprimitives.Log], 0) for _, fo := range fos { if fo.IsDir() { continue @@ -143,7 +144,7 @@ func CollectValidatorJSONFiles( return nil, err } - val := &types.Deposit{} + val := &types.Deposit[engineprimitives.Log]{} if err = json.Unmarshal(bz, val); err != nil { return nil, err } diff --git a/mod/cli/pkg/commands/genesis/deposit.go b/mod/cli/pkg/commands/genesis/deposit.go index bef7984ca7..55da78ef54 100644 --- a/mod/cli/pkg/commands/genesis/deposit.go +++ b/mod/cli/pkg/commands/genesis/deposit.go @@ -28,6 +28,7 @@ import ( "github.com/berachain/beacon-kit/mod/cli/pkg/context" "github.com/berachain/beacon-kit/mod/cli/pkg/utils/parser" "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/errors" "github.com/berachain/beacon-kit/mod/node-core/pkg/components" "github.com/berachain/beacon-kit/mod/node-core/pkg/components/signer" @@ -116,7 +117,7 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command { return err } - deposit := types.Deposit{ + deposit := types.Deposit[engineprimitives.Log]{ Pubkey: depositMsg.Pubkey, Amount: depositMsg.Amount, Signature: signature, @@ -165,7 +166,7 @@ func makeOutputFilepath(rootDir, pubkey string) (string, error) { func writeDepositToFile( outputDocument string, - depositMessage *types.Deposit, + depositMessage *types.Deposit[engineprimitives.Log], ) error { //#nosec:G302,G304 // Ignore errors on this line. outputFile, err := afero.NewOsFs().OpenFile( diff --git a/mod/cli/pkg/commands/genesis/payload.go b/mod/cli/pkg/commands/genesis/payload.go index deccc019ad..978490846c 100644 --- a/mod/cli/pkg/commands/genesis/payload.go +++ b/mod/cli/pkg/commands/genesis/payload.go @@ -83,7 +83,8 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command { } genesisInfo := &types.Genesis[ - *types.Deposit, *types.ExecutionPayloadHeader, + *types.Deposit[engineprimitives.Log], + *types.ExecutionPayloadHeader, ]{} if err = json.Unmarshal( diff --git a/mod/consensus-types/go.mod b/mod/consensus-types/go.mod index e271d2a9fb..c4be777f0b 100644 --- a/mod/consensus-types/go.mod +++ b/mod/consensus-types/go.mod @@ -44,7 +44,7 @@ require ( github.com/deckarep/golang-set/v2 v2.6.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.3 // indirect - github.com/ethereum/go-ethereum v1.14.7 // indirect + github.com/ethereum/go-ethereum v1.14.7 github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect github.com/getsentry/sentry-go v0.28.1 // indirect github.com/go-ole/go-ole v1.3.0 // indirect diff --git a/mod/consensus-types/pkg/types/block.go b/mod/consensus-types/pkg/types/block.go index 52036d1a5c..466b1d600c 100644 --- a/mod/consensus-types/pkg/types/block.go +++ b/mod/consensus-types/pkg/types/block.go @@ -21,6 +21,7 @@ package types import ( + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" "github.com/berachain/beacon-kit/mod/primitives/pkg/version" @@ -41,7 +42,7 @@ type BeaconBlock struct { StateRoot common.Root `json:"state_root"` // Body is the body of the BeaconBlock, containing the block's // operations. - Body *BeaconBlockBody `json:"body"` + Body *BeaconBlockBody[engineprimitives.Log] `json:"body"` } // Empty creates an empty beacon block. @@ -67,7 +68,7 @@ func (b *BeaconBlock) NewWithVersion( ProposerIndex: proposerIndex, ParentRoot: parentBlockRoot, StateRoot: common.Root{}, - Body: &BeaconBlockBody{}, + Body: &BeaconBlockBody[engineprimitives.Log]{}, } default: return &BeaconBlock{}, ErrForkVersionNotSupported @@ -218,7 +219,7 @@ func (b *BeaconBlock) SetStateRoot(root common.Root) { } // GetBody retrieves the body of the BeaconBlock. -func (b *BeaconBlock) GetBody() *BeaconBlockBody { +func (b *BeaconBlock) GetBody() *BeaconBlockBody[engineprimitives.Log] { return b.Body } diff --git a/mod/consensus-types/pkg/types/block_test.go b/mod/consensus-types/pkg/types/block_test.go index 8d2a2b9271..1ccb1d1ed6 100644 --- a/mod/consensus-types/pkg/types/block_test.go +++ b/mod/consensus-types/pkg/types/block_test.go @@ -40,7 +40,7 @@ func generateValidBeaconBlock() *types.BeaconBlock { ProposerIndex: 5, ParentRoot: common.Root{1, 2, 3, 4, 5}, StateRoot: common.Root{5, 4, 3, 2, 1}, - Body: &types.BeaconBlockBody{ + Body: &types.BeaconBlockBody[engineprimitives.Log]{ ExecutionPayload: &types.ExecutionPayload{ Number: 10, ExtraData: []byte("dummy extra data for testing"), @@ -56,7 +56,7 @@ func generateValidBeaconBlock() *types.BeaconBlock { BaseFeePerGas: math.NewU256(0), }, Eth1Data: &types.Eth1Data{}, - Deposits: []*types.Deposit{ + Deposits: []*types.Deposit[engineprimitives.Log]{ { Index: 1, }, diff --git a/mod/consensus-types/pkg/types/body.go b/mod/consensus-types/pkg/types/body.go index 456108eba6..429154efe0 100644 --- a/mod/consensus-types/pkg/types/body.go +++ b/mod/consensus-types/pkg/types/body.go @@ -51,22 +51,6 @@ const ( ExtraDataSize = 32 ) -// Empty returns a new BeaconBlockBody with empty fields -// for the given fork version. -func (b *BeaconBlockBody) Empty(forkVersion uint32) *BeaconBlockBody { - switch forkVersion { - case version.Deneb: - return &BeaconBlockBody{ - Eth1Data: new(Eth1Data), - ExecutionPayload: &ExecutionPayload{ - ExtraData: make([]byte, ExtraDataSize), - }, - } - default: - panic("unsupported fork version") - } -} - // BlockBodyKZGOffset returns the offset of the KZG commitments in the block // body. // TODO: I still feel like we need to clean this up somehow. @@ -84,7 +68,10 @@ func BlockBodyKZGOffset( // BeaconBlockBody represents the body of a beacon block in the Deneb // chain. -type BeaconBlockBody struct { +type BeaconBlockBody[LogT interface { + GetTopics() []common.ExecutionHash + GetData() []byte +}] struct { // RandaoReveal is the reveal of the RANDAO. RandaoReveal crypto.BLSSignature // Eth1Data is the data from the Eth1 chain. @@ -92,19 +79,37 @@ type BeaconBlockBody struct { // Graffiti is for a fun message or meme. Graffiti [32]byte // Deposits is the list of deposits included in the body. - Deposits []*Deposit + Deposits []*Deposit[LogT] // ExecutionPayload is the execution payload of the body. ExecutionPayload *ExecutionPayload // BlobKzgCommitments is the list of KZG commitments for the EIP-4844 blobs. BlobKzgCommitments []eip4844.KZGCommitment } +// Empty returns a new BeaconBlockBody with empty fields +// for the given fork version. +func (b *BeaconBlockBody[LogT]) Empty( + forkVersion uint32, +) *BeaconBlockBody[LogT] { + switch forkVersion { + case version.Deneb: + return &BeaconBlockBody[LogT]{ + Eth1Data: new(Eth1Data), + ExecutionPayload: &ExecutionPayload{ + ExtraData: make([]byte, ExtraDataSize), + }, + } + default: + panic("unsupported fork version") + } +} + /* -------------------------------------------------------------------------- */ /* SSZ */ /* -------------------------------------------------------------------------- */ // SizeSSZ returns the size of the BeaconBlockBody in SSZ. -func (b *BeaconBlockBody) SizeSSZ(fixed bool) uint32 { +func (b *BeaconBlockBody[_]) SizeSSZ(fixed bool) uint32 { var size uint32 = 96 + 72 + 32 + 4 + 4 + 4 if fixed { return size @@ -119,7 +124,7 @@ func (b *BeaconBlockBody) SizeSSZ(fixed bool) uint32 { // DefineSSZ defines the SSZ serialization of the BeaconBlockBody. // //nolint:mnd // TODO: chainspec. -func (b *BeaconBlockBody) DefineSSZ(codec *ssz.Codec) { +func (b *BeaconBlockBody[_]) DefineSSZ(codec *ssz.Codec) { // Define the static data (fields and dynamic offsets) ssz.DefineStaticBytes(codec, &b.RandaoReveal) ssz.DefineStaticObject(codec, &b.Eth1Data) @@ -135,18 +140,18 @@ func (b *BeaconBlockBody) DefineSSZ(codec *ssz.Codec) { } // MarshalSSZ serializes the BeaconBlockBody to SSZ-encoded bytes. -func (b *BeaconBlockBody) MarshalSSZ() ([]byte, error) { +func (b *BeaconBlockBody[_]) MarshalSSZ() ([]byte, error) { buf := make([]byte, b.SizeSSZ(false)) return buf, ssz.EncodeToBytes(buf, b) } // UnmarshalSSZ deserializes the BeaconBlockBody from SSZ-encoded bytes. -func (b *BeaconBlockBody) UnmarshalSSZ(buf []byte) error { +func (b *BeaconBlockBody[_]) UnmarshalSSZ(buf []byte) error { return ssz.DecodeFromBytes(buf, b) } // HashTreeRoot returns the SSZ hash tree root of the BeaconBlockBody. -func (b *BeaconBlockBody) HashTreeRoot() common.Root { +func (b *BeaconBlockBody[_]) HashTreeRoot() common.Root { return ssz.HashConcurrent(b) } @@ -155,7 +160,7 @@ func (b *BeaconBlockBody) HashTreeRoot() common.Root { /* -------------------------------------------------------------------------- */ // MarshalSSZTo serializes the BeaconBlockBody into a writer. -func (b *BeaconBlockBody) MarshalSSZTo(dst []byte) ([]byte, error) { +func (b *BeaconBlockBody[_]) MarshalSSZTo(dst []byte) ([]byte, error) { bz, err := b.MarshalSSZ() if err != nil { return nil, err @@ -167,7 +172,7 @@ func (b *BeaconBlockBody) MarshalSSZTo(dst []byte) ([]byte, error) { // HashTreeRootWith ssz hashes the BeaconBlockBody object with a hasher. // //nolint:mnd // todo fix. -func (b *BeaconBlockBody) HashTreeRootWith(hh fastssz.HashWalker) error { +func (b *BeaconBlockBody[_]) HashTreeRootWith(hh fastssz.HashWalker) error { indx := hh.Index() // Field (0) 'RandaoReveal' @@ -226,24 +231,24 @@ func (b *BeaconBlockBody) HashTreeRootWith(hh fastssz.HashWalker) error { } // GetTree ssz hashes the BeaconBlockBody object. -func (b *BeaconBlockBody) GetTree() (*fastssz.Node, error) { +func (b *BeaconBlockBody[_]) GetTree() (*fastssz.Node, error) { return fastssz.ProofTree(b) } // IsNil checks if the BeaconBlockBody is nil. -func (b *BeaconBlockBody) IsNil() bool { +func (b *BeaconBlockBody[_]) IsNil() bool { return b == nil } // GetExecutionPayload returns the ExecutionPayload of the Body. func ( - b *BeaconBlockBody, + b *BeaconBlockBody[_], ) GetExecutionPayload() *ExecutionPayload { return b.ExecutionPayload } // SetExecutionPayload sets the ExecutionData of the BeaconBlockBody. -func (b *BeaconBlockBody) SetExecutionPayload( +func (b *BeaconBlockBody[_]) SetExecutionPayload( executionData *ExecutionPayload, ) { b.ExecutionPayload = executionData @@ -251,51 +256,51 @@ func (b *BeaconBlockBody) SetExecutionPayload( // GetBlobKzgCommitments returns the BlobKzgCommitments of the Body. func ( - b *BeaconBlockBody, + b *BeaconBlockBody[_], ) GetBlobKzgCommitments() eip4844.KZGCommitments[common.ExecutionHash] { return b.BlobKzgCommitments } // SetBlobKzgCommitments sets the BlobKzgCommitments of the // BeaconBlockBody. -func (b *BeaconBlockBody) SetBlobKzgCommitments( +func (b *BeaconBlockBody[_]) SetBlobKzgCommitments( commitments eip4844.KZGCommitments[common.ExecutionHash], ) { b.BlobKzgCommitments = commitments } // SetEth1Data sets the Eth1Data of the BeaconBlockBody. -func (b *BeaconBlockBody) SetEth1Data(eth1Data *Eth1Data) { +func (b *BeaconBlockBody[_]) SetEth1Data(eth1Data *Eth1Data) { b.Eth1Data = eth1Data } -// SetDeposits is not implemented for BeaconBlockDeneb. -func (b *BeaconBlockBody) GetAttestations() []*AttestationData { +// GetAttestations is not implemented for BeaconBlockDeneb. +func (b *BeaconBlockBody[_]) GetAttestations() []*AttestationData { panic("not implemented") } -// SetDeposits is not implemented for BeaconBlockDeneb. -func (b *BeaconBlockBody) SetAttestations(_ []*AttestationData) { +// SetAttestations is not implemented for BeaconBlockDeneb. +func (b *BeaconBlockBody[_]) SetAttestations(_ []*AttestationData) { panic("not implemented") } // GetSlashingInfo is not implemented for BeaconBlockDeneb. -func (b *BeaconBlockBody) GetSlashingInfo() []*SlashingInfo { +func (b *BeaconBlockBody[_]) GetSlashingInfo() []*SlashingInfo { panic("not implemented") } // SetSlashingInfo is not implemented for BeaconBlockDeneb. -func (b *BeaconBlockBody) SetSlashingInfo(_ []*SlashingInfo) { +func (b *BeaconBlockBody[_]) SetSlashingInfo(_ []*SlashingInfo) { panic("not implemented") } // GetTopLevelRoots returns the top-level roots of the BeaconBlockBody. -func (b *BeaconBlockBody) GetTopLevelRoots() []common.Root { +func (b *BeaconBlockBody[LogT]) GetTopLevelRoots() []common.Root { return []common.Root{ common.Root(b.GetRandaoReveal().HashTreeRoot()), b.Eth1Data.HashTreeRoot(), common.Root(b.GetGraffiti().HashTreeRoot()), - Deposits(b.GetDeposits()).HashTreeRoot(), + Deposits[LogT](b.GetDeposits()).HashTreeRoot(), b.GetExecutionPayload().HashTreeRoot(), // I think this is a bug. common.Root{}, @@ -303,41 +308,41 @@ func (b *BeaconBlockBody) GetTopLevelRoots() []common.Root { } // Length returns the number of fields in the BeaconBlockBody struct. -func (b *BeaconBlockBody) Length() uint64 { +func (b *BeaconBlockBody[_]) Length() uint64 { return BodyLengthDeneb } // GetRandaoReveal returns the RandaoReveal of the Body. -func (b *BeaconBlockBody) GetRandaoReveal() crypto.BLSSignature { +func (b *BeaconBlockBody[_]) GetRandaoReveal() crypto.BLSSignature { return b.RandaoReveal } // SetRandaoReveal sets the RandaoReveal of the Body. -func (b *BeaconBlockBody) SetRandaoReveal(reveal crypto.BLSSignature) { +func (b *BeaconBlockBody[_]) SetRandaoReveal(reveal crypto.BLSSignature) { b.RandaoReveal = reveal } // GetEth1Data returns the Eth1Data of the Body. -func (b *BeaconBlockBody) GetEth1Data() *Eth1Data { +func (b *BeaconBlockBody[_]) GetEth1Data() *Eth1Data { return b.Eth1Data } // GetGraffiti returns the Graffiti of the Body. -func (b *BeaconBlockBody) GetGraffiti() common.Bytes32 { +func (b *BeaconBlockBody[_]) GetGraffiti() common.Bytes32 { return b.Graffiti } // SetGraffiti sets the Graffiti of the Body. -func (b *BeaconBlockBody) SetGraffiti(graffiti common.Bytes32) { +func (b *BeaconBlockBody[_]) SetGraffiti(graffiti common.Bytes32) { b.Graffiti = graffiti } // GetDeposits returns the Deposits of the BeaconBlockBody. -func (b *BeaconBlockBody) GetDeposits() []*Deposit { +func (b *BeaconBlockBody[LogT]) GetDeposits() []*Deposit[LogT] { return b.Deposits } // SetDeposits sets the Deposits of the BeaconBlockBody. -func (b *BeaconBlockBody) SetDeposits(deposits []*Deposit) { +func (b *BeaconBlockBody[LogT]) SetDeposits(deposits []*Deposit[LogT]) { b.Deposits = deposits } diff --git a/mod/consensus-types/pkg/types/body_test.go b/mod/consensus-types/pkg/types/body_test.go index b96046531f..28dd963327 100644 --- a/mod/consensus-types/pkg/types/body_test.go +++ b/mod/consensus-types/pkg/types/body_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/primitives/pkg/bytes" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" @@ -33,12 +34,12 @@ import ( "github.com/stretchr/testify/require" ) -func generateBeaconBlockBody() types.BeaconBlockBody { - return types.BeaconBlockBody{ +func generateBeaconBlockBody() types.BeaconBlockBody[engineprimitives.Log] { + return types.BeaconBlockBody[engineprimitives.Log]{ RandaoReveal: [96]byte{1, 2, 3}, Eth1Data: &types.Eth1Data{}, Graffiti: [32]byte{4, 5, 6}, - Deposits: []*types.Deposit{}, + Deposits: []*types.Deposit[engineprimitives.Log]{}, ExecutionPayload: &types.ExecutionPayload{ BaseFeePerGas: math.NewU256(0), }, @@ -47,11 +48,11 @@ func generateBeaconBlockBody() types.BeaconBlockBody { } func TestBeaconBlockBodyBase(t *testing.T) { - body := types.BeaconBlockBody{ + body := types.BeaconBlockBody[engineprimitives.Log]{ RandaoReveal: [96]byte{1, 2, 3}, Eth1Data: &types.Eth1Data{}, Graffiti: [32]byte{4, 5, 6}, - Deposits: []*types.Deposit{}, + Deposits: []*types.Deposit[engineprimitives.Log]{}, } require.Equal(t, bytes.B96{1, 2, 3}, body.GetRandaoReveal()) @@ -65,11 +66,11 @@ func TestBeaconBlockBodyBase(t *testing.T) { } func TestBeaconBlockBody(t *testing.T) { - body := types.BeaconBlockBody{ + body := types.BeaconBlockBody[engineprimitives.Log]{ RandaoReveal: [96]byte{1, 2, 3}, Eth1Data: &types.Eth1Data{}, Graffiti: [32]byte{4, 5, 6}, - Deposits: []*types.Deposit{}, + Deposits: []*types.Deposit[engineprimitives.Log]{}, ExecutionPayload: &types.ExecutionPayload{}, BlobKzgCommitments: []eip4844.KZGCommitment{}, } @@ -88,7 +89,7 @@ func TestBeaconBlockBody_GetTree(t *testing.T) { } func TestBeaconBlockBody_SetBlobKzgCommitments(t *testing.T) { - body := types.BeaconBlockBody{} + body := types.BeaconBlockBody[engineprimitives.Log]{} commitments := eip4844.KZGCommitments[common.ExecutionHash]{} body.SetBlobKzgCommitments(commitments) @@ -96,7 +97,7 @@ func TestBeaconBlockBody_SetBlobKzgCommitments(t *testing.T) { } func TestBeaconBlockBody_SetRandaoReveal(t *testing.T) { - body := types.BeaconBlockBody{} + body := types.BeaconBlockBody[engineprimitives.Log]{} randaoReveal := crypto.BLSSignature{1, 2, 3} body.SetRandaoReveal(randaoReveal) @@ -104,7 +105,7 @@ func TestBeaconBlockBody_SetRandaoReveal(t *testing.T) { } func TestBeaconBlockBody_SetEth1Data(t *testing.T) { - body := types.BeaconBlockBody{} + body := types.BeaconBlockBody[engineprimitives.Log]{} eth1Data := &types.Eth1Data{} body.SetEth1Data(eth1Data) @@ -112,19 +113,19 @@ func TestBeaconBlockBody_SetEth1Data(t *testing.T) { } func TestBeaconBlockBody_SetDeposits(t *testing.T) { - body := types.BeaconBlockBody{} - deposits := []*types.Deposit{} + body := types.BeaconBlockBody[engineprimitives.Log]{} + deposits := []*types.Deposit[engineprimitives.Log]{} body.SetDeposits(deposits) require.Equal(t, deposits, body.GetDeposits()) } func TestBeaconBlockBody_MarshalSSZ(t *testing.T) { - body := types.BeaconBlockBody{ + body := types.BeaconBlockBody[engineprimitives.Log]{ RandaoReveal: [96]byte{1, 2, 3}, Eth1Data: &types.Eth1Data{}, Graffiti: [32]byte{4, 5, 6}, - Deposits: []*types.Deposit{}, + Deposits: []*types.Deposit[engineprimitives.Log]{}, ExecutionPayload: &types.ExecutionPayload{}, BlobKzgCommitments: []eip4844.KZGCommitment{}, } @@ -156,7 +157,7 @@ func TestBeaconBlockBody_GetTopLevelRoots(t *testing.T) { } func TestBeaconBlockBody_Empty(t *testing.T) { - blockBody := types.BeaconBlockBody{} + blockBody := types.BeaconBlockBody[engineprimitives.Log]{} body := blockBody.Empty(version.Deneb) require.NotNil(t, body) } diff --git a/mod/consensus-types/pkg/types/deposit.go b/mod/consensus-types/pkg/types/deposit.go index a205abdf60..c9a22d0862 100644 --- a/mod/consensus-types/pkg/types/deposit.go +++ b/mod/consensus-types/pkg/types/deposit.go @@ -21,26 +21,46 @@ package types import ( + "encoding/binary" + "fmt" + + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" + "github.com/berachain/beacon-kit/mod/primitives/pkg/bytes" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/constraints" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" + gethcrypto "github.com/ethereum/go-ethereum/crypto" fastssz "github.com/ferranbt/fastssz" "github.com/karalabe/ssz" ) -// DepositSize is the size of the SSZ encoding of a Deposit. -const DepositSize = 192 // 48 + 32 + 8 + 96 + 8 +const ( + // DepositSize is the size of the SSZ encoding of a Deposit. + DepositSize = 192 // 48 + 32 + 8 + 96 + 8 + + // DepositEventSignatureString is the Deposit event signature human + // readable string that should be keccak256 hashed for the event's topic. + DepositEventSignatureString = "Deposit(bytes,bytes,uint64,bytes,uint64)" +) + +//nolint:gochecknoglobals // TODO: remove usage of geth's crypto.Keccak256. +var DepositEventSignature = common.ExecutionHash( + gethcrypto.Keccak256([]byte(DepositEventSignatureString)), +) // Compile-time assertions to ensure Deposit implements necessary interfaces. var ( - _ ssz.StaticObject = (*Deposit)(nil) - _ constraints.SSZMarshallableRootable = (*Deposit)(nil) + _ ssz.StaticObject = &Deposit[engineprimitives.Log]{} + _ constraints.SSZMarshallableRootable = &Deposit[engineprimitives.Log]{} ) // Deposit into the consensus layer from the deposit contract in the execution // layer. -type Deposit struct { +type Deposit[LogT interface { + GetTopics() []common.ExecutionHash + GetData() []byte +}] struct { // Public key of the validator specified in the deposit. Pubkey crypto.BLSPubkey `json:"pubkey"` // A staking credentials with @@ -55,14 +75,17 @@ type Deposit struct { } // NewDeposit creates a new Deposit instance. -func NewDeposit( +func NewDeposit[LogT interface { + GetTopics() []common.ExecutionHash + GetData() []byte +}]( pubkey crypto.BLSPubkey, credentials WithdrawalCredentials, amount math.Gwei, signature crypto.BLSSignature, index uint64, -) *Deposit { - return &Deposit{ +) *Deposit[LogT] { + return &Deposit[LogT]{ Pubkey: pubkey, Credentials: credentials, Amount: amount, @@ -72,25 +95,25 @@ func NewDeposit( } // Empty creates an empty Deposit instance. -func (d *Deposit) Empty() *Deposit { - return &Deposit{} +func (d *Deposit[LogT]) Empty() *Deposit[LogT] { + return &Deposit[LogT]{} } // New creates a new Deposit instance. -func (d *Deposit) New( +func (d *Deposit[LogT]) New( pubkey crypto.BLSPubkey, credentials WithdrawalCredentials, amount math.Gwei, signature crypto.BLSSignature, index uint64, -) *Deposit { - return NewDeposit( +) *Deposit[LogT] { + return NewDeposit[LogT]( pubkey, credentials, amount, signature, index, ) } // VerifySignature verifies the deposit data and signature. -func (d *Deposit) VerifySignature( +func (d *Deposit[_]) VerifySignature( forkData *ForkData, domainType common.DomainType, signatureVerificationFn func( @@ -112,7 +135,7 @@ func (d *Deposit) VerifySignature( /* -------------------------------------------------------------------------- */ // DefineSSZ defines the SSZ encoding for the Deposit object. -func (d *Deposit) DefineSSZ(c *ssz.Codec) { +func (d *Deposit[_]) DefineSSZ(c *ssz.Codec) { ssz.DefineStaticBytes(c, &d.Pubkey) ssz.DefineStaticBytes(c, &d.Credentials) ssz.DefineUint64(c, &d.Amount) @@ -121,23 +144,23 @@ func (d *Deposit) DefineSSZ(c *ssz.Codec) { } // MarshalSSZ marshals the Deposit object to SSZ format. -func (d *Deposit) MarshalSSZ() ([]byte, error) { +func (d *Deposit[_]) MarshalSSZ() ([]byte, error) { buf := make([]byte, d.SizeSSZ()) return buf, ssz.EncodeToBytes(buf, d) } // UnmarshalSSZ unmarshals the Deposit object from SSZ format. -func (d *Deposit) UnmarshalSSZ(buf []byte) error { +func (d *Deposit[_]) UnmarshalSSZ(buf []byte) error { return ssz.DecodeFromBytes(buf, d) } // SizeSSZ returns the SSZ encoded size of the Deposit object. -func (d *Deposit) SizeSSZ() uint32 { +func (d *Deposit[_]) SizeSSZ() uint32 { return DepositSize } // HashTreeRoot computes the Merkleization of the Deposit object. -func (d *Deposit) HashTreeRoot() common.Root { +func (d *Deposit[_]) HashTreeRoot() common.Root { return ssz.HashSequential(d) } @@ -146,7 +169,7 @@ func (d *Deposit) HashTreeRoot() common.Root { /* -------------------------------------------------------------------------- */ // MarshalSSZTo marshals the Deposit object into a pre-allocated byte slice. -func (d *Deposit) MarshalSSZTo(dst []byte) ([]byte, error) { +func (d *Deposit[_]) MarshalSSZTo(dst []byte) ([]byte, error) { bz, err := d.MarshalSSZ() if err != nil { return nil, err @@ -156,7 +179,7 @@ func (d *Deposit) MarshalSSZTo(dst []byte) ([]byte, error) { } // HashTreeRootWith ssz hashes the Deposit object with a hasher. -func (d *Deposit) HashTreeRootWith(hh fastssz.HashWalker) error { +func (d *Deposit[_]) HashTreeRootWith(hh fastssz.HashWalker) error { indx := hh.Index() // Field (0) 'Pubkey' @@ -179,35 +202,69 @@ func (d *Deposit) HashTreeRootWith(hh fastssz.HashWalker) error { } // GetTree ssz hashes the Deposit object. -func (d *Deposit) GetTree() (*fastssz.Node, error) { +func (d *Deposit[_]) GetTree() (*fastssz.Node, error) { return fastssz.ProofTree(d) } +/* -------------------------------------------------------------------------- */ +/* EthLog */ +/* -------------------------------------------------------------------------- */ + +// UnmarshalLog unmarshals the Deposit object from an Ethereum log. +// +// TODO: use abi decoding or constants for reading the bytes. +func (d *Deposit[LogT]) UnmarshalLog(log LogT) error { + topics := log.GetTopics() + if len(topics) != 1 { + return fmt.Errorf("expected 1 topic, got %d", len(topics)) + } + if topics[0] != DepositEventSignature { + return fmt.Errorf( + "expected topic %s, got %s", DepositEventSignature, topics[0], + ) + } + + data := log.GetData() + if len(data) < 448 { + return fmt.Errorf( + "log data is too short: expected at least 448 bytes, got %d", + len(data), + ) + } + + d.Index = binary.BigEndian.Uint64(data[152:160]) + d.Pubkey = bytes.B48(data[208:256]) + d.Amount = math.U64(binary.BigEndian.Uint64(data[280:288])) + d.Credentials = WithdrawalCredentials(bytes.B32(data[288:320])) + d.Signature = bytes.B96(data[352:448]) + return nil +} + /* -------------------------------------------------------------------------- */ /* Getters and Setters */ /* -------------------------------------------------------------------------- */ // GetAmount returns the deposit amount in gwei. -func (d *Deposit) GetAmount() math.Gwei { +func (d *Deposit[_]) GetAmount() math.Gwei { return d.Amount } // GetPubkey returns the public key of the validator specified in the deposit. -func (d *Deposit) GetPubkey() crypto.BLSPubkey { +func (d *Deposit[_]) GetPubkey() crypto.BLSPubkey { return d.Pubkey } // GetIndex returns the index of the deposit in the deposit contract. -func (d *Deposit) GetIndex() math.U64 { +func (d *Deposit[_]) GetIndex() math.U64 { return math.U64(d.Index) } // GetSignature returns the signature of the deposit data. -func (d *Deposit) GetSignature() crypto.BLSSignature { +func (d *Deposit[_]) GetSignature() crypto.BLSSignature { return d.Signature } // GetWithdrawalCredentials returns the staking credentials of the deposit. -func (d *Deposit) GetWithdrawalCredentials() WithdrawalCredentials { +func (d *Deposit[_]) GetWithdrawalCredentials() WithdrawalCredentials { return d.Credentials } diff --git a/mod/consensus-types/pkg/types/deposit_test.go b/mod/consensus-types/pkg/types/deposit_test.go index 5e9fb5b474..04cab4d9fc 100644 --- a/mod/consensus-types/pkg/types/deposit_test.go +++ b/mod/consensus-types/pkg/types/deposit_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" @@ -33,14 +34,14 @@ import ( ) // generateValidDeposit generates a valid deposit for testing purposes. -func generateValidDeposit() *types.Deposit { +func generateValidDeposit() *types.Deposit[engineprimitives.Log] { var pubKey crypto.BLSPubkey var signature crypto.BLSSignature var credentials types.WithdrawalCredentials amount := math.Gwei(32) index := uint64(1) - return &types.Deposit{ + return &types.Deposit[engineprimitives.Log]{ Pubkey: pubKey, Credentials: credentials, Amount: amount, @@ -69,7 +70,7 @@ func TestDeposit_MarshalUnmarshalSSZ(t *testing.T) { require.NoError(t, err) require.NotNil(t, sszDeposit) - var unmarshalledDeposit types.Deposit + var unmarshalledDeposit types.Deposit[engineprimitives.Log] err = unmarshalledDeposit.UnmarshalSSZ(sszDeposit) require.NoError(t, err) @@ -116,7 +117,7 @@ func TestDeposit_UnmarshalSSZ_ErrSize(t *testing.T) { // Create a byte slice of incorrect size buf := make([]byte, 10) // size less than 192 - var unmarshalledDeposit types.Deposit + var unmarshalledDeposit types.Deposit[engineprimitives.Log] err := unmarshalledDeposit.UnmarshalSSZ(buf) require.ErrorIs(t, err, io.ErrUnexpectedEOF) diff --git a/mod/consensus-types/pkg/types/deposits.go b/mod/consensus-types/pkg/types/deposits.go index fa01d881e7..155e7c2f54 100644 --- a/mod/consensus-types/pkg/types/deposits.go +++ b/mod/consensus-types/pkg/types/deposits.go @@ -27,34 +27,37 @@ import ( ) // Deposits is a typealias for a list of Deposits. -type Deposits []*Deposit +type Deposits[LogT interface { + GetTopics() []common.ExecutionHash + GetData() []byte +}] []*Deposit[LogT] /* -------------------------------------------------------------------------- */ /* SSZ */ /* -------------------------------------------------------------------------- */ // SizeSSZ returns the SSZ encoded size in bytes for the Deposits. -func (ds Deposits) SizeSSZ(bool) uint32 { - return ssz.SizeSliceOfStaticObjects(([]*Deposit)(ds)) +func (ds Deposits[LogT]) SizeSSZ(bool) uint32 { + return ssz.SizeSliceOfStaticObjects(([]*Deposit[LogT])(ds)) } // DefineSSZ defines the SSZ encoding for the Deposits object. -func (ds Deposits) DefineSSZ(c *ssz.Codec) { +func (ds Deposits[LogT]) DefineSSZ(c *ssz.Codec) { c.DefineDecoder(func(*ssz.Decoder) { ssz.DefineSliceOfStaticObjectsContent( - c, (*[]*Deposit)(&ds), constants.MaxDepositsPerBlock) + c, (*[]*Deposit[LogT])(&ds), constants.MaxDepositsPerBlock) }) c.DefineEncoder(func(*ssz.Encoder) { ssz.DefineSliceOfStaticObjectsContent( - c, (*[]*Deposit)(&ds), constants.MaxDepositsPerBlock) + c, (*[]*Deposit[LogT])(&ds), constants.MaxDepositsPerBlock) }) c.DefineHasher(func(*ssz.Hasher) { ssz.DefineSliceOfStaticObjectsOffset( - c, (*[]*Deposit)(&ds), constants.MaxDepositsPerBlock) + c, (*[]*Deposit[LogT])(&ds), constants.MaxDepositsPerBlock) }) } // HashTreeRoot returns the hash tree root of the Deposits. -func (ds Deposits) HashTreeRoot() common.Root { +func (ds Deposits[_]) HashTreeRoot() common.Root { return ssz.HashSequential(ds) } diff --git a/mod/consensus-types/pkg/types/genesis.go b/mod/consensus-types/pkg/types/genesis.go index 6dc80054ea..d1d4f5e590 100644 --- a/mod/consensus-types/pkg/types/genesis.go +++ b/mod/consensus-types/pkg/types/genesis.go @@ -108,7 +108,7 @@ func (g *Genesis[DepositT, ExecutionPayloadHeaderT]) UnmarshalJSON( // DefaultGenesisDeneb returns a the default genesis. func DefaultGenesisDeneb() *Genesis[ - *Deposit, *ExecutionPayloadHeader, + *Deposit[engineprimitives.Log], *ExecutionPayloadHeader, ] { defaultHeader, err := DefaultGenesisExecutionPayloadHeaderDeneb() @@ -117,11 +117,11 @@ func DefaultGenesisDeneb() *Genesis[ } // TODO: Uncouple from deneb. - return &Genesis[*Deposit, *ExecutionPayloadHeader]{ + return &Genesis[*Deposit[engineprimitives.Log], *ExecutionPayloadHeader]{ ForkVersion: version.FromUint32[common.Version]( version.Deneb, ), - Deposits: make([]*Deposit, 0), + Deposits: make([]*Deposit[engineprimitives.Log], 0), ExecutionPayloadHeader: defaultHeader, } } diff --git a/mod/consensus/pkg/cometbft/service/abci.go b/mod/consensus/pkg/cometbft/service/abci.go index 19acd798bc..cc9bfa74e6 100644 --- a/mod/consensus/pkg/cometbft/service/abci.go +++ b/mod/consensus/pkg/cometbft/service/abci.go @@ -67,14 +67,16 @@ func (s *Service[LoggerT]) InitChain( req.ChainId, ) - // Set the initial height, which will be used to determine if we are proposing + // Set the initial height, which will be used to determine if we are + // proposing // or processing the first block or not. s.initialHeight = req.InitialHeight if s.initialHeight == 0 { s.initialHeight = 1 } - // if req.InitialHeight is > 1, then we set the initial version on all stores + // if req.InitialHeight is > 1, then we set the initial version on all + // stores if req.InitialHeight > 1 { if err := s.sm.CommitMultiStore(). SetInitialVersion(req.InitialHeight); err != nil { @@ -121,7 +123,8 @@ func (s *Service[LoggerT]) InitChain( } } - // NOTE: We don't commit, but FinalizeBlock for block InitialHeight starts from + // NOTE: We don't commit, but FinalizeBlock for block InitialHeight starts + // from // this FinalizeBlockState. return &cmtabci.InitChainResponse{ ConsensusParams: req.ConsensusParams, @@ -242,10 +245,12 @@ func (s *Service[LoggerT]) ProcessProposal( ) } - // Since the application can get access to FinalizeBlock state and write to it, - // we must be sure to reset it in case ProcessProposal timeouts and is called + // Since the application can get access to FinalizeBlock state and write to + // it, we must be sure to reset it in case ProcessProposal timeouts and is + // called // again in a subsequent round. However, we only want to do this after we've - // processed the first block, as we want to avoid overwriting the finalizeState + // processed the first block, as we want to avoid overwriting the + // finalizeState // after state changes during InitChain. s.processProposalState = s.resetState() if req.Height > s.initialHeight { @@ -290,9 +295,10 @@ func (s *Service[LoggerT]) internalFinalizeBlock( return nil, err } - // finalizeBlockState should be set on InitChain or ProcessProposal. If it is - // nil, it means we are replaying this block and we need to set the state here - // given that during block replay ProcessProposal is not executed by CometBFT. + // finalizeBlockState should be set on InitChain or ProcessProposal. If it + // is nil, it means we are replaying this block and we need to set the state + // here given that during block replay ProcessProposal is not executed by + // CometBFT. if s.finalizeBlockState == nil { s.finalizeBlockState = s.resetState() } diff --git a/mod/consensus/pkg/cometbft/service/service.go b/mod/consensus/pkg/cometbft/service/service.go index f3acf90530..a506f1c648 100644 --- a/mod/consensus/pkg/cometbft/service/service.go +++ b/mod/consensus/pkg/cometbft/service/service.go @@ -57,18 +57,21 @@ type Service[ sm *statem.Manager Middleware MiddlewareI - // prepareProposalState is used for PrepareProposal, which is set based on the - // previous block's state. This state is never committed. In case of multiple - // consensus rounds, the state is always reset to the previous block's state. + // prepareProposalState is used for PrepareProposal, which is set based on + // the previous block's state. This state is never committed. In case of + // multiple consensus rounds, the state is always reset to the previous + // block's state. prepareProposalState *state - // processProposalState is used for ProcessProposal, which is set based on the - // previous block's state. This state is never committed. In case of multiple - // consensus rounds, the state is always reset to the previous block's state. + // processProposalState is used for ProcessProposal, which is set based on + // the previous block's state. This state is never committed. In case of + // multiple consensus rounds, the state is always reset to the previous + // block's state. processProposalState *state // finalizeBlockState is used for FinalizeBlock, which is set based on the - // previous block's state. This state is committed. finalizeBlockState is set + // previous block's state. This state is committed. finalizeBlockState is + // set // on InitChain and FinalizeBlock and set to nil on Commit. finalizeBlockState *state diff --git a/mod/engine-primitives/go.mod b/mod/engine-primitives/go.mod index 2b5b485bdb..2e78fc44ff 100644 --- a/mod/engine-primitives/go.mod +++ b/mod/engine-primitives/go.mod @@ -6,6 +6,8 @@ require ( github.com/berachain/beacon-kit/mod/errors v0.0.0-20240618214413-d5ec0e66b3dd github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570 + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc + github.com/ethereum/go-ethereum v1.14.7 github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79 github.com/holiman/uint256 v1.3.1 github.com/karalabe/ssz v0.2.1-0.20240724074312-3d1ff7a6f7c4 @@ -32,11 +34,9 @@ require ( github.com/consensys/gnark-crypto v0.13.0 // indirect github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/deckarep/golang-set/v2 v2.6.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.3 // indirect - github.com/ethereum/go-ethereum v1.14.7 // indirect github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect github.com/getsentry/sentry-go v0.28.1 // indirect github.com/go-ole/go-ole v1.3.0 // indirect diff --git a/mod/engine-primitives/pkg/engine-primitives/log.go b/mod/engine-primitives/pkg/engine-primitives/log.go new file mode 100644 index 0000000000..890725abb7 --- /dev/null +++ b/mod/engine-primitives/pkg/engine-primitives/log.go @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2024, Berachain Foundation. All rights reserved. +// Use of this software is governed by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package engineprimitives + +import ( + "encoding/json" + + "github.com/berachain/beacon-kit/mod/errors" + "github.com/berachain/beacon-kit/mod/primitives/pkg/bytes" + "github.com/berachain/beacon-kit/mod/primitives/pkg/common" + "github.com/berachain/beacon-kit/mod/primitives/pkg/math" +) + +// Log represents a contract log event. These events are generated by the LOG +// opcode and +// stored/indexed by the node. +type Log struct { + // Consensus fields: + // address of the contract that generated the event + Address common.ExecutionAddress `json:"address"` + // list of topics provided by the contract. + Topics []common.ExecutionHash `json:"topics"` + // supplied by the contract, usually ABI-encoded + Data []byte `json:"data"` + + // Derived fields. These fields are filled in by the node + // but not secured by consensus. + // block in which the transaction was included + BlockNumber uint64 `json:"blockNumber"` + // hash of the transaction + TxHash common.ExecutionHash `json:"transactionHash"` + // index of the transaction in the block + TxIndex uint `json:"transactionIndex"` + // hash of the block in which the transaction was included + BlockHash common.ExecutionHash `json:"blockHash"` + // index of the log in the block + Index uint `json:"logIndex"` + + // The Removed field is true if this log was reverted due to a chain + // reorganisation. You must pay attention to this field if you receive logs + // through a filter query. + Removed bool `json:"removed"` +} + +// GetAddress returns the address of contract that generated the event. +func (l Log) GetAddress() common.ExecutionAddress { + return l.Address +} + +// GetTopics returns the list of topics provided by the contract. +func (l Log) GetTopics() []common.ExecutionHash { + return l.Topics +} + +// GetData returns the data supplied by the contract, usually ABI-encoded. +func (l Log) GetData() []byte { + return l.Data +} + +// MarshalJSON marshals as JSON. +func (l Log) MarshalJSON() ([]byte, error) { + type Log struct { + Address common.ExecutionAddress `json:"address"` + Topics []common.ExecutionHash `json:"topics"` + Data bytes.Bytes `json:"data"` + BlockNumber math.U64 `json:"blockNumber"` + TxHash common.ExecutionHash `json:"transactionHash"` + TxIndex math.U64 `json:"transactionIndex"` + BlockHash common.ExecutionHash `json:"blockHash"` + Index math.U64 `json:"logIndex"` + Removed bool `json:"removed"` + } + var enc Log + enc.Address = l.Address + enc.Topics = l.Topics + enc.Data = l.Data + enc.BlockNumber = math.U64(l.BlockNumber) + enc.TxHash = l.TxHash + enc.TxIndex = math.U64(l.TxIndex) + enc.BlockHash = l.BlockHash + enc.Index = math.U64(l.Index) + enc.Removed = l.Removed + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (l *Log) UnmarshalJSON(input []byte) error { + type Log struct { + Address *common.ExecutionAddress `json:"address"` + Topics []common.ExecutionHash `json:"topics"` + Data *bytes.Bytes `json:"data"` + BlockNumber *math.U64 `json:"blockNumber"` + TxHash *common.ExecutionHash `json:"transactionHash"` + TxIndex *math.U64 `json:"transactionIndex"` + BlockHash *common.ExecutionHash `json:"blockHash"` + Index *math.U64 `json:"logIndex"` + Removed *bool `json:"removed"` + } + var dec Log + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.Address == nil { + return errors.New("missing required field 'address' for Log") + } + l.Address = *dec.Address + if dec.Topics == nil { + return errors.New("missing required field 'topics' for Log") + } + l.Topics = dec.Topics + if dec.Data == nil { + return errors.New("missing required field 'data' for Log") + } + l.Data = *dec.Data + if dec.BlockNumber != nil { + l.BlockNumber = uint64(*dec.BlockNumber) + } + if dec.TxHash == nil { + return errors.New("missing required field 'transactionHash' for Log") + } + l.TxHash = *dec.TxHash + if dec.TxIndex != nil { + l.TxIndex = uint(*dec.TxIndex) + } + if dec.BlockHash != nil { + l.BlockHash = *dec.BlockHash + } + if dec.Index != nil { + l.Index = uint(*dec.Index) + } + if dec.Removed != nil { + l.Removed = *dec.Removed + } + return nil +} diff --git a/mod/engine-primitives/pkg/engine-primitives/log_test.go b/mod/engine-primitives/pkg/engine-primitives/log_test.go new file mode 100644 index 0000000000..259d28ecf3 --- /dev/null +++ b/mod/engine-primitives/pkg/engine-primitives/log_test.go @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2024, Berachain Foundation. All rights reserved. +// Use of this software is governed by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package engineprimitives_test + +import ( + "encoding/json" + "errors" + "reflect" + "testing" + + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" + "github.com/berachain/beacon-kit/mod/primitives/pkg/common" + "github.com/davecgh/go-spew/spew" + "github.com/ethereum/go-ethereum/common/hexutil" +) + +//nolint:lll // test input data. +var unmarshalLogTests = map[string]struct { + input string + want *engineprimitives.Log + wantError error +}{ + "ok": { + input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x000000000000000000000000000000000000000000000001a055690d9db80000","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, + want: &engineprimitives.Log{ + Address: common.NewExecutionAddressFromHex( + "0xecf8f87f810ecf450940c9f60066b4a7a501d6a7", + ), + BlockHash: common.NewExecutionHashFromHex( + "0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056", + ), + BlockNumber: 2019236, + Data: hexutil.MustDecode( + "0x000000000000000000000000000000000000000000000001a055690d9db80000", + ), + Index: 2, + TxIndex: 3, + TxHash: common.NewExecutionHashFromHex( + "0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e", + ), + Topics: []common.ExecutionHash{ + common.NewExecutionHashFromHex( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + ), + common.NewExecutionHashFromHex( + "0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615", + ), + }, + }, + }, + "empty data": { + input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, + want: &engineprimitives.Log{ + Address: common.NewExecutionAddressFromHex( + "0xecf8f87f810ecf450940c9f60066b4a7a501d6a7", + ), + BlockHash: common.NewExecutionHashFromHex( + "0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056", + ), + BlockNumber: 2019236, + Data: []byte{}, + Index: 2, + TxIndex: 3, + TxHash: common.NewExecutionHashFromHex( + "0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e", + ), + Topics: []common.ExecutionHash{ + common.NewExecutionHashFromHex( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + ), + common.NewExecutionHashFromHex( + "0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615", + ), + }, + }, + }, + "missing block fields (pending logs)": { + input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","data":"0x","logIndex":"0x0","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, + want: &engineprimitives.Log{ + Address: common.NewExecutionAddressFromHex( + "0xecf8f87f810ecf450940c9f60066b4a7a501d6a7", + ), + BlockHash: common.ExecutionHash{}, + BlockNumber: 0, + Data: []byte{}, + Index: 0, + TxIndex: 3, + TxHash: common.NewExecutionHashFromHex( + "0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e", + ), + Topics: []common.ExecutionHash{ + common.NewExecutionHashFromHex( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + ), + }, + }, + }, + "Removed: true": { + input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3","removed":true}`, + want: &engineprimitives.Log{ + Address: common.NewExecutionAddressFromHex( + "0xecf8f87f810ecf450940c9f60066b4a7a501d6a7", + ), + BlockHash: common.NewExecutionHashFromHex( + "0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056", + ), + BlockNumber: 2019236, + Data: []byte{}, + Index: 2, + TxIndex: 3, + TxHash: common.NewExecutionHashFromHex( + "0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e", + ), + Topics: []common.ExecutionHash{ + common.NewExecutionHashFromHex( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + ), + }, + Removed: true, + }, + }, + "missing data": { + input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, + wantError: errors.New("missing required field 'data' for Log"), + }, +} + +func TestUnmarshalLog(t *testing.T) { + dumper := spew.ConfigState{DisableMethods: true, Indent: " "} + for name, test := range unmarshalLogTests { + var log *engineprimitives.Log + err := json.Unmarshal([]byte(test.input), &log) + checkError(t, name, err, test.wantError) + if test.wantError == nil && err == nil { + if !reflect.DeepEqual(log, test.want) { + t.Errorf( + "test %q:\nGOT %sWANT %s", name, + dumper.Sdump(log), dumper.Sdump(test.want), + ) + } + } + } +} + +func checkError(t *testing.T, testname string, got, want error) bool { + t.Helper() + if got == nil { + if want != nil { + t.Errorf("test %q: got no error, want %q", testname, want) + return false + } + return true + } + if want == nil { + t.Errorf("test %q: unexpected error %q", testname, got) + } else if got.Error() != want.Error() { + t.Errorf("test %q: got error %q, want %q", testname, got, want) + } + return false +} diff --git a/mod/execution/go.mod b/mod/execution/go.mod index 897bae8fb9..457b2b0930 100644 --- a/mod/execution/go.mod +++ b/mod/execution/go.mod @@ -4,12 +4,11 @@ go 1.23.0 require ( github.com/berachain/beacon-kit/mod/async v0.0.0-20240624204855-d8809d5c8588 + github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20241007140746-1c0a37893c46 github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197 github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0 - github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e github.com/berachain/beacon-kit/mod/log v0.0.0-20240807213340-5779c7a563cd github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570 - github.com/ethereum/go-ethereum v1.14.7 ) require ( @@ -17,7 +16,8 @@ require ( github.com/Microsoft/go-winio v0.6.2 // indirect github.com/VictoriaMetrics/fastcache v1.12.2 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db // indirect + github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df // indirect + github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e // indirect github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -29,15 +29,14 @@ require ( github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.13.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect github.com/deckarep/golang-set/v2 v2.6.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.3 // indirect + github.com/ethereum/go-ethereum v1.14.7 // indirect github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/getsentry/sentry-go v0.28.1 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/goccy/go-json v0.10.3 // indirect @@ -46,7 +45,6 @@ require ( github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/uint256 v1.3.1 // indirect @@ -58,7 +56,6 @@ require ( github.com/mattn/go-runewidth v0.0.16 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/mitchellh/pointerstructure v1.2.1 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect @@ -80,7 +77,6 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect diff --git a/mod/execution/go.sum b/mod/execution/go.sum index 5f8a084279..822481723f 100644 --- a/mod/execution/go.sum +++ b/mod/execution/go.sum @@ -10,8 +10,10 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/berachain/beacon-kit/mod/async v0.0.0-20240624204855-d8809d5c8588 h1:i2IzAwiYKcYsA/tjQtiLH1tx80RoQ1CvfP9pBZ2JtTg= github.com/berachain/beacon-kit/mod/async v0.0.0-20240624204855-d8809d5c8588/go.mod h1:tzZ5Oyg7BgCViZBkqDwHmfKPNI66xONwE5kWd1P2v7o= -github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db h1:vGczI1vJ6s86tSDS4tsllzlWZUVZ42xZ710GoHMd4to= -github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db/go.mod h1:rbvfJqTKUIckels2AlWy+XuG+UGnegoFQuHC+TUg+zA= +github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df h1:mnD1LKqDQ0n+OFdDqOuvKaEiUKRJzsO4V0wyyn/gJYg= +github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df/go.mod h1:bTFB4Rdvm7D/WdwPYkqQ+8T0XOMBv0pzXfp1E46BFX8= +github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20241007140746-1c0a37893c46 h1:F7KHcN/tOIWmIUyB04M+yQGjgN9uyUaXtrkybQVPQvU= +github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20241007140746-1c0a37893c46/go.mod h1:WzNxJq+naMO7DHoPWXBliTe9/Aol2wug4YamXs8N5Pc= github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197 h1:wVWkiiERY/7kaXvE/VNPPUtYp/l8ky6QSuKM3ThVMXU= github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197/go.mod h1:LiOiqrJhhLH/GPo0XE5fel3EYyi7X6dwBOyTqZakTeQ= github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0 h1:kCSrkb/uVXfMKJPKjf0c7nlJkwn5cNwMxtzRW4zNq2A= @@ -28,8 +30,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ens github.com/btcsuite/btcd/btcec/v2 v2.3.3/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ= github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU= -github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -54,8 +54,6 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.13.0 h1:VPULb/v6bbYELAPTDFINEVaMTTybV5GLxDdcjnS+4oc= github.com/consensys/gnark-crypto v0.13.0/go.mod h1:wKqwsieaKPThcFkHe0d0zMsbHEUWFmZcG7KBCse210o= -github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg= github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM= github.com/crate-crypto/go-kzg-4844 v1.1.0 h1:EN/u9k2TF6OWSHrCCDBBU6GLNMq88OspHHlMnHfoyU4= @@ -79,15 +77,11 @@ github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeV github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79 h1:oMYkNRlaY+YxcbYW4U84mQQkujiloBbxQFnTOHUbkec= github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79/go.mod h1:EGSbefgAPd3M0hlBwOCw4Mkj+0YAaSnXw1QeLasY6XQ= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= -github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k= github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -102,8 +96,6 @@ github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -128,24 +120,14 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hashicorp/go-bexpr v0.1.14 h1:uKDeyuOhWhT1r5CiMTjdVY4Aoxdxs6EtwgTGnlosyp4= -github.com/hashicorp/go-bexpr v0.1.14/go.mod h1:gN7hRKB3s7yT+YvTdnhZVLTENejvhlkZ8UE4YVBS+Q8= -github.com/holiman/billy v0.0.0-20240322075458-72a4e81ec6da h1:8qEhdMGSUx67L2s5aGQinJhOwLfIRKLRBHPQq8m6WxE= -github.com/holiman/billy v0.0.0-20240322075458-72a4e81ec6da/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs= github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= -github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/karalabe/ssz v0.2.1-0.20240724074312-3d1ff7a6f7c4 h1:CvO92iWYv7SS7hWzd1cYaAhGVZmanD/DtUfe0s+kTeg= github.com/karalabe/ssz v0.2.1-0.20240724074312-3d1ff7a6f7c4/go.mod h1:SUFJO5R2VkUK3vT80pjfIB/g7eaQgSU2RhbuL8GOJq4= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -162,20 +144,13 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/pointerstructure v1.2.1 h1:ZhBBeX8tSlRpu/FFhXH4RC4OJzFlqsQhoHZAz4x7TIw= -github.com/mitchellh/pointerstructure v1.2.1/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -225,14 +200,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po= -github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/status-im/keycard-go v0.3.2 h1:YusIF/bHx6YZis8UTOJrpZFnTs4IkRBdmJXqdiXkpFE= -github.com/status-im/keycard-go v0.3.2/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= @@ -249,14 +218,8 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY= github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE= -github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= -github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/umbracle/fastrlp v0.1.0 h1:V0W3f6ZKWqbu1KggdhnRWOi+t7+PfL3VyAffJqayI5s= github.com/umbracle/fastrlp v0.1.0/go.mod h1:5RHgqiFjd4vLJESMWagP/E7su+5Gzk0iqqmrotR8WdA= -github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= -github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= -github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= -github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= @@ -317,8 +280,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -343,8 +304,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= -gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/mod/execution/pkg/client/client.go b/mod/execution/pkg/client/client.go index e14d8cc559..5f1139f00b 100644 --- a/mod/execution/pkg/client/client.go +++ b/mod/execution/pkg/client/client.go @@ -38,9 +38,10 @@ import ( // EngineClient is a struct that holds a pointer to an Eth1Client. type EngineClient[ ExecutionPayloadT constraints.EngineType[ExecutionPayloadT], + LogT any, PayloadAttributesT PayloadAttributes, ] struct { - *ethclient.Client[ExecutionPayloadT] + *ethclient.Client[ExecutionPayloadT, LogT] // cfg is the supplied configuration for the engine client. cfg *Config // logger is the logger for the engine client. @@ -58,6 +59,7 @@ type EngineClient[ // EngineClient. func New[ ExecutionPayloadT constraints.EngineType[ExecutionPayloadT], + LogT any, PayloadAttributesT PayloadAttributes, ]( cfg *Config, @@ -66,12 +68,12 @@ func New[ telemetrySink TelemetrySink, eth1ChainID *big.Int, ) *EngineClient[ - ExecutionPayloadT, PayloadAttributesT, + ExecutionPayloadT, LogT, PayloadAttributesT, ] { - return &EngineClient[ExecutionPayloadT, PayloadAttributesT]{ + return &EngineClient[ExecutionPayloadT, LogT, PayloadAttributesT]{ cfg: cfg, logger: logger, - Client: ethclient.New[ExecutionPayloadT]( + Client: ethclient.New[ExecutionPayloadT, LogT]( ethclientrpc.NewClient( cfg.RPCDialURL.String(), ethclientrpc.WithJWTSecret(jwtSecret), @@ -87,14 +89,14 @@ func New[ // Name returns the name of the engine client. func (s *EngineClient[ - _, _, + _, _, _, ]) Name() string { return "engine-client" } // Start the engine client. func (s *EngineClient[ - _, _, + _, _, _, ]) Start( ctx context.Context, ) error { @@ -142,7 +144,7 @@ func (s *EngineClient[ // verifyChainID dials the execution client and // ensures the chain ID is correct. func (s *EngineClient[ - _, _, + _, _, _, ]) verifyChainIDAndConnection( ctx context.Context, ) error { diff --git a/mod/execution/pkg/client/engine.go b/mod/execution/pkg/client/engine.go index aad0e3efe9..81277ca763 100644 --- a/mod/execution/pkg/client/engine.go +++ b/mod/execution/pkg/client/engine.go @@ -38,7 +38,7 @@ import ( // NewPayload calls the engine_newPayloadVX method via JSON-RPC. func (s *EngineClient[ - ExecutionPayloadT, _, + ExecutionPayloadT, _, _, ]) NewPayload( ctx context.Context, payload ExecutionPayloadT, @@ -84,7 +84,7 @@ func (s *EngineClient[ // ForkchoiceUpdated calls the engine_forkchoiceUpdatedV1 method via JSON-RPC. func (s *EngineClient[ - _, PayloadAttributesT, + _, _, PayloadAttributesT, ]) ForkchoiceUpdated( ctx context.Context, state *engineprimitives.ForkchoiceStateV1, @@ -134,7 +134,7 @@ func (s *EngineClient[ // GetPayload calls the engine_getPayloadVX method via JSON-RPC. It returns // the execution data as well as the blobs bundle. func (s *EngineClient[ - ExecutionPayloadT, _, + ExecutionPayloadT, _, _, ]) GetPayload( ctx context.Context, payloadID engineprimitives.PayloadID, @@ -168,7 +168,7 @@ func (s *EngineClient[ // ExchangeCapabilities calls the engine_exchangeCapabilities method via // JSON-RPC. func (s *EngineClient[ - _, _, + _, _, _, ]) ExchangeCapabilities( ctx context.Context, ) ([]string, error) { diff --git a/mod/execution/pkg/client/errors.go b/mod/execution/pkg/client/errors.go index c5a3af8abe..64ead0460b 100644 --- a/mod/execution/pkg/client/errors.go +++ b/mod/execution/pkg/client/errors.go @@ -57,7 +57,7 @@ var ( // Handles errors received from the RPC server according to the specification. func (s *EngineClient[ - _, _, + _, _, _, ]) handleRPCError( err error, ) error { diff --git a/mod/execution/pkg/client/ethclient/engine.go b/mod/execution/pkg/client/ethclient/engine.go index 7fe54f115a..614a31dc9a 100644 --- a/mod/execution/pkg/client/ethclient/engine.go +++ b/mod/execution/pkg/client/ethclient/engine.go @@ -34,7 +34,7 @@ import ( /* -------------------------------------------------------------------------- */ // NewPayload calls the engine_newPayloadV3 method via JSON-RPC. -func (s *Client[ExecutionPayloadT]) NewPayload( +func (s *Client[ExecutionPayloadT, _]) NewPayload( ctx context.Context, payload ExecutionPayloadT, versionedHashes []common.ExecutionHash, @@ -51,7 +51,7 @@ func (s *Client[ExecutionPayloadT]) NewPayload( } // NewPayloadV3 is used to call the underlying JSON-RPC method for newPayload. -func (s *Client[ExecutionPayloadT]) NewPayloadV3( +func (s *Client[ExecutionPayloadT, _]) NewPayloadV3( ctx context.Context, payload ExecutionPayloadT, versionedHashes []common.ExecutionHash, @@ -72,7 +72,7 @@ func (s *Client[ExecutionPayloadT]) NewPayloadV3( // ForkchoiceUpdated is a helper function to call the appropriate version of // the. -func (s *Client[ExecutionPayloadT]) ForkchoiceUpdated( +func (s *Client[ExecutionPayloadT, _]) ForkchoiceUpdated( ctx context.Context, state *engineprimitives.ForkchoiceStateV1, attrs any, @@ -87,7 +87,7 @@ func (s *Client[ExecutionPayloadT]) ForkchoiceUpdated( } // ForkchoiceUpdatedV3 calls the engine_forkchoiceUpdatedV3 method via JSON-RPC. -func (s *Client[ExecutionPayloadT]) ForkchoiceUpdatedV3( +func (s *Client[ExecutionPayloadT, _]) ForkchoiceUpdatedV3( ctx context.Context, state *engineprimitives.ForkchoiceStateV1, attrs any, @@ -97,7 +97,7 @@ func (s *Client[ExecutionPayloadT]) ForkchoiceUpdatedV3( // forkchoiceUpdateCall is a helper function to call to any version // of the forkchoiceUpdates method. -func (s *Client[ExecutionPayloadT]) forkchoiceUpdated( +func (s *Client[ExecutionPayloadT, _]) forkchoiceUpdated( ctx context.Context, method string, state *engineprimitives.ForkchoiceStateV1, @@ -124,7 +124,7 @@ func (s *Client[ExecutionPayloadT]) forkchoiceUpdated( // GetPayload is a helper function to call the appropriate version of the // engine_getPayload method. -func (s *Client[ExecutionPayloadT]) GetPayload( +func (s *Client[ExecutionPayloadT, _]) GetPayload( ctx context.Context, payloadID engineprimitives.PayloadID, forkVersion uint32, @@ -138,7 +138,7 @@ func (s *Client[ExecutionPayloadT]) GetPayload( } // GetPayloadV3 calls the engine_getPayloadV3 method via JSON-RPC. -func (s *Client[ExecutionPayloadT]) GetPayloadV3( +func (s *Client[ExecutionPayloadT, _]) GetPayloadV3( ctx context.Context, payloadID engineprimitives.PayloadID, ) (engineprimitives.BuiltExecutionPayloadEnv[ExecutionPayloadT], error) { var t ExecutionPayloadT @@ -165,7 +165,7 @@ func (s *Client[ExecutionPayloadT]) GetPayloadV3( // ExchangeCapabilities calls the engine_exchangeCapabilities method via // JSON-RPC. -func (s *Client[ExecutionPayloadT]) ExchangeCapabilities( +func (s *Client[ExecutionPayloadT, _]) ExchangeCapabilities( ctx context.Context, capabilities []string, ) ([]string, error) { @@ -179,7 +179,7 @@ func (s *Client[ExecutionPayloadT]) ExchangeCapabilities( } // GetClientVersionV1 calls the engine_getClientVersionV1 method via JSON-RPC. -func (s *Client[ExecutionPayloadT]) GetClientVersionV1( +func (s *Client[ExecutionPayloadT, _]) GetClientVersionV1( ctx context.Context, ) ([]engineprimitives.ClientVersionV1, error) { result := make([]engineprimitives.ClientVersionV1, 0) diff --git a/mod/execution/pkg/client/ethclient/eth.go b/mod/execution/pkg/client/ethclient/eth.go index df92afe3a0..f140844ba2 100644 --- a/mod/execution/pkg/client/ethclient/eth.go +++ b/mod/execution/pkg/client/ethclient/eth.go @@ -22,19 +22,13 @@ package ethclient import ( "context" - "fmt" - "math/big" - "github.com/berachain/beacon-kit/mod/errors" - "github.com/berachain/beacon-kit/mod/geth-primitives/pkg/rpc" + "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/types" ) // ChainID retrieves the current chain ID. -func (ec *Client[ExecutionPayloadT]) ChainID( +func (ec *Client[ExecutionPayloadT, _]) ChainID( ctx context.Context, ) (math.U64, error) { var result math.U64 @@ -44,66 +38,40 @@ func (ec *Client[ExecutionPayloadT]) ChainID( return result, nil } -// TODO: Figure out how to unhood all this. - -// FilterLogs executes a filter query. -func (ec *Client[ExecutionPayloadT]) FilterLogs( +// GetLogsAtBlockNumber retrieves logs for a block number, contract address, +// and optional topics. +// +// The topics list restricts matches to particular event topics. Topics matches +// a prefix of that list. An empty element slice matches any topic. Non-empty +// elements represent an alternative that matches any of the contained topics. +// +// Examples: +// {} or nil matches any topic list +// {{A}} matches topic A in first position +// {{}, {B}} matches any topic in first position AND B in second +// +// position +// +// {{A}, {B}} matches topic A in first position AND B in second +// +// position +// +// {{A, B}, {C, D}} matches topic (A OR B) in first position AND (C OR D) in +// +// second position +func (ec *Client[ExecutionPayloadT, LogT]) GetLogsAtBlockNumber( ctx context.Context, - q ethereum.FilterQuery, -) ([]types.Log, error) { - var result []types.Log - arg, err := toFilterArg(q) - if err != nil { - return nil, err - } - return result, ec.Call(ctx, &result, "eth_getLogs", arg) -} - -// SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) -// (Subscription, error) - -func (ec *Client[ExecutionPayloadT]) SubscribeFilterLogs( - context.Context, - ethereum.FilterQuery, - chan<- types.Log, -) (ethereum.Subscription, error) { - return nil, errors.New("not implemented") -} - -func toFilterArg(q ethereum.FilterQuery) (interface{}, error) { - arg := map[string]interface{}{ - "address": q.Addresses, - "topics": q.Topics, - } - if q.BlockHash != nil { - arg["blockHash"] = *q.BlockHash - if q.FromBlock != nil || q.ToBlock != nil { - return nil, errors.New( - "cannot specify both BlockHash and FromBlock/ToBlock", - ) - } - } else { - if q.FromBlock == nil { - arg["fromBlock"] = "0x0" - } else { - arg["fromBlock"] = toBlockNumArg(q.FromBlock) - } - arg["toBlock"] = toBlockNumArg(q.ToBlock) - } - return arg, nil -} - -func toBlockNumArg(number *big.Int) string { - if number == nil { - return "latest" - } - if number.Sign() >= 0 { - return hexutil.EncodeBig(number) - } - // It's negative. - if number.IsInt64() { - return rpc.BlockNumber(number.Int64()).String() - } - // It's negative and large, which is invalid. - return fmt.Sprintf("", number) + number math.U64, + address common.ExecutionAddress, + topics [][]common.ExecutionHash, +) ([]LogT, error) { + var result []LogT + return result, + ec.Call(ctx, + &result, "eth_getLogs", map[string]interface{}{ + "fromBlock": number.Hex(), + "toBlock": number.Hex(), + "address": address, + "topics": topics, + }) } diff --git a/mod/execution/pkg/client/ethclient/ethclient.go b/mod/execution/pkg/client/ethclient/ethclient.go index 3579a4c007..9276b8ac2f 100644 --- a/mod/execution/pkg/client/ethclient/ethclient.go +++ b/mod/execution/pkg/client/ethclient/ethclient.go @@ -26,11 +26,14 @@ import ( ) // Client - Ethereum rpc client. -type Client[ExecutionPayloadT interface { - constraints.JSONMarshallable - Empty(uint32) ExecutionPayloadT - Version() uint32 -}] struct { +type Client[ + ExecutionPayloadT interface { + constraints.JSONMarshallable + Empty(uint32) ExecutionPayloadT + Version() uint32 + }, + LogT any, +] struct { *rpc.Client } @@ -41,8 +44,9 @@ func New[ Empty(uint32) ExecutionPayloadT Version() uint32 }, -](client *rpc.Client) *Client[ExecutionPayloadT] { - rpc := &Client[ExecutionPayloadT]{ + LogT any, +](client *rpc.Client) *Client[ExecutionPayloadT, LogT] { + rpc := &Client[ExecutionPayloadT, LogT]{ Client: client, } diff --git a/mod/execution/pkg/client/helpers.go b/mod/execution/pkg/client/helpers.go index 5834e741fe..7cb4f92f71 100644 --- a/mod/execution/pkg/client/helpers.go +++ b/mod/execution/pkg/client/helpers.go @@ -32,7 +32,7 @@ import ( // createContextWithTimeout creates a context with a timeout and returns it // along with the cancel function. func (s *EngineClient[ - _, _, + _, _, _, ]) createContextWithTimeout( ctx context.Context, ) (context.Context, context.CancelFunc) { diff --git a/mod/execution/pkg/deposit/contract.go b/mod/execution/pkg/deposit/contract.go index 1a9f30b4f5..ed1c798e93 100644 --- a/mod/execution/pkg/deposit/contract.go +++ b/mod/execution/pkg/deposit/contract.go @@ -22,84 +22,68 @@ package deposit import ( "context" - "errors" - gethprimitives "github.com/berachain/beacon-kit/mod/geth-primitives" - "github.com/berachain/beacon-kit/mod/geth-primitives/pkg/bind" - "github.com/berachain/beacon-kit/mod/geth-primitives/pkg/deposit" - "github.com/berachain/beacon-kit/mod/primitives/pkg/bytes" + "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" ) // WrappedBeaconDepositContract is a struct that holds a pointer to an ABI. type WrappedBeaconDepositContract[ - DepositT Deposit[DepositT, WithdrawalCredentialsT], + DepositT Deposit[DepositT, LogT, WithdrawalCredentialsT], + LogT Log, WithdrawalCredentialsT ~[32]byte, ] struct { - // BeaconDepositContractFilterer is a pointer to the codegen ABI binding. - deposit.BeaconDepositContractFilterer + client Client[LogT] + address common.ExecutionAddress } // NewWrappedBeaconDepositContract creates a new BeaconDepositContract. func NewWrappedBeaconDepositContract[ - DepositT Deposit[DepositT, WithdrawalCredentialsT], + DepositT Deposit[DepositT, LogT, WithdrawalCredentialsT], + LogT Log, WithdrawalCredentialsT ~[32]byte, ]( address common.ExecutionAddress, - client bind.ContractFilterer, + client Client[LogT], ) (*WrappedBeaconDepositContract[ DepositT, + LogT, WithdrawalCredentialsT, ], error) { - contract, err := deposit.NewBeaconDepositContractFilterer( - gethprimitives.ExecutionAddress(address), client, - ) - - if err != nil { - return nil, err - } else if contract == nil { - return nil, errors.New("contract must not be nil") - } - return &WrappedBeaconDepositContract[ DepositT, + LogT, WithdrawalCredentialsT, ]{ - BeaconDepositContractFilterer: *contract, + client: client, + address: address, }, nil } // ReadDeposits reads deposits from the deposit contract. -func (dc *WrappedBeaconDepositContract[ - DepositT, - WithdrawalCredentialsT, -]) ReadDeposits( +func (dc *WrappedBeaconDepositContract[DepositT, _, _]) ReadDeposits( ctx context.Context, blkNum math.U64, ) ([]DepositT, error) { - logs, err := dc.FilterDeposit( - &bind.FilterOpts{ - Context: ctx, - Start: blkNum.Unwrap(), - End: (*uint64)(&blkNum), - }, + logs, err := dc.client.GetLogsAtBlockNumber( + ctx, + blkNum, + dc.address, + [][]common.ExecutionHash{{types.DepositEventSignature}}, ) if err != nil { return nil, err } deposits := make([]DepositT, 0) - for logs.Next() { + for _, log := range logs { var d DepositT - deposits = append(deposits, d.New( - bytes.ToBytes48(logs.Event.Pubkey), - WithdrawalCredentialsT( - bytes.ToBytes32(logs.Event.Credentials)), - math.U64(logs.Event.Amount), - bytes.ToBytes96(logs.Event.Signature), - logs.Event.Index, - )) + d = d.Empty() + if err = d.UnmarshalLog(log); err != nil { + return nil, err + } + deposits = append(deposits, d) } return deposits, nil diff --git a/mod/execution/pkg/deposit/pruner.go b/mod/execution/pkg/deposit/pruner.go index c0bc068864..00319b61a0 100644 --- a/mod/execution/pkg/deposit/pruner.go +++ b/mod/execution/pkg/deposit/pruner.go @@ -31,7 +31,8 @@ func BuildPruneRangeFn[ BeaconBlockBodyT interface { GetDeposits() []DepositT }, - DepositT Deposit[DepositT, WithdrawalCredentialsT], + DepositT Deposit[DepositT, LogT, WithdrawalCredentialsT], + LogT any, WithdrawalCredentialsT any, ](cs common.ChainSpec) func(async.Event[BeaconBlockT]) (uint64, uint64) { return func(event async.Event[BeaconBlockT]) (uint64, uint64) { diff --git a/mod/execution/pkg/deposit/service.go b/mod/execution/pkg/deposit/service.go index fc4732c93e..395b2f4eb4 100644 --- a/mod/execution/pkg/deposit/service.go +++ b/mod/execution/pkg/deposit/service.go @@ -33,8 +33,9 @@ import ( type Service[ BeaconBlockT BeaconBlock[BeaconBlockBodyT], BeaconBlockBodyT BeaconBlockBody[DepositT, ExecutionPayloadT], - DepositT Deposit[DepositT, WithdrawalCredentialsT], + DepositT Deposit[DepositT, LogT, WithdrawalCredentialsT], ExecutionPayloadT ExecutionPayload, + LogT any, WithdrawalCredentialsT any, ] struct { // logger is used for logging information and errors. @@ -61,8 +62,9 @@ type Service[ func NewService[ BeaconBlockT BeaconBlock[BeaconBlockBodyT], BeaconBlockBodyT BeaconBlockBody[DepositT, ExecutionPayloadT], - DepositT Deposit[DepositT, WithdrawalCredentialsT], + DepositT Deposit[DepositT, LogT, WithdrawalCredentialsT], ExecutionPayloadT ExecutionPayload, + LogT any, WithdrawalCredentialsT any, ]( logger log.Logger, @@ -73,11 +75,11 @@ func NewService[ dispatcher asynctypes.EventDispatcher, ) *Service[ BeaconBlockT, BeaconBlockBodyT, DepositT, - ExecutionPayloadT, WithdrawalCredentialsT, + ExecutionPayloadT, LogT, WithdrawalCredentialsT, ] { return &Service[ BeaconBlockT, BeaconBlockBodyT, DepositT, - ExecutionPayloadT, WithdrawalCredentialsT, + ExecutionPayloadT, LogT, WithdrawalCredentialsT, ]{ dc: dc, dispatcher: dispatcher, @@ -93,7 +95,7 @@ func NewService[ // Start subscribes the Deposit service to BeaconBlockFinalized events and // begins the main event loop to handle them accordingly. func (s *Service[ - _, _, _, _, _, + _, _, _, _, _, _, ]) Start(ctx context.Context) error { if err := s.dispatcher.Subscribe( async.BeaconBlockFinalized, s.subFinalizedBlockEvents, @@ -114,7 +116,7 @@ func (s *Service[ // eventLoop starts the main event loop to listen and handle // BeaconBlockFinalized events. func (s *Service[ - _, _, _, _, _, + _, _, _, _, _, _, ]) eventLoop(ctx context.Context) { for { select { @@ -128,7 +130,7 @@ func (s *Service[ // Name returns the name of the service. func (s *Service[ - _, _, _, _, _, + _, _, _, _, _, _, ]) Name() string { return "deposit-handler" } diff --git a/mod/execution/pkg/deposit/sync.go b/mod/execution/pkg/deposit/sync.go index f87281016f..6535d5328d 100644 --- a/mod/execution/pkg/deposit/sync.go +++ b/mod/execution/pkg/deposit/sync.go @@ -34,7 +34,7 @@ const defaultRetryInterval = 20 * time.Second // depositFetcher returns a function that retrieves the block number from the // event and fetches and stores the deposits for that block. func (s *Service[ - BeaconBlockT, _, _, _, _, + BeaconBlockT, _, _, _, _, _, ]) depositFetcher(ctx context.Context, event async.Event[BeaconBlockT]) { blockNum := event.Data().GetBody().GetExecutionPayload().GetNumber() s.fetchAndStoreDeposits(ctx, blockNum-s.eth1FollowDistance) @@ -43,7 +43,7 @@ func (s *Service[ // depositCatchupFetcher fetches deposits for blocks that failed to be // processed. func (s *Service[ - _, _, _, _, _, + _, _, _, _, _, _, ]) depositCatchupFetcher(ctx context.Context) { ticker := time.NewTicker(defaultRetryInterval) defer ticker.Stop() @@ -70,10 +70,13 @@ func (s *Service[ } func (s *Service[ - _, _, _, _, _, + _, _, _, _, _, _, ]) fetchAndStoreDeposits(ctx context.Context, blockNum math.U64) { deposits, err := s.dc.ReadDeposits(ctx, blockNum) if err != nil { + s.logger.Error( + "Failed to read deposits", "error", err, "block", blockNum, + ) s.metrics.markFailedToGetBlockLogs(blockNum) s.failedBlocks[blockNum] = struct{}{} return @@ -87,7 +90,9 @@ func (s *Service[ } if err = s.ds.EnqueueDeposits(deposits); err != nil { - s.logger.Error("Failed to store deposits", "error", err) + s.logger.Error( + "Failed to store deposits", "error", err, "block", blockNum, + ) s.failedBlocks[blockNum] = struct{}{} return } diff --git a/mod/execution/pkg/deposit/types.go b/mod/execution/pkg/deposit/types.go index 6988aef84c..3c5eb12458 100644 --- a/mod/execution/pkg/deposit/types.go +++ b/mod/execution/pkg/deposit/types.go @@ -24,7 +24,7 @@ import ( "context" "github.com/berachain/beacon-kit/mod/primitives/pkg/async" - "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" + "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" ) @@ -60,6 +60,22 @@ type ExecutionPayload interface { GetNumber() math.U64 } +// Log is an interface for logs. +type Log interface { + GetAddress() common.ExecutionAddress + GetTopics() []common.ExecutionHash +} + +// Client is an interface for the client. +type Client[LogT any] interface { + GetLogsAtBlockNumber( + ctx context.Context, + number math.U64, + address common.ExecutionAddress, + topics [][]common.ExecutionHash, + ) ([]LogT, error) +} + // Contract is the ABI for the deposit contract. type Contract[DepositT any] interface { // ReadDeposits reads deposits from the deposit contract. @@ -70,17 +86,13 @@ type Contract[DepositT any] interface { } // Deposit is an interface for deposits. -type Deposit[DepositT, WithdrawalCredentialsT any] interface { - // New creates a new deposit. - New( - crypto.BLSPubkey, - WithdrawalCredentialsT, - math.U64, - crypto.BLSSignature, - uint64, - ) DepositT +type Deposit[DepositT, LogT, WithdrawalCredentialsT any] interface { + // Empty() returns a new empty deposit. + Empty() DepositT // GetIndex returns the index of the deposit. GetIndex() math.U64 + // UnmarshalLog unmarshals a log into a deposit. + UnmarshalLog(LogT) error } // Store defines the interface for managing deposit operations. diff --git a/mod/execution/pkg/engine/engine.go b/mod/execution/pkg/engine/engine.go index 9d30c9f097..970ecc90cd 100644 --- a/mod/execution/pkg/engine/engine.go +++ b/mod/execution/pkg/engine/engine.go @@ -37,6 +37,7 @@ import ( // from the Ethereum 2.0 Specification. type Engine[ ExecutionPayloadT ExecutionPayload[ExecutionPayloadT, WithdrawalsT], + LogT any, PayloadAttributesT engineprimitives.PayloadAttributer, PayloadIDT ~[8]byte, WithdrawalsT interface { @@ -46,7 +47,7 @@ type Engine[ ] struct { // ec is the engine client that the engine will use to // interact with the execution layer. - ec *client.EngineClient[ExecutionPayloadT, PayloadAttributesT] + ec *client.EngineClient[ExecutionPayloadT, LogT, PayloadAttributesT] // logger is the logger for the engine. logger log.Logger // metrics is the metrics for the engine. @@ -56,6 +57,7 @@ type Engine[ // New creates a new Engine. func New[ ExecutionPayloadT ExecutionPayload[ExecutionPayloadT, WithdrawalsT], + LogT any, PayloadAttributesT engineprimitives.PayloadAttributer, PayloadIDT ~[8]byte, WithdrawalsT interface { @@ -63,15 +65,15 @@ func New[ EncodeIndex(int, *bytes.Buffer) }, ]( - engineClient *client.EngineClient[ExecutionPayloadT, PayloadAttributesT], + engineClient *client.EngineClient[ExecutionPayloadT, LogT, PayloadAttributesT], logger log.Logger, telemtrySink TelemetrySink, ) *Engine[ - ExecutionPayloadT, PayloadAttributesT, + ExecutionPayloadT, LogT, PayloadAttributesT, PayloadIDT, WithdrawalsT, ] { return &Engine[ - ExecutionPayloadT, PayloadAttributesT, PayloadIDT, + ExecutionPayloadT, LogT, PayloadAttributesT, PayloadIDT, WithdrawalsT, ]{ ec: engineClient, @@ -81,7 +83,7 @@ func New[ } // Start spawns any goroutines required by the service. -func (ee *Engine[_, _, _, _]) Start( +func (ee *Engine[_, _, _, _, _]) Start( ctx context.Context, ) error { go func() { @@ -95,7 +97,7 @@ func (ee *Engine[_, _, _, _]) Start( // 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], @@ -108,7 +110,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], @@ -182,7 +184,7 @@ func (ee *Engine[ // VerifyAndNotifyNewPayload verifies the new payload and notifies the // execution client. func (ee *Engine[ - ExecutionPayloadT, _, _, WithdrawalsT, + ExecutionPayloadT, _, _, _, WithdrawalsT, ]) VerifyAndNotifyNewPayload( ctx context.Context, req *engineprimitives.NewPayloadRequest[ diff --git a/mod/node-core/pkg/components/chain_service.go b/mod/node-core/pkg/components/chain_service.go index 50ba9c5257..dd22a631b6 100644 --- a/mod/node-core/pkg/components/chain_service.go +++ b/mod/node-core/pkg/components/chain_service.go @@ -42,6 +42,7 @@ type ChainServiceInput[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, StorageBackendT any, LoggerT any, WithdrawalT Withdrawal[WithdrawalT], @@ -53,10 +54,12 @@ type ChainServiceInput[ Cfg *config.Config EngineClient *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] ExecutionEngine *engine.Engine[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], PayloadID, WithdrawalsT, @@ -96,6 +99,7 @@ func ProvideChainService[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, GenesisT Genesis[DepositT, ExecutionPayloadHeaderT], KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], @@ -107,7 +111,7 @@ func ProvideChainService[ ]( in ChainServiceInput[ BeaconBlockT, BeaconStateT, DepositT, ExecutionPayloadT, - ExecutionPayloadHeaderT, StorageBackendT, LoggerT, + ExecutionPayloadHeaderT, LogT, StorageBackendT, LoggerT, WithdrawalT, WithdrawalsT, ], ) *blockchain.Service[ diff --git a/mod/node-core/pkg/components/deposit_contract.go b/mod/node-core/pkg/components/deposit_contract.go index 7aa575db7a..516f9024bf 100644 --- a/mod/node-core/pkg/components/deposit_contract.go +++ b/mod/node-core/pkg/components/deposit_contract.go @@ -35,6 +35,7 @@ type BeaconDepositContractInput[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], ] struct { @@ -42,6 +43,7 @@ type BeaconDepositContractInput[ ChainSpec common.ChainSpec EngineClient *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] } @@ -50,25 +52,29 @@ type BeaconDepositContractInput[ // dep inject framework. func ProvideBeaconDepositContract[ DepositT Deposit[ - DepositT, *ForkData, WithdrawalCredentials, + DepositT, *ForkData, LogT, WithdrawalCredentialsT, ], ExecutionPayloadT ExecutionPayload[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT deposit.Log, WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], + WithdrawalCredentialsT ~[32]byte, ]( in BeaconDepositContractInput[ - ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalT, WithdrawalsT, + ExecutionPayloadT, ExecutionPayloadHeaderT, LogT, + WithdrawalT, WithdrawalsT, ], ) (*deposit.WrappedBeaconDepositContract[ - DepositT, WithdrawalCredentials, + DepositT, LogT, WithdrawalCredentialsT, ], error) { // Build the deposit contract. return deposit.NewWrappedBeaconDepositContract[ DepositT, - WithdrawalCredentials, + LogT, + WithdrawalCredentialsT, ]( in.ChainSpec.DepositContractAddress(), in.EngineClient, diff --git a/mod/node-core/pkg/components/deposit_service.go b/mod/node-core/pkg/components/deposit_service.go index a54cb739d6..f45355ff44 100644 --- a/mod/node-core/pkg/components/deposit_service.go +++ b/mod/node-core/pkg/components/deposit_service.go @@ -40,6 +40,7 @@ type DepositServiceIn[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, LoggerT any, WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], @@ -51,6 +52,7 @@ type DepositServiceIn[ Dispatcher Dispatcher EngineClient *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] Logger LoggerT @@ -69,7 +71,7 @@ func ProvideDepositService[ ], BeaconBlockHeaderT any, DepositT Deposit[ - DepositT, *ForkData, WithdrawalCredentials, + DepositT, *ForkData, LogT, WithdrawalCredentials, ], DepositContractT deposit.Contract[DepositT], DepositStoreT DepositStore[DepositT], @@ -77,17 +79,19 @@ func ProvideDepositService[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], + WithdrawalCredentialsT any, ]( in DepositServiceIn[ BeaconBlockT, DepositContractT, DepositStoreT, ExecutionPayloadT, - ExecutionPayloadHeaderT, LoggerT, WithdrawalT, WithdrawalsT, + ExecutionPayloadHeaderT, LogT, LoggerT, WithdrawalT, WithdrawalsT, ], ) (*deposit.Service[ BeaconBlockT, BeaconBlockBodyT, DepositT, - ExecutionPayloadT, WithdrawalCredentials, + ExecutionPayloadT, LogT, WithdrawalCredentialsT, ], error) { // Build the deposit service. return deposit.NewService[ @@ -95,6 +99,8 @@ func ProvideDepositService[ BeaconBlockBodyT, DepositT, ExecutionPayloadT, + LogT, + WithdrawalCredentialsT, ]( in.Logger.With("service", "deposit"), math.U64(in.ChainSpec.Eth1FollowDistance()), diff --git a/mod/node-core/pkg/components/deposit_store.go b/mod/node-core/pkg/components/deposit_store.go index ee0012f645..f2bc72e4fa 100644 --- a/mod/node-core/pkg/components/deposit_store.go +++ b/mod/node-core/pkg/components/deposit_store.go @@ -46,8 +46,9 @@ type DepositStoreInput struct { // application. func ProvideDepositStore[ DepositT Deposit[ - DepositT, *ForkData, WithdrawalCredentials, + DepositT, *ForkData, LogT, WithdrawalCredentials, ], + LogT any, ]( in DepositStoreInput, ) (*depositstore.KVStore[DepositT], error) { @@ -84,9 +85,10 @@ func ProvideDepositPruner[ }, BeaconBlockHeaderT any, DepositT Deposit[ - DepositT, *ForkData, WithdrawalCredentials, + DepositT, *ForkData, LogT, WithdrawalCredentials, ], DepositStoreT DepositStore[DepositT], + LogT any, LoggerT log.AdvancedLogger[LoggerT], ]( in DepositPrunerInput[BeaconBlockT, DepositStoreT, LoggerT], @@ -110,6 +112,7 @@ func ProvideDepositPruner[ BeaconBlockT, BeaconBlockBodyT, DepositT, + LogT, WithdrawalCredentials, ](in.ChainSpec), ), nil diff --git a/mod/node-core/pkg/components/engine.go b/mod/node-core/pkg/components/engine.go index 07e472ebed..4f8101806f 100644 --- a/mod/node-core/pkg/components/engine.go +++ b/mod/node-core/pkg/components/engine.go @@ -51,6 +51,7 @@ func ProvideEngineClient[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], @@ -58,10 +59,12 @@ func ProvideEngineClient[ in EngineClientInputs[LoggerT], ) *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] { return client.New[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ]( in.Config.GetEngine(), @@ -78,13 +81,15 @@ type ExecutionEngineInputs[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], - LoggerT any, + LogT any, + LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], ] struct { depinject.In EngineClient *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] Logger LoggerT @@ -98,22 +103,25 @@ func ProvideExecutionEngine[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], ]( in ExecutionEngineInputs[ - ExecutionPayloadT, ExecutionPayloadHeaderT, LoggerT, WithdrawalT, + ExecutionPayloadT, ExecutionPayloadHeaderT, LogT, LoggerT, WithdrawalT, WithdrawalsT, ], ) *engine.Engine[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], PayloadID, WithdrawalsT, ] { return engine.New[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], PayloadID, WithdrawalsT, diff --git a/mod/node-core/pkg/components/interfaces.go b/mod/node-core/pkg/components/interfaces.go index 62b275b576..77f70093dd 100644 --- a/mod/node-core/pkg/components/interfaces.go +++ b/mod/node-core/pkg/components/interfaces.go @@ -345,6 +345,7 @@ type ( Deposit[ T any, ForkDataT any, + LogT any, WithdrawalCredentialsT any, ] interface { constraints.Empty[T] @@ -374,6 +375,8 @@ type ( message []byte, signature crypto.BLSSignature, ) error, ) error + // UnmarshalLog unmarshals a log into a deposit. + UnmarshalLog(LogT) error } DepositStore[DepositT any] interface { diff --git a/mod/node-core/pkg/components/payload_builder.go b/mod/node-core/pkg/components/payload_builder.go index 24602fe49f..cad41f6a1d 100644 --- a/mod/node-core/pkg/components/payload_builder.go +++ b/mod/node-core/pkg/components/payload_builder.go @@ -39,6 +39,7 @@ type LocalBuilderInput[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], @@ -51,6 +52,7 @@ type LocalBuilderInput[ ChainSpec common.ChainSpec ExecutionEngine *engine.Engine[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], PayloadID, WithdrawalsT, @@ -72,14 +74,15 @@ func ProvideLocalBuilder[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], ]( in LocalBuilderInput[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, LoggerT, - WithdrawalT, WithdrawalsT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, LogT, + LoggerT, WithdrawalT, WithdrawalsT, ], ) *payloadbuilder.PayloadBuilder[ BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, diff --git a/mod/node-core/pkg/components/service_registry.go b/mod/node-core/pkg/components/service_registry.go index db930d4193..4c20ccceb6 100644 --- a/mod/node-core/pkg/components/service_registry.go +++ b/mod/node-core/pkg/components/service_registry.go @@ -56,12 +56,13 @@ type ServiceRegistryInput[ BeaconStateMarshallableT any, BlobSidecarT any, BlobSidecarsT BlobSidecars[BlobSidecarsT, BlobSidecarT], - DepositT Deposit[DepositT, *ForkData, WithdrawalCredentials], + DepositT Deposit[DepositT, *ForkData, LogT, WithdrawalCredentials], DepositStoreT DepositStore[DepositT], ExecutionPayloadT ExecutionPayload[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, GenesisT Genesis[DepositT, ExecutionPayloadHeaderT], KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], @@ -86,11 +87,12 @@ type ServiceRegistryInput[ DBManager *DBManager DepositService *deposit.Service[ BeaconBlockT, BeaconBlockBodyT, DepositT, - ExecutionPayloadT, WithdrawalCredentials, + ExecutionPayloadT, LogT, WithdrawalCredentials, ] Dispatcher Dispatcher EngineClient *client.EngineClient[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], ] Logger LoggerT @@ -125,11 +127,12 @@ func ProvideServiceRegistry[ BeaconStateMarshallableT any, BlobSidecarT any, BlobSidecarsT BlobSidecars[BlobSidecarsT, BlobSidecarT], - DepositT Deposit[DepositT, *ForkData, WithdrawalCredentials], + DepositT Deposit[DepositT, *ForkData, LogT, WithdrawalCredentials], DepositStoreT DepositStore[DepositT], ExecutionPayloadT ExecutionPayload[ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, GenesisT Genesis[DepositT, ExecutionPayloadHeaderT], KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], @@ -142,7 +145,8 @@ func ProvideServiceRegistry[ BeaconBlockHeaderT, BeaconBlockStoreT, BeaconStateT, BeaconStateMarshallableT, BlobSidecarT, BlobSidecarsT, DepositT, DepositStoreT, ExecutionPayloadT, ExecutionPayloadHeaderT, - GenesisT, KVStoreT, LoggerT, NodeAPIContextT, WithdrawalT, WithdrawalsT, + LogT, GenesisT, KVStoreT, LoggerT, NodeAPIContextT, WithdrawalT, + WithdrawalsT, ], ) *service.Registry { return service.NewRegistry( diff --git a/mod/node-core/pkg/components/state_processor.go b/mod/node-core/pkg/components/state_processor.go index 269154b8e5..1570f9ed47 100644 --- a/mod/node-core/pkg/components/state_processor.go +++ b/mod/node-core/pkg/components/state_processor.go @@ -36,6 +36,7 @@ type StateProcessorInput[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, WithdrawalT Withdrawal[WithdrawalT], WithdrawalsT Withdrawals[WithdrawalT], ] struct { @@ -43,6 +44,7 @@ type StateProcessorInput[ ChainSpec common.ChainSpec ExecutionEngine *engine.Engine[ ExecutionPayloadT, + LogT, *engineprimitives.PayloadAttributes[WithdrawalT], PayloadID, WithdrawalsT, @@ -65,11 +67,12 @@ func ProvideStateProcessor[ Validators, WithdrawalT, ], BeaconStateMarshallableT any, - DepositT Deposit[DepositT, *ForkData, WithdrawalCredentials], + DepositT Deposit[DepositT, *ForkData, LogT, WithdrawalCredentials], ExecutionPayloadT ExecutionPayload[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT], + LogT any, KVStoreT BeaconStore[ KVStoreT, BeaconBlockHeaderT, *Eth1Data, ExecutionPayloadHeaderT, *Fork, *Validator, Validators, WithdrawalT, @@ -78,7 +81,7 @@ func ProvideStateProcessor[ WithdrawalT Withdrawal[WithdrawalT], ]( in StateProcessorInput[ - ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalT, WithdrawalsT, + ExecutionPayloadT, ExecutionPayloadHeaderT, LogT, WithdrawalT, WithdrawalsT, ], ) *core.StateProcessor[ BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT, diff --git a/mod/primitives/pkg/crypto/sha256/sha256.go b/mod/primitives/pkg/crypto/sha256/sha256.go index 544f0a70ec..f805f241e1 100644 --- a/mod/primitives/pkg/crypto/sha256/sha256.go +++ b/mod/primitives/pkg/crypto/sha256/sha256.go @@ -34,7 +34,7 @@ var sha256Pool = sync.Pool{New: func() interface{} { return sha256.New() }} -// Sha256 defines a function that returns the sha256 checksum of the data passed +// Hash defines a function that returns the sha256 checksum of the data passed // in. Adheres to the crypto.HashFn signature. // https://github.com/ethereum/consensus-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#hash // diff --git a/mod/primitives/pkg/math/u64.go b/mod/primitives/pkg/math/u64.go index cad6b74ea8..c5dbb15ff2 100644 --- a/mod/primitives/pkg/math/u64.go +++ b/mod/primitives/pkg/math/u64.go @@ -87,6 +87,13 @@ func (u U64) Base10() string { return strconv.FormatUint(uint64(u), 10) } +// Hex returns the hex representation of the U64. +func (u U64) Hex() string { + //#nosec:G703 // its okay. + val, _ := hex.MarshalText(u.Unwrap()) + return string(val) +} + // ----------------------- U64 Mathematical Methods ----------------------- // Unwrap returns a copy of the underlying uint64 value of U64.