Pulse: Add work around for core_tests and fix cast

This commit is contained in:
Doyle 2020-08-19 19:40:33 +10:00 committed by Jason Rhinelander
parent 86aff9765e
commit 6cf53600e1
3 changed files with 28 additions and 7 deletions

View File

@ -668,7 +668,10 @@ bool pulse::get_round_timings(cryptonote::Blockchain const &blockchain, uint64_t
if (bool orphan = false; !blockchain.get_block_by_hash(top_hash, top_block, &orphan) || orphan)
return false;
static uint64_t const hf16_height = cryptonote::HardFork::get_hardcoded_hard_fork_height(blockchain.nettype(), cryptonote::network_version_16);
static uint64_t const hf16_height = blockchain.get_earliest_ideal_height_for_version(cryptonote::network_version_16);
if (hf16_height == std::numeric_limits<uint64_t>::max())
return false;
crypto::hash genesis_hash = blockchain.get_block_id_by_height(hf16_height - 1);
cryptonote::block genesis_block = {};
if (bool orphaned = false; !blockchain.get_block_by_hash(genesis_hash, genesis_block, &orphaned) || orphaned)

View File

@ -1290,11 +1290,12 @@ namespace service_nodes
std::lock_guard lock(m_sn_mutex);
process_block(block, txs);
// TODO(doyle): Check round closeness to expected round
pulse::timings timings = {};
uint64_t height = cryptonote::get_block_height(block);
if (block.major_version >= cryptonote::network_version_16)
{
if (!pulse::get_round_timings(m_blockchain, cryptonote::get_block_height(block), timings))
if (!pulse::get_round_timings(m_blockchain, height, timings))
{
MERROR("Failed to query the block data for Pulse timings to validate incoming block at height " << height);
return false;
@ -1305,7 +1306,15 @@ namespace service_nodes
// NOTE: Block Verification
//
std::shared_ptr<const quorum> pulse_quorum = get_quorum(quorum_type::pulse, m_state.height);
bool miner_blocks_only = pulse::clock::now() >= timings.miner_fallback_timestamp;
bool miner_blocks_only = pulse::clock::now() >= timings.miner_fallback_timestamp || !pulse_quorum;
if (m_blockchain.nettype() == cryptonote::FAKECHAIN)
{
// TODO(doyle): Core tests need to generate coherent timestamps with
// Pulse. So we relax the rules here for now.
miner_blocks_only = block.major_version <= cryptonote::network_version_15_lns || !pulse_quorum;
}
if (miner_blocks_only)
{
if (is_pulse_block(block))

View File

@ -269,11 +269,20 @@ namespace service_nodes
return false;
}
auto const &block = reinterpret_cast<cryptonote::block const &>(context);
if (block.pulse.validator_bitset >= (1 << PULSE_QUORUM_NUM_VALIDATORS))
try
{
auto mask = std::bitset<sizeof(pulse_validator_bit_mask()) * 8>(pulse_validator_bit_mask());
LOG_PRINT_L1("Pulse block specifies validator participation bits out of bounds. Expected the bit mask: " << mask);
auto const block = std::any_cast<cryptonote::block const &>(context);
if (block.pulse.validator_bitset >= (1 << PULSE_QUORUM_NUM_VALIDATORS))
{
auto mask = std::bitset<sizeof(pulse_validator_bit_mask()) * 8>(pulse_validator_bit_mask());
auto other = std::bitset<sizeof(pulse_validator_bit_mask()) * 8>(block.pulse.validator_bitset);
LOG_PRINT_L1("Pulse block specifies validator participation bits out of bounds. Expected the bit mask: " << mask << ", block: " << other);
return false;
}
}
catch (const std::bad_any_cast &e)
{
LOG_PRINT_L1("Internal Error: Wrong type passed in any object, expected block.");
return false;
}
}