Skip to content

Commit 38860f9

Browse files
committed
validation: remove redundant CChainParams params from ChainstateManager methods
1 parent 69675ea commit 38860f9

11 files changed

+32
-36
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int main(int argc, char* argv[])
190190
bool new_block;
191191
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
192192
RegisterSharedValidationInterface(sc);
193-
bool accepted = chainman.ProcessNewBlock(chainparams, blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
193+
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
194194
UnregisterSharedValidationInterface(sc);
195195
if (!new_block && accepted) {
196196
std::cerr << "duplicate" << std::endl;

src/net_processing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
22142214
}
22152215

22162216
BlockValidationState state;
2217-
if (!m_chainman.ProcessNewBlockHeaders(headers, state, m_chainparams, &pindexLast)) {
2217+
if (!m_chainman.ProcessNewBlockHeaders(headers, state, &pindexLast)) {
22182218
if (state.IsInvalid()) {
22192219
MaybePunishNodeForBlock(pfrom.GetId(), state, via_compact_block, "invalid header received");
22202220
return;
@@ -2591,7 +2591,7 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
25912591
void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing)
25922592
{
25932593
bool new_block{false};
2594-
m_chainman.ProcessNewBlock(m_chainparams, block, force_processing, &new_block);
2594+
m_chainman.ProcessNewBlock(block, force_processing, &new_block);
25952595
if (new_block) {
25962596
node.m_last_block_time = GetTime<std::chrono::seconds>();
25972597
} else {
@@ -3569,7 +3569,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35693569

35703570
const CBlockIndex *pindex = nullptr;
35713571
BlockValidationState state;
3572-
if (!m_chainman.ProcessNewBlockHeaders({cmpctblock.header}, state, m_chainparams, &pindex)) {
3572+
if (!m_chainman.ProcessNewBlockHeaders({cmpctblock.header}, state, &pindex)) {
35733573
if (state.IsInvalid()) {
35743574
MaybePunishNodeForBlock(pfrom.GetId(), state, /*via_compact_block=*/true, "invalid header via cmpctblock");
35753575
return;

src/rpc/mining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
133133
}
134134

135135
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
136-
if (!chainman.ProcessNewBlock(chainparams, shared_pblock, true, nullptr)) {
136+
if (!chainman.ProcessNewBlock(shared_pblock, true, nullptr)) {
137137
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
138138
}
139139

@@ -1000,7 +1000,7 @@ static RPCHelpMan submitblock()
10001000
bool new_block;
10011001
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
10021002
RegisterSharedValidationInterface(sc);
1003-
bool accepted = chainman.ProcessNewBlock(Params(), blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
1003+
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
10041004
UnregisterSharedValidationInterface(sc);
10051005
if (!new_block && accepted) {
10061006
return "duplicate";
@@ -1042,7 +1042,7 @@ static RPCHelpMan submitheader()
10421042
}
10431043

10441044
BlockValidationState state;
1045-
chainman.ProcessNewBlockHeaders({h}, state, Params());
1045+
chainman.ProcessNewBlockHeaders({h}, state);
10461046
if (state.IsValid()) return NullUniValue;
10471047
if (state.IsError()) {
10481048
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());

src/test/blockfilter_index_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
101101
CBlockHeader header = block->GetBlockHeader();
102102

103103
BlockValidationState state;
104-
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, Params(), &pindex)) {
104+
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, &pindex)) {
105105
return false;
106106
}
107107
}
@@ -178,7 +178,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
178178
uint256 chainA_last_header = last_header;
179179
for (size_t i = 0; i < 2; i++) {
180180
const auto& block = chainA[i];
181-
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
181+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr));
182182
}
183183
for (size_t i = 0; i < 2; i++) {
184184
const auto& block = chainA[i];
@@ -196,7 +196,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
196196
uint256 chainB_last_header = last_header;
197197
for (size_t i = 0; i < 3; i++) {
198198
const auto& block = chainB[i];
199-
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
199+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr));
200200
}
201201
for (size_t i = 0; i < 3; i++) {
202202
const auto& block = chainB[i];
@@ -227,7 +227,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
227227
// Reorg back to chain A.
228228
for (size_t i = 2; i < 4; i++) {
229229
const auto& block = chainA[i];
230-
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
230+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr));
231231
}
232232

233233
// Check that chain A and B blocks can be retrieved.

src/test/fuzz/utxo_snapshot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ FUZZ_TARGET_INIT(utxo_snapshot, initialize_chain)
5858
if (fuzzed_data_provider.ConsumeBool()) {
5959
for (const auto& block : *g_chain) {
6060
BlockValidationState dummy;
61-
bool processed{chainman.ProcessNewBlockHeaders({*block}, dummy, ::Params())};
61+
bool processed{chainman.ProcessNewBlockHeaders({*block}, dummy)};
6262
Assert(processed);
6363
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
6464
Assert(index);

src/test/miner_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
587587
pblock->nNonce = bi.nonce;
588588
}
589589
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
590-
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
590+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(shared_pblock, true, nullptr));
591591
pblock->hashPrevBlock = pblock->GetHash();
592592
}
593593

