diff options
| author | Alexander Blair <snipa@jagtech.io> | 2020-08-05 07:54:14 -0700 |
|---|---|---|
| committer | Alexander Blair <snipa@jagtech.io> | 2020-08-05 07:54:31 -0700 |
| commit | d9deb2c2fe66010bfb7978ae17c7d278143b546d (patch) | |
| tree | 75a052bb95f6087421c8fedde549d6930c5af847 /src/cryptonote_core/blockchain.cpp | |
| parent | 5d850dde99ca282d2c6f9a1b1eb00a3812cb15be (diff) | |
| parent | e5214a2ca22cecf123bcff1ab441ed0415d08a6f (diff) | |
| download | monzero-core-d9deb2c2fe66010bfb7978ae17c7d278143b546d.tar.gz monzero-core-d9deb2c2fe66010bfb7978ae17c7d278143b546d.tar.xz monzero-core-d9deb2c2fe66010bfb7978ae17c7d278143b546d.zip | |
Merge pull request #6418
e5214a2ca Adding ZMQ/Pub support for txpool_add and chain_main events (Lee Clagett)
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
| -rw-r--r-- | src/cryptonote_core/blockchain.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 7851b0f6a..b0726981c 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1234,10 +1234,15 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info> reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(), "%n", std::to_string(m_db->height() - split_height).c_str(), "%d", std::to_string(discarded_blocks).c_str(), NULL); - std::shared_ptr<tools::Notify> block_notify = m_block_notify; - if (block_notify) - for (const auto &bei: alt_chain) - block_notify->notify("%s", epee::string_tools::pod_to_hex(get_block_hash(bei.bl)).c_str(), NULL); + for (const auto& notifier : m_block_notifiers) + { + std::size_t notify_height = split_height; + for (const auto& bei: alt_chain) + { + notifier(notify_height, {std::addressof(bei.bl), 1}); + ++notify_height; + } + } MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height()); return true; @@ -4236,12 +4241,9 @@ leave: get_difficulty_for_next_block(); // just to cache it invalidate_block_template_cache(); - if (notify) - { - std::shared_ptr<tools::Notify> block_notify = m_block_notify; - if (block_notify) - block_notify->notify("%s", epee::string_tools::pod_to_hex(id).c_str(), NULL); - } + + for (const auto& notifier: m_block_notifiers) + notifier(new_height - 1, {std::addressof(bl), 1}); return true; } @@ -5132,6 +5134,15 @@ void Blockchain::set_user_options(uint64_t maxthreads, bool sync_on_blocks, uint m_max_prepare_blocks_threads = maxthreads; } +void Blockchain::add_block_notify(boost::function<void(std::uint64_t, epee::span<const block>)>&& notify) +{ + if (notify) + { + CRITICAL_REGION_LOCAL(m_blockchain_lock); + m_block_notifiers.push_back(std::move(notify)); + } +} + void Blockchain::safesyncmode(const bool onoff) { /* all of this is no-op'd if the user set a specific |
