synapsecns / sanguine

Synapse Monorepo
MIT License
38 stars 29 forks source link

[submitter] make tx.Nonce, tx.To, etc tags instead of events #2808

Open trajan0x opened 3 months ago

greptile-apps[bot] commented 3 months ago

To address the issue of making tx.Nonce, tx.To, etc., tags instead of events in the submitter package, follow these steps:

  1. Update SubmitTransaction method in submitter.go:
    • Locate the SubmitTransaction method.
    • Replace the current event-based attributes with tag-based attributes.
// submitter.go
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()),
        attribute.Int64("tx.Nonce", int64(tx.Nonce())),
        attribute.String("tx.To", tx.To().Hex()),
        // Add other tx attributes as needed
    ))
    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()
    // ... rest of the method
}
  1. Update setGasPrice method in submitter.go:
    • Locate the setGasPrice method.
    • Replace the current event-based attributes with tag-based attributes.
// submitter.go
func (t *txSubmitterImpl) setGasPrice(ctx context.Context, client client.EVM, transactor *bind.TransactOpts, bigChainID *big.Int, prevTx *types.Transaction) (err error) {
    ctx, span := t.metrics.Tracer().Start(ctx, "submitter.setGasPrice", trace.WithAttributes(
        attribute.Int(metrics.ChainID, chainID),
        attribute.Bool("use_dynamic", useDynamic),
        attribute.String("gas_price", bigPtrToString(transactor.GasPrice)),
        attribute.String("gas_fee_cap", bigPtrToString(transactor.GasFeeCap)),
        attribute.String("gas_tip_cap", bigPtrToString(transactor.GasTipCap)),
        attribute.Int64("tx.Nonce", int64(tx.Nonce())),
        attribute.String("tx.To", tx.To().Hex()),
        // Add other tx attributes as needed
    ))
    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()
    // ... rest of the method
}
  1. Update other methods where events are used for tx attributes:

    • Locate other methods in submitter.go where events are used for tx attributes.
    • Replace the event-based attributes with tag-based attributes similarly.
  2. Update tests in export_test.go:

    • Ensure that the tests reflect the changes from events to tags.
    • Update any test cases that check for events to check for tags instead.
// export_test.go
func TestSubmitTransaction(t *testing.T) {
    // ... setup code
    span := mockTracer.StartSpan("submitter.SubmitTransaction")
    // Check for tags instead of events
    assert.Equal(t, span.Attributes["tx.Nonce"], int64(expectedNonce))
    assert.Equal(t, span.Attributes["tx.To"], expectedTo.Hex())
    // ... rest of the test
}

These changes will ensure that tx.Nonce, tx.To, and other attributes are recorded as tags instead of events.

References

/ethergo/submitter/submitter.go /ethergo/submitter/export_test.go

Ask Greptile · Edit Issue Bot Settings