1. 程式人生 > >btcd源碼中對tx的校驗

btcd源碼中對tx的校驗

highlight des AI manager PE san more image info

  接上文,在這個函數中

 func (sm *SyncManager) handleTxMsg(tmsg *txMsg)

技術分享圖片

調用txMemPool成員函數ProcessTransaction對tx進行校驗。在syncmanager對象中,txMemPool,顧名思義就是交易池。負責對交易的驗證和管理。

技術分享圖片

tx的數據結構如下:

// Tx defines a bitcoin transaction that provides easier and more efficient
// manipulation of raw transactions.  It also memoizes the hash for the
// transaction on its first access so subsequent accesses don‘t have to repeat
// the relatively expensive hashing operations.
type Tx struct {
	msgTx         *wire.MsgTx     // Underlying MsgTx
	txHash        *chainhash.Hash // Cached transaction hash
	txHashWitness *chainhash.Hash // Cached transaction witness hash
	txHasWitness  *bool           // If the transaction has witness data
	txIndex       int             // Position within a block or TxIndexUnknown
}

  在ProcessTransaction函數中調用了maybeAcceptTransaction,其中CheckTransactionSanity,主要對交易的輸入個數和及交易的序列化大小、交易輸入的前向節點,交易輸出的比特幣大小進行驗證

技術分享圖片

btcd源碼中對tx的校驗