eth/catalyst,miner: include withdrawals in payload id calculation (#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>
This commit is contained in:
Marius van der Wijden 2023-02-07 19:16:53 +01:00 committed by GitHub
parent 31d401ea68
commit 2f73f4f028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 0 deletions

View File

@ -1041,6 +1041,7 @@ func TestWithdrawals(t *testing.T) {
Timestamp: blockParams.Timestamp, Timestamp: blockParams.Timestamp,
FeeRecipient: blockParams.SuggestedFeeRecipient, FeeRecipient: blockParams.SuggestedFeeRecipient,
Random: blockParams.Random, Random: blockParams.Random,
Withdrawals: blockParams.Withdrawals,
}).Id() }).Id()
execData, err := api.GetPayloadV2(payloadID) execData, err := api.GetPayloadV2(payloadID)
if err != nil { if err != nil {
@ -1087,6 +1088,7 @@ func TestWithdrawals(t *testing.T) {
Timestamp: blockParams.Timestamp, Timestamp: blockParams.Timestamp,
FeeRecipient: blockParams.SuggestedFeeRecipient, FeeRecipient: blockParams.SuggestedFeeRecipient,
Random: blockParams.Random, Random: blockParams.Random,
Withdrawals: blockParams.Withdrawals,
}).Id() }).Id()
execData, err = api.GetPayloadV2(payloadID) execData, err = api.GetPayloadV2(payloadID)
if err != nil { if err != nil {

View File

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
) )
// BuildPayloadArgs contains the provided parameters for building payload. // BuildPayloadArgs contains the provided parameters for building payload.
@ -49,6 +50,7 @@ func (args *BuildPayloadArgs) Id() engine.PayloadID {
binary.Write(hasher, binary.BigEndian, args.Timestamp) binary.Write(hasher, binary.BigEndian, args.Timestamp)
hasher.Write(args.Random[:]) hasher.Write(args.Random[:])
hasher.Write(args.FeeRecipient[:]) hasher.Write(args.FeeRecipient[:])
rlp.Encode(hasher, args.Withdrawals)
var out engine.PayloadID var out engine.PayloadID
copy(out[:], hasher.Sum(nil)[:8]) copy(out[:], hasher.Sum(nil)[:8])
return out return out

View File

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -79,3 +80,79 @@ func TestBuildPayload(t *testing.T) {
t.Fatal("Unexpected payload data") 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 (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
}
}