mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-24 23:12:31 +00:00

* [NOD-1128] Add all flows to a directory names flows * [NOD-1128] Make everything in protocol package a manager method * [NOD-1128] Add AddTransaction mechanism to protocol manager * [NOD-1128] Add mempool related flows * [NOD-1128] Add mempool related flows * [NOD-1128] Add mempool related flows * [NOD-1127] Fix router message types * [NOD-1127] Inline updateQueues * [NOD-1127] Rename acceptedTxs->transactionsAcceptedToMempool * [NOD-1127] Add TODOs to notify transactions to RPC * [NOD-1127] Fix comment * [NOD-1127] Rename acceptedTxs->transactionsAcceptedToMempool * [NOD-1127] Rename MsgTxInv->MsgInvTransaction * [NOD-1127] Rename MsgTxInv.TXIDs->TxIDS * [NOD-1127] Change flow name * [NOD-1127] Call m.addTransactionRelayFlow * [NOD-1127] Remove redundant line * [NOD-1127] Use common.DefaultTimeout * [NOD-1127] Return early if len(idsToRequest) == 0 * [NOD-1127] Add NewBlockHandler to IBD
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package relaytransactions
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
"sync"
|
|
)
|
|
|
|
// SharedRequestedTransactions is a data structure that is shared between peers that
|
|
// holds the IDs of all the requested transactions to prevent redundant requests.
|
|
type SharedRequestedTransactions struct {
|
|
transactions map[daghash.TxID]struct{}
|
|
sync.Mutex
|
|
}
|
|
|
|
func (s *SharedRequestedTransactions) remove(txID *daghash.TxID) {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
delete(s.transactions, *txID)
|
|
}
|
|
|
|
func (s *SharedRequestedTransactions) removeMany(txIDs []*daghash.TxID) {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
for _, txID := range txIDs {
|
|
delete(s.transactions, *txID)
|
|
}
|
|
}
|
|
|
|
func (s *SharedRequestedTransactions) addIfNotExists(txID *daghash.TxID) (exists bool) {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
_, ok := s.transactions[*txID]
|
|
if ok {
|
|
return true
|
|
}
|
|
s.transactions[*txID] = struct{}{}
|
|
return false
|
|
}
|
|
|
|
// NewSharedRequestedTransactions returns a new instance of SharedRequestedTransactions.
|
|
func NewSharedRequestedTransactions() *SharedRequestedTransactions {
|
|
return &SharedRequestedTransactions{
|
|
transactions: make(map[daghash.TxID]struct{}),
|
|
}
|
|
}
|