Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

electra payload fix for devnet1 #14235

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions beacon-chain/execution/engine_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ func TestClient_HTTP(t *testing.T) {
require.DeepEqual(t, proofs, resp.BlobsBundle.Proofs)
blobs := [][]byte{bytesutil.PadTo([]byte("a"), fieldparams.BlobLength), bytesutil.PadTo([]byte("b"), fieldparams.BlobLength)}
require.DeepEqual(t, blobs, resp.BlobsBundle.Blobs)
ede, ok := resp.ExecutionData.(interfaces.ExecutionDataElectra)
require.Equal(t, true, ok)
require.NotNil(t, ede.WithdrawalRequests())
wrequestsNotOverMax := len(ede.WithdrawalRequests()) <= int(params.BeaconConfig().MaxWithdrawalRequestsPerPayload)
require.Equal(t, true, wrequestsNotOverMax)
require.NotNil(t, ede.DepositRequests())
drequestsNotOverMax := len(ede.DepositRequests()) <= int(params.BeaconConfig().MaxDepositRequestsPerPayload)
require.Equal(t, true, drequestsNotOverMax)
require.NotNil(t, ede.ConsolidationRequests())
consolidationsNotOverMax := len(ede.ConsolidationRequests()) <= int(params.BeaconConfig().MaxConsolidationsRequestsPerPayload)
require.Equal(t, true, consolidationsNotOverMax)
})
t.Run(ForkchoiceUpdatedMethod+" VALID status", func(t *testing.T) {
forkChoiceState := &pb.ForkchoiceState{
Expand Down Expand Up @@ -1633,24 +1644,25 @@ func fixturesStruct() *payloadFixtures {
executionPayloadWithValueFixtureElectra := &pb.GetPayloadV4ResponseJson{
ShouldOverrideBuilder: true,
ExecutionPayload: &pb.ExecutionPayloadElectraJSON{
ParentHash: &common.Hash{'a'},
FeeRecipient: &common.Address{'b'},
StateRoot: &common.Hash{'c'},
ReceiptsRoot: &common.Hash{'d'},
LogsBloom: &hexutil.Bytes{'e'},
PrevRandao: &common.Hash{'f'},
BaseFeePerGas: "0x123",
BlockHash: &common.Hash{'g'},
Transactions: []hexutil.Bytes{{'h'}},
Withdrawals: []*pb.Withdrawal{},
BlockNumber: &hexUint,
GasLimit: &hexUint,
GasUsed: &hexUint,
Timestamp: &hexUint,
BlobGasUsed: &bgu,
ExcessBlobGas: &ebg,
DepositRequests: depositRequests,
WithdrawalRequests: withdrawalRequests,
ParentHash: &common.Hash{'a'},
FeeRecipient: &common.Address{'b'},
StateRoot: &common.Hash{'c'},
ReceiptsRoot: &common.Hash{'d'},
LogsBloom: &hexutil.Bytes{'e'},
PrevRandao: &common.Hash{'f'},
BaseFeePerGas: "0x123",
BlockHash: &common.Hash{'g'},
Transactions: []hexutil.Bytes{{'h'}},
Withdrawals: []*pb.Withdrawal{},
BlockNumber: &hexUint,
GasLimit: &hexUint,
GasUsed: &hexUint,
Timestamp: &hexUint,
BlobGasUsed: &bgu,
ExcessBlobGas: &ebg,
DepositRequests: depositRequests,
WithdrawalRequests: withdrawalRequests,
ConsolidationRequests: consolidationRequests,
},
BlockValue: "0x11fffffffff",
BlobsBundle: &pb.BlobBundleJSON{
Expand Down
39 changes: 20 additions & 19 deletions proto/engine/v1/json_marshal_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,25 +992,26 @@ func (e *ExecutionPayloadElectra) MarshalJSON() ([]byte, error) {
excessBlobGas := hexutil.Uint64(e.ExcessBlobGas)

return json.Marshal(ExecutionPayloadElectraJSON{
ParentHash: &pHash,
FeeRecipient: &recipient,
StateRoot: &sRoot,
ReceiptsRoot: &recRoot,
LogsBloom: &logsBloom,
PrevRandao: &prevRan,
BlockNumber: &blockNum,
GasLimit: &gasLimit,
GasUsed: &gasUsed,
Timestamp: &timeStamp,
ExtraData: e.ExtraData,
BaseFeePerGas: baseFeeHex,
BlockHash: &bHash,
Transactions: transactions,
Withdrawals: withdrawals,
BlobGasUsed: &blobGasUsed,
ExcessBlobGas: &excessBlobGas,
WithdrawalRequests: ProtoWithdrawalRequestsToJson(e.WithdrawalRequests),
DepositRequests: ProtoDepositRequestsToJson(e.DepositRequests),
ParentHash: &pHash,
FeeRecipient: &recipient,
StateRoot: &sRoot,
ReceiptsRoot: &recRoot,
LogsBloom: &logsBloom,
PrevRandao: &prevRan,
BlockNumber: &blockNum,
GasLimit: &gasLimit,
GasUsed: &gasUsed,
Timestamp: &timeStamp,
ExtraData: e.ExtraData,
BaseFeePerGas: baseFeeHex,
BlockHash: &bHash,
Transactions: transactions,
Withdrawals: withdrawals,
BlobGasUsed: &blobGasUsed,
ExcessBlobGas: &excessBlobGas,
WithdrawalRequests: ProtoWithdrawalRequestsToJson(e.WithdrawalRequests),
DepositRequests: ProtoDepositRequestsToJson(e.DepositRequests),
ConsolidationRequests: ProtoConsolidationRequestsToJson(e.ConsolidationRequests),
})
}

Expand Down
55 changes: 36 additions & 19 deletions proto/prysm/v1alpha1/cloners.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,25 +1002,26 @@ func CopyExecutionPayloadElectra(payload *enginev1.ExecutionPayloadElectra) *eng
return nil
}
return &enginev1.ExecutionPayloadElectra{
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: CopyWithdrawalSlice(payload.Withdrawals),
BlobGasUsed: payload.BlobGasUsed,
ExcessBlobGas: payload.ExcessBlobGas,
DepositRequests: CopyDepositRequests(payload.DepositRequests),
WithdrawalRequests: CopyWithdrawalRequests(payload.WithdrawalRequests),
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: CopyWithdrawalSlice(payload.Withdrawals),
BlobGasUsed: payload.BlobGasUsed,
ExcessBlobGas: payload.ExcessBlobGas,
DepositRequests: CopyDepositRequests(payload.DepositRequests),
WithdrawalRequests: CopyWithdrawalRequests(payload.WithdrawalRequests),
ConsolidationRequests: CopyConsolidationRequests(payload.ConsolidationRequests),
}
}

Expand Down Expand Up @@ -1058,6 +1059,22 @@ func CopyWithdrawalRequests(wr []*enginev1.WithdrawalRequest) []*enginev1.Withdr
return newWr
}

func CopyConsolidationRequests(cr []*enginev1.ConsolidationRequest) []*enginev1.ConsolidationRequest {
if cr == nil {
return nil
}
newCr := make([]*enginev1.ConsolidationRequest, len(cr))
for i, w := range cr {
newCr[i] = &enginev1.ConsolidationRequest{
SourceAddress: bytesutil.SafeCopyBytes(w.SourceAddress),
SourcePubkey: bytesutil.SafeCopyBytes(w.SourcePubkey),
TargetPubkey: bytesutil.SafeCopyBytes(w.TargetPubkey),
}
}

return newCr
}

func CopyExecutionPayloadHeaderElectra(payload *enginev1.ExecutionPayloadHeaderElectra) *enginev1.ExecutionPayloadHeaderElectra {
if payload == nil {
return nil
Expand Down
55 changes: 36 additions & 19 deletions proto/prysm/v1alpha1/cloners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,25 +1465,26 @@ func genBeaconBlockBodyElectra() *v1alpha1.BeaconBlockBodyElectra {

func genExecutionPayloadElectra() *enginev1.ExecutionPayloadElectra {
return &enginev1.ExecutionPayloadElectra{
ParentHash: bytes(32),
FeeRecipient: bytes(20),
StateRoot: bytes(32),
ReceiptsRoot: bytes(32),
LogsBloom: bytes(256),
PrevRandao: bytes(32),
BlockNumber: 1,
GasLimit: 2,
GasUsed: 3,
Timestamp: 4,
ExtraData: bytes(32),
BaseFeePerGas: bytes(32),
BlockHash: bytes(32),
Transactions: [][]byte{{'a'}, {'b'}, {'c'}},
Withdrawals: genWithdrawals(10),
BlobGasUsed: 5,
ExcessBlobGas: 6,
DepositRequests: genDepositRequests(10),
WithdrawalRequests: genWithdrawalRequests(10),
ParentHash: bytes(32),
FeeRecipient: bytes(20),
StateRoot: bytes(32),
ReceiptsRoot: bytes(32),
LogsBloom: bytes(256),
PrevRandao: bytes(32),
BlockNumber: 1,
GasLimit: 2,
GasUsed: 3,
Timestamp: 4,
ExtraData: bytes(32),
BaseFeePerGas: bytes(32),
BlockHash: bytes(32),
Transactions: [][]byte{{'a'}, {'b'}, {'c'}},
Withdrawals: genWithdrawals(10),
BlobGasUsed: 5,
ExcessBlobGas: 6,
DepositRequests: genDepositRequests(10),
WithdrawalRequests: genWithdrawalRequests(10),
ConsolidationRequests: genConsolidationRequests(10),
}
}

Expand Down Expand Up @@ -1521,6 +1522,22 @@ func genWithdrawalRequest() *enginev1.WithdrawalRequest {
}
}

func genConsolidationRequests(num int) []*enginev1.ConsolidationRequest {
crs := make([]*enginev1.ConsolidationRequest, num)
for i := 0; i < num; i++ {
crs[i] = genConsolidationRequest()
}
return crs
}

func genConsolidationRequest() *enginev1.ConsolidationRequest {
return &enginev1.ConsolidationRequest{
SourceAddress: bytes(20),
SourcePubkey: bytes(48),
TargetPubkey: bytes(48),
}
}

func genPendingPartialWithdrawals(num int) []*v1alpha1.PendingPartialWithdrawal {
ppws := make([]*v1alpha1.PendingPartialWithdrawal, num)
for i := 0; i < num; i++ {
Expand Down
Loading