mempool: make all methods pointer methods

Makes no sense copying the Pool around.
This commit is contained in:
Roman Khimov 2020-02-04 17:36:11 +03:00
parent 70c22ebc7b
commit f0bb886be3
4 changed files with 10 additions and 10 deletions

View file

@ -963,8 +963,8 @@ func (bc *Blockchain) IsLowPriority(t *transaction.Transaction) bool {
} }
// GetMemPool returns the memory pool of the blockchain. // GetMemPool returns the memory pool of the blockchain.
func (bc *Blockchain) GetMemPool() mempool.Pool { func (bc *Blockchain) GetMemPool() *mempool.Pool {
return bc.memPool return &bc.memPool
} }
// VerifyBlock verifies block against its current state. // VerifyBlock verifies block against its current state.

View file

@ -41,5 +41,5 @@ type Blockchainer interface {
References(t *transaction.Transaction) map[transaction.Input]*transaction.Output References(t *transaction.Transaction) map[transaction.Input]*transaction.Output
mempool.Feer // fee interface mempool.Feer // fee interface
VerifyTx(*transaction.Transaction, *block.Block) error VerifyTx(*transaction.Transaction, *block.Block) error
GetMemPool() mempool.Pool GetMemPool() *mempool.Pool
} }

View file

@ -77,7 +77,7 @@ func (p Item) CompareTo(otherP *Item) int {
} }
// Count returns the total number of uncofirm transactions. // Count returns the total number of uncofirm transactions.
func (mp Pool) Count() int { func (mp *Pool) Count() int {
mp.lock.RLock() mp.lock.RLock()
defer mp.lock.RUnlock() defer mp.lock.RUnlock()
@ -85,7 +85,7 @@ func (mp Pool) Count() int {
} }
// ContainsKey checks if a transactions hash is in the Pool. // ContainsKey checks if a transactions hash is in the Pool.
func (mp Pool) ContainsKey(hash util.Uint256) bool { func (mp *Pool) ContainsKey(hash util.Uint256) bool {
mp.lock.RLock() mp.lock.RLock()
defer mp.lock.RUnlock() defer mp.lock.RUnlock()
@ -101,7 +101,7 @@ func (mp Pool) ContainsKey(hash util.Uint256) bool {
} }
// TryAdd try to add the Item to the Pool. // TryAdd try to add the Item to the Pool.
func (mp Pool) TryAdd(hash util.Uint256, pItem *Item) bool { func (mp *Pool) TryAdd(hash util.Uint256, pItem *Item) bool {
var pool Items var pool Items
mp.lock.Lock() mp.lock.Lock()
@ -124,7 +124,7 @@ func (mp Pool) TryAdd(hash util.Uint256, pItem *Item) bool {
mp.lock.Unlock() mp.lock.Unlock()
if mp.Count() > mp.capacity { if mp.Count() > mp.capacity {
(&mp).RemoveOverCapacity() mp.RemoveOverCapacity()
} }
mp.lock.RLock() mp.lock.RLock()
_, ok := mp.unsortedTxn[hash] _, ok := mp.unsortedTxn[hash]
@ -225,7 +225,7 @@ func NewMemPool(capacity int) Pool {
} }
// TryGetValue returns a transaction if it exists in the memory pool. // TryGetValue returns a transaction if it exists in the memory pool.
func (mp Pool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) { func (mp *Pool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) {
mp.lock.RLock() mp.lock.RLock()
defer mp.lock.RUnlock() defer mp.lock.RUnlock()
if pItem, ok := mp.unsortedTxn[hash]; ok { if pItem, ok := mp.unsortedTxn[hash]; ok {
@ -286,7 +286,7 @@ func (mp *Pool) GetVerifiedTransactions() []*transaction.Transaction {
// Verify verifies if the inputs of a transaction tx are already used in any other transaction in the memory pool. // Verify verifies if the inputs of a transaction tx are already used in any other transaction in the memory pool.
// If yes, the transaction tx is not a valid transaction and the function return false. // If yes, the transaction tx is not a valid transaction and the function return false.
// If no, the transaction tx is a valid transaction and the function return true. // If no, the transaction tx is a valid transaction and the function return true.
func (mp Pool) Verify(tx *transaction.Transaction) bool { func (mp *Pool) Verify(tx *transaction.Transaction) bool {
mp.lock.RLock() mp.lock.RLock()
defer mp.lock.RUnlock() defer mp.lock.RUnlock()
for _, item := range mp.unsortedTxn { for _, item := range mp.unsortedTxn {

View file

@ -118,7 +118,7 @@ func (chain testChain) GetUnspentCoinState(util.Uint256) *core.UnspentCoinState
panic("TODO") panic("TODO")
} }
func (chain testChain) GetMemPool() mempool.Pool { func (chain testChain) GetMemPool() *mempool.Pool {
panic("TODO") panic("TODO")
} }