Skip to content
Draft
6 changes: 6 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <primitives/block.h>
#include <sync.h>
#include <uint256.h>
#include <util/time.h>

#include <vector>

Expand Down Expand Up @@ -255,6 +256,11 @@ class CBlockIndex
*/
bool HaveTxsDownloaded() const { return nChainTx != 0; }

NodeSeconds Time() const
{
return NodeSeconds{std::chrono::seconds{nTime}};
}

int64_t GetBlockTime() const
{
return (int64_t)nTime;
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class CCoinJoinQueue
[[nodiscard]] bool CheckSignature(const CBLSPublicKey& blsPubKey) const;

/// Check if a queue is too old or too far into the future
[[nodiscard]] bool IsTimeOutOfBounds(int64_t current_time = GetAdjustedTime()) const;
[[nodiscard]] bool IsTimeOutOfBounds(int64_t current_time = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime())) const;

[[nodiscard]] std::string ToString() const;

Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void CCoinJoinServer::CommitFinalTransaction()
// create and sign masternode dstx transaction
if (!m_dstxman.GetDSTX(hashTx)) {
CCoinJoinBroadcastTx dstxNew(finalTransaction, m_mn_activeman.GetOutPoint(), m_mn_activeman.GetProTxHash(),
GetAdjustedTime());
TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()));
dstxNew.vchSig = m_mn_activeman.SignBasic(dstxNew.GetSignatureHash());
m_dstxman.AddDSTX(dstxNew);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ void CCoinJoinServer::CheckForCompleteQueue()
SetState(POOL_STATE_ACCEPTING_ENTRIES);

CCoinJoinQueue dsq(nSessionDenom, m_mn_activeman.GetOutPoint(), m_mn_activeman.GetProTxHash(),
GetAdjustedTime(), true);
TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()), true);
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) " /* Continued */
"with %d participants\n", dsq.ToString(), vecSessionCollaterals.size());
dsq.vchSig = m_mn_activeman.SignBasic(dsq.GetSignatureHash());
Expand Down Expand Up @@ -728,7 +728,7 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage&
if (!fUnitTest) {
//broadcast that I'm accepting entries, only if it's the first entry through
CCoinJoinQueue dsq(nSessionDenom, m_mn_activeman.GetOutPoint(), m_mn_activeman.GetProTxHash(),
GetAdjustedTime(), false);
TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()), false);
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
dsq.vchSig = m_mn_activeman.SignBasic(dsq.GetSignatureHash());
m_peerman.RelayDSQ(dsq);
Expand Down
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <uint256.h>
#include <llmq/params.h>

#include <chrono>
#include <limits>
#include <vector>

Expand Down Expand Up @@ -170,6 +171,10 @@ struct Params {
int64_t nPowTargetTimespan;
int nPowKGWHeight;
int nPowDGWHeight;
std::chrono::seconds PowTargetSpacing() const
{
return std::chrono::seconds{nPowTargetSpacing};
}
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/ripemd160.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)

////// RIPEMD160

