-
Notifications
You must be signed in to change notification settings - Fork 289
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
refactor: index submitted txs in tx client and improve nonce management #3830
Changes from 34 commits
a2e490c
faa460c
c98a337
3dd6abb
9aa7af6
6d2c828
ee0e7b2
e050bc0
500e5be
6eb72e0
4d6b196
6e02de3
bd3f5e0
4046a59
7832fdc
437e4a7
1c7a7b3
f3c0af3
330c525
1e0353b
1e35d86
9ac1e5c
088aeda
ba4a7cc
0fc939f
046ce94
918089b
30985ae
30c1dc0
c2b72fb
c676a97
1e1de7f
def40f2
54ff169
5b1f1d2
a492e39
4d47ce9
58d6c23
d7ea9b9
ac47d8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
package user | ||||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"testing" | ||||||
"time" | ||||||
|
||||||
"github.com/stretchr/testify/require" | ||||||
) | ||||||
|
||||||
func TestPruningInTxTracker(t *testing.T) { | ||||||
txClient := &TxClient{ | ||||||
txTracker: make(map[string]txInfo), | ||||||
} | ||||||
numTransactions := 10 | ||||||
|
||||||
// Add 10 transactions to the tracker that are 10 minutes old | ||||||
var txsToBePruned int | ||||||
var txsNotReadyToBePruned int | ||||||
for i := 0; i < numTransactions; i++ { | ||||||
// 5 transactions will be pruned | ||||||
if i%2 == 0 { | ||||||
txClient.txTracker["tx"+fmt.Sprint(i)] = txInfo{ | ||||||
signer: "signer" + fmt.Sprint(i), | ||||||
sequence: uint64(i), | ||||||
timestamp: time.Now(). | ||||||
Add(-10 * time.Minute), | ||||||
} | ||||||
txsToBePruned++ | ||||||
} else { | ||||||
txClient.txTracker["tx"+fmt.Sprint(i)] = txInfo{ | ||||||
signer: "signer" + fmt.Sprint(i), | ||||||
sequence: uint64(i), | ||||||
timestamp: time.Now(). | ||||||
Add(-5 * time.Minute), | ||||||
} | ||||||
txsNotReadyToBePruned++ | ||||||
} | ||||||
} | ||||||
|
||||||
txTrackerBeforePruning := len(txClient.txTracker) | ||||||
|
||||||
// All transactions were indexed | ||||||
require.Equal(t, numTransactions, len(txClient.txTracker)) | ||||||
txClient.pruneTxTracker() | ||||||
// Prunes the transactions that are 10 minutes old | ||||||
// 5 transactions will be pruned | ||||||
require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the assertion by swapping the expected and actual values. The assertion on line 48 compares the wrong values. It should compare the difference between the tracker size before pruning and the number of transactions to be pruned with the actual size of the tracker after pruning. Swap the expected and actual values in the assertion: -require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned)
+require.Equal(t, txsToBePruned, txTrackerBeforePruning-txsToBePruned) Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Would be nice to apply this comment of coderabbit. |
||||||
// 5 transactions will not be pruned | ||||||
require.Equal(t, len(txClient.txTracker), txsNotReadyToBePruned) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment seems incorrect. It looks like the implementation below adds 5 transactions that are 10 minutes old and 5 transactions that are 5 minutes old.