Skip to content

Commit

Permalink
concurrency fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Feb 19, 2024
1 parent 3a74586 commit 847a2b5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/enclave/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/big"
"strings"
"sync"

// unsafe package imported in order to link to a private function in go-ethereum.
// This allows us to validate transactions against the tx pool rules.
Expand All @@ -28,6 +29,7 @@ type TxPool struct {
Chain *ethchainadapter.EthChainAdapter
gasTip *big.Int
running bool
stateMutex sync.Mutex
logger gethlog.Logger
}

Expand All @@ -41,6 +43,7 @@ func NewTxPool(blockchain *ethchainadapter.EthChainAdapter, gasTip *big.Int, log
txPoolConfig: txPoolConfig,
legacyPool: legacyPool,
gasTip: gasTip,
stateMutex: sync.Mutex{},
logger: logger,
}, nil
}
Expand Down Expand Up @@ -96,6 +99,8 @@ func (t *TxPool) Validate(tx *common.L2Tx) error {
return err
}

t.stateMutex.Lock()
defer t.stateMutex.Unlock()
// validate against the state. Things like nonce, balance, etc
return validateTx(t.legacyPool, tx, false)
}
Expand Down

0 comments on commit 847a2b5

Please sign in to comment.