src/test/util/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
6868
assert(block->nNonce);
6969
}
7070

71-
bool processed{Assert(node.chainman)->ProcessNewBlock(Params(), block, true, nullptr)};
71+
bool processed{Assert(node.chainman)->ProcessNewBlock(block, true, nullptr)};
7272
assert(processed);
7373

7474
return CTxIn{block->vtx[0]->GetHash(), 0};

src/test/util/setup_common.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,9 @@ CBlock TestChain100Setup::CreateAndProcessBlock(
300300
chainstate = &Assert(m_node.chainman)->ActiveChainstate();
301301
}
302302

303-
const CChainParams& chainparams = Params();
304303
const CBlock block = this->CreateBlock(txns, scriptPubKey, *chainstate);
305304
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
306-
Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
305+
Assert(m_node.chainman)->ProcessNewBlock(shared_pblock, true, nullptr);
307306

308307
return block;
309308
}

src/test/validation_block_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock>
100100
// submit block header, so that miner can get the block height from the
101101
// global state and the node has the topology of the chain
102102
BlockValidationState ignored;
103-
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, ignored, Params()));
103+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, ignored));
104104

105105
return pblock;
106106
}
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
157157

158158
bool ignored;
159159
// Connect the genesis block and drain any outstanding events
160-
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
160+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
161161
SyncWithValidationInterfaceQueue();
162162

163163
// subscribe to events (this subscriber will validate event ordering)
@@ -179,13 +179,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
179179
FastRandomContext insecure;
180180
for (int i = 0; i < 1000; i++) {
181181
auto block = blocks[insecure.randrange(blocks.size() - 1)];
182-
Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
182+
Assert(m_node.chainman)->ProcessNewBlock(block, true, &ignored);
183183
}
184184

185185
// to make sure that eventually we process the full chain - do it here
186186
for (auto block : blocks) {
187187
if (block->vtx.size() == 1) {
188-
bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
188+
bool processed = Assert(m_node.chainman)->ProcessNewBlock(block, true, &ignored);
189189
assert(processed);
190190
}
191191
}
@@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
224224
{
225225
bool ignored;
226226
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool {
227-
return Assert(m_node.chainman)->ProcessNewBlock(Params(), block, /*force_processing=*/true, /*new_block=*/&ignored);
227+
return Assert(m_node.chainman)->ProcessNewBlock(block, /*force_processing=*/true, /*new_block=*/&ignored);
228228
};
229229

230230
// Process all mined blocks

src/validation.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,13 +3576,13 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
35763576
return true;
35773577
}
35783578

