Skip to content

Commit

Permalink
fix trx manager
Browse files Browse the repository at this point in the history
  • Loading branch information
s7v7nislands committed Apr 27, 2023
1 parent 8397563 commit 2d2912d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 41 deletions.
2 changes: 1 addition & 1 deletion op-bindings/bindings/erc20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/optimismportal.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/optimismportal_more.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
observice "github.com/ethereum-optimism/optimism/op-service"
opservice "github.com/ethereum-optimism/optimism/op-service"
)

// TestAttributesQueue checks that it properly uses the PreparePayloadAttributes function
// (which is well tested) and that it properly sets NoTxPool and adds in the candidate
// transactions.
func TestAttributesQueue(t *testing.T) {
observice.ForBSC = false
opservice.ForBSC = false
// test config, only init the necessary fields
cfg := &rollup.Config{
BlockTime: 2,
Expand Down
3 changes: 2 additions & 1 deletion op-proposer/proposer/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func TestManualABIPacking(t *testing.T) {
opts,
output.OutputRoot,
new(big.Int).SetUint64(output.BlockRef.Number),
output.Status.CurrentL1.Hash,
// output.Status.CurrentL1.Hash,
[32]byte{},
new(big.Int).SetUint64(output.Status.CurrentL1.Number))
require.NoError(t, err)

Expand Down
118 changes: 83 additions & 35 deletions op-service/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
)

Expand Down Expand Up @@ -163,38 +164,68 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
}
m.metr.RecordNonce(nonce)

rawTx := &types.DynamicFeeTx{
ChainID: m.chainID,
Nonce: nonce,
To: candidate.To,
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Data: candidate.TxData,
}

m.l.Info("creating tx", "to", rawTx.To, "from", m.cfg.From)

// If the gas limit is set, we can use that as the gas
if candidate.GasLimit != 0 {
rawTx.Gas = candidate.GasLimit
var tx *types.Transaction
if opservice.ForBSC {
rawTx := &types.LegacyTx{
Nonce: nonce,
To: candidate.To,
GasPrice: gasFeeCap,
Data: candidate.TxData,
}
m.l.Info("creating tx", "to", rawTx.To, "from", m.cfg.From)

// If the gas limit is set, we can use that as the gas
if candidate.GasLimit != 0 {
rawTx.Gas = candidate.GasLimit
} else {
// Calculate the intrinsic gas for the transaction
gas, err := m.backend.EstimateGas(ctx, ethereum.CallMsg{
From: m.cfg.From,
To: candidate.To,
GasPrice: gasFeeCap,
Data: rawTx.Data,
})
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
}
rawTx.Gas = gas
}
tx = types.NewTx(rawTx)
} else {
// Calculate the intrinsic gas for the transaction
gas, err := m.backend.EstimateGas(ctx, ethereum.CallMsg{
From: m.cfg.From,
rawTx := &types.DynamicFeeTx{
ChainID: m.chainID,
Nonce: nonce,
To: candidate.To,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: rawTx.Data,
})
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
GasFeeCap: gasFeeCap,
Data: candidate.TxData,
}
rawTx.Gas = gas

m.l.Info("creating tx", "to", rawTx.To, "from", m.cfg.From)

// If the gas limit is set, we can use that as the gas
if candidate.GasLimit != 0 {
rawTx.Gas = candidate.GasLimit
} else {
// Calculate the intrinsic gas for the transaction
gas, err := m.backend.EstimateGas(ctx, ethereum.CallMsg{
From: m.cfg.From,
To: candidate.To,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: rawTx.Data,
})
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
}
rawTx.Gas = gas
}
tx = types.NewTx(rawTx)
}

ctx, cancel = context.WithTimeout(ctx, m.cfg.NetworkTimeout)
defer cancel()
return m.cfg.Signer(ctx, m.cfg.From, types.NewTx(rawTx))
return m.cfg.Signer(ctx, m.cfg.From, tx)
}

// send submits the same transaction several times with increasing gas prices as necessary.
Expand Down Expand Up @@ -392,20 +423,34 @@ func (m *SimpleTxManager) increaseGasPrice(ctx context.Context, tx *types.Transa
return tx
}

rawTx := &types.DynamicFeeTx{
ChainID: tx.ChainId(),
Nonce: tx.Nonce(),
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Gas: tx.Gas(),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
var rtx *types.Transaction
if opservice.ForBSC {
rawTx := &types.LegacyTx{
Nonce: tx.Nonce(),
Gas: tx.Gas(),
GasPrice: gasFeeCap,
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
}
rtx = types.NewTx(rawTx)
} else {
rawTx := &types.DynamicFeeTx{
ChainID: tx.ChainId(),
Nonce: tx.Nonce(),
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Gas: tx.Gas(),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
}
rtx = types.NewTx(rawTx)
}
ctx, cancel := context.WithTimeout(ctx, m.cfg.NetworkTimeout)
defer cancel()
newTx, err := m.cfg.Signer(ctx, m.cfg.From, types.NewTx(rawTx))
newTx, err := m.cfg.Signer(ctx, m.cfg.From, rtx)
if err != nil {
m.l.Warn("failed to sign new transaction", "err", err)
return tx
Expand All @@ -431,6 +476,9 @@ func (m *SimpleTxManager) suggestGasPriceCaps(ctx context.Context) (*big.Int, *b
m.metr.RPCError()
return nil, nil, fmt.Errorf("failed to fetch the suggested basefee: %w", err)
} else if head.BaseFee == nil {
if opservice.ForBSC {
return tip, big.NewInt(0), nil
}
return nil, nil, errors.New("txmgr does not support pre-london blocks that do not have a basefee")
}
return tip, head.BaseFee, nil
Expand Down
2 changes: 2 additions & 0 deletions op-service/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-node/testlog"
opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -739,6 +740,7 @@ func doGasPriceIncrease(t *testing.T, txTipCap, txFeeCap, newTip, newBaseFee int
}

func TestIncreaseGasPrice(t *testing.T) {
opservice.ForBSC = false
// t.Parallel()
tests := []struct {
name string
Expand Down

0 comments on commit 2d2912d

Please sign in to comment.