Skip to content

Commit eb1b18f

Browse files
committed
Merge pull request #148 from evoskuil/version2
Fix subscription, add OpenBSD to build, use config settings.
2 parents f36a055 + 0d9e8eb commit eb1b18f

File tree

6 files changed

+170
-98
lines changed

6 files changed

+170
-98
lines changed

include/bitcoin/server/server_node.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ class BCS_API server_node
6969
const incoming_message& request, queue_send_callback queue_send);
7070

7171
protected:
72-
// Result of store operation in transaction pool.
73-
virtual void new_unconfirm_valid_tx(const std::error_code& ec,
74-
const index_list& unconfirmed, const transaction_type& tx);
72+
bool handle_tx(const std::error_code& ec, const index_list& unconfirmed,
73+
const transaction_type& tx);
7574

76-
virtual void broadcast_new_blocks(const std::error_code& ec,
77-
uint32_t fork_point, const chain::blockchain::block_list& new_blocks,
78-
const chain::blockchain::block_list& replaced_blocks);
75+
bool handle_reorg(const std::error_code& ec, uint64_t fork_point,
76+
const chain::blockchain::block_list& new_blocks,
77+
const chain::blockchain::block_list&);
7978

8079
private:
8180
typedef std::vector<block_notify_callback> block_notify_list;

include/bitcoin/server/subscribe_manager.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <cstdint>
2424
#include <unordered_map>
25+
#include <vector>
2526
#include <boost/date_time/posix_time/posix_time.hpp>
2627
#include <bitcoin/bitcoin.hpp>
2728
#include <bitcoin/server/define.hpp>
@@ -41,7 +42,7 @@ enum class subscribe_type
4142
class BCS_API subscribe_manager
4243
{
4344
public:
44-
subscribe_manager(server_node& node,
45+
subscribe_manager(server_node& server,
4546
uint32_t maximum_subscriptions=100000000,
4647
uint32_t subscription_expiration_minutes=10);
4748

@@ -74,11 +75,16 @@ class BCS_API subscribe_manager
7475
queue_send_callback queue_send);
7576
void do_submit(size_t height, const hash_digest& block_hash,
7677
const transaction_type& tx);
77-
void post_updates(const payment_address& address,
78-
size_t height, const hash_digest& block_hash,
79-
const transaction_type& tx);
80-
void post_stealth_updates(const binary_type& prefix, size_t height,
78+
79+
void post(const std::vector<payment_address>& addresses, size_t height,
80+
const hash_digest& block_hash, const transaction_type& tx);
81+
void post(const std::vector<binary_type>& prefixes, size_t height,
8182
const hash_digest& block_hash, const transaction_type& tx);
83+
void post(const payment_address& address, size_t height,
84+
const hash_digest& block_hash, const transaction_type& tx);
85+
void post(const binary_type& prefix, size_t height,
86+
const hash_digest& block_hash, const transaction_type& tx);
87+
8288
void sweep_expired();
8389

8490
sequencer strand_;

install.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ set -e
6161
#------------------------------------------------------------------------------
6262
SEQUENTIAL=1
6363
OS=`uname -s`
64-
if [[ $TRAVIS == true ]]; then
64+
if [[ $PARALLEL ]]; then
65+
echo "Using shell-defined PARALLEL value."
66+
elif [[ $TRAVIS == true ]]; then
6567
PARALLEL=$SEQUENTIAL
6668
elif [[ $OS == Linux ]]; then
6769
PARALLEL=`nproc`
68-
elif [[ $OS == Darwin ]]; then
70+
elif [[ ($OS == Darwin) || ($OS == OpenBSD) ]]; then
6971
PARALLEL=`sysctl -n hw.ncpu`
7072
else
7173
echo "Unsupported system: $OS"
@@ -81,14 +83,20 @@ if [[ $OS == Darwin ]]; then
8183
export CC="clang"
8284
export CXX="clang++"
8385
LIBC="libc++"
84-
86+
8587
# Always initialize prefix on OSX so default is useful.
8688
PREFIX="/usr/local"
89+
elif [[ $OS == OpenBSD ]]; then
90+
make() { gmake "$@"; }
91+
export CC="egcc"
92+
export CXX="eg++"
93+
LIBC="libestdc++"
8794
else
8895
LIBC="libstdc++"
8996
fi
9097
echo "Make with cc: $CC"
9198
echo "Make with cxx: $CXX"
99+
echo "Make with stdlib: $LIBC"
92100

93101
# Define compiler specific settings.
94102
#------------------------------------------------------------------------------
@@ -357,7 +365,7 @@ initialize_boost_icu()
357365

358366
initialize_icu_packages()
359367
{
360-
if [[ $OS == Darwin && !($BUILD_ICU) ]]; then
368+
if [[ ($OS == Darwin) && !($BUILD_ICU) ]]; then
361369
# Update PKG_CONFIG_PATH for ICU package installations on OSX.
362370
# OSX provides libicucore.dylib with no pkgconfig and doesn't support
363371
# renaming or important features, so we can't use that.

src/dispatch.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,13 @@ static console_result run(const settings_type& config, std::ostream& output,
268268
}
269269

270270
// By the current design this must be kept in scope until end of run.
271-
subscribe_manager subscriber(full_node);
271+
subscribe_manager subscriber(full_node, config.server.subscription_limit,
272+
config.server.subscription_expiration_minutes);
273+
274+
request_worker worker(config.server.log_requests,
275+
config.server.heartbeat_interval_seconds,
276+
config.server.polling_interval_milliseconds);
272277

273-
request_worker worker;
274278
if (config.server.queries_enabled)
275279
{
276280
if (!worker.start(config))

src/server_node.cpp

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ using namespace bc::chain;
3636
using namespace bc::node;
3737
using std::placeholders::_1;
3838
using std::placeholders::_2;
39+
using std::placeholders::_3;
40+
using std::placeholders::_4;
3941

4042
const settings_type server_node::defaults
4143
{
@@ -111,7 +113,20 @@ server_node::server_node(const settings_type& config)
111113

112114
bool 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

117132
void 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

161189
void server_node::fullnode_fetch_history(server_node& node,

0 commit comments

Comments
 (0)