Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[submitter] track oldest pending txes age per chain #2819

Closed
trajan0x opened this issue Jun 29, 2024 · 1 comment · Fixed by #2821
Closed

[submitter] track oldest pending txes age per chain #2819

trajan0x opened this issue Jun 29, 2024 · 1 comment · Fixed by #2821

Comments

@trajan0x
Copy link
Contributor

For each chain id track oldest pending nonce.

Copy link

greptile-apps bot commented Jun 29, 2024

To track the oldest pending transaction age per chain, follow these steps:

  1. Add a field to chainQueue struct in chain_queue.go:
// chainQueue is a single use queue for a single chain.
type chainQueue struct {
    // ... existing fields
    oldestPendingTxAge time.Duration
}
  1. Update chainPendingQueue method in chain_queue.go to calculate the oldest pending transaction age:
func (t *txSubmitterImpl) chainPendingQueue(parentCtx context.Context, chainID *big.Int, txes []db.TX) (err error) {
    // ... existing code

    // Calculate the oldest pending transaction age
    if len(txes) > 0 {
        oldestTx := txes[0]
        for _, tx := range txes {
            if tx.CreationTime().Before(oldestTx.CreationTime()) {
                oldestTx = tx
            }
        }
        cq.oldestPendingTxAge = time.Since(oldestTx.CreationTime())
    }

    // ... existing code
}
  1. Expose the oldest pending transaction age in txSubmitterImpl struct in submitter.go:
// txSubmitterImpl is the implementation of the transaction submitter.
type txSubmitterImpl struct {
    // ... existing fields
    oldestPendingTxAgePerChain *hashmap.Map[uint32, time.Duration]
}
  1. Update NewTransactionSubmitter function in submitter.go to initialize the new field:
func NewTransactionSubmitter(metrics metrics.Handler, signer signer.Signer, fetcher ClientFetcher, db db.Service, config config.IConfig) TransactionSubmitter {
    return &txSubmitterImpl{
        // ... existing fields
        oldestPendingTxAgePerChain: hashmap.New[uint32, time.Duration](),
    }
}
  1. Store the oldest pending transaction age in chainPendingQueue method in chain_queue.go:
func (t *txSubmitterImpl) chainPendingQueue(parentCtx context.Context, chainID *big.Int, txes []db.TX) (err error) {
    // ... existing code

    // Store the oldest pending transaction age
    if len(txes) > 0 {
        t.oldestPendingTxAgePerChain.Set(uint32(chainID.Int64()), cq.oldestPendingTxAge)
    }

    // ... existing code
}

References

/ethergo/submitter/chain_queue.go
/ethergo/submitter/submitter.go
/ethergo/submitter/db/txdb/store.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 · Edit Issue Bot Settings

trajan0x added a commit that referenced this issue Jun 29, 2024
@coderabbitai coderabbitai bot mentioned this issue Jun 29, 2024
@trajan0x trajan0x linked a pull request Jun 29, 2024 that will close this issue
trajan0x added a commit that referenced this issue Jun 29, 2024
address #2823, #2822, #2820 and #2819

---------

Co-authored-by: Trajan0x <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant