synapsecns / sanguine

Synapse Monorepo
MIT License
35 stars 25 forks source link

[submitter] should resign pending on gas limit change #2771

Open trajan0x opened 2 weeks ago

trajan0x commented 2 weeks ago

if config gas limit changes, submitter should "bump"

greptile-apps[bot] commented 2 weeks ago

To address the issue of the submitter needing to resign pending transactions on gas limit change, follow these steps:

  1. Modify SubmitTransaction in submitter.go: Add logic to check for gas limit changes before submitting a transaction.
func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error) {
    ctx, span := t.metrics.Tracer().Start(parentCtx, "submitter.SubmitTransaction", trace.WithAttributes(
        attribute.Stringer("chainID", chainID),
        attribute.String("caller", runtime.FuncForPC(reflect.ValueOf(call).Pointer()).Name()),
    ))

    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()

    // Check for gas limit changes
    if t.config.GetGasEstimate(int(chainID.Uint64())) != transactor.GasLimit {
        t.triggerProcessQueue(ctx)
    }

    // Existing logic...
}
  1. Update triggerProcessQueue in submitter.go: Ensure it handles the gas limit change appropriately.
func (t *txSubmitterImpl) triggerProcessQueue(ctx context.Context) {
    select {
    case <-ctx.Done():
        return
    case t.retryNow <- true:
    default:
        // Handle gas limit change
        t.retryNow <- true
    }
}
  1. Update config.go: Ensure the configuration changes are detected and propagated correctly.
// Add a method to detect gas limit changes
func (c *Config) HasGasLimitChanged(chainID int, currentGasLimit uint64) bool {
    return c.GetGasEstimate(chainID) != currentGasLimit
}

These changes ensure that the submitter will reprocess transactions if the gas limit configuration changes.

References

/ethergo/submitter/submitter.go /ethergo/submitter/config/config.go /ethergo/submitter

Ask Greptile

greptile-apps[bot] commented 2 weeks ago

To implement the feature where the submitter should bump transactions when the gas limit changes, follow these steps:

  1. Update Configuration Handling:

    • Modify config.go to include a method for detecting changes in the gas limit.
  2. Modify chain_queue.go:

    • In the chainQueue struct, add logic to check for gas limit changes and trigger a bump if detected.
    • Update the bumpTX method to handle gas limit changes.
  3. Modify submitter.go:

    • In the SubmitTransaction method, add logic to check for gas limit changes before submitting a transaction.

Example code snippets:

config.go:

func (c *Config) HasGasLimitChanged(chainID int, newGasLimit uint64) bool {
    currentGasLimit := c.GetGasEstimate(chainID)
    return currentGasLimit != newGasLimit
}

chain_queue.go:

func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) (err error) {
    // Existing logic...
    newGasEstimate, err := c.getGasEstimate(ctx, c.client, c.chainIDInt(), tx)
    if err != nil {
        return fmt.Errorf("could not get gas estimate: %w", err)
    }
    if c.config.HasGasLimitChanged(c.chainIDInt(), newGasEstimate) {
        // Logic to bump transaction due to gas limit change
    }
    // Existing logic...
}

submitter.go:

func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error) {
    // Existing logic...
    gasEstimate := t.config.GetGasEstimate(int(chainID.Uint64()))
    if t.config.HasGasLimitChanged(int(chainID.Uint64()), gasEstimate) {
        // Logic to handle gas limit change
    }
    // Existing logic...
}

References

/ethergo/submitter/chain_queue.go /ethergo/submitter/submitter.go /ethergo/submitter/config/config.go

Ask Greptile