Skip to content

Commit ed7c64e

Browse files
committed
Implement reorg lock in node and pass thru chaser base.
1 parent 10a4956 commit ed7c64e

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

include/bitcoin/node/chasers/chaser.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class BCN_API chaser
9393
/// Reset store disk full condition.
9494
virtual code reload(const store::event_handler& handler) NOEXCEPT;
9595

96+
/// Get reorganization lock.
97+
virtual lock get_reorganization_lock() NOEXCEPT;
98+
9699
/// Events.
97100
/// -----------------------------------------------------------------------
98101

include/bitcoin/node/define.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/// Standard includes (do not include directly).
2323
#include <functional>
2424
#include <memory>
25+
#include <mutex>
2526
#include <utility>
2627
#include <variant>
2728

@@ -57,6 +58,7 @@ typedef std::error_code code;
5758
typedef std::function<void(const code&, size_t)> organize_handler;
5859
typedef database::store<database::map> store;
5960
typedef database::query<store> query;
61+
typedef std::unique_lock<std::mutex> lock;
6062

6163
/// Work types.
6264
typedef network::race_all<const code&> job;

include/bitcoin/node/full_node.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class BCN_API full_node
139139
/// Get the memory resource.
140140
virtual network::memory& get_memory() NOEXCEPT;
141141

142+
/// Get reorganization lock.
143+
/// Used to prevent candidate chain reorganization during confirmation.
144+
virtual lock get_reorganization_lock() NOEXCEPT;
145+
142146
protected:
143147
/// Session attachments.
144148
/// -----------------------------------------------------------------------
@@ -161,6 +165,7 @@ class BCN_API full_node
161165

162166
// These are thread safe.
163167
const configuration& config_;
168+
std::mutex reorganization_mutex_{};
164169
memory_controller memory_;
165170
query& query_;
166171

src/chasers/chaser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ code chaser::reload(const store::event_handler& handler) NOEXCEPT
8383
return node_.reload(handler);
8484
}
8585

86+
lock chaser::get_reorganization_lock() NOEXCEPT
87+
{
88+
return node_.get_reorganization_lock();
89+
}
90+
8691
// Events.
8792
// ----------------------------------------------------------------------------
8893

src/full_node.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ network::memory& full_node::get_memory() NOEXCEPT
370370
return memory_;
371371
}
372372

373+
lock full_node::get_reorganization_lock() NOEXCEPT
374+
{
375+
return lock{ reorganization_mutex_ };
376+
}
377+
373378
// Session attachments.
374379
// ----------------------------------------------------------------------------
375380

0 commit comments

Comments
 (0)