Skip to content

Commit 30af8b3

Browse files
committed
Add ledger::force
1 parent 379ac5a commit 30af8b3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

nano/node/election.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void nano::election::confirm_if_quorum (nano::unique_lock<nano::mutex> & lock_a)
393393
{
394394
status.winner = block_l;
395395
remove_votes (status_winner_hash_l);
396-
node.block_processor.force (block_l);
396+
node.ledger.force (node.store.tx_begin_write (), block_l);
397397
}
398398
if (have_quorum (tally_l))
399399
{

nano/secure/ledger.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,10 @@ nano::epoch nano::ledger::version (store::transaction const & transaction, nano:
13821382

13831383
void nano::ledger::confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash)
13841384
{
1385+
if (confirmed (transaction, hash))
1386+
{
1387+
return;
1388+
}
13851389
auto view = unconfirmed (transaction);
13861390
debug_assert (unconfirmed_set.block.count (hash) == 1);
13871391
std::deque<nano::block_hash> queue;
@@ -1506,6 +1510,20 @@ void nano::ledger::confirm (nano::store::write_transaction const & transaction,
15061510
store.account.put (transaction, account_l, account_info (view, block, representative));
15071511
}
15081512

1513+
void nano::ledger::force (nano::store::write_transaction const & transaction, std::shared_ptr<nano::block> block)
1514+
{
1515+
auto view = unconfirmed (transaction);
1516+
if (view.exists (block->hash ()))
1517+
{
1518+
return;
1519+
}
1520+
auto successor = view.successor (block->previous ());
1521+
release_assert (successor);
1522+
auto error = rollback (transaction, successor.value ());
1523+
release_assert (!error);
1524+
process (transaction, block);
1525+
}
1526+
15091527
std::unique_ptr<nano::container_info_component> nano::collect_container_info (ledger & ledger, std::string const & name)
15101528
{
15111529
auto count = ledger.bootstrap_weights.size ();

nano/secure/ledger.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ledger final
7575
nano::epoch version (store::transaction const & transaction, nano::block_hash const & hash) const;
7676
void confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash);
7777
nano::account_info account_info (nano::ledger_view & view, nano::block const & block, nano::account const & representative);
78+
void force (nano::store::write_transaction const & transaction, std::shared_ptr<nano::block> block);
7879
static nano::uint128_t const unit;
7980
nano::ledger_constants & constants;
8081
nano::store::component & store;

0 commit comments

Comments
 (0)