-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the process_live_dipatcher class (#4181)
* Add the process_live_dispatcher class * Move from block_processor::process_live to process_live_dispatcher class * Remove block_post_events class
- Loading branch information
Showing
7 changed files
with
100 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <nano/lib/blocks.hpp> | ||
#include <nano/node/blockprocessor.hpp> | ||
#include <nano/node/election_scheduler.hpp> | ||
#include <nano/node/process_live_dispatcher.hpp> | ||
#include <nano/node/vote_cache.hpp> | ||
#include <nano/node/websocket.hpp> | ||
#include <nano/secure/common.hpp> | ||
#include <nano/secure/ledger.hpp> | ||
#include <nano/secure/store.hpp> | ||
|
||
nano::process_live_dispatcher::process_live_dispatcher (nano::ledger & ledger, nano::election_scheduler & scheduler, nano::vote_cache & inactive_vote_cache, nano::websocket_server & websocket) : | ||
ledger{ ledger }, | ||
scheduler{ scheduler }, | ||
inactive_vote_cache{ inactive_vote_cache }, | ||
websocket{ websocket } | ||
{ | ||
} | ||
|
||
void nano::process_live_dispatcher::connect (nano::block_processor & block_processor) | ||
{ | ||
block_processor.batch_processed.add ([this] (auto const & batch) { | ||
auto const transaction = ledger.store.tx_begin_read (); | ||
for (auto const & [result, block] : batch) | ||
{ | ||
debug_assert (block != nullptr); | ||
inspect (result, *block, transaction); | ||
} | ||
}); | ||
} | ||
|
||
void nano::process_live_dispatcher::inspect (nano::process_return const & result, nano::block const & block, nano::transaction const & transaction) | ||
{ | ||
switch (result.code) | ||
{ | ||
case nano::process_result::progress: | ||
process_live (block, transaction); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void nano::process_live_dispatcher::process_live (nano::block const & block, nano::transaction const & transaction) | ||
{ | ||
// Start collecting quorum on block | ||
if (ledger.dependents_confirmed (transaction, block)) | ||
{ | ||
auto account = block.account ().is_zero () ? block.sideband ().account : block.account (); | ||
scheduler.activate (account, transaction); | ||
} | ||
|
||
// Notify inactive vote cache about a new live block | ||
inactive_vote_cache.trigger (block.hash ()); | ||
|
||
if (websocket.server && websocket.server->any_subscriber (nano::websocket::topic::new_unconfirmed_block)) | ||
{ | ||
websocket.server->broadcast (nano::websocket::message_builder ().new_block_arrived (block)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
namespace nano | ||
{ | ||
class ledger; | ||
class election_scheduler; | ||
class vote_cache; | ||
class websocket_server; | ||
class block_processor; | ||
class process_return; | ||
class block; | ||
class transaction; | ||
|
||
// Observes confirmed blocks and dispatches the process_live function. | ||
class process_live_dispatcher | ||
{ | ||
public: | ||
process_live_dispatcher (nano::ledger & ledger, nano::election_scheduler & scheduler, nano::vote_cache & inactive_vote_cache, nano::websocket_server & websocket); | ||
void connect (nano::block_processor & block_processor); | ||
|
||
private: | ||
// Block_processor observer | ||
void inspect (nano::process_return const & result, nano::block const & block, nano::transaction const & transaction); | ||
void process_live (nano::block const & block, nano::transaction const & transaction); | ||
|
||
nano::ledger & ledger; | ||
nano::election_scheduler & scheduler; | ||
nano::vote_cache & inactive_vote_cache; | ||
nano::websocket_server & websocket; | ||
}; | ||
} |