mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-26 15:35:55 +00:00
* RPC: include orphans into mempool entries * no need for + 1 * give request option to choose mempool pool(s) * add to wallet, fix bg * use orphanpool rpc to test for orphans * fix fmt * fix crash when quering orphan pool in get_mempool_entries * pass the tests, fix fromAppMessage bug * Update config_test.go don't think this is needed * needed for tests to pass * inverse to transactionpoolfilter, cut down code to two ifs. * fmt * update test to true false, forgot one includetransactionpool renaming * update and simplyfiy get_mempool_entry handler * comment outdated * i think we usually use make instead of var. * Fix some leftovers of includeTransactionPool Co-authored-by: Ori Newman <orinewman1@gmail.com>
116 lines
3.1 KiB
Go
116 lines
3.1 KiB
Go
package mempool
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensusreference"
|
|
"sync"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
miningmanagermodel "github.com/kaspanet/kaspad/domain/miningmanager/model"
|
|
)
|
|
|
|
type mempool struct {
|
|
mtx sync.RWMutex
|
|
|
|
config *Config
|
|
consensusReference consensusreference.ConsensusReference
|
|
|
|
mempoolUTXOSet *mempoolUTXOSet
|
|
transactionsPool *transactionsPool
|
|
orphansPool *orphansPool
|
|
}
|
|
|
|
// New constructs a new mempool
|
|
func New(config *Config, consensusReference consensusreference.ConsensusReference) miningmanagermodel.Mempool {
|
|
mp := &mempool{
|
|
config: config,
|
|
consensusReference: consensusReference,
|
|
}
|
|
|
|
mp.mempoolUTXOSet = newMempoolUTXOSet(mp)
|
|
mp.transactionsPool = newTransactionsPool(mp)
|
|
mp.orphansPool = newOrphansPool(mp)
|
|
|
|
return mp
|
|
}
|
|
|
|
func (mp *mempool) ValidateAndInsertTransaction(transaction *externalapi.DomainTransaction, isHighPriority bool, allowOrphan bool) (
|
|
acceptedTransactions []*externalapi.DomainTransaction, err error) {
|
|
|
|
mp.mtx.Lock()
|
|
defer mp.mtx.Unlock()
|
|
|
|
return mp.validateAndInsertTransaction(transaction, isHighPriority, allowOrphan)
|
|
}
|
|
|
|
func (mp *mempool) GetTransaction(transactionID *externalapi.DomainTransactionID) (*externalapi.DomainTransaction, bool) {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.transactionsPool.getTransaction(transactionID)
|
|
}
|
|
|
|
func (mp *mempool) AllTransactions() []*externalapi.DomainTransaction {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.transactionsPool.getAllTransactions()
|
|
}
|
|
|
|
func (mp *mempool) GetOrphanTransaction(transactionID *externalapi.DomainTransactionID) (*externalapi.DomainTransaction, bool) {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.orphansPool.getOrphanTransaction(transactionID)
|
|
}
|
|
|
|
func (mp *mempool) AllOrphanTransactions() []*externalapi.DomainTransaction {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.orphansPool.getAllOrphanTransactions()
|
|
}
|
|
|
|
func (mp *mempool) TransactionCount() int {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.transactionsPool.transactionCount()
|
|
}
|
|
|
|
func (mp *mempool) HandleNewBlockTransactions(transactions []*externalapi.DomainTransaction) (
|
|
acceptedOrphans []*externalapi.DomainTransaction, err error) {
|
|
|
|
mp.mtx.Lock()
|
|
defer mp.mtx.Unlock()
|
|
|
|
return mp.handleNewBlockTransactions(transactions)
|
|
}
|
|
|
|
func (mp *mempool) BlockCandidateTransactions() []*externalapi.DomainTransaction {
|
|
mp.mtx.RLock()
|
|
defer mp.mtx.RUnlock()
|
|
|
|
return mp.transactionsPool.allReadyTransactions()
|
|
}
|
|
|
|
func (mp *mempool) RevalidateHighPriorityTransactions() (validTransactions []*externalapi.DomainTransaction, err error) {
|
|
mp.mtx.Lock()
|
|
defer mp.mtx.Unlock()
|
|
|
|
return mp.revalidateHighPriorityTransactions()
|
|
}
|
|
|
|
func (mp *mempool) RemoveTransactions(transactions []*externalapi.DomainTransaction, removeRedeemers bool) error {
|
|
mp.mtx.Lock()
|
|
defer mp.mtx.Unlock()
|
|
|
|
return mp.removeTransactions(transactions, removeRedeemers)
|
|
}
|
|
|
|
func (mp *mempool) RemoveTransaction(transactionID *externalapi.DomainTransactionID, removeRedeemers bool) error {
|
|
mp.mtx.Lock()
|
|
defer mp.mtx.Unlock()
|
|
|
|
return mp.removeTransaction(transactionID, removeRedeemers)
|
|
}
|