Skip to content

Commit

Permalink
Merge pull request #755 from peercoin/develop
Browse files Browse the repository at this point in the history
release 0.14.2
  • Loading branch information
backpacker69 committed May 7, 2024
2 parents 50199a6 + 89823cc commit 88e6408
Show file tree
Hide file tree
Showing 29 changed files with 243 additions and 259 deletions.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2024)
define(_PEERCOIN_VERSION_MAJOR, 0)
define(_PEERCOIN_VERSION_MINOR, 14)
define(_PEERCOIN_VERSION_REVISION, 1)
define(_PEERCOIN_VERSION_REVISION, 2)
define(_PEERCOIN_VERSION_BUILD, 0)
define(_PEERCOIN_VERSION_RC, 0)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down Expand Up @@ -478,6 +478,7 @@ if test "$CXXFLAGS_overridden" = "no"; then
dnl set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wself-assign], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wsuggest-override], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-suggest-override"], [], [$CXXFLAG_WERROR])
if test "$suppress_external_warnings" != "yes" ; then
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"], [], [$CXXFLAG_WERROR])
fi
Expand Down
2 changes: 1 addition & 1 deletion src/headerssync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static_assert(sizeof(CompressedHeader) == 52);
HeadersSyncState::HeadersSyncState(NodeId id, const Consensus::Params& consensus_params,
const CBlockIndex* chain_start, const arith_uint256& minimum_required_work) :
m_commit_offset(GetRand<unsigned>(HEADER_COMMITMENT_PERIOD)),
m_id(id), m_consensus_params(consensus_params),
m_id(id),
m_chain_start(chain_start),
m_minimum_required_work(minimum_required_work),
m_current_chain_work(chain_start->nChainTrust),
Expand Down
3 changes: 0 additions & 3 deletions src/headerssync.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ class HeadersSyncState {
/** NodeId of the peer (used for log messages) **/
const NodeId m_id;

/** We use the consensus params in our anti-DoS calculations */
const Consensus::Params& m_consensus_params;

/** Store the last block in our block index that the peer's chain builds from */
const CBlockIndex* m_chain_start{nullptr};

Expand Down
72 changes: 0 additions & 72 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,78 +1506,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
};

