Skip to content

Commit 684e846

Browse files
authored
Merge pull request #928 from evoskuil/master
Add defer_validation/confirmation.
2 parents 63b2036 + 2ea3b28 commit 684e846

File tree

8 files changed

+39
-8
lines changed

8 files changed

+39
-8
lines changed

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class BCN_API chaser_confirm
6969
size_t top) NOEXCEPT;
7070
void announce(const header_link& link, height_t height) NOEXCEPT;
7171

72-
// This is thread safe.
72+
// These are thread safe.
7373
const bool filter_;
74+
const bool defer_;
7475
};
7576

7677
} // namespace node

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class BCN_API chaser_validate
8989
const size_t maximum_backlog_;
9090
const bool node_witness_;
9191
const bool filter_;
92+
const bool defer_;
9293
};
9394

9495
} // namespace node

include/bitcoin/node/settings.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class BCN_API settings
7474
bool headers_first;
7575
bool thread_priority;
7676
bool memory_priority;
77+
bool defer_validation;
78+
bool defer_confirmation;
7779
float allowed_deviation;
7880
uint16_t announcement_cache;
7981
uint16_t allocation_multiple;

src/chasers/chaser_confirm.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
3535

3636
chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT
3737
: chaser(node),
38-
filter_(node.archive().filter_enabled())
38+
filter_(node.archive().filter_enabled()),
39+
defer_(node.config().node.defer_confirmation)
3940
{
4041
}
4142

@@ -49,7 +50,11 @@ code chaser_confirm::start() NOEXCEPT
4950
LOGN("Node is current at startup block [" << position() << "].");
5051
}
5152

52-
SUBSCRIBE_EVENTS(handle_event, _1, _2, _3);
53+
if (!defer_)
54+
{
55+
SUBSCRIBE_EVENTS(handle_event, _1, _2, _3);
56+
}
57+
5358
return error::success;
5459
}
5560

src/chasers/chaser_validate.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
4444
initial_subsidy_(node.config().bitcoin.initial_subsidy()),
4545
maximum_backlog_(node.config().node.maximum_concurrency_()),
4646
node_witness_(node.config().network.witness_node()),
47-
filter_(node.archive().filter_enabled())
47+
filter_(node.archive().filter_enabled()),
48+
defer_(node.config().node.defer_validation)
4849
{
4950
}
5051

@@ -170,12 +171,13 @@ void chaser_validate::do_bumped(height_t height) NOEXCEPT
170171
if (ec == database::error::unassociated)
171172
return;
172173

173-
const auto bypass = is_under_checkpoint(height) ||
174+
const auto bypass = defer_ || is_under_checkpoint(height) ||
174175
query.is_milestone(link);
175176

176177
if (bypass)
177178
{
178-
if (filter_)
179+
// Filters will be set on subsequent unsupressed run.
180+
if (filter_ && !defer_)
179181
{
180182
post_block(link, bypass);
181183
}
@@ -350,9 +352,15 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
350352
}
351353

352354
// VALID BLOCK
355+
// Under deferral there is no state change, but downloads will stall unless
356+
// he window is closed out, so notify the check chaser of the increment.
353357
notify(ec, chase::valid, possible_wide_cast<height_t>(height));
354-
fire(events::block_validated, height);
355-
LOGV("Block validated: " << height << (bypass ? " (bypass)" : ""));
358+
359+
if (!defer_)
360+
{
361+
fire(events::block_validated, height);
362+
LOGV("Block validated: " << height << (bypass ? " (bypass)" : ""));
363+
}
356364
}
357365

358366
// Overrides due to independent priority thread pool

src/parser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,16 @@ options_metadata parser::load_settings() THROWS
10291029
value<bool>(&configured.node.delay_inbound),
10301030
"Delay accepting inbound connections until node is current, defaults to 'true'."
10311031
)
1032+
(
1033+
"node.defer_validation",
1034+
value<bool>(&configured.node.defer_validation),
1035+
"Defer validation, defaults to 'false'."
1036+
)
1037+
(
1038+
"node.defer_confirmation",
1039+
value<bool>(&configured.node.defer_confirmation),
1040+
"Defer confirmation, defaults to 'false'."
1041+
)
10321042
////(
10331043
//// "node.headers_first",
10341044
//// value<bool>(&configured.node.headers_first),

src/settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ settings::settings() NOEXCEPT
8585
headers_first{ true },
8686
memory_priority{ true },
8787
thread_priority{ true },
88+
defer_validation{ false },
89+
defer_confirmation{ false },
8890
allowed_deviation{ 1.5 },
8991
announcement_cache{ 42 },
9092
allocation_multiple{ 20 },

test/settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ BOOST_AUTO_TEST_CASE(settings__node__default_context__expected)
5858
BOOST_REQUIRE_EQUAL(node.thread_priority, true);
5959
BOOST_REQUIRE_EQUAL(node.delay_inbound, true);
6060
BOOST_REQUIRE_EQUAL(node.headers_first, true);
61+
BOOST_REQUIRE_EQUAL(node.defer_validation, false);
62+
BOOST_REQUIRE_EQUAL(node.defer_confirmation, false);
6163
BOOST_REQUIRE_EQUAL(node.allowed_deviation, 1.5);
6264
BOOST_REQUIRE_EQUAL(node.announcement_cache, 42_u16);
6365
BOOST_REQUIRE_EQUAL(node.allocation_multiple, 20_u16);

0 commit comments

Comments
 (0)