Skip to content

Commit ff9039f

Browse files
committed
Remove GetAdjustedTime
1 parent 4b1196a commit ff9039f

13 files changed

+15
-29
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ int main(int argc, char* argv[])
117117
const ChainstateManager::Options chainman_opts{
118118
.chainparams = *chainparams,
119119
.datadir = abs_datadir,
120-
.adjusted_time_callback = NodeClock::now,
121120
.notifications = *notifications,
122121
};
123122
const node::BlockManager::Options blockman_opts{

src/headerssync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ HeadersSyncState::HeadersSyncState(NodeId id, const Consensus::Params& consensus
4141
// exceeds this bound, because it's not possible for a consensus-valid
4242
// chain to be longer than this (at the current time -- in the future we
4343
// could try again, if necessary, to sync a longer chain).
44-
m_max_commitments = 6*(Ticks<std::chrono::seconds>(GetAdjustedTime() - NodeSeconds{std::chrono::seconds{chain_start->GetMedianTimePast()}}) + MAX_FUTURE_BLOCK_TIME) / HEADER_COMMITMENT_PERIOD;
44+
m_max_commitments = 6*(Ticks<std::chrono::seconds>(NodeClock::now() - NodeSeconds{std::chrono::seconds{chain_start->GetMedianTimePast()}}) + MAX_FUTURE_BLOCK_TIME) / HEADER_COMMITMENT_PERIOD;
4545

4646
LogPrint(BCLog::NET, "Initial headers sync started with peer=%d: height=%i, max_commitments=%i, min_work=%s\n", m_id, m_current_height, m_max_commitments, m_minimum_required_work.ToString());
4747
}

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14591459
ChainstateManager::Options chainman_opts{
14601460
.chainparams = chainparams,
14611461
.datadir = args.GetDataDirNet(),
1462-
.adjusted_time_callback = GetAdjustedTime,
14631462
.notifications = *node.notifications,
14641463
};
14651464
Assert(ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction

src/kernel/chainstatemanager_opts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace kernel {
3232
struct ChainstateManagerOpts {
3333
const CChainParams& chainparams;
3434
fs::path datadir;
35-
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
3635
std::optional<bool> check_block_index{};
3736
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
3837
//! If set, it will override the minimum work we will assume exists on some valid chain.

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ bool PeerManagerImpl::TipMayBeStale()
13131313

13141314
bool PeerManagerImpl::CanDirectFetch()
13151315
{
1316-
return m_chainman.ActiveChain().Tip()->Time() > GetAdjustedTime() - m_chainparams.GetConsensus().PowTargetSpacing() * 20;
1316+
return m_chainman.ActiveChain().Tip()->Time() > NodeClock::now() - m_chainparams.GetConsensus().PowTargetSpacing() * 20;
13171317
}
13181318

13191319
static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -5552,7 +5552,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
55525552

55535553
if (!state.fSyncStarted && CanServeBlocks(*peer) && !m_chainman.m_blockman.LoadingBlocks()) {
55545554
// Only actively request headers from a single peer, unless we're close to today.
5555-
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->Time() > GetAdjustedTime() - 24h) {
5555+
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->Time() > NodeClock::now() - 24h) {
55565556
const CBlockIndex* pindexStart = m_chainman.m_best_header;
55575557
/* If possible, start at the block preceding the currently
55585558
best known header. This ensures that we always get a
@@ -5572,7 +5572,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
55725572
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
55735573
// to maintain precision
55745574
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
5575-
Ticks<std::chrono::seconds>(GetAdjustedTime() - m_chainman.m_best_header->Time()) / consensusParams.nPowTargetSpacing
5575+
Ticks<std::chrono::seconds>(NodeClock::now() - m_chainman.m_best_header->Time()) / consensusParams.nPowTargetSpacing
55765576
);
55775577
nSyncStarted++;
55785578
}
@@ -5876,7 +5876,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58765876
// Check for headers sync timeouts
58775877
if (state.fSyncStarted && peer->m_headers_sync_timeout < std::chrono::microseconds::max()) {
58785878
// Detect whether this is a stalling initial-headers-sync peer
5879-
if (m_chainman.m_best_header->Time() <= GetAdjustedTime() - 24h) {
5879+
if (m_chainman.m_best_header->Time() <= NodeClock::now() - 24h) {
58805880
if (current_time > peer->m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) {
58815881
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
58825882
// and we have others we could be using instead.

src/node/miner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace node {
3131
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
3232
{
3333
int64_t nOldTime = pblock->nTime;
34-
int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()))};
34+
int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()))};
3535

3636
if (nOldTime < nNewTime) {
3737
pblock->nTime = nNewTime;
@@ -133,7 +133,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
133133
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
134134
}
135135

136-
pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
136+
pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(NodeClock::now());
137137
m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
138138

139139
int nPackagesSelected = 0;
@@ -171,7 +171,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
171171

172172
BlockValidationState state;
173173
if (m_options.test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,
174-
GetAdjustedTime, /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
174+
/*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
175175
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
176176
}
177177
const auto time_2{SteadyClock::now()};

src/rpc/mining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static RPCHelpMan generateblock()
383383
LOCK(cs_main);
384384

385385
BlockValidationState state;
386-
if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), GetAdjustedTime, false, false)) {
386+
if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), false, false)) {
387387
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString()));
388388
}
389389
}
@@ -693,7 +693,7 @@ static RPCHelpMan getblocktemplate()
693693
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
694694
return "inconclusive-not-best-prevblk";
695695
BlockValidationState state;
696-
TestBlockValidity(state, chainman.GetParams(), active_chainstate, block, pindexPrev, GetAdjustedTime, false, true);
696+
TestBlockValidity(state, chainman.GetParams(), active_chainstate, block, pindexPrev, false, true);
697697
return BIP22ValidationResult(state);
698698
}
699699

src/test/util/setup_common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
184184
const ChainstateManager::Options chainman_opts{
185185
.chainparams = chainparams,
186186
.datadir = m_args.GetDataDirNet(),
187-
.adjusted_time_callback = GetAdjustedTime,
188187
.check_block_index = true,
189188
.notifications = *m_node.notifications,
190189
.worker_threads_num = 2,

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ struct SnapshotTestSetup : TestChain100Setup {
383383
const ChainstateManager::Options chainman_opts{
384384
.chainparams = ::Params(),
385385
.datadir = chainman.m_options.datadir,
386-
.adjusted_time_callback = GetAdjustedTime,
387386
.notifications = *m_node.notifications,
388387
};
389388
const BlockManager::Options blockman_opts{

src/timedata.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ int64_t GetTimeOffset()
3333
return nTimeOffset;
3434
}
3535

36-
NodeClock::time_point GetAdjustedTime()
37-
{
38-
return NodeClock::now() + std::chrono::seconds{GetTimeOffset()};
39-
}
40-
4136
#define BITCOIN_TIMEDATA_MAX_SAMPLES 200
4237

4338
static std::set<CNetAddr> g_sources;

0 commit comments

Comments
 (0)