-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: index submitted txs in tx client and improve nonce manageme…
…nt (#3830) ## Overview Fixes #3899 --------- Co-authored-by: Callum Waters <[email protected]> Co-authored-by: Rootul P <[email protected]>
- Loading branch information
1 parent
e24c0e8
commit e9278ed
Showing
4 changed files
with
242 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 and 5 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, txsToBePruned, txTrackerBeforePruning-txsToBePruned) | ||
require.Equal(t, len(txClient.txTracker), txsNotReadyToBePruned) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.