Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental ledger pruning #2881

Merged
merged 125 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
c6a8020
Experimental ledger pruning
SergiySW Aug 13, 2020
90727b8
Minumum 5 minutes pruning age
SergiySW Aug 13, 2020
4deb894
Formatting
SergiySW Aug 13, 2020
1757b9c
Cache pruned block count
SergiySW Aug 13, 2020
db97682
Formatting
SergiySW Aug 13, 2020
08ccf6d
Update unit tests to wait for next election activation
SergiySW Aug 14, 2020
de7ba56
Update bulk.genesis_pruning test to prevent long bootstrap
SergiySW Aug 14, 2020
df6ee27
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Aug 14, 2020
f3a1ddb
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Aug 14, 2020
a95c0f4
Pruned cache cannot guarantee that pruned blocks are already commited
SergiySW Aug 14, 2020
3ac8895
Fix merge error
SergiySW Aug 14, 2020
3bc6b47
Fix merge error
SergiySW Aug 14, 2020
cdb1518
Wesley suggestion to receive exact pruned block count
SergiySW Aug 14, 2020
9315f2f
Formatting
SergiySW Aug 14, 2020
ddefff7
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Aug 14, 2020
91adda5
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Aug 26, 2020
bb6e867
Fix merge error
SergiySW Aug 26, 2020
fccf9d9
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 1, 2020
fd38029
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 3, 2020
845f31e
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 10, 2020
e1fcbce
Fix merge issue
SergiySW Sep 10, 2020
e40072a
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 10, 2020
7172984
Fix merge issues
SergiySW Sep 10, 2020
2a49840
Fix RocksDB build error
SergiySW Sep 10, 2020
fcb0a7e
Fix merge issues for strict uint256_union type
SergiySW Sep 10, 2020
a80d1bf
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 10, 2020
0dc7238
Confirmation height pruned source test
SergiySW Sep 10, 2020
b8fe757
Update pruned source confirmation height test
SergiySW Sep 10, 2020
ad5c712
Wesley's correct confirmation_height.pruned_source test
SergiySW Sep 10, 2020
c3cedf5
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 10, 2020
fc7d37f
Wesley's fix confirmation height infinite loop for pruned source
SergiySW Sep 10, 2020
c48af08
Apply Wesley review
SergiySW Sep 10, 2020
0434bc5
Wesley's fix for RocksDB pruned issue
SergiySW Sep 10, 2020
1a3107b
Extremely frequent pruning for beta network to catch possible issues
SergiySW Sep 10, 2020
3d3e710
Move pruning table creation to new mdb upgrade
guilhermelawless Sep 11, 2020
47c51a9
Shutdown node if voting with any pruned blocks recorded
guilhermelawless Sep 11, 2020
9feb0c8
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 11, 2020
3776a1f
Fix possible QT wallet crashes with pruning
SergiySW Sep 11, 2020
d67c01f
Prevent pruned node start without proper flag
SergiySW Sep 11, 2020
a1a5d5d
QT pruned history test
SergiySW Sep 11, 2020
86ff7f6
Fix test & receive block amount
SergiySW Sep 11, 2020
7825f5e
Add doc to ledger::amount_safe
guilhermelawless Sep 11, 2020
21a7346
Support pending blocks for wallet search pending & receive async actions
SergiySW Sep 12, 2020
62c5e27
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
guilhermelawless Sep 14, 2020
274c4c7
Formatting
guilhermelawless Sep 14, 2020
da393f4
Fix pruning setting incompatibility check
guilhermelawless Sep 14, 2020
7b2e278
Fix tests for Guilherme's changes
SergiySW Sep 14, 2020
cdfa698
Wallet receive pruned & search pending pruned tests
SergiySW Sep 14, 2020
f3a5715
Pending blocks support for RPC "receive"
SergiySW Sep 14, 2020
1f8e5e6
Formatting
SergiySW Sep 14, 2020
cebeb0f
Use non-atomic value for ledger pruning boolean
SergiySW Sep 14, 2020
30fad44
Don't check voting for pruned inactive node
SergiySW Sep 14, 2020
1e610a3
Relax --enable_pruning requirements for CLI commands
SergiySW Sep 14, 2020
93d75df
Add pruning mode check for block confirmation in search_pending
SergiySW Sep 14, 2020
d9093fa
Prevent possible scan_receivable () assert
SergiySW Sep 14, 2020
d645364
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 14, 2020
fac293b
Fix merge
SergiySW Sep 14, 2020
cbccadb
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 15, 2020
6050dd1
Fix bulk.genesis_pruning test
SergiySW Sep 15, 2020
7d0184b
Increase tests frontiers confirmation speed
SergiySW Sep 15, 2020
36d119a
Improve bulk.genesis_pruning test
SergiySW Sep 16, 2020
80123e1
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 16, 2020
2c34e38
Remove unused db value conversion
SergiySW Sep 16, 2020
01fec74
Revert "Remove unused db value conversion"
SergiySW Sep 16, 2020
2b1bbde
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 17, 2020
728053b
block destination () function
SergiySW Sep 17, 2020
a649220
Fix comment
SergiySW Sep 17, 2020
16650ee
Fix build error from merge
guilhermelawless Sep 18, 2020
7761fc3
Formatting
guilhermelawless Sep 18, 2020
c5f0004
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 18, 2020
fcaf45b
Fix merge
SergiySW Sep 18, 2020
da83edf
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 21, 2020
c512ba1
Remove unused function
SergiySW Sep 21, 2020
a191351
Merge remote-tracking branch 'upstream/develop' into block_destination
SergiySW Sep 21, 2020
16e5043
Check block destination, source, link in block builder tests
SergiySW Sep 21, 2020
13edbaa
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 23, 2020
7baab92
Remove unused variables & RocksDB pruned count calculation
SergiySW Sep 23, 2020
e4c70e4
Typo
SergiySW Sep 23, 2020
ff8159a
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 23, 2020
ff9e84d
Use election->force_confirm ()
SergiySW Sep 23, 2020
8008412
Rename prune () function to pruning_action ()
SergiySW Sep 23, 2020
945cbf8
Fix
SergiySW Sep 23, 2020
cf859af
Make functions const (Wesley review)
SergiySW Sep 23, 2020
6896365
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 24, 2020
b2bd94f
[Pruning] Suppord pruned blocks in bootstrap actions
SergiySW Sep 24, 2020
347b5c3
Improve gap cache check
SergiySW Sep 24, 2020
ab0ef40
Replace not-yet-introduced function
SergiySW Sep 24, 2020
f217c76
Use const reference for hash-root pair
SergiySW Sep 25, 2020
9764cad
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 26, 2020
2e31f93
Fix merge
SergiySW Sep 28, 2020
8b444cf
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 28, 2020
4552fbc
Fix open block pruned source rollback & add test (Guilherme review)
SergiySW Sep 28, 2020
78b3fed
Add state block comment
SergiySW Sep 28, 2020
1ccd9c3
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Sep 29, 2020
77cab6e
Guilherme review
SergiySW Sep 29, 2020
3c10f8b
Fix processing open/receive blocks with pruned source after rollback
SergiySW Sep 29, 2020
0f79b34
Use C++17 [[maybe_unused]]
SergiySW Oct 2, 2020
3bf5f07
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 2, 2020
583d265
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 2, 2020
42c28d8
Fix build error
SergiySW Oct 2, 2020
1ea4e3c
Merge remote-tracking branch 'upstream/develop' into pruning/bootstra…
SergiySW Oct 3, 2020
91b7204
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 3, 2020
8dcf8d0
Fix bootstrap_processor.lazy_pruning_missing_block test
SergiySW Oct 3, 2020
0bca97b
Merge branch 'block_destination' into store/pruning_experimental
SergiySW Oct 3, 2020
f60f9de
Remove scan_receivable () function
SergiySW Oct 3, 2020
1f80d77
Fix build
SergiySW Oct 3, 2020
746230c
Inline transaction usage in tests (Wesley review)
SergiySW Oct 7, 2020
dfe0e04
Void unused variable
SergiySW Oct 7, 2020
042c080
Fix inline transactions
SergiySW Oct 7, 2020
a41257c
Fix inline transactions
SergiySW Oct 7, 2020
bc2ab69
Fix inline transactions
SergiySW Oct 7, 2020
23bab80
Merge remote-tracking branch 'upstream/develop' into pruning/bootstra…
SergiySW Oct 8, 2020
96c378f
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 8, 2020
0ec5271
Increase timeout for MacOS X actions
SergiySW Oct 8, 2020
aba0f3b
Use node flags for node2
SergiySW Oct 8, 2020
49d6859
Merge peer (OS X failures)
SergiySW Oct 8, 2020
c9abf5c
Disable ongoing bootstrap for specific tests
SergiySW Oct 8, 2020
b7bfadb
Add small delay for frontiers confirmation failure restart
SergiySW Oct 8, 2020
57826c6
Merge branch 'pruning/bootstrap_support' into store/pruning_experimental
SergiySW Oct 9, 2020
81d4bc5
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 12, 2020
aaf0de6
RPC pruned_exists
SergiySW Oct 13, 2020
2427060
Use read transaction refresh () [Wesley review]
SergiySW Oct 14, 2020
9ef9ba1
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Oct 28, 2020
cc1bd35
Merge remote-tracking branch 'upstream/develop' into store/pruning_ex…
SergiySW Nov 6, 2020
e65e90d
Fix merge issue
SergiySW Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ TEST (block_builder, state)
.link_hex ("E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86");
}

