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

eth/catalyst,miner: include withdrawals in payload id calculation #26554

Merged
merged 5 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ func TestWithdrawals(t *testing.T) {
Timestamp: blockParams.Timestamp,
FeeRecipient: blockParams.SuggestedFeeRecipient,
Random: blockParams.Random,
Withdrawals: blockParams.Withdrawals,
}).Id()
execData, err := api.GetPayloadV2(payloadID)
if err != nil {
Expand Down Expand Up @@ -1083,6 +1084,7 @@ func TestWithdrawals(t *testing.T) {
Timestamp: blockParams.Timestamp,
FeeRecipient: blockParams.SuggestedFeeRecipient,
Random: blockParams.Random,
Withdrawals: blockParams.Withdrawals,
}).Id()
execData, err = api.GetPayloadV2(payloadID)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
)

// BuildPayloadArgs contains the provided parameters for building payload.
Expand All @@ -49,6 +50,7 @@ func (args *BuildPayloadArgs) Id() beacon.PayloadID {
binary.Write(hasher, binary.BigEndian, args.Timestamp)
hasher.Write(args.Random[:])
hasher.Write(args.FeeRecipient[:])
rlp.Encode(hasher, args.Withdrawals)
var out beacon.PayloadID
copy(out[:], hasher.Sum(nil)[:8])
return out
Expand Down
86 changes: 86 additions & 0 deletions miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -79,3 +80,88 @@ func TestBuildPayload(t *testing.T) {
t.Fatal("Unexpected payload data")
}
}

func TestPayloadId(t *testing.T) {
ids := make(map[string]int)
for i, tt := range []*BuildPayloadArgs{
&BuildPayloadArgs{
Parent: common.Hash{1},
Timestamp: 1,
Random: common.Hash{0x1},
FeeRecipient: common.Address{0x1},
},
// Different parent
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 1,
Random: common.Hash{0x1},
FeeRecipient: common.Address{0x1},
},
// Different timestamp
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x1},
FeeRecipient: common.Address{0x1},
},
// Different Random
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x2},
FeeRecipient: common.Address{0x1},
},
// Different fee-recipient
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x2},
FeeRecipient: common.Address{0x2},
},
// Different withdrawals (empty list)
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x2},
FeeRecipient: common.Address{0x2},
Withdrawals: make([]*types.Withdrawal, 0),
},
fjl marked this conversation as resolved.
Show resolved Hide resolved
// Different withdrawals (non-empty)
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x2},
FeeRecipient: common.Address{0x2},
Withdrawals: []*types.Withdrawal{
&types.Withdrawal{
Index: 0,
Validator: 0,
Address: common.Address{},
Amount: 0,
},
},
},
// Different withdrawals (non-empty)
&BuildPayloadArgs{
Parent: common.Hash{2},
Timestamp: 2,
Random: common.Hash{0x2},
FeeRecipient: common.Address{0x2},
Withdrawals: []*types.Withdrawal{
&types.Withdrawal{
Index: 2,
Validator: 0,
Address: common.Address{},
Amount: 0,
},
},
},
} {
id := tt.Id().String()
if prev, exists := ids[id]; exists {
t.Errorf("ID collision, case %d and case %d: id %v", prev, i, id)
}
ids[id] = i
}

holiman marked this conversation as resolved.
Show resolved Hide resolved
}