Skip to content

Commit

Permalink
Merge pull request #559 from evoskuil/master
Browse files Browse the repository at this point in the history
Fix cached chain state -> set to fork point on deorg.
  • Loading branch information
evoskuil authored Mar 11, 2024
2 parents 599d5be + 3d38fcb commit ca0bd0e
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 111 deletions.
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BCN_API chaser

typedef database::store<database::map> store;
typedef database::query<store> query;
DELETE_COPY_MOVE(chaser);
DELETE_COPY_MOVE_DESTRUCT(chaser);

/// Synchronously subscribe to notify and asynchronously initialize state.
virtual code start() NOEXCEPT = 0;
Expand All @@ -129,7 +129,6 @@ class BCN_API chaser
}

chaser(full_node& node) NOEXCEPT;
~chaser() NOEXCEPT;

/// Close the node after logging the code.
void close(const code& ec) const NOEXCEPT;
Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ class BCN_API chaser_block
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_block);
DELETE_COPY_MOVE_DESTRUCT(chaser_block);

chaser_block(full_node& node) NOEXCEPT;
virtual ~chaser_block() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class BCN_API chaser_candidate
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_candidate);
DELETE_COPY_MOVE_DESTRUCT(chaser_candidate);

chaser_candidate(full_node& node) NOEXCEPT;
virtual ~chaser_candidate() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class BCN_API chaser_check
typedef std::function<void(const code&, const map_ptr&)> handler;
typedef std::list<map_ptr> maps;

DELETE_COPY_MOVE(chaser_check);
DELETE_COPY_MOVE_DESTRUCT(chaser_check);

chaser_check(full_node& node) NOEXCEPT;
virtual ~chaser_check() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class BCN_API chaser_confirm
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_confirm);
DELETE_COPY_MOVE_DESTRUCT(chaser_confirm);

chaser_confirm(full_node& node) NOEXCEPT;
virtual ~chaser_confirm() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class BCN_API chaser_connect
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_connect);
DELETE_COPY_MOVE_DESTRUCT(chaser_connect);

chaser_connect(full_node& node) NOEXCEPT;
virtual ~chaser_connect() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand Down
30 changes: 17 additions & 13 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ class BCN_API chaser_header
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_header);
DELETE_COPY_MOVE_DESTRUCT(chaser_header);

chaser_header(full_node& node) NOEXCEPT;
virtual ~chaser_header() NOEXCEPT;

virtual code start() NOEXCEPT;

Expand All @@ -60,12 +59,25 @@ class BCN_API chaser_header
// This is protected by strand.
std::unordered_map<system::hash_digest, proposed_header> tree_{};

/// Disorganize unconfirmable candidate header.
/// -----------------------------------------------------------------------

/// Handle chaser events.
virtual void handle_event(const code& ec, chase event_,
link value) NOEXCEPT;

// Handle events.
virtual void handle_unchecked(header_t height) NOEXCEPT;
// Reorganize the candidate chain due to block invalidity.
virtual void do_disorganize(header_t height) NOEXCEPT;

/// Organize next candidate header.
/// -----------------------------------------------------------------------

/// Validate and organize next header in sequence relative to caller peer.
virtual void do_organize(const system::chain::header::cptr& header,
const organize_handler& handler) NOEXCEPT;

/// Utilities.
/// -----------------------------------------------------------------------

/// Sum of work from header to branch point (excluded).
virtual bool get_branch_work(uint256_t& work, size_t& point,
Expand All @@ -79,7 +91,7 @@ class BCN_API chaser_header
size_t point) const NOEXCEPT;

/// Obtain chain state for the given header hash, nullptr if not found.
virtual system::chain::chain_state::ptr get_state(
virtual system::chain::chain_state::ptr get_chain_state(
const system::hash_digest& hash) const NOEXCEPT;

/// Header timestamp is within configured span from current time.
Expand All @@ -97,14 +109,6 @@ class BCN_API chaser_header
/// Move tree header to database and push to top of candidate chain.
virtual bool push_header(const system::hash_digest& key) NOEXCEPT;

/// Validate and organize next header in sequence relative to caller peer.
virtual void do_organize(const system::chain::header::cptr& header,
const organize_handler& handler) NOEXCEPT;

/// A strong header branch is committed to store when current.
virtual const network::wall_clock::duration& currency_window() const NOEXCEPT;
virtual bool use_currency_window() const NOEXCEPT;

private:
// These are thread safe.
const uint256_t minimum_work_;
Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class BCN_API chaser_transaction
: public chaser
{
public:
DELETE_COPY_MOVE(chaser_transaction);
DELETE_COPY_MOVE_DESTRUCT(chaser_transaction);

chaser_transaction(full_node& node) NOEXCEPT;
virtual ~chaser_transaction() NOEXCEPT;

code start() NOEXCEPT override;
virtual void store(const system::chain::transaction::cptr& block) NOEXCEPT;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace error {
enum error_t : uint8_t
{
success,
unknown,
internal_error,
unexpected_event,

// database
Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ chaser::chaser(full_node& node) NOEXCEPT
{
}

chaser::~chaser() NOEXCEPT
{
}

void chaser::close(const code& ec) const NOEXCEPT
{
LOGF("Chaser failed, " << ec.message());
Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ chaser_block::chaser_block(full_node& node) NOEXCEPT
{
}

chaser_block::~chaser_block() NOEXCEPT
{
}

// start
// ----------------------------------------------------------------------------

Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser_candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ chaser_candidate::chaser_candidate(full_node& node) NOEXCEPT
{
}

chaser_candidate::~chaser_candidate() NOEXCEPT
{
}

// start
// ----------------------------------------------------------------------------

Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ chaser_check::chaser_check(full_node& node) NOEXCEPT
{
}

chaser_check::~chaser_check() NOEXCEPT
{
}

// utility
// ----------------------------------------------------------------------------
// private
Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT
{
}

chaser_confirm::~chaser_confirm() NOEXCEPT
{
}

// start
// ----------------------------------------------------------------------------

Expand Down
4 changes: 0 additions & 4 deletions src/chasers/chaser_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ chaser_connect::chaser_connect(full_node& node) NOEXCEPT
{
}

chaser_connect::~chaser_connect() NOEXCEPT
{
}

// start
// ----------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit ca0bd0e

Please sign in to comment.