Skip to content

Commit 388b5df

Browse files
committed
Move final fluid tx check to CheckTransactionToBlock
1 parent 5a9c3e8 commit 388b5df

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/fluid.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,12 @@ bool CFluid::ProvisionalCheckTransaction(const CTransaction &transaction) {
610610
return true;
611611
}
612612

613-
bool CFluid::CheckTransactionToBlock(const CTransaction &transaction, const CBlockHeader& blockHeader) {
613+
bool CFluid::CheckTransactionToBlock(const CTransaction& transaction, const CBlockHeader& blockHeader) {
614614
uint256 hash = blockHeader.GetHash();
615+
return CheckTransactionToBlock(transaction, hash);
616+
}
617+
618+
bool CFluid::CheckTransactionToBlock(const CTransaction& transaction, const uint256 hash) {
615619
if (mapBlockIndex.count(hash) == 0)
616620
return true;
617621

@@ -627,4 +631,4 @@ bool CFluid::CheckTransactionToBlock(const CTransaction &transaction, const CBlo
627631
}
628632

629633
return true;
630-
}
634+
}

src/fluid.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class CFluid : public CFluidParameters, public COperations {
7676

7777
bool ValidationProcesses(CValidationState& state, CScript txOut, CAmount txValue);
7878

79-
bool CheckTransactionToBlock(const CTransaction &transaction, const CBlockHeader& blockHeader);
79+
bool CheckTransactionToBlock(const CTransaction& transaction, const CBlockHeader& blockHeader);
80+
bool CheckTransactionToBlock(const CTransaction& transaction, const uint256 hash);
81+
8082
bool ProvisionalCheckTransaction(const CTransaction &transaction);
8183
bool InsertTransactionToRecord(CScript fluidInstruction, std::vector<std::string>& transactionRecord);
8284
CDynamicAddress GetAddressFromDigestSignature(const std::string digestSignature, const std::string messageTokenKey);

src/validation.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,16 @@ CBlockTreeDB *pblocktree = NULL;
205205

206206
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
207207
{
208-
CBlockIndex* pblockindex = chainActive[nBlockHeight-1];
209-
210208
if (tx.nLockTime == 0)
211209
return true;
210+
212211
if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))
213212
return true;
214213

215214
if (nBlockHeight >= fluid.FLUID_ACTIVATE_HEIGHT) {
216215
if (!fluid.ProvisionalCheckTransaction(tx))
217216
return false;
218217

219-
if (!fluid.CheckTransactionToBlock(tx, pblockindex->GetBlockHeader()))
220-
return false;
221-
222218
BOOST_FOREACH(const CTxOut& txout, tx.vout) {
223219
if (IsTransactionFluid(txout.scriptPubKey)) {
224220
std::string strErrorMessage;
@@ -3374,6 +3370,9 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const CB
33743370

33753371
// Check that all transactions are finalized
33763372
for (const CTransaction& tx : block.vtx) {
3373+
if (!fluid.CheckTransactionToBlock(tx, pindexPrev->GetBlockHeader()))
3374+
return state.DoS(10, error("%s: contains an invalid fluid transaction", __func__), REJECT_INVALID, "invalid-fluid-txns");
3375+
33773376
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) {
33783377
return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal");
33793378
}
@@ -3390,13 +3389,6 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const CB
33903389
}
33913390
}
33923391

3393-
// Check that all transactions are finalized
3394-
for (const CTransaction& tx : block.vtx) {
3395-
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) {
3396-
return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal");
3397-
}
3398-
}
3399-
34003392
// If Fluid transaction present, has it been adhered to?
34013393
CDynamicAddress mintAddress; CAmount fluidIssuance;
34023394

0 commit comments

Comments
 (0)