Skip to content

Commit 82b66b1

Browse files
MariusVanDerWijdenlightclientholimanfjl
authored andcommitted
eth/catalyst,miner: include withdrawals in payload id calculation (ethereum#26554)
According to the spec the payloadID needs to be random or dependent on all arguments, to prevent two payloads from clashing. This change adds withdrawals into the payload derivation. --------- Co-authored-by: lightclient@protonmail.com <lightclient@protonmail.com> Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent 62090db commit 82b66b1

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

eth/catalyst/api_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ func TestWithdrawals(t *testing.T) {
10411041
Timestamp: blockParams.Timestamp,
10421042
FeeRecipient: blockParams.SuggestedFeeRecipient,
10431043
Random: blockParams.Random,
1044+
Withdrawals: blockParams.Withdrawals,
10441045
}).Id()
10451046
execData, err := api.GetPayloadV2(payloadID)
10461047
if err != nil {
@@ -1087,6 +1088,7 @@ func TestWithdrawals(t *testing.T) {
10871088
Timestamp: blockParams.Timestamp,
10881089
FeeRecipient: blockParams.SuggestedFeeRecipient,
10891090
Random: blockParams.Random,
1091+
Withdrawals: blockParams.Withdrawals,
10901092
}).Id()
10911093
execData, err = api.GetPayloadV2(payloadID)
10921094
if err != nil {

miner/payload_building.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/core/types"
2929
"github.com/ethereum/go-ethereum/log"
3030
"github.com/ethereum/go-ethereum/params"
31+
"github.com/ethereum/go-ethereum/rlp"
3132
)
3233

3334
// BuildPayloadArgs contains the provided parameters for building payload.
@@ -49,6 +50,7 @@ func (args *BuildPayloadArgs) Id() engine.PayloadID {
4950
binary.Write(hasher, binary.BigEndian, args.Timestamp)
5051
hasher.Write(args.Random[:])
5152
hasher.Write(args.FeeRecipient[:])
53+
rlp.Encode(hasher, args.Withdrawals)
5254
var out engine.PayloadID
5355
copy(out[:], hasher.Sum(nil)[:8])
5456
return out

miner/payload_building_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/consensus/ethash"
2727
"github.com/ethereum/go-ethereum/core/rawdb"
28+
"github.com/ethereum/go-ethereum/core/types"
2829
"github.com/ethereum/go-ethereum/params"
2930
)
3031

@@ -79,3 +80,79 @@ func TestBuildPayload(t *testing.T) {
7980
t.Fatal("Unexpected payload data")
8081
}
8182
}
83+
84+
func TestPayloadId(t *testing.T) {
85+
ids := make(map[string]int)
86+
for i, tt := range []*BuildPayloadArgs{
87+
&BuildPayloadArgs{
88+
Parent: common.Hash{1},
89+
Timestamp: 1,
90+
Random: common.Hash{0x1},
91+
FeeRecipient: common.Address{0x1},
92+
},
93+
// Different parent
94+
&BuildPayloadArgs{
95+
Parent: common.Hash{2},
96+
Timestamp: 1,
97+
Random: common.Hash{0x1},
98+
FeeRecipient: common.Address{0x1},
99+
},
100+
// Different timestamp
101+
&BuildPayloadArgs{
102+
Parent: common.Hash{2},
103+
Timestamp: 2,
104+
Random: common.Hash{0x1},
105+
FeeRecipient: common.Address{0x1},
106+
},
107+
// Different Random
108+
&BuildPayloadArgs{
109+
Parent: common.Hash{2},
110+
Timestamp: 2,
111+
Random: common.Hash{0x2},
112+
FeeRecipient: common.Address{0x1},
113+
},
114+
// Different fee-recipient
115+
&BuildPayloadArgs{
116+
Parent: common.Hash{2},
117+
Timestamp: 2,
118+
Random: common.Hash{0x2},
119+
FeeRecipient: common.Address{0x2},
120+
},
121+
// Different withdrawals (non-empty)
122+
&BuildPayloadArgs{
123+
Parent: common.Hash{2},
124+
Timestamp: 2,
125+
Random: common.Hash{0x2},
126+
FeeRecipient: common.Address{0x2},
127+
Withdrawals: []*types.Withdrawal{
128+
&types.Withdrawal{
129+
Index: 0,
130+
Validator: 0,
131+
Address: common.Address{},
132+
Amount: 0,
133+
},
134+
},
135+
},
136+
// Different withdrawals (non-empty)
137+
&BuildPayloadArgs{
138+
Parent: common.Hash{2},
139+
Timestamp: 2,
140+
Random: common.Hash{0x2},
141+
FeeRecipient: common.Address{0x2},
142+
Withdrawals: []*types.Withdrawal{
143+
&types.Withdrawal{
144+
Index: 2,
145+
Validator: 0,
146+
Address: common.Address{},
147+
Amount: 0,
148+
},
149+
},
150+
},
151+
} {
152+
id := tt.Id().String()
153+
if prev, exists := ids[id]; exists {
154+
t.Errorf("ID collision, case %d and case %d: id %v", prev, i, id)
155+
}
156+
ids[id] = i
157+
}
158+
}

0 commit comments

Comments
 (0)