@@ -36,6 +36,8 @@ using namespace bc::chain;
3636using namespace bc ::node;
3737using std::placeholders::_1;
3838using std::placeholders::_2;
39+ using std::placeholders::_3;
40+ using std::placeholders::_4;
3941
4042const settings_type server_node::defaults
4143{
@@ -111,7 +113,20 @@ server_node::server_node(const settings_type& config)
111113
112114bool server_node::start (const settings_type& config)
113115{
114- return full_node::start (config);
116+ if (!full_node::start (config))
117+ return false ;
118+
119+ // Subscribe to reorganizations.
120+ blockchain_.subscribe_reorganize (
121+ std::bind (&server_node::handle_reorg,
122+ this , _1, _2, _3, _4));
123+
124+ // Subscribe to mempool acceptances.
125+ tx_pool_.subscribe_transaction (
126+ std::bind (&server_node::handle_tx,
127+ this , _1, _2, _3));
128+
129+ return true ;
115130}
116131
117132void server_node::subscribe_blocks (block_notify_callback notify_block)
@@ -124,38 +139,51 @@ void server_node::subscribe_transactions(transaction_notify_callback notify_tx)
124139 tx_subscriptions_.push_back (notify_tx);
125140}
126141
127- void server_node::new_unconfirm_valid_tx (const std::error_code& ec,
142+ bool server_node::handle_tx (const std::error_code& ec,
128143 const index_list& unconfirmed, const transaction_type& tx)
129144{
130- full_node::new_unconfirm_valid_tx (ec, unconfirmed, tx);
131-
132145 if (ec == bc::error::service_stopped)
133- return ;
146+ return false ;
147+
148+ if (ec)
149+ {
150+ log_error (LOG_SERVICE)
151+ << " Failure handling tx: " << ec.message ();
152+ return false ;
153+ }
134154
135155 // Fire server protocol tx subscription notifications.
136156 for (const auto notify: tx_subscriptions_)
137157 notify (tx);
158+
159+ return true ;
138160}
139161
140- void server_node::broadcast_new_blocks (const std::error_code& ec,
141- uint32_t fork_point, const blockchain::block_list& new_blocks,
142- const blockchain::block_list& replaced_blocks)
162+ bool server_node::handle_reorg (const std::error_code& ec, uint64_t fork_point,
163+ const blockchain::block_list& new_blocks, const blockchain::block_list&)
143164{
144- broadcast_new_blocks (ec, fork_point, new_blocks, replaced_blocks);
145-
146165 if (ec == bc::error::service_stopped)
147- return ;
166+ return false ;
148167
149168 if (fork_point < minimum_start_height_)
150- return ;
169+ return false ;
170+
171+ if (ec)
172+ {
173+ log_error (LOG_SERVICE)
174+ << " Failure handling reorg: " << ec.message ();
175+ return false ;
176+ }
177+
178+ BITCOIN_ASSERT (fork_point < max_size_t - new_blocks.size ());
179+ auto height = static_cast <size_t >(fork_point);
151180
152181 // Fire server protocol block subscription notifications.
153182 for (auto new_block: new_blocks)
154- {
155- const size_t height = ++fork_point;
156183 for (const auto notify: block_sunscriptions_)
157- notify (height, *new_block);
158- }
184+ notify (++height, *new_block);
185+
186+ return true ;
159187}
160188
161189void server_node::fullnode_fetch_history (server_node& node,
0 commit comments