Skip to content

Commit

Permalink
Adjust transactions root computation (ethereum#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteri authored and avalonche committed Mar 8, 2023
1 parent 1acc3c4 commit 2dd19c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
26 changes: 7 additions & 19 deletions builder/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package builder
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"math/big"
"net/http"
Expand All @@ -17,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/gorilla/mux"

"github.com/flashbots/go-boost-utils/bls"
Expand Down Expand Up @@ -358,7 +356,7 @@ func (b *Backend) newSealedBlock(data *beacon.ExecutableDataV1, block *types.Blo
log.Info("newSealedBlock", "data", string(dataJson))
}
payload := executableDataToExecutionPayload(data)
payloadHeader, err := payloadToPayloadHeader(payload)
payloadHeader, err := payloadToPayloadHeader(payload, data)
if err != nil {
log.Error("could not convert payload to header", "err", err)
return
Expand All @@ -371,23 +369,13 @@ func (b *Backend) newSealedBlock(data *beacon.ExecutableDataV1, block *types.Blo
b.bestDataLock.Unlock()
}

func decodeTransactions(enc []hexutil.Bytes) ([]*types.Transaction, error) {
var txs = make([]*types.Transaction, len(enc))
for i, encTx := range enc {
var tx types.Transaction
if err := tx.UnmarshalBinary(encTx); err != nil {
return nil, fmt.Errorf("invalid transaction %d: %v", i, err)
}
txs[i] = &tx
}
return txs, nil
}

func payloadToPayloadHeader(p *boostTypes.ExecutionPayload) (*boostTypes.ExecutionPayloadHeader, error) {
txs, err := decodeTransactions(p.Transactions)
func payloadToPayloadHeader(p *boostTypes.ExecutionPayload, data *beacon.ExecutableDataV1) (*boostTypes.ExecutionPayloadHeader, error) {
txs := boostTypes.Transactions{data.Transactions}
txroot, err := txs.HashTreeRoot()
if err != nil {
return nil, err
}

return &boostTypes.ExecutionPayloadHeader{
ParentHash: p.ParentHash,
FeeRecipient: p.FeeRecipient,
Expand All @@ -399,10 +387,10 @@ func payloadToPayloadHeader(p *boostTypes.ExecutionPayload) (*boostTypes.Executi
GasLimit: p.GasLimit,
GasUsed: p.GasUsed,
Timestamp: p.Timestamp,
ExtraData: []byte(p.ExtraData),
ExtraData: data.ExtraData,
BaseFeePerGas: p.BaseFeePerGas,
BlockHash: p.BlockHash,
TransactionsRoot: [32]byte(types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil))),
TransactionsRoot: [32]byte(txroot),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion builder/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestGetHeader(t *testing.T) {
err := json.Unmarshal(rr.Body.Bytes(), bid)
require.NoError(t, err)

expectedHeader, err := payloadToPayloadHeader(executableDataToExecutionPayload(forkchoiceData))
expectedHeader, err := payloadToPayloadHeader(executableDataToExecutionPayload(forkchoiceData), forkchoiceData)
require.NoError(t, err)
require.EqualValues(t, &boostTypes.BuilderBid{
Header: expectedHeader,
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlK
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/flashbots/go-boost-utils v0.1.2 h1:xcwO6rhLmdbZ+ttN8PjHQynqY1pm+RCA56eGP9wPp10=
github.com/flashbots/go-boost-utils v0.1.2/go.mod h1:v4f01OjPm5jFjzVhcJEKHLFZzX/yTeme9284Tbuah8s=
github.com/flashbots/go-boost-utils v0.1.3-0.20220601173756-01db408b8c89 h1:3wVzFGJbXm8BjuFav3ZPKFAz01IY6JDjV38b3Ccuk2I=
github.com/flashbots/go-boost-utils v0.1.3-0.20220601173756-01db408b8c89/go.mod h1:v4f01OjPm5jFjzVhcJEKHLFZzX/yTeme9284Tbuah8s=
github.com/flashbots/go-utils v0.4.4 h1:J0LUifVEpVYE+ZbK/DeGay4E3B6+Yh8pKLgfv5A0Oq0=
github.com/flashbots/go-utils v0.4.4/go.mod h1:weSbiNnH+xsmK8t3TDDJxluv4+qnwRWmKay2QQa8Yfc=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
Expand Down

0 comments on commit 2dd19c9

Please sign in to comment.