mirror of https://github.com/oxen-io/oxen-core.git
Rename block_added hook to block_add
This hook *isn't* called after a block is added, but rather it is part of the block addition process and can abort the whole thing by raising an exception (or returning false, prior to this PR). This is unintuitive and causes bugs if using it as a "block has been added" hook.
This commit is contained in:
parent
9c9552380d
commit
59f90dcf75
|
@ -167,7 +167,7 @@ namespace cryptonote
|
|||
return result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void checkpoints::block_added(const block_added_info& info)
|
||||
void checkpoints::block_add(const block_add_info& info)
|
||||
{
|
||||
uint64_t const height = get_block_height(info.block);
|
||||
if (height < service_nodes::CHECKPOINT_STORE_PERSISTENTLY_INTERVAL || info.block.major_version < hf::hf12_checkpointing)
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace cryptonote
|
|||
class checkpoints
|
||||
{
|
||||
public:
|
||||
void block_added(const block_added_info& info);
|
||||
void block_add(const block_add_info& info);
|
||||
void blockchain_detached(uint64_t height);
|
||||
|
||||
bool get_checkpoint(uint64_t height, checkpoint_t &checkpoint) const;
|
||||
|
|
|
@ -37,12 +37,12 @@
|
|||
|
||||
namespace cryptonote {
|
||||
struct checkpoint_t;
|
||||
struct block_added_info {
|
||||
struct block_add_info {
|
||||
const cryptonote::block& block;
|
||||
const std::vector<transaction>& txs;
|
||||
const checkpoint_t* const checkpoint;
|
||||
};
|
||||
using BlockAddedHook = std::function<void(const block_added_info& info)>;
|
||||
using BlockAddHook = std::function<void(const block_add_info& info)>;
|
||||
struct detached_info {
|
||||
uint64_t height;
|
||||
bool by_pop_blocks;
|
||||
|
|
|
@ -402,7 +402,7 @@ bool Blockchain::load_missing_blocks_into_oxen_subsystems()
|
|||
checkpoint_ptr = &checkpoint;
|
||||
|
||||
try {
|
||||
m_service_node_list.block_added(blk, txs, checkpoint_ptr);
|
||||
m_service_node_list.block_add(blk, txs, checkpoint_ptr);
|
||||
} catch (const std::exception& e) {
|
||||
MFATAL("Unable to process block {} for updating service node list: " << e.what());
|
||||
return false;
|
||||
|
@ -605,7 +605,7 @@ bool Blockchain::init(BlockchainDB* db, sqlite3 *ons_db, std::shared_ptr<crypton
|
|||
}
|
||||
|
||||
|
||||
hook_block_added([this] (const auto& info) { m_checkpoints.block_added(info); });
|
||||
hook_block_add([this] (const auto& info) { m_checkpoints.block_add(info); });
|
||||
hook_blockchain_detached([this] (const auto& info) { m_checkpoints.blockchain_detached(info.height); });
|
||||
for (const auto& hook : m_init_hooks)
|
||||
hook();
|
||||
|
@ -1975,7 +1975,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||
{
|
||||
// NOTE: Pulse blocks don't use PoW. They use Service Node signatures.
|
||||
// Delay signature verification until Service Node List adds the block in
|
||||
// the block_added hook.
|
||||
// the block_add hook.
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2102,8 +2102,8 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||
txs.push_back(tx);
|
||||
}
|
||||
|
||||
block_added_info hook_data{b, txs, checkpoint};
|
||||
for (const auto& hook : m_alt_block_added_hooks)
|
||||
block_add_info hook_data{b, txs, checkpoint};
|
||||
for (const auto& hook : m_alt_block_add_hooks)
|
||||
{
|
||||
try {
|
||||
hook(hook_data);
|
||||
|
@ -4309,7 +4309,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
{
|
||||
// NOTE: Pulse blocks don't use PoW. They use Service Node signatures.
|
||||
// Delay signature verification until Service Node List adds the block in
|
||||
// the block_added hook.
|
||||
// the block_add hook.
|
||||
}
|
||||
else // check proof of work
|
||||
{
|
||||
|
@ -4521,7 +4521,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
|
||||
// TODO(oxen): Not nice, making the hook take in a vector of pair<transaction,
|
||||
// std::string> messes with service_node_list::init which only constructs
|
||||
// a vector of transactions and then subsequently calls block_added, so the
|
||||
// a vector of transactions and then subsequently calls block_add, so the
|
||||
// init step would have to intentionally allocate the blobs or retrieve them
|
||||
// from the DB.
|
||||
// Secondly we don't use the blobs at all in the hooks, so passing it in
|
||||
|
@ -4532,7 +4532,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
only_txs.push_back(tx_pair.first);
|
||||
|
||||
try {
|
||||
m_service_node_list.block_added(bl, only_txs, checkpoint);
|
||||
m_service_node_list.block_add(bl, only_txs, checkpoint);
|
||||
} catch (const std::exception& e) {
|
||||
MGINFO_RED("Failed to add block to Service Node List: " << e.what());
|
||||
bvc.m_verifivation_failed = true;
|
||||
|
@ -4558,13 +4558,13 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
throw std::logic_error("Blockchain missing SQLite Database");
|
||||
}
|
||||
|
||||
block_added_info hook_data{bl, only_txs, checkpoint};
|
||||
for (const auto& hook : m_block_added_hooks)
|
||||
block_add_info hook_data{bl, only_txs, checkpoint};
|
||||
for (const auto& hook : m_block_add_hooks)
|
||||
{
|
||||
try {
|
||||
hook(hook_data);
|
||||
} catch (const std::exception& e) {
|
||||
MGINFO_RED("Block added hook failed with exception: " << e.what());
|
||||
MGINFO_RED("Block add hook failed with exception: " << e.what());
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -980,7 +980,7 @@ namespace cryptonote
|
|||
/**
|
||||
* @brief add a hook called during new block handling; should throw to abort adding the block.
|
||||
*/
|
||||
void hook_block_added(BlockAddedHook hook) { m_block_added_hooks.push_back(std::move(hook)); }
|
||||
void hook_block_add(BlockAddHook hook) { m_block_add_hooks.push_back(std::move(hook)); }
|
||||
/**
|
||||
* @brief add a hook called when blocks are removed from the chain.
|
||||
*/
|
||||
|
@ -997,7 +997,7 @@ namespace cryptonote
|
|||
/**
|
||||
* @brief add a hook to be called when adding an alt-chain block; should throw to abort adding.
|
||||
*/
|
||||
void hook_alt_block_added(BlockAddedHook hook) { m_alt_block_added_hooks.push_back(std::move(hook)); }
|
||||
void hook_alt_block_add(BlockAddHook hook) { m_alt_block_add_hooks.push_back(std::move(hook)); }
|
||||
|
||||
/**
|
||||
* @brief returns the timestamps of the last N blocks
|
||||
|
@ -1130,8 +1130,8 @@ namespace cryptonote
|
|||
// some invalid blocks
|
||||
std::set<crypto::hash> m_invalid_blocks;
|
||||
|
||||
std::vector<BlockAddedHook> m_block_added_hooks;
|
||||
std::vector<BlockAddedHook> m_alt_block_added_hooks;
|
||||
std::vector<BlockAddHook> m_block_add_hooks;
|
||||
std::vector<BlockAddHook> m_alt_block_add_hooks;
|
||||
std::vector<BlockchainDetachedHook> m_blockchain_detached_hooks;
|
||||
std::vector<InitHook> m_init_hooks;
|
||||
std::vector<ValidateMinerTxHook> m_validate_miner_tx_hooks;
|
||||
|
|
|
@ -771,11 +771,11 @@ namespace cryptonote
|
|||
m_blockchain_storage.hook_blockchain_detached([this] (const auto& info) { m_service_node_list.blockchain_detached(info.height); });
|
||||
m_blockchain_storage.hook_init([this] { m_service_node_list.init(); });
|
||||
m_blockchain_storage.hook_validate_miner_tx([this] (const auto& info) { m_service_node_list.validate_miner_tx(info); });
|
||||
m_blockchain_storage.hook_alt_block_added([this] (const auto& info) { m_service_node_list.alt_block_added(info); });
|
||||
m_blockchain_storage.hook_alt_block_add([this] (const auto& info) { m_service_node_list.alt_block_add(info); });
|
||||
|
||||
// NOTE: There is an implicit dependency on service node lists being hooked first!
|
||||
m_blockchain_storage.hook_init([this] { m_quorum_cop.init(); });
|
||||
m_blockchain_storage.hook_block_added([this] (const auto& info) { m_quorum_cop.block_added(info.block, info.txs); });
|
||||
m_blockchain_storage.hook_block_add([this] (const auto& info) { m_quorum_cop.block_add(info.block, info.txs); });
|
||||
m_blockchain_storage.hook_blockchain_detached([this] (const auto& info) { m_quorum_cop.blockchain_detached(info.height, info.by_pop_blocks); });
|
||||
}
|
||||
|
||||
|
|
|
@ -1667,7 +1667,7 @@ namespace service_nodes
|
|||
block_type, height)};
|
||||
}
|
||||
|
||||
void service_node_list::block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, cryptonote::checkpoint_t const *checkpoint)
|
||||
void service_node_list::block_add(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, cryptonote::checkpoint_t const *checkpoint)
|
||||
{
|
||||
if (block.major_version < hf::hf9_service_nodes)
|
||||
return;
|
||||
|
@ -2710,7 +2710,7 @@ namespace service_nodes
|
|||
}
|
||||
}
|
||||
|
||||
void service_node_list::alt_block_added(const cryptonote::block_added_info& info)
|
||||
void service_node_list::alt_block_add(const cryptonote::block_add_info& info)
|
||||
{
|
||||
// NOTE: The premise is to search the main list and the alternative list for
|
||||
// the parent of the block we just received, generate the new Service Node
|
||||
|
|
|
@ -455,7 +455,7 @@ namespace service_nodes
|
|||
service_node_list(const service_node_list &) = delete;
|
||||
service_node_list &operator=(const service_node_list &) = delete;
|
||||
|
||||
void block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, const cryptonote::checkpoint_t* checkpoint);
|
||||
void block_add(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, const cryptonote::checkpoint_t* checkpoint);
|
||||
void reset_batching_to_latest_height();
|
||||
bool state_history_exists(uint64_t height);
|
||||
bool process_batching_rewards(const cryptonote::block& block);
|
||||
|
@ -463,7 +463,7 @@ namespace service_nodes
|
|||
void blockchain_detached(uint64_t height);
|
||||
void init();
|
||||
void validate_miner_tx(const cryptonote::miner_tx_info& info) const;
|
||||
void alt_block_added(const cryptonote::block_added_info& info);
|
||||
void alt_block_add(const cryptonote::block_add_info& info);
|
||||
payout get_block_leader() const { std::lock_guard lock{m_sn_mutex}; return m_state.get_block_leader(); }
|
||||
bool is_service_node(const crypto::public_key& pubkey, bool require_active = true) const;
|
||||
bool is_key_image_locked(crypto::key_image const &check_image, uint64_t *unlock_height = nullptr, service_node_info::contribution_t *the_locked_contribution = nullptr) const;
|
||||
|
|
|
@ -510,7 +510,7 @@ namespace service_nodes
|
|||
}
|
||||
}
|
||||
|
||||
void quorum_cop::block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs)
|
||||
void quorum_cop::block_add(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs)
|
||||
{
|
||||
process_quorums(block);
|
||||
uint64_t const height = cryptonote::get_block_height(block) + 1; // chain height = new top block height + 1
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace service_nodes
|
|||
explicit quorum_cop(cryptonote::core& core);
|
||||
|
||||
void init();
|
||||
void block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs);
|
||||
void block_add(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs);
|
||||
void blockchain_detached(uint64_t height, bool by_pop_blocks);
|
||||
|
||||
void set_votes_relayed (std::vector<quorum_vote_t> const &relayed_votes);
|
||||
|
|
|
@ -315,7 +315,7 @@ omq_rpc::omq_rpc(cryptonote::core& core, core_rpc_server& rpc, const boost::prog
|
|||
}
|
||||
});
|
||||
|
||||
core_.get_blockchain_storage().hook_block_added([this] (const auto& info) { send_block_notifications(info.block); return true; });
|
||||
core_.get_blockchain_storage().hook_block_add([this] (const auto& info) { send_block_notifications(info.block); return true; });
|
||||
core_.get_pool().add_notify([this](const crypto::hash& id, const transaction& tx, const std::string& blob, const tx_pool_options& opts) {
|
||||
send_mempool_notifications(id, tx, blob, opts);
|
||||
});
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
namespace oxenmq { class OxenMQ; }
|
||||
|
||||
namespace cryptonote { namespace rpc {
|
||||
namespace cryptonote::rpc {
|
||||
|
||||
void init_omq_options(boost::program_options::options_description& desc);
|
||||
|
||||
|
@ -70,4 +70,4 @@ public:
|
|||
void send_mempool_notifications(const crypto::hash& id, const transaction& tx, const std::string& blob, const tx_pool_options& opts);
|
||||
};
|
||||
|
||||
}} // namespace cryptonote::rpc
|
||||
} // namespace cryptonote::rpc
|
||||
|
|
Loading…
Reference in New Issue