TEST (block_builder, state_missing_rep)
Expand Down Expand Up @@ -573,6 +576,9 @@ TEST (block_builder, open)
.source_hex ("E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948");
ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA");
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
}

TEST (block_builder, open_equality)
Expand Down Expand Up @@ -609,6 +615,9 @@ TEST (block_builder, change)
.previous_hex ("088EE46429CA936F76C4EAA20B97F6D33E5D872971433EE0C1311BCB98764456")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
}

TEST (block_builder, change_equality)
Expand Down Expand Up @@ -645,6 +654,9 @@ TEST (block_builder, send)
.balance_hex ("00F035A9C7D818E7C34148C524FFFFEE")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_EQ (block->destination ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb");
ASSERT_TRUE (block->link ().is_zero ());
}

TEST (block_builder, send_equality)
Expand Down Expand Up @@ -704,4 +716,7 @@ TEST (block_builder, receive)
.source_hex ("7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722");
ASSERT_EQ (block->source ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135");
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
}
15 changes: 3 additions & 12 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
}
ASSERT_TIMELY (2s, node1->active.empty () && node1->block_confirmed (change2->hash ()));
// Pruning action
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_EQ (3, node1->ledger.pruning_action (transaction, change1->hash (), 1));
}
node1->ledger_pruning (2, false, false);
ASSERT_EQ (9, node0->ledger.cache.block_count);
ASSERT_EQ (0, node0->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
Expand Down Expand Up @@ -931,10 +928,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
}
ASSERT_TIMELY (2s, node1->active.empty () && node1->block_confirmed (state_open->hash ()));
// Pruning action
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1));
}
node1->ledger_pruning (2, false, false);
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (1, node1->ledger.cache.pruned_count);
ASSERT_FALSE (node1->ledger.block_exists (send1->hash ()));
Expand Down Expand Up @@ -1362,10 +1356,7 @@ TEST (bulk, genesis_pruning)
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1->active.empty () && node1->block_confirmed (send3->hash ()));
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_EQ (2, node1->ledger.pruning_action (transaction, send2->hash (), 2));
}
node1->ledger_pruning (2, false, false);
ASSERT_EQ (2, node1->ledger.cache.pruned_count);
ASSERT_EQ (4, node1->ledger.cache.block_count);
ASSERT_FALSE (node1->ledger.block_exists (send1->hash ()));
Expand Down
168 changes: 168 additions & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,174 @@ TEST (online_reps, backup)
ASSERT_EQ (0, online_reps.list ().size ());
}

