Skip to content

Commit 90c6c7a

Browse files
committed
Fix failing functional tests(feature_cltv.py)
1 parent ac4f103 commit 90c6c7a

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/validation.cpp

+20-23
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
10361036
ws.m_conflicts.insert(err->second->GetHash());
10371037
// Adding the sibling to m_iters_conflicting here means that it doesn't count towards
10381038
// RBF Carve Out above. This is correct, since removing to-be-replaced transactions from
1039-
// the descendant count is done separately in SingleV3Checks for TRUC transactions.
1039+
// the descendant count is done separately in SingleTRUCChecks for TRUC transactions.
10401040
ws.m_iters_conflicting.insert(m_pool.GetIter(err->second->GetHash()).value());
10411041
ws.m_sibling_eviction = true;
10421042
// The sibling will be treated as part of the to-be-replaced set in ReplacementChecks.
@@ -1877,7 +1877,6 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
18771877

18781878
MempoolAcceptResult AcceptToMemoryPool(Chainstate& active_chainstate, const CTransactionRef& tx,
18791879
int64_t accept_time, bool bypass_limits, bool test_accept)
1880-
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
18811880
{
18821881
AssertLockHeld(::cs_main);
18831882
const CChainParams& chainparams{active_chainstate.m_chainman.GetParams()};
@@ -2606,9 +2605,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26062605
for (const auto& tx : block.vtx) {
26072606
for (size_t o = 0; o < tx->vout.size(); o++) {
26082607
if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
2609-
LogPrintf("ERROR: ConnectBlock(): tried to overwrite transaction\n");
2610-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
2611-
"tried to overwrite transaction");
2608+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
2609+
"tried to overwrite transaction");
26122610
}
26132611
}
26142612
}
@@ -2666,14 +2664,13 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26662664
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
26672665
tx_state.GetRejectReason(),
26682666
tx_state.GetDebugMessage() + " in transaction " + tx.GetHash().ToString());
2669-
LogError("%s: Consensus::CheckTxInputs: %s, %s\n", __func__, tx.GetHash().ToString(), state.ToString());
2670-
return false;
2667+
break;
26712668
}
26722669
nFees += txfee;
26732670
if (!MoneyRange(nFees)) {
2674-
LogPrintf("ERROR: %s: accumulated fee in the block out of range.\n", __func__);
2675-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange",
2676-
"accumulated fee in the block out of range");
2671+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange",
2672+
"accumulated fee in the block out of range");
2673+
break;
26772674
}
26782675

26792676
// Check that transaction is BIP68 final
@@ -2685,9 +2682,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26852682
}
26862683

26872684
if (!SequenceLocks(tx, nLockTimeFlags, prevheights, *pindex)) {
2688-
LogPrintf("ERROR: %s: contains a non-BIP68-final transaction\n", __func__);
2689-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal",
2690-
"contains a non-BIP68-final transaction " + tx.GetHash().ToString());
2685+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal",
2686+
"contains a non-BIP68-final transaction " + tx.GetHash().ToString());
2687+
break;
26912688
}
26922689
}
26932690

@@ -2697,8 +2694,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26972694
// * witness (when witness enabled in flags and excludes coinbase)
26982695
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
26992696
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
2700-
LogPrintf("ERROR: ConnectBlock(): too many sigops\n");
2701-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops", "too many sigops");
2697+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops", "too many sigops");
2698+
break;
27022699
}
27032700

27042701
if (!tx.IsCoinBase())
@@ -2710,8 +2707,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27102707
// Any transaction validation failure in ConnectBlock is a block consensus failure
27112708
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
27122709
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
2713-
LogInfo("Script validation error in block: %s\n", state.ToString());
2714-
return false;
2710+
break;
27152711
}
27162712
control.Add(std::move(vChecks));
27172713
}
@@ -2731,16 +2727,17 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27312727
Ticks<MillisecondsDouble>(m_chainman.time_connect) / m_chainman.num_blocks_total);
27322728

27332729
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, params.GetConsensus());
2734-
if (block.vtx[0]->GetValueOut() > blockReward) {
2735-
LogPrintf("ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n", block.vtx[0]->GetValueOut(), blockReward);
2736-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
2737-
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
2730+
if (block.vtx[0]->GetValueOut() > blockReward && state.IsValid()) {
2731+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
2732+
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
27382733
}
27392734

27402735
auto parallel_result = control.Complete();
2741-
if (parallel_result.has_value()) {
2736+
if (parallel_result.has_value() && state.IsValid()) {
27422737
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
2743-
LogInfo("Script validation error in block: %s", state.ToString());
2738+
}
2739+
if (!state.IsValid()) {
2740+
LogInfo("Block validation error: %s", state.ToString());
27442741
return false;
27452742
}
27462743
const auto time_4{SteadyClock::now()};

test/functional/feature_cltv.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test BIP65 (CHECKLOCKTIMEVERIFY).
6+
67
Test that the CHECKLOCKTIMEVERIFY soft-fork activates.
78
"""
89

@@ -147,6 +148,10 @@ def run_test(self):
147148
# create and test one invalid tx per CLTV failure reason (5 in total)
148149
for i in range(5):
149150
spendtx = wallet.create_self_transfer()['tx']
151+
assert_equal(len(spendtx.vin), 1)
152+
coin = spendtx.vin[0]
153+
coin_txid = format(coin.prevout.hash, '064x')
154+
coin_vout = coin.prevout.n
150155
cltv_invalidate(spendtx, i)
151156

152157
expected_cltv_reject_reason = [
@@ -158,12 +163,15 @@ def run_test(self):
158163
][i]
159164
# First we show that this tx is valid except for CLTV by getting it
160165
# rejected from the mempool for exactly that reason.
166+
spendtx_txid = spendtx.hash
167+
spendtx_wtxid = spendtx.getwtxid()
161168
assert_equal(
162169
[{
163-
'txid': spendtx.hash,
164-
'wtxid': spendtx.getwtxid(),
170+
'txid': spendtx_txid,
171+
'wtxid': spendtx_wtxid,
165172
'allowed': False,
166173
'reject-reason': expected_cltv_reject_reason,
174+
'reject-details': expected_cltv_reject_reason + f", input 0 of {spendtx_txid} (wtxid {spendtx_wtxid}), spending {coin_txid}:{coin_vout}"
167175
}],
168176
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0),
169177
)

0 commit comments

Comments
 (0)