3579-
bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex)
3579+
bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationState& state, CBlockIndex** ppindex)
35803580
{
35813581
AssertLockHeld(cs_main);
35823582
// Check for duplicate
35833583
uint256 hash = block.GetHash();
35843584
BlockMap::iterator miSelf{m_blockman.m_block_index.find(hash)};
3585-
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
3585+
if (hash != GetConsensus().hashGenesisBlock) {
35863586
if (miSelf != m_blockman.m_block_index.end()) {
35873587
// Block header is already known.
35883588
CBlockIndex* pindex = &(miSelf->second);
@@ -3595,7 +3595,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
35953595
return true;
35963596
}
35973597

3598-
if (!CheckBlockHeader(block, state, chainparams.GetConsensus())) {
3598+
if (!CheckBlockHeader(block, state, GetConsensus())) {
35993599
LogPrint(BCLog::VALIDATION, "%s: Consensus::CheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
36003600
return false;
36013601
}
@@ -3612,7 +3612,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
36123612
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
36133613
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
36143614
}
3615-
if (!ContextualCheckBlockHeader(block, state, m_blockman, chainparams, pindexPrev, GetAdjustedTime())) {
3615+
if (!ContextualCheckBlockHeader(block, state, m_blockman, GetParams(), pindexPrev, GetAdjustedTime())) {
36163616
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
36173617
return false;
36183618
}
@@ -3665,14 +3665,14 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
36653665
}
36663666

36673667
// Exposed wrapper for AcceptBlockHeader
3668-
bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex)
3668+
bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValidationState& state, const CBlockIndex** ppindex)
36693669
{
36703670
AssertLockNotHeld(cs_main);
36713671
{
36723672
LOCK(cs_main);
36733673
for (const CBlockHeader& header : headers) {
36743674
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
3675-
bool accepted{AcceptBlockHeader(header, state, chainparams, &pindex)};
3675+
bool accepted{AcceptBlockHeader(header, state, &pindex)};
36763676
ActiveChainstate().CheckBlockIndex();
36773677

36783678
if (!accepted) {
@@ -3686,7 +3686,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
36863686
if (NotifyHeaderTip(ActiveChainstate())) {
36873687
if (ActiveChainstate().IsInitialBlockDownload() && ppindex && *ppindex) {
36883688
const CBlockIndex& last_accepted{**ppindex};
3689-
const int64_t blocks_left{(GetTime() - last_accepted.GetBlockTime()) / chainparams.GetConsensus().nPowTargetSpacing};
3689+
const int64_t blocks_left{(GetTime() - last_accepted.GetBlockTime()) / GetConsensus().nPowTargetSpacing};
36903690
const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)};
36913691
LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
36923692
}
@@ -3705,7 +3705,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
37053705
CBlockIndex *pindexDummy = nullptr;
37063706
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;
37073707

3708-
bool accepted_header{m_chainman.AcceptBlockHeader(block, state, m_params, &pindex)};
3708+
bool accepted_header{m_chainman.AcceptBlockHeader(block, state, &pindex)};
37093709
CheckBlockIndex();
37103710

37113711
if (!accepted_header)
@@ -3778,7 +3778,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
37783778
return true;
37793779
}
37803780

3781-
bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block)
3781+
bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block)
37823782
{
37833783
AssertLockNotHeld(cs_main);
37843784

@@ -3796,7 +3796,7 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
37963796
// malleability that cause CheckBlock() to fail; see e.g. CVE-2012-2459 and
37973797
// https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-February/016697.html. Because CheckBlock() is
37983798
// not very expensive, the anti-DoS benefits of caching failure (of a definitely-invalid block) are not substantial.
3799-
bool ret = CheckBlock(*block, state, chainparams.GetConsensus());
3799+
bool ret = CheckBlock(*block, state, GetConsensus());
38003800
if (ret) {
38013801
// Store to disk
38023802
ret = ActiveChainstate().AcceptBlock(block, state, &pindex, force_processing, nullptr, new_block);

0 commit comments

Comments
 (0)