TEST (node, pruning_automatic)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.max_pruning_age = std::chrono::seconds (1);
node_config.enable_voting = false; // Remove after allowing pruned voting
nano::node_flags node_flags;
node_flags.enable_pruning = true;
auto & node1 = *system.add_node (node_config, node_flags);
nano::genesis genesis;
nano::keypair key1;
auto send1 = nano::send_block_builder ()
.previous (genesis.hash ())
.destination (key1.pub)
.balance (nano::genesis_amount - nano::Gxrb_ratio)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (genesis.hash ()))
.build_shared ();
auto send2 = nano::send_block_builder ()
.previous (send1->hash ())
.destination (key1.pub)
.balance (0)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
.build_shared ();
// Process as local blocks
node1.process_active (send1);
node1.process_active (send2);
node1.block_processor.flush ();
// Confirm last block to prune previous
{
auto election = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.block_confirmed (send1->hash ()) && node1.active.active (send2->qualified_root ()));
ASSERT_EQ (0, node1.ledger.cache.pruned_count);
{
auto election = node1.active.election (send2->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.active.empty () && node1.block_confirmed (send2->hash ()));
// Check pruning result
ASSERT_TIMELY (3s, node1.ledger.cache.pruned_count == 1);
ASSERT_TIMELY (2s, node1.store.pruned_count (node1.store.tx_begin_read ()) == 1); // Transaction commit
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
ASSERT_EQ (3, node1.ledger.cache.block_count);
ASSERT_TRUE (node1.ledger.block_exists (genesis.hash ()));
ASSERT_FALSE (node1.ledger.block_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_exists (send2->hash ()));
}

