Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
backpacker69 committed Jul 5, 2020
1 parent 4737e1e commit 195b0fa
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 303 deletions.
9 changes: 4 additions & 5 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "timedata.h"
#include "ui_interface.h"
#include "util.h"
#include "utilstrencodings.h"
#include "util/strencodings.h"
#include "validation.h"

#include <stdint.h>
Expand Down Expand Up @@ -125,7 +125,7 @@ bool CAlert::AppliesToMe() const
return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, PEERCOIN_VERSION, std::vector<std::string>()));
}

bool CAlert::RelayTo(CNode* pnode) const
bool CAlert::RelayTo(CNode* pnode, CConnman* connman) const
{
if (!IsInEffect())
return false;
Expand All @@ -135,12 +135,11 @@ bool CAlert::RelayTo(CNode* pnode) const
// returns true if wasn't already contained in the set
if (pnode->setKnown.insert(GetHash()).second)
{
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
if (AppliesTo(pnode->nVersion, pnode->cleanSubVer) ||
AppliesToMe() ||
GetAdjustedTime() < nRelayUntil)
{
if (g_connman)
g_connman->PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::ALERT, *this));
connman->PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::ALERT, *this));
return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "serialize.h"
#include "sync.h"
#include <net.h>

#include <map>
#include <set>
Expand Down Expand Up @@ -98,7 +99,7 @@ class CAlert : public CUnsignedAlert
bool Cancels(const CAlert& alert) const;
bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool RelayTo(CNode* pnode, CConnman* connman) const;
bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
bool ProcessAlert(const std::vector<unsigned char>& alertKey);

Expand Down
8 changes: 8 additions & 0 deletions src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex*
assert(pa == pb);
return pa;
}

// peercoin: find last block index up to pindex
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake)
{
while (pindex && pindex->pprev && (pindex->IsProofOfStake() != fProofOfStake))
pindex = pindex->pprev;
return pindex;
}
28 changes: 12 additions & 16 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <tinyformat.h>
#include <uint256.h>

#include <utilmoneystr.h>
#include <util/moneystr.h>

#include <vector>

Expand Down Expand Up @@ -206,7 +206,7 @@ class CBlockIndex
unsigned int nStakeModifierChecksum{0}; // checksum of index; in-memeory only
COutPoint prevoutStake{};
unsigned int nStakeTime{0};
uint256 hashProofOfStake{0};
uint256 hashProofOfStake{};

bool IsProofOfWork() const
{
Expand Down Expand Up @@ -437,21 +437,15 @@ class CDiskBlockIndex : public CBlockIndex
if (obj.nStatus & BLOCK_HAVE_DATA) READWRITE(VARINT(obj.nDataPos));
if (obj.nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(obj.nUndoPos));

READWRITE(nMint);
READWRITE(nMoneySupply);
READWRITE(nFlags);
READWRITE(nStakeModifier);
if (IsProofOfStake())
READWRITE(obj.nMint);
READWRITE(obj.nMoneySupply);
READWRITE(obj.nFlags);
READWRITE(obj.nStakeModifier);
if (s.GetType() & SER_POSMARKER)
{
READWRITE(prevoutStake);
READWRITE(nStakeTime);
READWRITE(hashProofOfStake);
}
else if (ser_action.ForRead())
{
const_cast<CDiskBlockIndex*>(this)->prevoutStake.SetNull();
const_cast<CDiskBlockIndex*>(this)->nStakeTime = 0;
const_cast<CDiskBlockIndex*>(this)->hashProofOfStake = uint256();
READWRITE(obj.prevoutStake);
READWRITE(obj.nStakeTime);
READWRITE(obj.hashProofOfStake);
}

// block header
Expand Down Expand Up @@ -547,4 +541,6 @@ class CChain {
CBlockIndex* FindEarliestAtLeast(int64_t nTime, int height) const;
};

const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake);

#endif // BITCOIN_CHAIN_H
10 changes: 5 additions & 5 deletions src/checkpointsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void SetCheckpointEnforce(bool fEnforce)
gArgs.ForceSetArg("-enforcecheckpoint", fEnforce ? "1" : "0");
}

