Skip to content

Commit

Permalink
Add ledger::force
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 19, 2024
1 parent 379ac5a commit 30af8b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void nano::election::confirm_if_quorum (nano::unique_lock<nano::mutex> & lock_a)
{
status.winner = block_l;
remove_votes (status_winner_hash_l);
node.block_processor.force (block_l);
node.ledger.force (node.store.tx_begin_write (), block_l);
}
if (have_quorum (tally_l))
{
Expand Down
18 changes: 18 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,10 @@ nano::epoch nano::ledger::version (store::transaction const & transaction, nano:

void nano::ledger::confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash)
{
if (confirmed (transaction, hash))
{
return;
}
auto view = unconfirmed (transaction);
debug_assert (unconfirmed_set.block.count (hash) == 1);
std::deque<nano::block_hash> queue;
Expand Down Expand Up @@ -1506,6 +1510,20 @@ void nano::ledger::confirm (nano::store::write_transaction const & transaction,
store.account.put (transaction, account_l, account_info (view, block, representative));
}

void nano::ledger::force (nano::store::write_transaction const & transaction, std::shared_ptr<nano::block> block)
{
auto view = unconfirmed (transaction);
if (view.exists (block->hash ()))
{
return;
}
auto successor = view.successor (block->previous ());
release_assert (successor);
auto error = rollback (transaction, successor.value ());
release_assert (!error);
process (transaction, block);
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (ledger & ledger, std::string const & name)
{
auto count = ledger.bootstrap_weights.size ();
Expand Down
1 change: 1 addition & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ledger final
nano::epoch version (store::transaction const & transaction, nano::block_hash const & hash) const;
void confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash);
nano::account_info account_info (nano::ledger_view & view, nano::block const & block, nano::account const & representative);
void force (nano::store::write_transaction const & transaction, std::shared_ptr<nano::block> block);
static nano::uint128_t const unit;
nano::ledger_constants & constants;
nano::store::component & store;
Expand Down

0 comments on commit 30af8b3

Please sign in to comment.