@@ -848,8 +848,8 @@ bool CTxLockRequest::IsValid(bool fRequireUnspent) const
848
848
return false ;
849
849
}
850
850
851
- int64_t nValueIn = 0 ;
852
- int64_t nValueOut = 0 ;
851
+ CAmount nValueIn = 0 ;
852
+ CAmount nValueOut = 0 ;
853
853
854
854
BOOST_FOREACH (const CTxOut& txout, vout) {
855
855
// InstantSend supports normal scripts and unspendable (i.e. data) scripts.
@@ -865,6 +865,8 @@ bool CTxLockRequest::IsValid(bool fRequireUnspent) const
865
865
866
866
CCoins coins;
867
867
int nPrevoutHeight = 0 ;
868
+ CAmount nValue = 0 ;
869
+
868
870
if (!pcoinsTip->GetCoins (txin.prevout .hash , coins) ||
869
871
(unsigned int )txin.prevout .n >=coins.vout .size () ||
870
872
coins.vout [txin.prevout .n ].IsNull ()) {
@@ -875,20 +877,29 @@ bool CTxLockRequest::IsValid(bool fRequireUnspent) const
875
877
CTransaction txOutpointCreated;
876
878
uint256 nHashOutpointConfirmed;
877
879
if (!GetTransaction (txin.prevout .hash , txOutpointCreated, Params ().GetConsensus (), nHashOutpointConfirmed, true ) || nHashOutpointConfirmed == uint256 ()) {
878
- LogPrint (" instantsend" , " txLockRequest::IsValid -- Failed to find outpoint %s\n " , txin.prevout .ToStringShort ());
880
+ LogPrint (" instantsend" , " CTxLockRequest::IsValid -- Failed to find outpoint %s\n " , txin.prevout .ToStringShort ());
881
+ return false ;
882
+ }
883
+ if (txin.prevout .n >= txOutpointCreated.vout .size ()) {
884
+ LogPrint (" instantsend" , " CTxLockRequest::IsValid -- Outpoint %s is out of bounds, size() = %lld\n " ,
885
+ txin.prevout .ToStringShort (), txOutpointCreated.vout .size ());
879
886
return false ;
880
887
}
881
- LOCK (cs_main);
882
888
BlockMap::iterator mi = mapBlockIndex.find (nHashOutpointConfirmed);
883
- if (mi == mapBlockIndex.end ()) {
884
- // not on this chain?
885
- LogPrint (" instantsend" , " txLockRequest::IsValid -- Failed to find block %s for outpoint %s\n " , nHashOutpointConfirmed.ToString (), txin.prevout .ToStringShort ());
889
+ if (mi == mapBlockIndex.end () || !mi->second ) {
890
+ // shouldn't happen
891
+ LogPrint (" instantsend" , " CTxLockRequest::IsValid -- Failed to find block %s for outpoint %s\n " ,
892
+ nHashOutpointConfirmed.ToString (), txin.prevout .ToStringShort ());
886
893
return false ;
887
894
}
888
- nPrevoutHeight = mi->second ? mi->second ->nHeight : 0 ;
895
+ nPrevoutHeight = mi->second ->nHeight ;
896
+ nValue = txOutpointCreated.vout [txin.prevout .n ].nValue ;
897
+ } else {
898
+ nPrevoutHeight = coins.nHeight ;
899
+ nValue = coins.vout [txin.prevout .n ].nValue ;
889
900
}
890
901
891
- int nTxAge = chainActive.Height () - ( nPrevoutHeight ? nPrevoutHeight : coins. nHeight ) + 1 ;
902
+ int nTxAge = chainActive.Height () - nPrevoutHeight + 1 ;
892
903
// 1 less than the "send IX" gui requires, in case of a block propagating the network at the time
893
904
int nConfirmationsRequired = INSTANTSEND_CONFIRMATIONS_REQUIRED - 1 ;
894
905
@@ -898,7 +909,7 @@ bool CTxLockRequest::IsValid(bool fRequireUnspent) const
898
909
return false ;
899
910
}
900
911
901
- nValueIn += coins. vout [txin. prevout . n ]. nValue ;
912
+ nValueIn += nValue;
902
913
}
903
914
904
915
if (nValueOut > sporkManager.GetSporkValue (SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) {
0 commit comments