TEST (node, pruning_age)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.enable_voting = false; // Remove after allowing pruned voting
nano::node_flags node_flags;
node_flags.enable_pruning = true;
auto & node1 = *system.add_node (node_config, node_flags);
nano::genesis genesis;
nano::keypair key1;
auto send1 = nano::send_block_builder ()
.previous (genesis.hash ())
.destination (key1.pub)
.balance (nano::genesis_amount - nano::Gxrb_ratio)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (genesis.hash ()))
.build_shared ();
auto send2 = nano::send_block_builder ()
.previous (send1->hash ())
.destination (key1.pub)
.balance (0)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
.build_shared ();
// Process as local blocks
node1.process_active (send1);
node1.process_active (send2);
node1.block_processor.flush ();
// Confirm last block to prune previous
{
auto election = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.block_confirmed (send1->hash ()) && node1.active.active (send2->qualified_root ()));
ASSERT_EQ (0, node1.ledger.cache.pruned_count);
{
auto election = node1.active.election (send2->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.active.empty () && node1.block_confirmed (send2->hash ()));
// Pruning with default age 1 day
node1.ledger_pruning (1, true, false);
ASSERT_EQ (0, node1.ledger.cache.pruned_count);
ASSERT_EQ (3, node1.ledger.cache.block_count);
// Pruning with max age 0
node1.config.max_pruning_age = std::chrono::seconds (0);
node1.ledger_pruning (1, true, false);
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
ASSERT_EQ (3, node1.ledger.cache.block_count);
ASSERT_TRUE (node1.ledger.block_exists (genesis.hash ()));
ASSERT_FALSE (node1.ledger.block_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_exists (send2->hash ()));
}

TEST (node, pruning_depth)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.enable_voting = false; // Remove after allowing pruned voting
nano::node_flags node_flags;
node_flags.enable_pruning = true;
auto & node1 = *system.add_node (node_config, node_flags);
nano::genesis genesis;
nano::keypair key1;
auto send1 = nano::send_block_builder ()
.previous (genesis.hash ())
.destination (key1.pub)
.balance (nano::genesis_amount - nano::Gxrb_ratio)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (genesis.hash ()))
.build_shared ();
auto send2 = nano::send_block_builder ()
.previous (send1->hash ())
.destination (key1.pub)
.balance (0)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
.build_shared ();
// Process as local blocks
node1.process_active (send1);
node1.process_active (send2);
node1.block_processor.flush ();
// Confirm last block to prune previous
{
auto election = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.block_confirmed (send1->hash ()) && node1.active.active (send2->qualified_root ()));
ASSERT_EQ (0, node1.ledger.cache.pruned_count);
{
auto election = node1.active.election (send2->qualified_root ());
ASSERT_NE (nullptr, election);
election->force_confirm ();
}
ASSERT_TIMELY (2s, node1.active.empty () && node1.block_confirmed (send2->hash ()));
// Pruning with default depth (unlimited)
node1.ledger_pruning (1, true, false);
ASSERT_EQ (0, node1.ledger.cache.pruned_count);
ASSERT_EQ (3, node1.ledger.cache.block_count);
// Pruning with max depth 1
node1.config.max_pruning_depth = 1;
node1.ledger_pruning (1, true, false);
ASSERT_EQ (1, node1.ledger.cache.pruned_count);
ASSERT_EQ (3, node1.ledger.cache.block_count);
ASSERT_TRUE (node1.ledger.block_exists (genesis.hash ()));
ASSERT_FALSE (node1.ledger.block_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_TRUE (node1.ledger.block_exists (send2->hash ()));
}

