Skip to content

Commit fcd8586

Browse files
Ruteriavalonche
authored andcommitted
Adjust transactions root computation (ethereum#3)
1 parent 367e949 commit fcd8586

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

builder/backend.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package builder
33
import (
44
"bytes"
55
"encoding/json"
6-
"fmt"
76
"html/template"
87
"math/big"
98
"net/http"
@@ -17,7 +16,6 @@ import (
1716
"github.com/ethereum/go-ethereum/core/beacon"
1817
"github.com/ethereum/go-ethereum/core/types"
1918
"github.com/ethereum/go-ethereum/log"
20-
"github.com/ethereum/go-ethereum/trie"
2119
"github.com/gorilla/mux"
2220

2321
"github.com/flashbots/go-boost-utils/bls"
@@ -358,7 +356,7 @@ func (b *Backend) newSealedBlock(data *beacon.ExecutableDataV1, block *types.Blo
358356
log.Info("newSealedBlock", "data", string(dataJson))
359357
}
360358
payload := executableDataToExecutionPayload(data)
361-
payloadHeader, err := payloadToPayloadHeader(payload)
359+
payloadHeader, err := payloadToPayloadHeader(payload, data)
362360
if err != nil {
363361
log.Error("could not convert payload to header", "err", err)
364362
return
@@ -371,23 +369,13 @@ func (b *Backend) newSealedBlock(data *beacon.ExecutableDataV1, block *types.Blo
371369
b.bestDataLock.Unlock()
372370
}
373371

374-
func decodeTransactions(enc []hexutil.Bytes) ([]*types.Transaction, error) {
375-
var txs = make([]*types.Transaction, len(enc))
376-
for i, encTx := range enc {
377-
var tx types.Transaction
378-
if err := tx.UnmarshalBinary(encTx); err != nil {
379-
return nil, fmt.Errorf("invalid transaction %d: %v", i, err)
380-
}
381-
txs[i] = &tx
382-
}
383-
return txs, nil
384-
}
385-
386-
func payloadToPayloadHeader(p *boostTypes.ExecutionPayload) (*boostTypes.ExecutionPayloadHeader, error) {
387-
txs, err := decodeTransactions(p.Transactions)
372+
func payloadToPayloadHeader(p *boostTypes.ExecutionPayload, data *beacon.ExecutableDataV1) (*boostTypes.ExecutionPayloadHeader, error) {
373+
txs := boostTypes.Transactions{data.Transactions}
374+
txroot, err := txs.HashTreeRoot()
388375
if err != nil {
389376
return nil, err
390377
}
378+
391379
return &boostTypes.ExecutionPayloadHeader{
392380
ParentHash: p.ParentHash,
393381
FeeRecipient: p.FeeRecipient,
@@ -399,10 +387,10 @@ func payloadToPayloadHeader(p *boostTypes.ExecutionPayload) (*boostTypes.Executi
399387
GasLimit: p.GasLimit,
400388
GasUsed: p.GasUsed,
401389
Timestamp: p.Timestamp,
402-
ExtraData: []byte(p.ExtraData),
390+
ExtraData: data.ExtraData,
403391
BaseFeePerGas: p.BaseFeePerGas,
404392
BlockHash: p.BlockHash,
405-
TransactionsRoot: [32]byte(types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil))),
393+
TransactionsRoot: [32]byte(txroot),
406394
}, nil
407395
}
408396

builder/backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestGetHeader(t *testing.T) {
146146
err := json.Unmarshal(rr.Body.Bytes(), bid)
147147
require.NoError(t, err)
148148

149-
expectedHeader, err := payloadToPayloadHeader(executableDataToExecutionPayload(forkchoiceData))
149+
expectedHeader, err := payloadToPayloadHeader(executableDataToExecutionPayload(forkchoiceData), forkchoiceData)
150150
require.NoError(t, err)
151151
require.EqualValues(t, &boostTypes.BuilderBid{
152152
Header: expectedHeader,

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlK
171171
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
172172
github.com/flashbots/go-boost-utils v0.1.2 h1:xcwO6rhLmdbZ+ttN8PjHQynqY1pm+RCA56eGP9wPp10=
173173
github.com/flashbots/go-boost-utils v0.1.2/go.mod h1:v4f01OjPm5jFjzVhcJEKHLFZzX/yTeme9284Tbuah8s=
174+
github.com/flashbots/go-boost-utils v0.1.3-0.20220601173756-01db408b8c89 h1:3wVzFGJbXm8BjuFav3ZPKFAz01IY6JDjV38b3Ccuk2I=
175+
github.com/flashbots/go-boost-utils v0.1.3-0.20220601173756-01db408b8c89/go.mod h1:v4f01OjPm5jFjzVhcJEKHLFZzX/yTeme9284Tbuah8s=
174176
github.com/flashbots/go-utils v0.4.4 h1:J0LUifVEpVYE+ZbK/DeGay4E3B6+Yh8pKLgfv5A0Oq0=
175177
github.com/flashbots/go-utils v0.4.4/go.mod h1:weSbiNnH+xsmK8t3TDDJxluv4+qnwRWmKay2QQa8Yfc=
176178
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=

0 commit comments

Comments
 (0)