@@ -818,58 +818,8 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
818
818
819
819
bool CheckTransaction (const CTransaction& tx, CValidationState &state)
820
820
{
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 ());
873
823
return true ;
874
824
}
875
825
@@ -1845,7 +1795,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
1845
1795
if (!FindUndoPos (state, pindex->nFile , pos, ::GetSerializeSize (blockundo, SER_DISK, CLIENT_VERSION) + 40 ))
1846
1796
return error (" ConnectBlock() : FindUndoPos failed" );
1847
1797
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" );
1849
1799
1850
1800
// update nUndoPos in block index
1851
1801
pindex->nUndoPos = pos.nPos ;
@@ -1858,7 +1808,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
1858
1808
1859
1809
if (fTxIndex )
1860
1810
if (!pblocktree->WriteTxIndex (vPos))
1861
- return state. Abort ( " Failed to write transaction index" );
1811
+ return AbortNode (state, " Failed to write transaction index" );
1862
1812
1863
1813
// add this block to the view's block chain
1864
1814
view.SetBestBlock (pindex->GetBlockHash ());
@@ -1919,20 +1869,20 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
1919
1869
setDirtyBlockIndex.erase (it++);
1920
1870
}
1921
1871
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" );
1923
1873
}
1924
1874
}
1925
1875
// Finally flush the chainstate (which may refer to block index entries).
1926
1876
if (!pcoinsTip->Flush ())
1927
- return state. Abort ( " Failed to write to coin database" );
1877
+ return AbortNode (state, " Failed to write to coin database" );
1928
1878
// Update best block in wallet (so we can detect restored wallets).
1929
1879
if (mode != FLUSH_STATE_IF_NEEDED) {
1930
1880
g_signals.SetBestChain (chainActive.GetLocator ());
1931
1881
}
1932
1882
nLastWrite = GetTimeMicros ();
1933
1883
}
1934
1884
} 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 ());
1936
1886
}
1937
1887
return true ;
1938
1888
}
@@ -1989,7 +1939,7 @@ bool static DisconnectTip(CValidationState &state) {
1989
1939
// Read block from disk.
1990
1940
CBlock block;
1991
1941
if (!ReadBlockFromDisk (block, pindexDelete))
1992
- return state. Abort ( " Failed to read block" );
1942
+ return AbortNode (state, " Failed to read block" );
1993
1943
// Apply the block atomically to the chain state.
1994
1944
int64_t nStart = GetTimeMicros ();
1995
1945
{
@@ -2040,7 +1990,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
2040
1990
CBlock block;
2041
1991
if (!pblock) {
2042
1992
if (!ReadBlockFromDisk (block, pindexNew))
2043
- return state. Abort ( " Failed to read block" );
1993
+ return AbortNode (state, " Failed to read block" );
2044
1994
pblock = █
2045
1995
}
2046
1996
// Apply the block atomically to the chain state.
@@ -2706,11 +2656,11 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
2706
2656
return error (" AcceptBlock() : FindBlockPos failed" );
2707
2657
if (dbp == NULL )
2708
2658
if (!WriteBlockToDisk (block, blockPos))
2709
- return state. Abort ( " Failed to write block" );
2659
+ AbortNode (state, " Failed to write block" );
2710
2660
if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
2711
2661
return error (" AcceptBlock() : ReceivedBlockTransactions failed" );
2712
2662
} 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 ());
2714
2664
}
2715
2665
2716
2666
return true ;
@@ -2799,6 +2749,12 @@ bool AbortNode(const std::string &strMessage, const std::string &userMessage) {
2799
2749
return false ;
2800
2750
}
2801
2751
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
+
2802
2758
bool CheckDiskSpace (uint64_t nAdditionalBytes)
2803
2759
{
2804
2760
uint64_t nFreeBytesAvailable = boost::filesystem::space (GetDataDir ()).available ;
0 commit comments