bool AcceptPendingSyncCheckpoint()
bool AcceptPendingSyncCheckpoint(CConnman* connman)
{
LOCK(cs_hashSyncCheckpoint);
if (hashPendingCheckpoint != uint256() && mapBlockIndex.count(hashPendingCheckpoint))
Expand Down Expand Up @@ -188,8 +188,8 @@ bool AcceptPendingSyncCheckpoint()
checkpointMessagePending.SetNull();
LogPrintf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString());
// relay the checkpoint
if (g_connman && !checkpointMessage.IsNull())
g_connman->ForEachNode([](CNode* pnode) {
if (!checkpointMessage.IsNull())
connman->ForEachNode([](CNode* pnode) {
checkpointMessage.RelayTo(pnode);
});
return true;
Expand Down Expand Up @@ -321,7 +321,7 @@ bool SetCheckpointPrivKey(std::string strPrivKey)
return true;
}

bool SendSyncCheckpoint(uint256 hashCheckpoint)
bool SendSyncCheckpoint(uint256 hashCheckpoint, CConnman* connman)
{
CSyncCheckpoint checkpoint;
checkpoint.hashCheckpoint = hashCheckpoint;
Expand All @@ -348,7 +348,7 @@ bool SendSyncCheckpoint(uint256 hashCheckpoint)
}

// Relay checkpoint
g_connman->ForEachNode([&checkpoint](CNode* pnode) {
connman->ForEachNode([&checkpoint](CNode* pnode) {
checkpoint.RelayTo(pnode);
});
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/checkpointsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ class CSyncCheckpoint : public CUnsignedSyncCheckpoint
return Hash(this->vchMsg.begin(), this->vchMsg.end());
}

bool RelayTo(CNode* pnode) const
bool RelayTo(CNode* pnode, CConnman* connman) const
{
// returns true if wasn't already sent
if (g_connman && pnode->hashCheckpointKnown != hashCheckpoint)
if (pnode->hashCheckpointKnown != hashCheckpoint)
{
pnode->hashCheckpointKnown = hashCheckpoint;
g_connman->PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make("checkpoint", *this));
connman->PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make("checkpoint", *this));
return true;
}
return false;
Expand Down
40 changes: 5 additions & 35 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void SetupServerArgs()
#endif
gArgs.AddArg("-assumevalid=<hex>", strprintf("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-alerts", strprintf("Receive and display P2P network alerts (default: %u)", DEFAULT_ALERTS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#if HAVE_SYSTEM
gArgs.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#endif
Expand Down Expand Up @@ -527,9 +527,8 @@ void SetupServerArgs()


gArgs.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
gArgs.AddArg("-blockmintxfee=<amt>", strprintf("Set lowest fee rate (in %s/kB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
gArgs.AddArg("-blockversion=<n>", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION);
gArgs.AddArg("-nominting", _("Disable minting of POS blocks"), false, OptionsCategory::BLOCK_CREATION);
gArgs.AddArg("-nominting", "Disable minting of POS blocks", ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);

gArgs.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
Expand Down Expand Up @@ -778,19 +777,6 @@ void InitParameterInteraction()
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
}

// Warn if network-specific options (-addnode, -connect, etc) are
// specified in default section of config file, but not overridden
// on the command line or in this network's section of the config file.
std::string network = gArgs.GetChainName();
for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) {
InitWarning(strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, network, network));
}

// Warn if unrecognized section name are present in the config file.
for (const auto& section : gArgs.GetUnrecognizedSections()) {
InitWarning(strprintf("%s:%i " + _("Section [%s] is not recognized."), section.m_file, section.m_line, section.m_name));
}
}

/**
Expand Down Expand Up @@ -912,11 +898,6 @@ bool AppInitParameterInteraction()
}
}

if (!g_enabled_filter_types.empty()) {
return InitError(_("Prune mode is incompatible with -blockfilterindex.").translated);
}
}

// -bind and -whitebind can't be set when not listening
size_t nUserBind = gArgs.GetArgs("-bind").size() + gArgs.GetArgs("-whitebind").size();
if (nUserBind != 0 && !gArgs.GetBoolArg("-listen", DEFAULT_LISTEN)) {
Expand Down Expand Up @@ -1010,17 +991,6 @@ bool AppInitParameterInteraction()
return InitError("peertimeout cannot be configured with a negative value.");
}

// Sanity check argument for min fee for including tx in block
// TODO: Harmonize which arguments need sanity checking and where that happens
if (gArgs.IsArgSet("-blockmintxfee"))
{
CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n))
return InitError(AmountErrMsg("blockmintxfee", gArgs.GetArg("-blockmintxfee", "")).translated);
}

}

fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
if (!chainparams.IsTestChain() && !fRequireStandard) {
return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
Expand Down Expand Up @@ -1083,7 +1053,7 @@ bool AppInitSanityChecks()
if (gArgs.IsArgSet("-checkpointkey")) // peercoin: checkpoint master priv key
{
if (!SetCheckpointPrivKey(gArgs.GetArg("-checkpointkey", "")))
return InitError(_("Unable to sign checkpoint, wrong checkpointkey?"));
return InitError("Unable to sign checkpoint, wrong checkpointkey?");
}
#endif

Expand Down Expand Up @@ -1753,8 +1723,8 @@ bool AppInitMain(NodeContext& node)
banman->DumpBanlist();
}, DUMP_BANS_INTERVAL);

if (gArgs.GetBoolArg("-stakegen", true))
MintStake(threadGroup);
if (GetWallets()[0] && gArgs.GetBoolArg("-stakegen", true))
MintStake(threadGroup, GetWallets()[0], node.connman.get(), node.mempool);

return true;
}
41 changes: 0 additions & 41 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include <node/coin.h>
#include <node/context.h>
#include <node/transaction.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/rbf.h>
#include <policy/settings.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
Expand Down Expand Up @@ -95,20 +93,6 @@ class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex>
}
return nullopt;
}
Optional<int> findPruned(int start_height, Optional<int> stop_height) override
{
LockAssertion lock(::cs_main);
if (::fPruneMode) {
CBlockIndex* block = stop_height ? ::ChainActive()[*stop_height] : ::ChainActive().Tip();
while (block && block->nHeight >= start_height) {
if ((block->nStatus & BLOCK_HAVE_DATA) == 0) {
return block->nHeight;
}
block = block->pprev;
}
}
return nullopt;
}
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
{
LockAssertion lock(::cs_main);
Expand Down Expand Up @@ -274,11 +258,6 @@ class ChainImpl : public Chain
LOCK(cs_main);
return GuessVerificationProgress(Params().TxData(), LookupBlockIndex(block_hash));
}
RBFTransactionState isRBFOptIn(const CTransaction& tx) override
{
LOCK(::mempool.cs);
return IsRBFOptIn(tx, ::mempool);
}
bool hasDescendantsInMempool(const uint256& txid) override
{
LOCK(::mempool.cs);
Expand Down Expand Up @@ -319,26 +298,6 @@ class ChainImpl : public Chain
return ::mempool.CalculateMemPoolAncestors(entry, ancestors, limit_ancestor_count, limit_ancestor_size,
limit_descendant_count, limit_descendant_size, unused_error_string);
}
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
{
return ::feeEstimator.estimateSmartFee(num_blocks, calc, conservative);
}
unsigned int estimateMaxBlocks() override
{
return ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
}
CFeeRate mempoolMinFee() override
{
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
}
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
CFeeRate relayDustFee() override { return ::dustRelayFee; }
bool havePruned() override
{
LOCK(cs_main);
return ::fHavePruned;
}
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
bool shutdownRequested() override { return ShutdownRequested(); }
Expand Down
30 changes: 0 additions & 30 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
#include <vector>

class CBlock;
class CFeeRate;
class CRPCCommand;
class CScheduler;
class Coin;
class uint256;
enum class RBFTransactionState;
struct CBlockLocator;
struct FeeCalculation;
struct NodeContext;
Expand Down Expand Up @@ -97,10 +95,6 @@ class Chain
//! (to avoid the cost of a second lookup in case this information is needed.)
virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0;

//! Return height of last block in the specified range which is pruned, or
//! nullopt if no block in the range is pruned. Range is inclusive.
virtual Optional<int> findPruned(int start_height = 0, Optional<int> stop_height = nullopt) = 0;

//! Return height of the specified block if it is on the chain, otherwise
//! return the height of the highest block on chain that's an ancestor
//! of the specified block, or nullopt if there is no common ancestor.
Expand Down Expand Up @@ -145,9 +139,6 @@ class Chain
//! the specified block hash are verified.
virtual double guessVerificationProgress(const uint256& block_hash) = 0;

//! Check if transaction is RBF opt in.
virtual RBFTransactionState isRBFOptIn(const CTransaction& tx) = 0;

//! Check if transaction has descendants in mempool.
virtual bool hasDescendantsInMempool(const uint256& txid) = 0;

Expand All @@ -170,27 +161,6 @@ class Chain
//! Check if transaction will pass the mempool's chain limits.
virtual bool checkChainLimits(const CTransactionRef& tx) = 0;

//! Estimate smart fee.
virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc = nullptr) = 0;

//! Fee estimator max target.
virtual unsigned int estimateMaxBlocks() = 0;

//! Mempool minimum fee.
virtual CFeeRate mempoolMinFee() = 0;

//! Relay current minimum fee (from -minrelaytxfee and -incrementalrelayfee settings).
virtual CFeeRate relayMinFee() = 0;

//! Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay.
virtual CFeeRate relayIncrementalFee() = 0;

//! Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend.
virtual CFeeRate relayDustFee() = 0;

//! Check if any block has been pruned.
virtual bool havePruned() = 0;

//! Check if the node is ready to broadcast transactions.
virtual bool isReadyToBroadcast() = 0;

Expand Down

0 comments on commit 195b0fa

Please sign in to comment.