synapsecns / sanguine

Synapse Monorepo
MIT License
35 stars 25 forks source link

[submitter] confirmed queue gauge #2822

Closed trajan0x closed 6 days ago

greptile-apps[bot] commented 6 days ago

To implement a confirmed queue gauge in the submitter package, follow these steps:

  1. Define the Gauge in txSubmitterImpl struct: Add a new field for the confirmed queue gauge in the txSubmitterImpl struct in submitter.go:

    confirmedQueueGauge metric.Int64ObservableGauge
  2. Initialize the Gauge in setupMetrics: Initialize the confirmed queue gauge in the setupMetrics method in submitter.go:

    func (t *txSubmitterImpl) setupMetrics() (err error) {
       // ... existing code ...
       t.confirmedQueueGauge, err = t.meter.Int64ObservableGauge("confirmed_queue_size")
       if err != nil {
           return fmt.Errorf("could not create confirmed queue gauge: %w", err)
       }
       _, err = t.meter.RegisterCallback(t.recordConfirmedQueueSize, t.confirmedQueueGauge)
       if err != nil {
           return fmt.Errorf("could not register callback: %w", err)
       }
       return nil
    }
  3. Implement the Callback Method: Implement the recordConfirmedQueueSize method to update the gauge value in submitter.go:

    func (t *txSubmitterImpl) recordConfirmedQueueSize(ctx context.Context, result metric.Int64ObserverResult) {
       size, err := t.db.GetConfirmedQueueSize(ctx, t.signer.Address())
       if err != nil {
           logger.Errorf("could not get confirmed queue size: %v", err)
           return
       }
       result.Observe(int64(size))
    }
  4. Update the Database Interface: Ensure the db.Service interface has the GetConfirmedQueueSize method in db.go:

    type Service interface {
       // ... existing methods ...
       GetConfirmedQueueSize(ctx context.Context, address common.Address) (int, error)
    }
  5. Implement the Database Method: Implement the GetConfirmedQueueSize method in the database service implementation in db.go:

    func (d *dbService) GetConfirmedQueueSize(ctx context.Context, address common.Address) (int, error) {
       // Implement the logic to count the confirmed transactions in the queue
    }

References

/ethergo/submitter/submitter.go /ethergo/submitter/queue.go

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/synapsecns/sanguine/master) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)