uiInterface.InitMessage(_("Loading block index…").translated);
/*
const int64_t load_block_index_start_time = GetTimeMillis();
std::optional<ChainstateLoadingError> maybe_load_error;
try {
maybe_load_error = LoadChainstate(fReset,
chainman,
Assert(node.mempool.get()),
chainparams.GetConsensus(),
fReindexChainState,
cache_sizes.block_tree_db,
cache_sizes.coins_db,
cache_sizes.coins,
/*block_tree_db_in_memory=false,
/*coins_db_in_memory=false,
/*shutdown_requested=ShutdownRequested,
/*coins_error_cb=[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
}
if (maybe_load_error.has_value()) {
switch (maybe_load_error.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
strLoadError = _("Error loading block database");
break;
case ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK:
// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
case ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED:
strLoadError = _("Error initializing block database");
break;
case ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED:
return InitError(_("Unsupported chainstate database format found. "
"Please restart with -reindex-chainstate. This will "
"rebuild the chainstate database."));
case ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED:
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
break;
case ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED:
strLoadError = _("Error initializing block database");
break;
case ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED:
strLoadError = _("Error opening block database");
break;
case ChainstateLoadingError::ERROR_BLOCKS_WITNESS_INSUFFICIENTLY_VALIDATED:
strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
chainman.GetConsensus().SegwitHeight);
break;
case ChainstateLoadingError::SHUTDOWN_PROBED:
break;
}
} else {
std::optional<ChainstateLoadVerifyError> maybe_verify_error;
try {
uiInterface.InitMessage(_("Verifying blocks…").translated);
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
maybe_verify_error = VerifyLoadedChainstate(chainman,
fReset,
fReindexChainState,
check_blocks,
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL));
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
}
};
*/
const auto load_block_index_start_time{SteadyClock::now()};
auto catch_exceptions = [](auto&& f) {
try {
Expand Down
10 changes: 9 additions & 1 deletion src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static bool SelectBlockFromCandidates(
const CBlockIndex** pindexSelected,
Chainstate& chainstate)
{
LOCK(cs_main);
bool fSelected = false;
arith_uint256 hashBest = 0;
*pindexSelected = (const CBlockIndex*) 0;
Expand Down Expand Up @@ -452,7 +453,12 @@ static bool GetKernelStakeModifierV03(CBlockIndex* pindexPrev, uint256 hashBlock
const Consensus::Params& params = Params().GetConsensus();
nStakeModifier = 0;

const CBlockIndex* pindexFrom = chainstate.m_blockman.LookupBlockIndex(hashBlockFrom);
const CBlockIndex* pindexFrom;
{
LOCK(cs_main);
pindexFrom = chainstate.m_blockman.LookupBlockIndex(hashBlockFrom);
}

if (!pindexFrom)
return error("GetKernelStakeModifier() : block not indexed");

Expand Down Expand Up @@ -576,6 +582,7 @@ bool CheckStakeKernelHash(unsigned int nBits, CBlockIndex* pindexPrev, const CBl
if (fPrintProofOfStake)
{
if (IsProtocolV03(nTimeTx)) {
LOCK(cs_main);
const CBlockIndex* pindexTmp = chainstate.m_blockman.LookupBlockIndex(blockFrom.GetHash());
LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
nStakeModifier, nStakeModifierHeight,
Expand All @@ -596,6 +603,7 @@ bool CheckStakeKernelHash(unsigned int nBits, CBlockIndex* pindexPrev, const CBl
if (gArgs.GetBoolArg("-debug", false) && !fPrintProofOfStake)
{
if (IsProtocolV03(nTimeTx)) {
LOCK(cs_main);
const CBlockIndex* pindexTmp = chainstate.m_blockman.LookupBlockIndex(blockFrom.GetHash());
LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
nStakeModifier, nStakeModifierHeight,
Expand Down
54 changes: 24 additions & 30 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ static constexpr unsigned int INVENTORY_MAX_RECENT_RELAY = 3500;
* lower bound, and it should be larger to account for higher inv rate to outbound
* peers, and random variations in the broadcast mechanism. */
static_assert(INVENTORY_MAX_RECENT_RELAY >= INVENTORY_BROADCAST_PER_SECOND * UNCONDITIONAL_RELAY_DELAY / std::chrono::seconds{1}, "INVENTORY_RELAY_MAX too low");
/** Average delay between feefilter broadcasts in seconds. */
static constexpr auto AVG_FEEFILTER_BROADCAST_INTERVAL{10min};
/** Maximum feefilter broadcast delay after significant change. */
static constexpr auto MAX_FEEFILTER_CHANGE_DELAY{5min};
/** Maximum number of compact filters that may be requested with one getcfilters. See BIP 157. */
static constexpr uint32_t MAX_GETCFILTERS_SIZE = 1000;
/** Maximum number of cf hashes that may be requested with one getcfheaders. See BIP 157. */
Expand Down Expand Up @@ -705,12 +701,6 @@ class PeerManagerImpl final : public PeerManager
*/
void RelayAddress(NodeId originator, const CAddress& addr, bool fReachable) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);

/** Send `feefilter` message. */
// void MaybeSendFeefilter(CNode& node, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/** Send `feefilter` message. */
void MaybeSendFeefilter(CNode& node, Peer& peer, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);

const CChainParams& m_chainparams;
CConnman& m_connman;
AddrMan& m_addrman;
Expand Down Expand Up @@ -4227,32 +4217,34 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,

bool received_new_header = false;
const auto blockhash = cmpctblock.header.GetHash();

CBlockIndex* tip;
{
LOCK(cs_main);
LOCK(cs_main);

tip = m_chainman.ActiveChain().Tip();

const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock);
if (!prev_block) {
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock);
if (!prev_block) {
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
}
return;
} else if (prev_block->nChainTrust + CalculateHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
// If we get a low-work header in a compact block, we can ignore it.
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
return;
}
return;
} else if (prev_block->nChainTrust + CalculateHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
// If we get a low-work header in a compact block, we can ignore it.
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
return;
}

if (!m_chainman.m_blockman.LookupBlockIndex(blockhash)) {
received_new_header = true;
}
if (!m_chainman.m_blockman.LookupBlockIndex(blockhash)) {
received_new_header = true;
}
}

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

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

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

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

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

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

static CBlockIndex* pindexLastAccepted = nullptr;
if (pindexLastAccepted == nullptr)
pindexLastAccepted = m_chainman.ActiveChain().Tip();
pindexLastAccepted = tip;
bool fContinue = true;

// peercoin: accept as many blocks as we possibly can from mapBlocksWait
Expand Down
4 changes: 2 additions & 2 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne

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

bool out_of_space;
size_t bytes_allocated = UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
if (out_of_space) {
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class NodeImpl : public Node
m_context = context;
}
ArgsManager& args() { return *Assert(Assert(m_context)->args); }
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
ChainstateManager& chainman() override { return *Assert(m_context->chainman); }
NodeContext* m_context{nullptr};
};

Expand Down Expand Up @@ -776,7 +776,7 @@ class ChainImpl : public Chain

NodeContext* context() override { return &m_node; }
ArgsManager& args() { return *Assert(m_node.args); }
ChainstateManager& chainman() { return *Assert(m_node.chainman); }
ChainstateManager& chainman() override { return *Assert(m_node.chainman); }
NodeContext& m_node;
};
} // namespace
Expand Down
28 changes: 16 additions & 12 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,26 +589,31 @@ void PoSMiner(NodeContext& m_node)
return;
}

//if (Params().MiningRequiresPeers()) {
if (Params().MiningRequiresPeers()) {
// Busy-wait for the network to come online so we don't waste time mining
// on an obsolete chain. In regtest mode we expect to fly solo.
while(connman == nullptr || connman->GetNodeCount(ConnectionDirection::Both) == 0 || m_node.chainman->ActiveChainstate().IsInitialBlockDownload()) {
while(connman == nullptr) {UninterruptibleSleep(1s);}
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
return;
}
//}

while (GuessVerificationProgress(Params().TxData(), m_node.chainman->ActiveChain().Tip()) < 0.996)
}
CBlockIndex* pindexPrev;
{
LogPrintf("Minter thread sleeps while sync at %f\n", GuessVerificationProgress(Params().TxData(), m_node.chainman->ActiveChain().Tip()));
if (strMintWarning != strMintSyncMessage) {
strMintWarning = strMintSyncMessage;
uiInterface.NotifyAlertChanged();
LOCK(cs_main);
pindexPrev = m_node.chainman->ActiveChain().Tip();

while (GuessVerificationProgress(Params().TxData(), pindexPrev) < 0.996)
{
LogPrintf("Minter thread sleeps while sync at %f\n", GuessVerificationProgress(Params().TxData(), pindexPrev));
if (strMintWarning != strMintSyncMessage) {
strMintWarning = strMintSyncMessage;
uiInterface.NotifyAlertChanged();
}
fNeedToClear = true;
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
return;
}
fNeedToClear = true;
if (!connman->interruptNet.sleep_for(std::chrono::seconds(10)))
return;
}
if (fNeedToClear) {
strMintWarning = strMintEmpty;
Expand All @@ -619,7 +624,6 @@ void PoSMiner(NodeContext& m_node)
//
// Create new block
//
CBlockIndex* pindexPrev = m_node.chainman->ActiveChain().Tip();
bool fPoSCancel = false;
CScript scriptPubKey = GetScriptForDestination(dest);
CBlock *pblock;
Expand Down
3 changes: 0 additions & 3 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
else if ((whichType == TxoutType::MULTISIG) && (!permit_bare_multisig)) {
reason = "bare-multisig";
return false;
} else if (IsDust(txout)) {
reason = "dust";
return false;
}
}

Expand Down

0 comments on commit 88e6408

Please sign in to comment.