mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-20 23:29:01 +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
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package protocol
|
|
|
|
import (
|
|
peerpkg "github.com/kaspanet/kaspad/protocol/peer"
|
|
"github.com/kaspanet/kaspad/util"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
"github.com/kaspanet/kaspad/wire"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// OnNewBlock updates the mempool after a new block arrival, and
|
|
// relays newly unorphaned transactions and possibly rebroadcast
|
|
// manually added transactions when not in IBD.
|
|
// TODO(libp2p) Call this function from IBD as well.
|
|
func (m *Manager) OnNewBlock(block *util.Block) error {
|
|
transactionsAcceptedToMempool, err := m.txPool.HandleNewBlock(block)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// TODO(libp2p) Notify transactionsAcceptedToMempool to RPC
|
|
|
|
m.updateTransactionsToRebroadcast(block)
|
|
|
|
// Don't relay transactions when in IBD.
|
|
if atomic.LoadUint32(&m.isInIBD) != 0 {
|
|
return nil
|
|
}
|
|
|
|
var txIDsToRebroadcast []*daghash.TxID
|
|
if m.shouldRebroadcastTransactions() {
|
|
txIDsToRebroadcast = m.txIDsToRebroadcast()
|
|
}
|
|
|
|
txIDsToBroadcast := make([]*daghash.TxID, len(transactionsAcceptedToMempool)+len(txIDsToRebroadcast))
|
|
for i, tx := range transactionsAcceptedToMempool {
|
|
txIDsToBroadcast[i] = tx.ID()
|
|
}
|
|
|
|
copy(txIDsToBroadcast[len(transactionsAcceptedToMempool):], txIDsToBroadcast)
|
|
txIDsToBroadcast = txIDsToBroadcast[:wire.MaxInvPerTxInvMsg]
|
|
inv := wire.NewMsgTxInv(txIDsToBroadcast)
|
|
return m.netAdapter.Broadcast(peerpkg.ReadyPeerIDs(), inv)
|
|
}
|