CRIPEMD160::CRIPEMD160() : bytes(0)
CRIPEMD160::CRIPEMD160()
{
ripemd160::Initialize(s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/ripemd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CRIPEMD160
private:
uint32_t s[5];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 20;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)

////// SHA1

CSHA1::CSHA1() : bytes(0)
CSHA1::CSHA1()
{
sha1::Initialize(s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CSHA1
private:
uint32_t s[5];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 20;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem

////// SHA-256

CSHA256::CSHA256() : bytes(0)
CSHA256::CSHA256()
{
sha256::Initialize(s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CSHA256
private:
uint32_t s[8];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 32;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Transform(uint64_t* s, const unsigned char* chunk)

////// SHA-512

CSHA512::CSHA512() : bytes(0)
CSHA512::CSHA512()
{
sha512::Initialize(s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CSHA512
private:
uint64_t s[8];
unsigned char buf[128];
uint64_t bytes;
uint64_t bytes{0};

public:
static constexpr size_t OUTPUT_SIZE = 64;
Expand Down
11 changes: 5 additions & 6 deletions src/cuckoocache.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class cache
std::vector<Element> table;

/** size stores the total available slots in the hash table */
uint32_t size;
uint32_t size{0};

/** The bit_packed_atomic_flags array is marked mutable because we want
* garbage collection to be allowed to occur from const methods */
Expand All @@ -181,7 +181,7 @@ class cache
* decremented on insert and reset to the new number of inserts which would
* cause the epoch to reach epoch_size when it reaches zero.
*/
uint32_t epoch_heuristic_counter;
uint32_t epoch_heuristic_counter{0};

/** epoch_size is set to be the number of elements supposed to be in a
* epoch. When the number of non-erased elements in an epoch
Expand All @@ -191,12 +191,12 @@ class cache
* one "dead" which has been erased, one "dying" which has been marked to be
* erased next, and one "living" which new inserts add to.
*/
uint32_t epoch_size;
uint32_t epoch_size{0};

/** depth_limit determines how many elements insert should try to replace.
* Should be set to log2(n).
*/
uint8_t depth_limit;
uint8_t depth_limit{0};

/** hash_function is a const instance of the hash function. It cannot be
* static or initialized at call time as it may have internal state (such as
Expand Down Expand Up @@ -320,8 +320,7 @@ class cache
/** You must always construct a cache with some elements via a subsequent
* call to setup or setup_bytes, otherwise operations may segfault.
*/
cache() : table(), size(), collection_flags(0), epoch_flags(),
epoch_heuristic_counter(), epoch_size(), depth_limit(0), hash_function()
cache() : table(), collection_flags(0), epoch_flags(), hash_function()
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class CDBBatch
CDataStream ssKey;
CDataStream ssValue;

size_t size_estimate;
size_t size_estimate{0};

public:
/**
* @param[in] _parent CDBWrapper that this batch is to be submitted to
*/
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0) { };
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION) { };

void Clear()
{
Expand Down
6 changes: 3 additions & 3 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj)

ScopedLockBool guard(cs_store, fRateChecksEnabled, false);

int64_t nNow = GetAdjustedTime();
int64_t nNow = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
for (const auto& pairVote : vecVotePairs) {
const auto& [vote, time] = pairVote;
Expand Down Expand Up @@ -860,7 +860,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo

const COutPoint& masternodeOutpoint = govobj.GetMasternodeOutpoint();
int64_t nTimestamp = govobj.GetCreationTime();
int64_t nNow = GetAdjustedTime();
int64_t nNow = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
int64_t nSuperblockCycleSeconds = Params().GetConsensus().nSuperblockCycle * Params().GetConsensus().nPowTargetSpacing;

std::string strHash = govobj.GetHash().ToString();
Expand Down Expand Up @@ -1014,7 +1014,7 @@ void CGovernanceManager::CheckPostponedObjects()


// Perform additional relays for triggers
int64_t nNow = GetAdjustedTime();
int64_t nNow = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
int64_t nSuperblockCycleSeconds = Params().GetConsensus().nSuperblockCycle * Params().GetConsensus().nPowTargetSpacing;

for (auto it = setAdditionalRelayObjects.begin(); it != setAdditionalRelayObjects.end();) {
Expand Down
2 changes: 1 addition & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
LogPrint(BCLog::GOBJECT, "%s\n", msg);
}

int64_t nNow = GetAdjustedTime();
int64_t nNow = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
int64_t nVoteTimeUpdate = voteInstanceRef.nTime;
if (govman.AreRateChecksEnabled()) {
int64_t nTimeDelta = nNow - voteInstanceRef.nTime;
Expand Down
4 changes: 2 additions & 2 deletions src/governance/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ std::optional<const CGovernanceObject> GovernanceSigner::CreateGovernanceTrigger
LOCK(::cs_main);

// Check if identical trigger (equal DataHash()) is already created (signed by other masternode)
CGovernanceObject gov_sb(uint256(), 1, GetAdjustedTime(), uint256(), sb_opt.value().GetHexStrData());
CGovernanceObject gov_sb(uint256(), 1, TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()), uint256(), sb_opt.value().GetHexStrData());
if (auto identical_sb = m_govman.FindGovernanceObjectByDataHash(gov_sb.GetDataHash())) {
// Somebody submitted a trigger with the same data, support it instead of submitting a duplicate
return std::make_optional<CGovernanceObject>(*identical_sb);
Expand Down Expand Up @@ -261,7 +261,7 @@ void GovernanceSigner::VoteGovernanceTriggers(const std::optional<const CGoverna
bool GovernanceSigner::VoteFundingTrigger(const uint256& nHash, const vote_outcome_enum_t outcome)
{
CGovernanceVote vote(m_mn_activeman.GetOutPoint(), nHash, VOTE_SIGNAL_FUNDING, outcome);
vote.SetTime(GetAdjustedTime());
vote.SetTime(TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()));
vote.SetSignature(m_mn_activeman.SignBasic(vote.GetSignatureHash()));

CGovernanceException exception;
Expand Down
2 changes: 1 addition & 1 deletion src/governance/validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool CProposalValidator::ValidateStartEndEpoch(bool fCheckExpiration)
return false;
}

if (fCheckExpiration && nEndEpoch <= GetAdjustedTime()) {
if (fCheckExpiration && nEndEpoch <= TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime())) {
strErrorMessages += "expired;";
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/governance/vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ CGovernanceVote::CGovernanceVote(const COutPoint& outpointMasternodeIn, const ui
nParentHash(nParentHashIn),
nVoteOutcome(eVoteOutcomeIn),
nVoteSignal(eVoteSignalIn),
nTime(GetAdjustedTime())
nTime(TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()))
{
UpdateHash();
}
Expand Down Expand Up @@ -154,8 +154,8 @@ bool CGovernanceVote::CheckSignature(const CBLSPublicKey& pubKey) const

bool CGovernanceVote::IsValid(const CDeterministicMNList& tip_mn_list, bool useVotingKey) const
{
if (nTime > GetAdjustedTime() + (60 * 60)) {
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetAdjustedTime() + (60 * 60));
if (nTime > TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime() + 1h)) {
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime() + 1h));
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class CKey
private:
//! Whether this private key is valid. We check for correctness when modifying the key
//! data, so fValid should always correspond to the actual state.
bool fValid;
bool fValid{false};

//! Whether the public key corresponding to this private key is (to be) compressed.
bool fCompressed;
bool fCompressed{false};

//! The actual byte data
std::vector<unsigned char, secure_allocator<unsigned char> > keydata;
Expand All @@ -61,7 +61,7 @@ class CKey

public:
//! Construct an invalid private key.
CKey() : fValid(false), fCompressed(false)
CKey()
{
// Important: vch must be 32 bytes in length to not break serialization
keydata.resize(32);
Expand Down
6 changes: 3 additions & 3 deletions src/llmq/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void CDKGDebugManager::ResetLocalSessionStatus(Consensus::LLMQType llmqType, int
}

localStatus.sessions.erase(it);
localStatus.nTime = GetAdjustedTime();
localStatus.nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
}

void CDKGDebugManager::InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, int quorumIndex, const uint256& quorumHash, int quorumHeight)
Expand Down Expand Up @@ -186,7 +186,7 @@ void CDKGDebugManager::UpdateLocalSessionStatus(Consensus::LLMQType llmqType, in
}

if (func(it->second)) {
localStatus.nTime = GetAdjustedTime();
localStatus.nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
}
}

Expand All @@ -200,7 +200,7 @@ void CDKGDebugManager::UpdateLocalMemberStatus(Consensus::LLMQType llmqType, int
}

if (func(it->second.members.at(memberIdx))) {
localStatus.nTime = GetAdjustedTime();
localStatus.nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ bool PeerManagerImpl::TipMayBeStale()

bool PeerManagerImpl::CanDirectFetch()
{
return m_chainman.ActiveChain().Tip()->GetBlockTime() > GetAdjustedTime() - m_chainparams.GetConsensus().nPowTargetSpacing * 20;
return m_chainman.ActiveChain().Tip()->Time() > GetAdjustedTime() - m_chainparams.GetConsensus().PowTargetSpacing() * 20;
}

static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Expand Down Expand Up @@ -6004,7 +6004,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)

if (!state.fSyncStarted && CanServeBlocks(*peer) && !fImporting && !fReindex && pto->CanRelay()) {
// Only actively request headers from a single peer, unless we're close to end of initial download.
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) {
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->Time() > GetAdjustedTime() - 24h) {
const CBlockIndex* pindexStart = m_chainman.m_best_header;
/* If possible, start at the block preceding the currently
best known header. This ensures that we always get a
Expand All @@ -6025,7 +6025,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
// to maintain precision
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
(GetAdjustedTime() - m_chainman.m_best_header->GetBlockTime()) / consensusParams.nPowTargetSpacing
Ticks<std::chrono::seconds>(GetAdjustedTime() - m_chainman.m_best_header->Time()) / consensusParams.nPowTargetSpacing
);
nSyncStarted++;
}
Expand Down Expand Up @@ -6407,7 +6407,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// Check for headers sync timeouts
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) {
// Detect whether this is a stalling initial-headers-sync peer
if (m_chainman.m_best_header->GetBlockTime() <= GetAdjustedTime() - nMaxTipAge) {
if (m_chainman.m_best_header->Time() <= GetAdjustedTime() - 24h) {
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) {
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
// and we have others we could be using instead.
Expand Down
4 changes: 2 additions & 2 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace node {
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{
int64_t nOldTime = pblock->nTime;
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()))};

if (nOldTime < nNewTime) {
pblock->nTime = nNewTime;
Expand Down Expand Up @@ -219,7 +219,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
}

pblock->nTime = GetAdjustedTime();
pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
m_lock_time_cutoff = pindexPrev->GetMedianTimePast();

if (fDIP0003Active_context) {
Expand Down
1 change: 0 additions & 1 deletion src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ bool CBlockPolicyEstimator::_removeTx(const uint256& hash, bool inBlock)
}

CBlockPolicyEstimator::CBlockPolicyEstimator()
: nBestSeenHeight(0), firstRecordedHeight(0), historicalFirst(0), historicalBest(0), trackedTxs(0), untrackedTxs(0)
{
static_assert(MIN_BUCKET_FEERATE > 0, "Min feerate must be nonzero");
size_t bucketIndex = 0;
Expand Down
Loading
Loading