Skip to content

Commit

Permalink
Merge branch 'taikoxyz:taiko' into taiko
Browse files Browse the repository at this point in the history
  • Loading branch information
lwedge99 committed Jun 19, 2024
2 parents 2004d3b + 451a668 commit d2cb81f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 38 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.3.0](https://github.com/taikoxyz/taiko-geth/compare/v1.2.0...v1.3.0) (2024-06-06)


### Features

* **miner:** compress the txlist bytes after checking the transaction is executable ([#269](https://github.com/taikoxyz/taiko-geth/issues/269)) ([aa70708](https://github.com/taikoxyz/taiko-geth/commit/aa70708a69d9612bf2dffd218db7e703de1654c1))
* **miner:** move `TAIKO_MIN_TIP` check to `commitL2Transactions` ([#272](https://github.com/taikoxyz/taiko-geth/issues/272)) ([f3a7fb6](https://github.com/taikoxyz/taiko-geth/commit/f3a7fb6311e9d59ba2fb55799b9eab614d488095))

## [1.2.0](https://github.com/taikoxyz/taiko-geth/compare/v1.1.0...v1.2.0) (2024-06-05)


Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.21-alpine as builder
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine as builder

RUN apk add --no-cache gcc musl-dev linux-headers git

Expand All @@ -14,7 +14,9 @@ COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

ADD . /go-ethereum
RUN --mount=type=cache,target=/root/.cache/go-build,sharing=locked \
ARG TARGETOS
ARG TARGETARCH
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
cd /go-ethereum && go run build/ci.go install -static ./cmd/geth

# Pull Geth into a second stage deploy alpine container
Expand Down
18 changes: 2 additions & 16 deletions core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"math/big"
"os"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -100,21 +99,8 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
return core.ErrTipAboveFeeCap
}
// CHANGE(taiko): check gasFeeCap.
if os.Getenv("TAIKO_TEST") == "" {
if os.Getenv("TAIKO_MIN_TIP") != "" {
minTip, err := strconv.Atoi(os.Getenv("TAIKO_MIN_TIP"))
if err != nil {
log.Error("Failed to parse TAIKO_MIN_TIP", "err", err)
} else {
if tx.GasTipCapIntCmp(new(big.Int).SetUint64(uint64(minTip))) < 0 {
return fmt.Errorf("max fee per gas is less than %d wei", minTip)
}
}
} else {
if tx.GasFeeCap().Cmp(common.Big0) == 0 {
return errors.New("max fee per gas is 0")
}
}
if os.Getenv("TAIKO_TEST") == "" && tx.GasFeeCap().Cmp(common.Big0) == 0 {
return errors.New("max fee per gas is 0")
}
// Make sure the transaction is signed properly
if _, err := types.Sender(signer, tx); err != nil {
Expand Down
71 changes: 51 additions & 20 deletions miner/taiko_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"errors"
"fmt"
"math/big"
"os"
"strconv"
"time"

"github.com/ethereum/go-ethereum/beacon/engine"
Expand Down Expand Up @@ -70,7 +72,7 @@ func (w *worker) BuildTransactionsLists(
localTxs, remoteTxs = w.getPendingTxs(localAccounts, baseFee)
)

commitTxs := func() (*PreBuiltTxList, error) {
commitTxs := func(firstTransaction *types.Transaction) (*types.Transaction, *PreBuiltTxList, error) {
env.tcount = 0
env.txs = []*types.Transaction{}
env.gasPool = new(core.GasPool).AddGas(blockMaxGasLimit)
Expand All @@ -88,28 +90,32 @@ func (w *worker) BuildTransactionsLists(
remotes[address] = txs
}

w.commitL2Transactions(
lastTransaction := w.commitL2Transactions(
env,
firstTransaction,
newTransactionsByPriceAndNonce(signer, locals, baseFee),
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
maxBytesPerTxList,
)

b, err := encodeAndComporeessTxList(env.txs)
if err != nil {
return nil, err
return nil, nil, err
}

return &PreBuiltTxList{
return lastTransaction, &PreBuiltTxList{
TxList: env.txs,
EstimatedGasUsed: env.header.GasLimit - env.gasPool.Gas(),
BytesLength: uint64(len(b)),
}, nil
}

var (
lastTx *types.Transaction
res *PreBuiltTxList
)
for i := 0; i < int(maxTransactionsLists); i++ {
res, err := commitTxs()
if err != nil {
if lastTx, res, err = commitTxs(lastTx); err != nil {
return nil, err
}

Expand Down Expand Up @@ -228,15 +234,21 @@ func (w *worker) getPendingTxs(localAccounts []string, baseFee *big.Int) (
// commitL2Transactions tries to commit the transactions into the given state.
func (w *worker) commitL2Transactions(
env *environment,
firstTransaction *types.Transaction,
txsLocal *transactionsByPriceAndNonce,
txsRemote *transactionsByPriceAndNonce,
maxBytesPerTxList uint64,
) {
) *types.Transaction {
var (
txs = txsLocal
isLocal = true
txs = txsLocal
isLocal = true
lastTransaction *types.Transaction
)

if firstTransaction != nil {
env.txs = append(env.txs, firstTransaction)
}

for {
// If we don't have enough gas for any further transactions then we're done.
if env.gasPool.Gas() < params.TxGas {
Expand All @@ -261,20 +273,24 @@ func (w *worker) commitL2Transactions(
txs.Pop()
continue
}

if os.Getenv("TAIKO_MIN_TIP") != "" {
minTip, err := strconv.Atoi(os.Getenv("TAIKO_MIN_TIP"))
if err != nil {
log.Error("Failed to parse TAIKO_MIN_TIP", "err", err)
} else {
if tx.GasTipCapIntCmp(new(big.Int).SetUint64(uint64(minTip))) < 0 {
log.Trace("Ignoring transaction with low tip", "hash", tx.Hash(), "tip", tx.GasTipCap(), "minTip", minTip)
txs.Pop()
continue
}
}
}

// Error may be ignored here. The error has already been checked
// during transaction acceptance is the transaction pool.
from, _ := types.Sender(env.signer, tx)

b, err := encodeAndComporeessTxList(append(env.txs, tx))
if err != nil {
log.Trace("Failed to rlp encode and compress the pending transaction %s: %w", tx.Hash(), err)
txs.Pop()
continue
}
if len(b) > int(maxBytesPerTxList) {
break
}

// Check whether the tx is replay protected. If we're not in the EIP155 hf
// phase, start ignoring the sender until we do.
if tx.Protected() && !w.chainConfig.IsEIP155(env.header.Number) {
Expand All @@ -286,7 +302,7 @@ func (w *worker) commitL2Transactions(
// Start executing the transaction
env.state.SetTxContext(tx.Hash(), env.tcount)

_, err = w.commitTransaction(env, tx)
_, err := w.commitTransaction(env, tx)
switch {
case errors.Is(err, core.ErrNonceTooLow):
// New head notification data race between the transaction pool and miner, shift
Expand All @@ -304,7 +320,22 @@ func (w *worker) commitL2Transactions(
log.Trace("Transaction failed, account skipped", "hash", ltx.Hash, "err", err)
txs.Pop()
}

// Encode and compress the txList, if the byte length is > maxBytesPerTxList, remove the latest tx and break.
b, err := encodeAndComporeessTxList(append(env.txs, tx))
if err != nil {
log.Trace("Failed to rlp encode and compress the pending transaction %s: %w", tx.Hash(), err)
txs.Pop()
continue
}
if len(b) > int(maxBytesPerTxList) {
lastTransaction = env.txs[env.tcount-1]
env.txs = env.txs[0 : env.tcount-1]
break
}
}

return lastTransaction
}

// encodeAndComporeessTxList encodes and compresses the given transactions list.
Expand Down

0 comments on commit d2cb81f

Please sign in to comment.