Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jul 1, 2024
1 parent 80f9836 commit 296a370
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions types/mempool/priority_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,6 @@ func (mp *PriorityNonceMempool[C]) NextSenderTx(sender string) sdk.Tx {
// Inserting a duplicate tx with a different priority overwrites the existing tx,
// changing the total order of the mempool.
func (mp *PriorityNonceMempool[C]) InsertWithGasWanted(ctx context.Context, tx sdk.Tx, gasWanted uint64) error {
mp.mtx.Lock()
defer mp.mtx.Unlock()
if mp.cfg.MaxTx > 0 && mp.priorityIndex.Len() >= mp.cfg.MaxTx {
return ErrMempoolTxMaxCapacity
} else if mp.cfg.MaxTx < 0 {
return nil
}

memTx := NewMempoolTx(tx, gasWanted)

sigs, err := mp.cfg.SignerExtractor.GetSigners(tx)
if err != nil {
return err
Expand All @@ -226,6 +216,16 @@ func (mp *PriorityNonceMempool[C]) InsertWithGasWanted(ctx context.Context, tx s
nonce := sig.Sequence
key := txMeta[C]{nonce: nonce, priority: priority, sender: sender}

mp.mtx.Lock()
defer mp.mtx.Unlock()
if mp.cfg.MaxTx > 0 && mp.priorityIndex.Len() >= mp.cfg.MaxTx {
return ErrMempoolTxMaxCapacity
} else if mp.cfg.MaxTx < 0 {
return nil
}

memTx := NewMempoolTx(tx, gasWanted)

senderIndex, ok := mp.senderIndices[sender]
if !ok {
senderIndex = skiplist.New(skiplist.LessThanFunc(func(a, b any) int {
Expand Down Expand Up @@ -440,9 +440,6 @@ func (mp *PriorityNonceMempool[C]) CountTx() int {
// Remove removes a transaction from the mempool in O(log n) time, returning an
// error if unsuccessful.
func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
mp.mtx.Lock()
defer mp.mtx.Unlock()

sigs, err := mp.cfg.SignerExtractor.GetSigners(tx)
if err != nil {
return err
Expand All @@ -455,6 +452,9 @@ func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
sender := sig.Signer.String()
nonce := sig.Sequence

mp.mtx.Lock()
defer mp.mtx.Unlock()

scoreKey := txMeta[C]{nonce: nonce, sender: sender}
score, ok := mp.scores[scoreKey]
if !ok {
Expand Down

0 comments on commit 296a370

Please sign in to comment.