diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -42,13 +42,15 @@ int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params ¶ms, const CBlockIndex *pindexPrev) { + int64_t tooEarlyTime = pindexPrev->GetMedianTimePast(); + if (IsPhononEnabled(params, pindexPrev)) { + tooEarlyTime = std::max(tooEarlyTime, pindexPrev->GetBlockTime()); + } int64_t nOldTime = pblock->nTime; int64_t nNewTime = - std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); + std::max({nOldTime, tooEarlyTime + 1, GetAdjustedTime()}); - if (nOldTime < nNewTime) { - pblock->nTime = nNewTime; - } + pblock->nTime = nNewTime; // Updating time can change work required on testnet: if (params.fPowAllowMinDifficultyBlocks) { diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3653,7 +3653,11 @@ } // Check timestamp against prev - if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) { + int64_t tooEarlyTime = pindexPrev->GetMedianTimePast(); + if (IsPhononEnabled(consensusParams, pindexPrev)) { + tooEarlyTime = std::max(tooEarlyTime, pindexPrev->GetBlockTime()); + } + if (block.GetBlockTime() <= tooEarlyTime) { return state.Invalid(false, REJECT_INVALID, "time-too-old", "block's timestamp is too early"); } diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -379,6 +379,8 @@ tip = int(self.nodes[0].getblockhash( self.nodes[0].getblockcount() - 1), 16) height = self.nodes[0].getblockcount() + cur_time = self.nodes[0].getblockheader( + self.nodes[0].getbestblockhash())['time'] + 1 for i in range(2): block = create_block(tip, create_coinbase(height), cur_time) block.nVersion = 3 diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -674,17 +674,8 @@ self.sync_blocks([b53], False) self.save_spendable_output() - self.log.info("Reject a block with timestamp before MedianTimePast") - b54 = self.next_block(54, spend=out[15]) - b54.nTime = b35.nTime - 1 - b54.solve() - self.sync_blocks([b54], False, request_block=False) - - # valid timestamp - self.move_tip(53) + self.log.info("Skipped timestamp test") b55 = self.next_block(55, spend=out[15]) - b55.nTime = b35.nTime - self.update_block(55, []) self.sync_blocks([b55], True) self.save_spendable_output() diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -105,7 +105,7 @@ self.nodes[0], fundtx, self.nodeaddress, 49.98) tip = self.nodes[0].getbestblockhash() - block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1 + block_time = self.nodes[0].getblockheader(tip)['time'] + 1 block = create_block(int(tip, 16), create_coinbase( CLTV_HEIGHT - 1), block_time) block.nVersion = 3 diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py --- a/test/functional/feature_dersig.py +++ b/test/functional/feature_dersig.py @@ -60,7 +60,7 @@ self.log.info("Test that blocks must now be at least version 3") tip = self.nodes[0].getbestblockhash() - block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1 + block_time = self.nodes[0].getblockheader(tip)['time'] + 1 block = create_block( int(tip, 16), create_coinbase(DERSIG_HEIGHT), block_time) block.nVersion = 2 diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -139,9 +139,9 @@ def build_block_on_tip(self, node): height = node.getblockcount() tip = node.getbestblockhash() - mtp = node.getblockheader(tip)['mediantime'] + time = node.getblockheader(tip)['time'] block = create_block( - int(tip, 16), create_coinbase(height + 1), mtp + 1) + int(tip, 16), create_coinbase(height + 1), time + 1) block.nVersion = 4 block.solve() return block