From 55547aa7c486cc8087ad346fefcb073de0fb318f Mon Sep 17 00:00:00 2001 From: james-prysm Date: Fri, 19 Jul 2024 17:01:36 -0500 Subject: [PATCH 1/3] creating execution payload copy and fuzz tests --- proto/engine/v1/execution_engine.go | 183 +++++++++++++++++ proto/engine/v1/execution_engine_fuzz_test.go | 10 + proto/prysm/v1alpha1/cloners.go | 191 +----------------- proto/prysm/v1alpha1/cloners_test.go | 39 ---- 4 files changed, 200 insertions(+), 223 deletions(-) diff --git a/proto/engine/v1/execution_engine.go b/proto/engine/v1/execution_engine.go index fb03e21af6ea..5b9691184a5f 100644 --- a/proto/engine/v1/execution_engine.go +++ b/proto/engine/v1/execution_engine.go @@ -15,6 +15,7 @@ func copySlice[T any, C copier[T]](original []C) []T { return newSlice } +// Copy -- func (w *Withdrawal) Copy() *Withdrawal { if w == nil { return nil @@ -28,6 +29,7 @@ func (w *Withdrawal) Copy() *Withdrawal { } } +// Copy -- func (d *DepositRequest) Copy() *DepositRequest { if d == nil { return nil @@ -41,6 +43,7 @@ func (d *DepositRequest) Copy() *DepositRequest { } } +// Copy -- func (wr *WithdrawalRequest) Copy() *WithdrawalRequest { if wr == nil { return nil @@ -52,6 +55,7 @@ func (wr *WithdrawalRequest) Copy() *WithdrawalRequest { } } +// Copy -- func (cr *ConsolidationRequest) Copy() *ConsolidationRequest { if cr == nil { return nil @@ -63,6 +67,7 @@ func (cr *ConsolidationRequest) Copy() *ConsolidationRequest { } } +// Copy -- Electra func (payload *ExecutionPayloadElectra) Copy() *ExecutionPayloadElectra { if payload == nil { return nil @@ -90,3 +95,181 @@ func (payload *ExecutionPayloadElectra) Copy() *ExecutionPayloadElectra { ConsolidationRequests: copySlice(payload.ConsolidationRequests), } } + +// Copy -- Deneb +func (payload *ExecutionPayloadDeneb) Copy() *ExecutionPayloadDeneb { + if payload == nil { + return nil + } + return &ExecutionPayloadDeneb{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), + Withdrawals: copySlice(payload.Withdrawals), + BlobGasUsed: payload.BlobGasUsed, + ExcessBlobGas: payload.ExcessBlobGas, + } +} + +// Copy -- Capella +func (payload *ExecutionPayloadCapella) Copy() *ExecutionPayloadCapella { + if payload == nil { + return nil + } + + return &ExecutionPayloadCapella{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), + Withdrawals: copySlice(payload.Withdrawals), + } +} + +// Copy -- Bellatrix +func (payload *ExecutionPayload) Copy() *ExecutionPayload { + if payload == nil { + return nil + } + + return &ExecutionPayload{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), + } +} + +// Copy -- Electra +func (payload *ExecutionPayloadHeaderElectra) Copy() *ExecutionPayloadHeaderElectra { + if payload == nil { + return nil + } + + return &ExecutionPayloadHeaderElectra{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), + WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), + BlobGasUsed: payload.BlobGasUsed, + ExcessBlobGas: payload.ExcessBlobGas, + DepositRequestsRoot: bytesutil.SafeCopyBytes(payload.DepositRequestsRoot), + WithdrawalRequestsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalRequestsRoot), + ConsolidationRequestsRoot: bytesutil.SafeCopyBytes(payload.ConsolidationRequestsRoot), + } +} + +// Copy -- Deneb +func (payload *ExecutionPayloadHeaderDeneb) Copy() *ExecutionPayloadHeaderDeneb { + if payload == nil { + return nil + } + return &ExecutionPayloadHeaderDeneb{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), + WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), + BlobGasUsed: payload.BlobGasUsed, + ExcessBlobGas: payload.ExcessBlobGas, + } +} + +// Copy -- Capella +func (payload *ExecutionPayloadHeaderCapella) Copy() *ExecutionPayloadHeaderCapella { + if payload == nil { + return nil + } + return &ExecutionPayloadHeaderCapella{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), + WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), + } +} + +// Copy -- Bellatrix +func (payload *ExecutionPayloadHeader) Copy() *ExecutionPayloadHeader { + if payload == nil { + return nil + } + return &ExecutionPayloadHeader{ + ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), + FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), + StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), + ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), + LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), + PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), + BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), + BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), + TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), + } +} diff --git a/proto/engine/v1/execution_engine_fuzz_test.go b/proto/engine/v1/execution_engine_fuzz_test.go index 28d4fb9fa964..fbed9d9b6141 100644 --- a/proto/engine/v1/execution_engine_fuzz_test.go +++ b/proto/engine/v1/execution_engine_fuzz_test.go @@ -11,6 +11,16 @@ import ( func TestCopyExecutionPayload_Fuzz(t *testing.T) { fuzzCopies(t, &enginev1.ExecutionPayloadElectra{}) + fuzzCopies(t, &enginev1.ExecutionPayloadDeneb{}) + fuzzCopies(t, &enginev1.ExecutionPayloadCapella{}) + fuzzCopies(t, &enginev1.ExecutionPayload{}) +} + +func TestCopyExecutionPayloadHeader_Fuzz(t *testing.T) { + fuzzCopies(t, &enginev1.ExecutionPayloadHeaderElectra{}) + fuzzCopies(t, &enginev1.ExecutionPayloadHeaderDeneb{}) + fuzzCopies(t, &enginev1.ExecutionPayloadHeaderCapella{}) + fuzzCopies(t, &enginev1.ExecutionPayloadHeader{}) } func fuzzCopies[T any, C enginev1.Copier[T]](t *testing.T, obj C) { diff --git a/proto/prysm/v1alpha1/cloners.go b/proto/prysm/v1alpha1/cloners.go index 04009820059e..fa680129913a 100644 --- a/proto/prysm/v1alpha1/cloners.go +++ b/proto/prysm/v1alpha1/cloners.go @@ -2,7 +2,6 @@ package eth import ( "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" - enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" ) // CopyETH1Data copies the provided eth1data object. @@ -474,7 +473,7 @@ func CopyBeaconBlockBodyBellatrix(body *BeaconBlockBodyBellatrix) *BeaconBlockBo Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayload: CopyExecutionPayload(body.ExecutionPayload), + ExecutionPayload: body.ExecutionPayload.Copy(), } } @@ -518,7 +517,7 @@ func CopyBeaconBlockBodyCapella(body *BeaconBlockBodyCapella) *BeaconBlockBodyCa Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayload: CopyExecutionPayloadCapella(body.ExecutionPayload), + ExecutionPayload: body.ExecutionPayload.Copy(), BlsToExecutionChanges: CopyBLSToExecutionChanges(body.BlsToExecutionChanges), } } @@ -563,7 +562,7 @@ func CopyBlindedBeaconBlockBodyCapella(body *BlindedBeaconBlockBodyCapella) *Bli Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayloadHeader: CopyExecutionPayloadHeaderCapella(body.ExecutionPayloadHeader), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), BlsToExecutionChanges: CopyBLSToExecutionChanges(body.BlsToExecutionChanges), } } @@ -608,7 +607,7 @@ func CopyBlindedBeaconBlockBodyDeneb(body *BlindedBeaconBlockBodyDeneb) *Blinded Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayloadHeader: CopyExecutionPayloadHeaderDeneb(body.ExecutionPayloadHeader), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), BlsToExecutionChanges: CopyBLSToExecutionChanges(body.BlsToExecutionChanges), BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), } @@ -654,108 +653,12 @@ func CopyBlindedBeaconBlockBodyElectra(body *BlindedBeaconBlockBodyElectra) *Bli Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayloadHeader: CopyExecutionPayloadHeaderElectra(body.ExecutionPayloadHeader), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), BlsToExecutionChanges: CopyBLSToExecutionChanges(body.BlsToExecutionChanges), BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), } } -// CopyExecutionPayload copies the provided execution payload. -func CopyExecutionPayload(payload *enginev1.ExecutionPayload) *enginev1.ExecutionPayload { - if payload == nil { - return nil - } - - return &enginev1.ExecutionPayload{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), - } -} - -// CopyExecutionPayloadCapella copies the provided execution payload. -func CopyExecutionPayloadCapella(payload *enginev1.ExecutionPayloadCapella) *enginev1.ExecutionPayloadCapella { - if payload == nil { - return nil - } - - return &enginev1.ExecutionPayloadCapella{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), - Withdrawals: copySlice(payload.Withdrawals), - } -} - -// CopyExecutionPayloadHeader copies the provided execution payload object. -func CopyExecutionPayloadHeader(payload *enginev1.ExecutionPayloadHeader) *enginev1.ExecutionPayloadHeader { - if payload == nil { - return nil - } - return &enginev1.ExecutionPayloadHeader{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), - } -} - -// CopyExecutionPayloadHeaderCapella copies the provided execution payload object. -func CopyExecutionPayloadHeaderCapella(payload *enginev1.ExecutionPayloadHeaderCapella) *enginev1.ExecutionPayloadHeaderCapella { - if payload == nil { - return nil - } - return &enginev1.ExecutionPayloadHeaderCapella{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), - WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), - } -} - // CopySignedBlindedBeaconBlockBellatrix copies the provided SignedBlindedBeaconBlockBellatrix. func CopySignedBlindedBeaconBlockBellatrix(sigBlock *SignedBlindedBeaconBlockBellatrix) *SignedBlindedBeaconBlockBellatrix { if sigBlock == nil { @@ -796,7 +699,7 @@ func CopyBlindedBeaconBlockBodyBellatrix(body *BlindedBeaconBlockBodyBellatrix) Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayloadHeader: CopyExecutionPayloadHeader(body.ExecutionPayloadHeader), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), } } @@ -865,64 +768,12 @@ func CopyBeaconBlockBodyDeneb(body *BeaconBlockBodyDeneb) *BeaconBlockBodyDeneb Deposits: CopyDeposits(body.Deposits), VoluntaryExits: CopySignedVoluntaryExits(body.VoluntaryExits), SyncAggregate: CopySyncAggregate(body.SyncAggregate), - ExecutionPayload: CopyExecutionPayloadDeneb(body.ExecutionPayload), + ExecutionPayload: body.ExecutionPayload.Copy(), BlsToExecutionChanges: CopyBLSToExecutionChanges(body.BlsToExecutionChanges), BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), } } -// CopyExecutionPayloadHeaderDeneb copies the provided execution payload object. -func CopyExecutionPayloadHeaderDeneb(payload *enginev1.ExecutionPayloadHeaderDeneb) *enginev1.ExecutionPayloadHeaderDeneb { - if payload == nil { - return nil - } - return &enginev1.ExecutionPayloadHeaderDeneb{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), - WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), - BlobGasUsed: payload.BlobGasUsed, - ExcessBlobGas: payload.ExcessBlobGas, - } -} - -// CopyExecutionPayloadDeneb copies the provided execution payload. -func CopyExecutionPayloadDeneb(payload *enginev1.ExecutionPayloadDeneb) *enginev1.ExecutionPayloadDeneb { - if payload == nil { - return nil - } - return &enginev1.ExecutionPayloadDeneb{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), - Withdrawals: copySlice(payload.Withdrawals), - BlobGasUsed: payload.BlobGasUsed, - ExcessBlobGas: payload.ExcessBlobGas, - } -} - // CopySignedBeaconBlockElectra copies the provided SignedBeaconBlockElectra. func CopySignedBeaconBlockElectra(sigBlock *SignedBeaconBlockElectra) *SignedBeaconBlockElectra { if sigBlock == nil { @@ -969,34 +820,6 @@ func CopyBeaconBlockBodyElectra(body *BeaconBlockBodyElectra) *BeaconBlockBodyEl } } -func CopyExecutionPayloadHeaderElectra(payload *enginev1.ExecutionPayloadHeaderElectra) *enginev1.ExecutionPayloadHeaderElectra { - if payload == nil { - return nil - } - return &enginev1.ExecutionPayloadHeaderElectra{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: payload.BlockNumber, - GasLimit: payload.GasLimit, - GasUsed: payload.GasUsed, - Timestamp: payload.Timestamp, - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(payload.TransactionsRoot), - WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot), - BlobGasUsed: payload.BlobGasUsed, - ExcessBlobGas: payload.ExcessBlobGas, - DepositRequestsRoot: bytesutil.SafeCopyBytes(payload.DepositRequestsRoot), - WithdrawalRequestsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalRequestsRoot), - ConsolidationRequestsRoot: bytesutil.SafeCopyBytes(payload.ConsolidationRequestsRoot), - } -} - // CopyHistoricalSummaries copies the historical summaries. func CopyHistoricalSummaries(summaries []*HistoricalSummary) []*HistoricalSummary { if summaries == nil { diff --git a/proto/prysm/v1alpha1/cloners_test.go b/proto/prysm/v1alpha1/cloners_test.go index 22a348f31660..90dbdd450381 100644 --- a/proto/prysm/v1alpha1/cloners_test.go +++ b/proto/prysm/v1alpha1/cloners_test.go @@ -309,36 +309,6 @@ func TestCopyPendingAttestationSlice(t *testing.T) { } } -func TestCopyPayloadHeader(t *testing.T) { - p := genPayloadHeader() - - got := v1alpha1.CopyExecutionPayloadHeader(p) - if !reflect.DeepEqual(got, p) { - t.Errorf("CopyExecutionPayloadHeader() = %v, want %v", got, p) - } - assert.NotEmpty(t, got, "Copied execution payload header has empty fields") -} - -func TestCopyPayloadHeaderCapella(t *testing.T) { - p := genPayloadHeaderCapella() - - got := v1alpha1.CopyExecutionPayloadHeaderCapella(p) - if !reflect.DeepEqual(got, p) { - t.Errorf("TestCopyPayloadHeaderCapella() = %v, want %v", got, p) - } - assert.NotEmpty(t, got, "Copied execution payload header has empty fields") -} - -func TestCopyPayloadHeaderDeneb(t *testing.T) { - p := genPayloadHeaderDeneb() - - got := v1alpha1.CopyExecutionPayloadHeaderDeneb(p) - if !reflect.DeepEqual(got, p) { - t.Errorf("TestCopyPayloadHeaderDeneb() = %v, want %v", got, p) - } - assert.NotEmpty(t, got, "Copied execution payload header has empty fields") -} - func TestCopySignedBeaconBlockBellatrix(t *testing.T) { sbb := genSignedBeaconBlockBellatrix() @@ -638,15 +608,6 @@ func TestCopyBeaconBlockBodyElectra(t *testing.T) { } } -func TestCopyExecutionPayloadHeaderElectra(t *testing.T) { - p := genExecutionPayloadHeaderElectra() - - got := v1alpha1.CopyExecutionPayloadHeaderElectra(p) - if !reflect.DeepEqual(got, p) { - t.Errorf("TestCopyExecutionPayloadHeaderElectra() = %v, want %v", got, p) - } -} - func TestCopyPendingPartialWithdrawals(t *testing.T) { ppws := genPendingPartialWithdrawals(10) From 05e865a25eb6da40a242a66a29e763c19b2f9c0d Mon Sep 17 00:00:00 2001 From: james-prysm Date: Fri, 19 Jul 2024 17:10:20 -0500 Subject: [PATCH 2/3] fixing build --- .../state-native/getters_payload_header.go | 30 +++---------------- .../state/state-native/getters_state.go | 8 ++--- beacon-chain/state/state-native/state_trie.go | 8 ++--- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/beacon-chain/state/state-native/getters_payload_header.go b/beacon-chain/state/state-native/getters_payload_header.go index ff27b8a7ab32..577105346c5a 100644 --- a/beacon-chain/state/state-native/getters_payload_header.go +++ b/beacon-chain/state/state-native/getters_payload_header.go @@ -5,8 +5,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" - enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" ) @@ -21,34 +19,14 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (interfaces.ExecutionData, switch b.version { case version.Bellatrix: - return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeaderVal()) + return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeader.Copy()) case version.Capella: - return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapellaVal()) + return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella.Copy()) case version.Deneb: - return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDenebVal()) + return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDeneb.Copy()) case version.Electra: - return blocks.WrappedExecutionPayloadHeaderElectra(b.latestExecutionPayloadHeaderElectraVal()) + return blocks.WrappedExecutionPayloadHeaderElectra(b.latestExecutionPayloadHeaderElectra.Copy()) default: return nil, fmt.Errorf("unsupported version (%s) for latest execution payload header", version.String(b.version)) } } - -// latestExecutionPayloadHeaderVal of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestExecutionPayloadHeaderVal() *enginev1.ExecutionPayloadHeader { - return ethpb.CopyExecutionPayloadHeader(b.latestExecutionPayloadHeader) -} - -// latestExecutionPayloadHeaderCapellaVal of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestExecutionPayloadHeaderCapellaVal() *enginev1.ExecutionPayloadHeaderCapella { - return ethpb.CopyExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella) -} - -func (b *BeaconState) latestExecutionPayloadHeaderDenebVal() *enginev1.ExecutionPayloadHeaderDeneb { - return ethpb.CopyExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDeneb) -} - -func (b *BeaconState) latestExecutionPayloadHeaderElectraVal() *enginev1.ExecutionPayloadHeaderElectra { - return ethpb.CopyExecutionPayloadHeaderElectra(b.latestExecutionPayloadHeaderElectra) -} diff --git a/beacon-chain/state/state-native/getters_state.go b/beacon-chain/state/state-native/getters_state.go index 65cae0787134..66f512369f9b 100644 --- a/beacon-chain/state/state-native/getters_state.go +++ b/beacon-chain/state/state-native/getters_state.go @@ -314,7 +314,7 @@ func (b *BeaconState) ToProto() interface{} { InactivityScores: inactivityScores, CurrentSyncCommittee: b.currentSyncCommitteeVal(), NextSyncCommittee: b.nextSyncCommitteeVal(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderVal(), + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeader.Copy(), } case version.Capella: return ðpb.BeaconStateCapella{ @@ -342,7 +342,7 @@ func (b *BeaconState) ToProto() interface{} { InactivityScores: inactivityScores, CurrentSyncCommittee: b.currentSyncCommitteeVal(), NextSyncCommittee: b.nextSyncCommitteeVal(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(), + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapella.Copy(), NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, HistoricalSummaries: b.historicalSummariesVal(), @@ -373,7 +373,7 @@ func (b *BeaconState) ToProto() interface{} { InactivityScores: b.inactivityScoresVal(), CurrentSyncCommittee: b.currentSyncCommitteeVal(), NextSyncCommittee: b.nextSyncCommitteeVal(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderDenebVal(), + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderDeneb.Copy(), NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, HistoricalSummaries: b.historicalSummariesVal(), @@ -404,7 +404,7 @@ func (b *BeaconState) ToProto() interface{} { InactivityScores: b.inactivityScoresVal(), CurrentSyncCommittee: b.currentSyncCommitteeVal(), NextSyncCommittee: b.nextSyncCommitteeVal(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderElectraVal(), + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderElectra.Copy(), NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, HistoricalSummaries: b.historicalSummariesVal(), diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index 095fd9e52817..c1c052ed3fbe 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -907,10 +907,10 @@ func (b *BeaconState) Copy() state.BeaconState { finalizedCheckpoint: b.finalizedCheckpointVal(), currentSyncCommittee: b.currentSyncCommitteeVal(), nextSyncCommittee: b.nextSyncCommitteeVal(), - latestExecutionPayloadHeader: b.latestExecutionPayloadHeaderVal(), - latestExecutionPayloadHeaderCapella: b.latestExecutionPayloadHeaderCapellaVal(), - latestExecutionPayloadHeaderDeneb: b.latestExecutionPayloadHeaderDenebVal(), - latestExecutionPayloadHeaderElectra: b.latestExecutionPayloadHeaderElectraVal(), + latestExecutionPayloadHeader: b.latestExecutionPayloadHeader.Copy(), + latestExecutionPayloadHeaderCapella: b.latestExecutionPayloadHeaderCapella.Copy(), + latestExecutionPayloadHeaderDeneb: b.latestExecutionPayloadHeaderDeneb.Copy(), + latestExecutionPayloadHeaderElectra: b.latestExecutionPayloadHeaderElectra.Copy(), id: types.Enumerator.Inc(), From 7799f922ec35c2c78198a49750860ae0d49f91da Mon Sep 17 00:00:00 2001 From: james-prysm Date: Fri, 19 Jul 2024 17:19:03 -0500 Subject: [PATCH 3/3] removing unused code --- proto/prysm/v1alpha1/cloners.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/proto/prysm/v1alpha1/cloners.go b/proto/prysm/v1alpha1/cloners.go index fa680129913a..f8c4610ccf42 100644 --- a/proto/prysm/v1alpha1/cloners.go +++ b/proto/prysm/v1alpha1/cloners.go @@ -878,16 +878,3 @@ func CopyPendingBalanceDeposits(pbd []*PendingBalanceDeposit) []*PendingBalanceD } return newPbd } - -type cloneable[T any] interface { - Copy() T -} - -func copySlice[T any, C cloneable[T]](original []C) []T { - // Create a new slice with the same length as the original - newSlice := make([]T, len(original)) - for i := 0; i < len(newSlice); i++ { - newSlice[i] = original[i].Copy() - } - return newSlice -}