Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(proposer): add --proposeBlockTxGasTipCap flag (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Aug 4, 2023
1 parent 7ccedd2 commit e40115b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ var (
Usage: "Gas tip multiplier when replacing a TaikoL1.proposeBlock transaction with same nonce",
Category: proposerCategory,
}
ProposeBlockTxGasTipCap = &cli.Uint64Flag{
Name: "proposeBlockTxGasTipCap",
Usage: "Gas tip cap (in wei) for a TaikoL1.proposeBlock transaction when doing the transaction replacement",
Category: proposerCategory,
}
)

// All proposer flags.
Expand All @@ -73,4 +78,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
MaxProposedTxListsPerEpoch,
ProposeBlockTxGasLimit,
ProposeBlockTxReplacementMultiplier,
ProposeBlockTxGasTipCap,
})
9 changes: 8 additions & 1 deletion proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proposer
import (
"crypto/ecdsa"
"fmt"
"math/big"
"strings"
"time"

Expand Down Expand Up @@ -30,6 +31,7 @@ type Config struct {
ProposeBlockTxReplacementMultiplier uint64
RPCTimeout *time.Duration
WaitReceiptTimeout time.Duration
ProposeBlockTxGasTipCap *big.Int
}

// NewConfigFromCliContext initializes a Config instance from
Expand Down Expand Up @@ -91,12 +93,16 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}

var timeout *time.Duration

if c.IsSet(flags.RPCTimeout.Name) {
duration := time.Duration(c.Uint64(flags.RPCTimeout.Name)) * time.Second
timeout = &duration
}

var proposeBlockTxGasTipCap *big.Int
if c.IsSet(flags.ProposeBlockTxGasTipCap.Name) {
proposeBlockTxGasTipCap = new(big.Int).SetUint64(c.Uint64(flags.ProposeBlockTxGasTipCap.Name))
}

return &Config{
L1Endpoint: c.String(flags.L1WSEndpoint.Name),
L2Endpoint: c.String(flags.L2HTTPEndpoint.Name),
Expand All @@ -114,5 +120,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
ProposeBlockTxReplacementMultiplier: proposeBlockTxReplacementMultiplier,
RPCTimeout: timeout,
WaitReceiptTimeout: time.Duration(c.Uint64(flags.WaitReceiptTimeout.Name)) * time.Second,
ProposeBlockTxGasTipCap: proposeBlockTxGasTipCap,
}, nil
}
18 changes: 16 additions & 2 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -51,6 +52,7 @@ type Proposer struct {
maxProposedTxListsPerEpoch uint64
proposeBlockTxGasLimit *uint64
txReplacementTipMultiplier uint64
proposeBlockTxGasTipCap *big.Int

// Protocol configurations
protocolConfigs *bindings.TaikoDataConfig
Expand Down Expand Up @@ -88,6 +90,7 @@ func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) {
p.localsOnly = cfg.LocalAddressesOnly
p.maxProposedTxListsPerEpoch = cfg.MaxProposedTxListsPerEpoch
p.txReplacementTipMultiplier = cfg.ProposeBlockTxReplacementMultiplier
p.proposeBlockTxGasTipCap = cfg.ProposeBlockTxGasTipCap
p.ctx = ctx
p.waitReceiptTimeout = cfg.WaitReceiptTimeout

Expand Down Expand Up @@ -353,14 +356,25 @@ func (p *Proposer) sendProposeBlockTx(
"Original transaction to replace",
"sender", p.l1ProposerAddress,
"nonce", nonce,
"tx", originalTx,
"gasTipCap", originalTx.GasTipCap(),
"gasFeeCap", originalTx.GasFeeCap(),
)

opts.GasTipCap = new(big.Int).Mul(
originalTx.GasTipCap(),
new(big.Int).SetUint64(p.txReplacementTipMultiplier),
)
}

if p.proposeBlockTxGasTipCap != nil && opts.GasTipCap.Cmp(p.proposeBlockTxGasTipCap) > 0 {
log.Info(
"New gasTipCap exceeds limit, keep waiting",
"multiplier", p.txReplacementTipMultiplier,
"newGasTipCap", opts.GasTipCap,
"maxTipCap", p.proposeBlockTxGasTipCap,
)
return nil, txpool.ErrReplaceUnderpriced
}
}

proposeTx, err := p.rpc.TaikoL1.ProposeBlock(opts, inputs, txListBytes)
Expand Down Expand Up @@ -391,7 +405,7 @@ func (p *Proposer) ProposeTxList(
}
if tx, err = p.sendProposeBlockTx(ctx, meta, txListBytes, nonce, isReplacement); err != nil {
log.Warn("Failed to send propose block transaction, retrying", "error", err)
if strings.Contains(err.Error(), "replacement transaction underpriced") {
if strings.Contains(err.Error(), txpool.ErrReplaceUnderpriced.Error()) {
isReplacement = true
} else {
isReplacement = false
Expand Down

0 comments on commit e40115b

Please sign in to comment.