namespace
{
void add_required_children_node_config_tree (nano::jsonconfig & tree)
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ std::string nano::error_rpc_messages::message (int ev) const
return "Unable to create transaction account";
case nano::error_rpc::peer_not_found:
return "Peer not found";
case nano::error_rpc::pruning_disabled:
return "Pruning is disabled";
case nano::error_rpc::requires_port_and_address:
return "Both port and address required";
case nano::error_rpc::rpc_control_disabled:
Expand Down
1 change: 1 addition & 0 deletions nano/lib/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum class error_rpc
payment_account_balance,
payment_unable_create_account,
peer_not_found,
pruning_disabled,
requires_port_and_address,
rpc_control_disabled,
sign_hash_disabled,
Expand Down
10 changes: 10 additions & 0 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ int main (int argc, char * const * argv)
("debug_account_versions", "Display the total counts of each version for all accounts (including unpocketed)")
("debug_unconfirmed_frontiers", "Displays the account, height (sorted), frontier and cemented frontier for all accounts which are not fully confirmed")
("validate_blocks,debug_validate_blocks", "Check all blocks for correct hash, signature, work value")
("debug_prune", "Prune accounts up to last confirmed blocks (EXPERIMENTAL)")
("platform", boost::program_options::value<std::string> (), "Defines the <platform> for OpenCL commands")
("device", boost::program_options::value<std::string> (), "Defines <device> for OpenCL command")
("threads", boost::program_options::value<std::string> (), "Defines <threads> count for various commands")
Expand Down Expand Up @@ -1895,6 +1896,15 @@ int main (int argc, char * const * argv)
nano::inactive_node node (data_path, node_flags);
std::cout << "Total cemented block count: " << node.node->ledger.cache.cemented_count << std::endl;
}
else if (vm.count ("debug_prune"))
{
auto node_flags = nano::inactive_node_flag_defaults ();
node_flags.read_only = false;
nano::update_flags (node_flags, vm);
nano::inactive_node inactive_node (data_path, node_flags);
auto node = inactive_node.node;
node->ledger_pruning (node_flags.block_processor_batch_size != 0 ? node_flags.block_processor_batch_size : 16 * 1024, true, true);
}
else if (vm.count ("debug_stacktrace"))
{
std::cout << boost::stacktrace::stacktrace ();
Expand Down
20 changes: 20 additions & 0 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,25 @@ void nano::json_handler::process ()
}));
}

void nano::json_handler::pruned_exists ()
{
auto hash (hash_impl ());
if (!ec)
{
auto transaction (node.store.tx_begin_read ());
if (node.ledger.pruning)
{
auto exists (node.store.pruned_exists (transaction, hash));
response_l.put ("exists", exists ? "1" : "0");
}
else
{
ec = nano::error_rpc::pruning_disabled;
}
}
response_errors ();
}

void nano::json_handler::receive ()
{
auto wallet (wallet_impl ());
Expand Down Expand Up @@ -5147,6 +5166,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map ()
no_arg_funcs.emplace ("pending", &nano::json_handler::pending);
no_arg_funcs.emplace ("pending_exists", &nano::json_handler::pending_exists);
no_arg_funcs.emplace ("process", &nano::json_handler::process);
no_arg_funcs.emplace ("pruned_exists", &nano::json_handler::pruned_exists);
no_arg_funcs.emplace ("receive", &nano::json_handler::receive);
no_arg_funcs.emplace ("receive_minimum", &nano::json_handler::receive_minimum);
no_arg_funcs.emplace ("receive_minimum_set", &nano::json_handler::receive_minimum_set);
Expand Down
1 change: 1 addition & 0 deletions nano/node/json_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class json_handler : public std::enable_shared_from_this<nano::json_handler>
void pending ();
void pending_exists ();
void process ();
void pruned_exists ();
void receive ();
void receive_minimum ();
void receive_minimum_set ();
Expand Down
Loading