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

* [NOD-386] Extract net parsing functionality to a shared place. * [NOD-386] Add extract ActiveNetParams to cmdconfig * [NOD-386] Adding comments so go-vet won't shout at me * [NOD-386] Rename package name to config * [NOD-386] Rename commandConfig to configFlags * [NOD-386] Rename function to ResolveNetwork * [NOD-386] Fix renaming errors * [NOD-386] Refactor network config to btcd level so APIserver and btcd could use it * [NOD-386] Refactor network config to config package * [NOD-386] Move ActiveNetParams to network section * [NOD-386] Explictly return nil * [NOD-386] Reuse activeNetParams from netwrok config * [NOD-386] Set ActiveNetworkFlags instance to be global * [NOD-386] Remove redundant newline * [NOD-386] Init ActiveNetParams in address manager test * [NOD-386] Add dnsseeder network config * [NOD-386] Use ActiveConfig() method to access configuration
37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/daglabs/btcd/config"
|
|
"github.com/daglabs/btcd/peer"
|
|
"github.com/daglabs/btcd/util"
|
|
"github.com/daglabs/btcd/util/daghash"
|
|
"github.com/daglabs/btcd/wire"
|
|
)
|
|
|
|
// OnTx is invoked when a peer receives a tx bitcoin message. It blocks
|
|
// until the bitcoin transaction has been fully processed. Unlock the block
|
|
// handler this does not serialize all transactions through a single thread
|
|
// transactions don't rely on the previous one in a linear fashion like blocks.
|
|
func (sp *Peer) OnTx(_ *peer.Peer, msg *wire.MsgTx) {
|
|
if config.ActiveConfig().BlocksOnly {
|
|
peerLog.Tracef("Ignoring tx %s from %s - blocksonly enabled",
|
|
msg.TxID(), sp)
|
|
return
|
|
}
|
|
|
|
// Add the transaction to the known inventory for the peer.
|
|
// Convert the raw MsgTx to a util.Tx which provides some convenience
|
|
// methods and things such as hash caching.
|
|
tx := util.NewTx(msg)
|
|
iv := wire.NewInvVect(wire.InvTypeTx, (*daghash.Hash)(tx.ID()))
|
|
sp.AddKnownInventory(iv)
|
|
|
|
// Queue the transaction up to be handled by the sync manager and
|
|
// intentionally block further receives until the transaction is fully
|
|
// processed and known good or bad. This helps prevent a malicious peer
|
|
// from queuing up a bunch of bad transactions before disconnecting (or
|
|
// being disconnected) and wasting memory.
|
|
sp.server.SyncManager.QueueTx(tx, sp.Peer, sp.txProcessed)
|
|
<-sp.txProcessed
|
|
}
|