Skip to content

Commit

Permalink
enforce txtype (#2413)
Browse files Browse the repository at this point in the history

Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
  • Loading branch information
trajan0x and trajan0x authored Apr 1, 2024
1 parent 813de8e commit bf0e73d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions ethergo/submitter/chain_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package submitter
import (
"context"
"fmt"
"github.com/synapsecns/sanguine/ethergo/util"
"math/big"
"sort"
"sync"
Expand Down Expand Up @@ -150,7 +151,12 @@ func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) {
c.addToReprocessQueue(ogTx)
return nil
}
tx := ogTx.Transaction
// copy the transaction, switching the type if we need to.
// this is required if the config changes to use legacy transactions on a tx that is already bumped.
tx, err := util.CopyTX(ogTx.Transaction, util.WithTxType(c.txTypeForChain(c.chainID)))
if err != nil {
return fmt.Errorf("could not copy tx: %w", err)
}

ctx, span := c.metrics.Tracer().Start(parentCtx, "chainPendingQueue.bumpTX", trace.WithAttributes(attribute.Stringer(metrics.TxHash, tx.Hash())))
defer func() {
Expand All @@ -176,7 +182,7 @@ func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) {
return fmt.Errorf("could not set gas price: %w", err)
}

switch ogTx.Type() {
switch tx.Type() {
case types.LegacyTxType:
tx = types.NewTx(&types.LegacyTx{
Nonce: tx.Nonce(),
Expand Down
14 changes: 10 additions & 4 deletions ethergo/submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *
return nil, fmt.Errorf("could not sign tx: %w", err)
}

txType := transaction.Type()
if t.config.SupportsEIP1559(int(chainID.Uint64())) {
txType = types.DynamicFeeTxType
}
txType := t.txTypeForChain(chainID)

transaction, err = util.CopyTX(transaction, util.WithNonce(newNonce), util.WithTxType(txType))
if err != nil {
Expand Down Expand Up @@ -339,6 +336,15 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *
return tx.Nonce(), nil
}

func (t *txSubmitterImpl) txTypeForChain(chainID *big.Int) (txType uint8) {
if t.config.SupportsEIP1559(int(chainID.Uint64())) {
txType = types.DynamicFeeTxType
} else {
txType = types.LegacyTxType
}
return txType
}

// setGasPrice sets the gas price for the transaction.
// it bumps if prevtx is set
// nolint: cyclop
Expand Down

0 comments on commit bf0e73d

Please sign in to comment.