Skip to content

Commit 88e6408

Browse files
authored
Merge pull request #755 from peercoin/develop
release 0.14.2
2 parents 50199a6 + 89823cc commit 88e6408

29 files changed

+243
-259
lines changed

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ define(_CLIENT_VERSION_IS_RELEASE, true)
77
define(_COPYRIGHT_YEAR, 2024)
88
define(_PEERCOIN_VERSION_MAJOR, 0)
99
define(_PEERCOIN_VERSION_MINOR, 14)
10-
define(_PEERCOIN_VERSION_REVISION, 1)
10+
define(_PEERCOIN_VERSION_REVISION, 2)
1111
define(_PEERCOIN_VERSION_BUILD, 0)
1212
define(_PEERCOIN_VERSION_RC, 0)
1313
define(_COPYRIGHT_HOLDERS,[The %s developers])
@@ -478,6 +478,7 @@ if test "$CXXFLAGS_overridden" = "no"; then
478478
dnl set the -Wno-foo case if it works.
479479
AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"], [], [$CXXFLAG_WERROR])
480480
AX_CHECK_COMPILE_FLAG([-Wself-assign], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"], [], [$CXXFLAG_WERROR])
481+
AX_CHECK_COMPILE_FLAG([-Wsuggest-override], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-suggest-override"], [], [$CXXFLAG_WERROR])
481482
if test "$suppress_external_warnings" != "yes" ; then
482483
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"], [], [$CXXFLAG_WERROR])
483484
fi

src/headerssync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static_assert(sizeof(CompressedHeader) == 52);
2525
HeadersSyncState::HeadersSyncState(NodeId id, const Consensus::Params& consensus_params,
2626
const CBlockIndex* chain_start, const arith_uint256& minimum_required_work) :
2727
m_commit_offset(GetRand<unsigned>(HEADER_COMMITMENT_PERIOD)),
28-
m_id(id), m_consensus_params(consensus_params),
28+
m_id(id),
2929
m_chain_start(chain_start),
3030
m_minimum_required_work(minimum_required_work),
3131
m_current_chain_work(chain_start->nChainTrust),

src/headerssync.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ class HeadersSyncState {
214214
/** NodeId of the peer (used for log messages) **/
215215
const NodeId m_id;
216216

217-
/** We use the consensus params in our anti-DoS calculations */
218-
const Consensus::Params& m_consensus_params;
219-
220217
/** Store the last block in our block index that the peer's chain builds from */
221218
const CBlockIndex* m_chain_start{nullptr};
222219

src/init.cpp

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,78 +1506,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15061506
};
15071507

15081508
uiInterface.InitMessage(_("Loading block index…").translated);
1509-
/*
1510-
const int64_t load_block_index_start_time = GetTimeMillis();
1511-
std::optional<ChainstateLoadingError> maybe_load_error;
1512-
try {
1513-
maybe_load_error = LoadChainstate(fReset,
1514-
chainman,
1515-
Assert(node.mempool.get()),
1516-
chainparams.GetConsensus(),
1517-
fReindexChainState,
1518-
cache_sizes.block_tree_db,
1519-
cache_sizes.coins_db,
1520-
cache_sizes.coins,
1521-
/*block_tree_db_in_memory=false,
1522-
/*coins_db_in_memory=false,
1523-
/*shutdown_requested=ShutdownRequested,
1524-
/*coins_error_cb=[]() {
1525-
uiInterface.ThreadSafeMessageBox(
1526-
_("Error reading from database, shutting down."),
1527-
"", CClientUIInterface::MSG_ERROR);
1528-
});
1529-
} catch (const std::exception& e) {
1530-
LogPrintf("%s\n", e.what());
1531-
maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
1532-
}
1533-
if (maybe_load_error.has_value()) {
1534-
switch (maybe_load_error.value()) {
1535-
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
1536-
strLoadError = _("Error loading block database");
1537-
break;
1538-
case ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK:
1539-
// If the loaded chain has a wrong genesis, bail out immediately
1540-
// (we're likely using a testnet datadir, or the other way around).
1541-
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
1542-
case ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED:
1543-
strLoadError = _("Error initializing block database");
1544-
break;
1545-
case ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED:
1546-
return InitError(_("Unsupported chainstate database format found. "
1547-
"Please restart with -reindex-chainstate. This will "
1548-
"rebuild the chainstate database."));
1549-
case ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED:
1550-
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
1551-
break;
1552-
case ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED:
1553-
strLoadError = _("Error initializing block database");
1554-
break;
1555-
case ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED:
1556-
strLoadError = _("Error opening block database");
1557-
break;
1558-
case ChainstateLoadingError::ERROR_BLOCKS_WITNESS_INSUFFICIENTLY_VALIDATED:
1559-
strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
1560-
chainman.GetConsensus().SegwitHeight);
1561-
break;
1562-
case ChainstateLoadingError::SHUTDOWN_PROBED:
1563-
break;
1564-
}
1565-
} else {
1566-
std::optional<ChainstateLoadVerifyError> maybe_verify_error;
1567-
try {
1568-
uiInterface.InitMessage(_("Verifying blocks…").translated);
1569-
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
1570-
maybe_verify_error = VerifyLoadedChainstate(chainman,
1571-
fReset,
1572-
fReindexChainState,
1573-
check_blocks,
1574-
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL));
1575-
} catch (const std::exception& e) {
1576-
LogPrintf("%s\n", e.what());
1577-
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
1578-
}
1579-
};
1580-
*/
15811509
const auto load_block_index_start_time{SteadyClock::now()};
15821510
auto catch_exceptions = [](auto&& f) {
15831511
try {

src/kernel.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static bool SelectBlockFromCandidates(
219219
const CBlockIndex** pindexSelected,
220220
Chainstate& chainstate)
221221
{
222+
LOCK(cs_main);
222223
bool fSelected = false;
223224
arith_uint256 hashBest = 0;
224225
*pindexSelected = (const CBlockIndex*) 0;
@@ -452,7 +453,12 @@ static bool GetKernelStakeModifierV03(CBlockIndex* pindexPrev, uint256 hashBlock
452453
const Consensus::Params& params = Params().GetConsensus();
453454
nStakeModifier = 0;
454455

455-
const CBlockIndex* pindexFrom = chainstate.m_blockman.LookupBlockIndex(hashBlockFrom);
456+
const CBlockIndex* pindexFrom;
457+
{
458+
LOCK(cs_main);
459+
pindexFrom = chainstate.m_blockman.LookupBlockIndex(hashBlockFrom);
460+
}
461+
456462
if (!pindexFrom)
457463
return error("GetKernelStakeModifier() : block not indexed");
458464

@@ -576,6 +582,7 @@ bool CheckStakeKernelHash(unsigned int nBits, CBlockIndex* pindexPrev, const CBl
576582
if (fPrintProofOfStake)
577583
{
578584
if (IsProtocolV03(nTimeTx)) {
585+
LOCK(cs_main);
579586
const CBlockIndex* pindexTmp = chainstate.m_blockman.LookupBlockIndex(blockFrom.GetHash());
580587
LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
581588
nStakeModifier, nStakeModifierHeight,
@@ -596,6 +603,7 @@ bool CheckStakeKernelHash(unsigned int nBits, CBlockIndex* pindexPrev, const CBl
596603
if (gArgs.GetBoolArg("-debug", false) && !fPrintProofOfStake)
597604
{
598605
if (IsProtocolV03(nTimeTx)) {
606+
LOCK(cs_main);
599607
const CBlockIndex* pindexTmp = chainstate.m_blockman.LookupBlockIndex(blockFrom.GetHash());
600608
LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
601609
nStakeModifier, nStakeModifierHeight,

src/net_processing.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ static constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500;
164164
* lower bound, and it should be larger to account for higher inv rate to outbound
165165
* peers, and random variations in the broadcast mechanism. */
166166
static_assert(INVENTORY_MAX_RECENT_RELAY >= INVENTORY_BROADCAST_PER_SECOND * UNCONDITIONAL_RELAY_DELAY / std::chrono::seconds{1}, "INVENTORY_RELAY_MAX too low");
167-
/** Average delay between feefilter broadcasts in seconds. */
168-
static constexpr auto AVG_FEEFILTER_BROADCAST_INTERVAL{10min};
169-
/** Maximum feefilter broadcast delay after significant change. */
170-
static constexpr auto MAX_FEEFILTER_CHANGE_DELAY{5min};
171167
/** Maximum number of compact filters that may be requested with one getcfilters. See BIP 157. */
172168
static constexpr uint32_t MAX_GETCFILTERS_SIZE = 1000;
173169
/** Maximum number of cf hashes that may be requested with one getcfheaders. See BIP 157. */
@@ -705,12 +701,6 @@ class PeerManagerImpl final : public PeerManager
705701
*/
706702
void RelayAddress(NodeId originator, const CAddress& addr, bool fReachable) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);
707703

708-
/** Send `feefilter` message. */
709-
// void MaybeSendFeefilter(CNode& node, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
710-
711-
/** Send `feefilter` message. */
712-
void MaybeSendFeefilter(CNode& node, Peer& peer, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
713-
714704
const CChainParams& m_chainparams;
715705
CConnman& m_connman;
716706
AddrMan& m_addrman;
@@ -4227,32 +4217,34 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42274217

42284218
bool received_new_header = false;
42294219
const auto blockhash = cmpctblock.header.GetHash();
4230-
4220+
CBlockIndex* tip;
42314221
{
4232-
LOCK(cs_main);
4222+
LOCK(cs_main);
4223+
4224+
tip = m_chainman.ActiveChain().Tip();
42334225

4234-
const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock);
4235-
if (!prev_block) {
4236-
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
4237-
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
4238-
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
4226+
const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock);
4227+
if (!prev_block) {
4228+
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
4229+
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
4230+
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
4231+
}
4232+
return;
4233+
} else if (prev_block->nChainTrust + CalculateHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
4234+
// If we get a low-work header in a compact block, we can ignore it.
4235+
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
4236+
return;
42394237
}
4240-
return;
4241-
} else if (prev_block->nChainTrust + CalculateHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
4242-
// If we get a low-work header in a compact block, we can ignore it.
4243-
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
4244-
return;
4245-
}
42464238

4247-
if (!m_chainman.m_blockman.LookupBlockIndex(blockhash)) {
4248-
received_new_header = true;
4249-
}
4239+
if (!m_chainman.m_blockman.LookupBlockIndex(blockhash)) {
4240+
received_new_header = true;
4241+
}
42504242
}
42514243

42524244
int32_t& nPoSTemperature = mapPoSTemperature[pfrom.addr];
42534245
const CBlockIndex *pindex = nullptr;
42544246
BlockValidationState state;
4255-
if (!m_chainman.ProcessNewBlockHeaders(nPoSTemperature, m_chainman.ActiveChain().Tip()->GetBlockHash(), {cmpctblock.header}, /*min_pow_checked=*/true, state, m_chainparams, &pindex)) {
4247+
if (!m_chainman.ProcessNewBlockHeaders(nPoSTemperature, tip->GetBlockHash(), {cmpctblock.header}, /*min_pow_checked=*/true, state, m_chainparams, &pindex)) {
42564248
if (state.IsInvalid()) {
42574249
MaybePunishNodeForBlock(pfrom.GetId(), state, /*via_compact_block=*/true, "invalid header via cmpctblock");
42584250
return;
@@ -4293,7 +4285,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42934285

42944286
// If this was a new header with more work than our tip, update the
42954287
// peer's last block announcement time
4296-
if (received_new_header && pindex->nChainTrust > m_chainman.ActiveChain().Tip()->nChainTrust) {
4288+
if (received_new_header && pindex->nChainTrust > tip->nChainTrust) {
42974289
nodestate->m_last_block_announcement = GetTime();
42984290
}
42994291

@@ -4303,7 +4295,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
43034295
if (pindex->nStatus & BLOCK_HAVE_DATA) // Nothing to do here
43044296
return;
43054297

4306-
if (pindex->nChainTrust <= m_chainman.ActiveChain().Tip()->nChainTrust || // We know something better
4298+
if (pindex->nChainTrust <= tip->nChainTrust || // We know something better
43074299
pindex->nTx != 0) { // We had this block at some point
43084300
if (fAlreadyInFlight) {
43094301
// We requested this block for some reason, but our mempool will probably be useless
@@ -4605,6 +4597,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46054597

46064598
LogPrint(BCLog::NET, "received block %s peer=%d\n", pblock2->GetHash().ToString(), pfrom.GetId());
46074599

4600+
CBlockIndex* tip;
46084601
{
46094602
const uint256 hash2(pblock2->GetHash());
46104603
LOCK(cs_main);
@@ -4638,11 +4631,12 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46384631
// peercoin: store in memory until we can connect it to some chain
46394632
WaitElement we; we.pblock = pblock2; we.time = nTimeNow;
46404633
mapBlocksWait[headerPrev] = we;
4634+
tip = m_chainman.ActiveChain().Tip();
46414635
}
46424636

46434637
static CBlockIndex* pindexLastAccepted = nullptr;
46444638
if (pindexLastAccepted == nullptr)
4645-
pindexLastAccepted = m_chainman.ActiveChain().Tip();
4639+
pindexLastAccepted = tip;
46464640
bool fContinue = true;
46474641

46484642
// peercoin: accept as many blocks as we possibly can from mapBlocksWait

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
460460

461461
if (!fKnown) {
462462
bool out_of_space;
463-
size_t bytes_allocated = BlockFileSeq().Allocate(pos, nAddSize, out_of_space);
463+
BlockFileSeq().Allocate(pos, nAddSize, out_of_space);
464464
if (out_of_space) {
465465
return AbortNode("Disk space is too low!", _("Disk space is too low!"));
466466
}
@@ -481,7 +481,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
481481
m_dirty_fileinfo.insert(nFile);
482482

483483
bool out_of_space;
484-
size_t bytes_allocated = UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
484+
UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
485485
if (out_of_space) {
486486
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
487487
}

src/node/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class NodeImpl : public Node
383383
m_context = context;
384384
}
385385
ArgsManager& args() { return *Assert(Assert(m_context)->args); }
386-
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
386+
ChainstateManager& chainman() override { return *Assert(m_context->chainman); }
387387
NodeContext* m_context{nullptr};
388388
};
389389

@@ -776,7 +776,7 @@ class ChainImpl : public Chain
776776

777777
NodeContext* context() override { return &m_node; }
778778
ArgsManager& args() { return *Assert(m_node.args); }
779-
ChainstateManager& chainman() { return *Assert(m_node.chainman); }
779+
ChainstateManager& chainman() override { return *Assert(m_node.chainman); }
780780
NodeContext& m_node;
781781
};
782782
} // namespace

src/node/miner.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,26 +589,31 @@ void PoSMiner(NodeContext& m_node)
589589
return;
590590
}
591591

592-
//if (Params().MiningRequiresPeers()) {
592+
if (Params().MiningRequiresPeers()) {
593593
// Busy-wait for the network to come online so we don't waste time mining
594594
// on an obsolete chain. In regtest mode we expect to fly solo.
595595
while(connman == nullptr || connman->GetNodeCount(ConnectionDirection::Both) == 0 || m_node.chainman->ActiveChainstate().IsInitialBlockDownload()) {
596596
while(connman == nullptr) {UninterruptibleSleep(1s);}
597597
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
598598
return;
599599
}
600-
//}
601-
602-
while (GuessVerificationProgress(Params().TxData(), m_node.chainman->ActiveChain().Tip()) < 0.996)
600+
}
601+
CBlockIndex* pindexPrev;
603602
{
604-
LogPrintf("Minter thread sleeps while sync at %f\n", GuessVerificationProgress(Params().TxData(), m_node.chainman->ActiveChain().Tip()));
605-
if (strMintWarning != strMintSyncMessage) {
606-
strMintWarning = strMintSyncMessage;
607-
uiInterface.NotifyAlertChanged();
603+
LOCK(cs_main);
604+
pindexPrev = m_node.chainman->ActiveChain().Tip();
605+
606+
while (GuessVerificationProgress(Params().TxData(), pindexPrev) < 0.996)
607+
{
608+
LogPrintf("Minter thread sleeps while sync at %f\n", GuessVerificationProgress(Params().TxData(), pindexPrev));
609+
if (strMintWarning != strMintSyncMessage) {
610+
strMintWarning = strMintSyncMessage;
611+
uiInterface.NotifyAlertChanged();
612+
}
613+
fNeedToClear = true;
614+
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
615+
return;
608616
}
609-
fNeedToClear = true;
610-
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
611-
return;
612617
}
613618
if (fNeedToClear) {
614619
strMintWarning = strMintEmpty;
@@ -619,7 +624,6 @@ void PoSMiner(NodeContext& m_node)
619624
//
620625
// Create new block
621626
//
622-
CBlockIndex* pindexPrev = m_node.chainman->ActiveChain().Tip();
623627
bool fPoSCancel = false;
624628
CScript scriptPubKey = GetScriptForDestination(dest);
625629
CBlock *pblock;

src/policy/policy.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
102102
else if ((whichType == TxoutType::MULTISIG) && (!permit_bare_multisig)) {
103103
reason = "bare-multisig";
104104
return false;
105-
} else if (IsDust(txout)) {
106-
reason = "dust";
107-
return false;
108105
}
109106
}
110107

0 commit comments

Comments
 (0)