Merge pull request #39 from wowario/release-v0.2.1.0

Merge branch 'master' into release-v0.2.1.0
This commit is contained in:
jw 2018-05-27 07:10:57 -07:00 committed by GitHub
commit 1977bc6e2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View file

@ -1195,6 +1195,12 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
b.prev_id = get_tail_id();
b.timestamp = time(NULL);
uint64_t median_ts;
if (!check_block_timestamp(b, median_ts))
{
b.timestamp = median_ts;
}
diffic = get_difficulty_for_next_block();
CHECK_AND_ASSERT_MES(diffic, false, "difficulty overhead.");
@ -3192,10 +3198,10 @@ uint64_t Blockchain::get_adjusted_time() const
}
//------------------------------------------------------------------
//TODO: revisit, has changed a bit on upstream
bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b) const
bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b, uint64_t& median_ts) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
uint64_t median_ts = epee::misc_utils::median(timestamps);
median_ts = epee::misc_utils::median(timestamps);
uint64_t blockchain_timestamp_check_window = get_current_hard_fork_version() < 9 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2;
if(b.timestamp < median_ts)
@ -3214,7 +3220,7 @@ bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const
// true if the block's timestamp is not less than the timestamp of the
// median of the selected blocks
// false otherwise
bool Blockchain::check_block_timestamp(const block& b) const
bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
uint64_t cryptonote_block_future_time_limit = get_current_hard_fork_version() < 9 ? CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 : CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V3;
@ -3241,7 +3247,7 @@ bool Blockchain::check_block_timestamp(const block& b) const
timestamps.push_back(m_db->get_block_timestamp(offset));
}
return check_block_timestamp(timestamps, b);
return check_block_timestamp(timestamps, b, median_ts);
}
//------------------------------------------------------------------
void Blockchain::return_tx_to_pool(std::vector<transaction> &txs)

View file

@ -1292,10 +1292,12 @@ namespace cryptonote
* false otherwise
*
* @param b the block to be checked
* @param median_ts return-by-reference the median of timestamps
*
* @return true if the block's timestamp is valid, otherwise false
*/
bool check_block_timestamp(const block& b) const;
bool check_block_timestamp(const block& b, uint64_t& median_ts) const;
bool check_block_timestamp(const block& b) const { uint64_t median_ts; return check_block_timestamp(b, median_ts); }
/**
* @brief checks a block's timestamp
@ -1308,7 +1310,8 @@ namespace cryptonote
*
* @return true if the block's timestamp is valid, otherwise false
*/
bool check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b) const;
bool check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b, uint64_t& median_ts) const;
bool check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b) const { uint64_t median_ts; return check_block_timestamp(timestamps, b, median_ts); }
/**
* @brief get the "adjusted time"