@@ -818,58 +818,8 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
818818
819819bool CheckTransaction (const CTransaction& tx, CValidationState &state)
820820{
821- // Basic checks that don't depend on any context
822- if (tx.vin .empty ())
823- return state.DoS (10 , error (" CheckTransaction() : vin empty" ),
824- REJECT_INVALID, " bad-txns-vin-empty" );
825- if (tx.vout .empty ())
826- return state.DoS (10 , error (" CheckTransaction() : vout empty" ),
827- REJECT_INVALID, " bad-txns-vout-empty" );
828- // Size limits
829- if (::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
830- return state.DoS (100 , error (" CheckTransaction() : size limits failed" ),
831- REJECT_INVALID, " bad-txns-oversize" );
832-
833- // Check for negative or overflow output values
834- CAmount nValueOut = 0 ;
835- BOOST_FOREACH (const CTxOut& txout, tx.vout )
836- {
837- if (txout.nValue < 0 )
838- return state.DoS (100 , error (" CheckTransaction() : txout.nValue negative" ),
839- REJECT_INVALID, " bad-txns-vout-negative" );
840- if (txout.nValue > MAX_MONEY)
841- return state.DoS (100 , error (" CheckTransaction() : txout.nValue too high" ),
842- REJECT_INVALID, " bad-txns-vout-toolarge" );
843- nValueOut += txout.nValue ;
844- if (!MoneyRange (nValueOut))
845- return state.DoS (100 , error (" CheckTransaction() : txout total out of range" ),
846- REJECT_INVALID, " bad-txns-txouttotal-toolarge" );
847- }
848-
849- // Check for duplicate inputs
850- set<COutPoint> vInOutPoints;
851- BOOST_FOREACH (const CTxIn& txin, tx.vin )
852- {
853- if (vInOutPoints.count (txin.prevout ))
854- return state.DoS (100 , error (" CheckTransaction() : duplicate inputs" ),
855- REJECT_INVALID, " bad-txns-inputs-duplicate" );
856- vInOutPoints.insert (txin.prevout );
857- }
858-
859- if (tx.IsCoinBase ())
860- {
861- if (tx.vin [0 ].scriptSig .size () < 2 || tx.vin [0 ].scriptSig .size () > 100 )
862- return state.DoS (100 , error (" CheckTransaction() : coinbase script size" ),
863- REJECT_INVALID, " bad-cb-length" );
864- }
865- else
866- {
867- BOOST_FOREACH (const CTxIn& txin, tx.vin )
868- if (txin.prevout .IsNull ())
869- return state.DoS (10 , error (" CheckTransaction() : prevout is null" ),
870- REJECT_INVALID, " bad-txns-prevout-null" );
871- }
872-
821+ if (!Consensus::CheckTransaction (tx,state))
822+ return error (std::string (std::string (__func__) + " : " + state.GetRejectReason ()).c_str ());
873823 return true ;
874824}
875825
@@ -1845,7 +1795,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18451795 if (!FindUndoPos (state, pindex->nFile , pos, ::GetSerializeSize (blockundo, SER_DISK, CLIENT_VERSION) + 40 ))
18461796 return error (" ConnectBlock() : FindUndoPos failed" );
18471797 if (!UndoWriteToDisk (blockundo, pos, pindex->pprev ->GetBlockHash ()))
1848- return state. Abort ( " Failed to write undo data" );
1798+ return AbortNode (state, " Failed to write undo data" );
18491799
18501800 // update nUndoPos in block index
18511801 pindex->nUndoPos = pos.nPos ;
@@ -1858,7 +1808,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18581808
18591809 if (fTxIndex )
18601810 if (!pblocktree->WriteTxIndex (vPos))
1861- return state. Abort ( " Failed to write transaction index" );
1811+ return AbortNode (state, " Failed to write transaction index" );
18621812
18631813 // add this block to the view's block chain
18641814 view.SetBestBlock (pindex->GetBlockHash ());
@@ -1919,20 +1869,20 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19191869 setDirtyBlockIndex.erase (it++);
19201870 }
19211871 if (!pblocktree->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
1922- return state. Abort ( " Files to write to block index database" );
1872+ return AbortNode (state, " Files to write to block index database" );
19231873 }
19241874 }
19251875 // Finally flush the chainstate (which may refer to block index entries).
19261876 if (!pcoinsTip->Flush ())
1927- return state. Abort ( " Failed to write to coin database" );
1877+ return AbortNode (state, " Failed to write to coin database" );
19281878 // Update best block in wallet (so we can detect restored wallets).
19291879 if (mode != FLUSH_STATE_IF_NEEDED) {
19301880 g_signals.SetBestChain (chainActive.GetLocator ());
19311881 }
19321882 nLastWrite = GetTimeMicros ();
19331883 }
19341884 } catch (const std::runtime_error& e) {
1935- return state. Abort ( std::string (" System error while flushing: " ) + e.what ());
1885+ return AbortNode (state, std::string (" System error while flushing: " ) + e.what ());
19361886 }
19371887 return true ;
19381888}
@@ -1989,7 +1939,7 @@ bool static DisconnectTip(CValidationState &state) {
19891939 // Read block from disk.
19901940 CBlock block;
19911941 if (!ReadBlockFromDisk (block, pindexDelete))
1992- return state. Abort ( " Failed to read block" );
1942+ return AbortNode (state, " Failed to read block" );
19931943 // Apply the block atomically to the chain state.
19941944 int64_t nStart = GetTimeMicros ();
19951945 {
@@ -2040,7 +1990,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
20401990 CBlock block;
20411991 if (!pblock) {
20421992 if (!ReadBlockFromDisk (block, pindexNew))
2043- return state. Abort ( " Failed to read block" );
1993+ return AbortNode (state, " Failed to read block" );
20441994 pblock = █
20451995 }
20461996 // Apply the block atomically to the chain state.
@@ -2706,11 +2656,11 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
27062656 return error (" AcceptBlock() : FindBlockPos failed" );
27072657 if (dbp == NULL )
27082658 if (!WriteBlockToDisk (block, blockPos))
2709- return state. Abort ( " Failed to write block" );
2659+ AbortNode (state, " Failed to write block" );
27102660 if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
27112661 return error (" AcceptBlock() : ReceivedBlockTransactions failed" );
27122662 } catch (const std::runtime_error& e) {
2713- return state. Abort ( std::string (" System error: " ) + e.what ());
2663+ return AbortNode (state, std::string (" System error: " ) + e.what ());
27142664 }
27152665
27162666 return true ;
@@ -2799,6 +2749,12 @@ bool AbortNode(const std::string &strMessage, const std::string &userMessage) {
27992749 return false ;
28002750}
28012751
2752+ bool AbortNode (CValidationState& state, const std::string &strMessage, const std::string &userMessage)
2753+ {
2754+ AbortNode (strMessage, userMessage);
2755+ return state.Error (strMessage);
2756+ }
2757+
28022758bool CheckDiskSpace (uint64_t nAdditionalBytes)
28032759{
28042760 uint64_t nFreeBytesAvailable = boost::filesystem::space (GetDataDir ()).available ;
0 commit comments