@@ -429,59 +429,59 @@ code CLASS::prune(const event_handler& handler) NOEXCEPT
429429 }
430430
431431 code ec{ error::success };
432- const auto prune = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
433- {
434- if (!ec)
435- {
436- handler (event_t ::prune_table, table);
437- if (!storage.reset ())
438- ec = error::prune_table;
439- }
440- };
441-
442- const auto unload = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
443- {
444- if (!ec)
445- {
446- handler (event_t ::unload_file, table);
447- ec = storage.unload ();
448- }
449- };
450-
451- const auto load = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
452- {
453- if (!ec)
454- {
455- handler (event_t ::load_file, table);
456- ec = storage.load ();
457- }
458- };
459432
460433 // Prevouts resettable if all candidates confirmed (fork is candidate top).
461- if (query<CLASS>{ *this }.is_coalesced ())
434+ if (! query<CLASS>{ *this }.is_coalesced ())
462435 {
463- // zeroize table head, set body logical size to zero.
464- prune (ec, prevout, table_t ::prevout_table);
465-
466- // unmap body, setting mapped size to logical size (zero).
467- unload (ec, prevout_body_, table_t ::prevout_body);
468-
469- // map body, making table usable again.
470- load (ec, prevout_body_, table_t ::prevout_body);
436+ ec = error::not_coalesced;
471437 }
472438 else
473439 {
474- ec = error::not_coalesced;
440+ // nullify table head, set reference body count to zero.
441+ handler (event_t ::prune_table, table_t ::prevout_head);
442+ if (!prevout.clear ())
443+ {
444+ ec = error::prune_table;
445+ }
446+ else
447+ {
448+ // Snapshot with nullified head and zero body count.
449+ // The 'prune' parameter signals to not reset body count.
450+ ec = snapshot (handler, true );
451+
452+ if (!ec)
453+ {
454+ // zeroize table body, set logical body count to zero.
455+ handler (event_t ::prune_table, table_t ::prevout_body);
456+ if (!prevout_body_.truncate (zero))
457+ {
458+ ec = error::prune_table;
459+ }
460+ else
461+ {
462+ // unmap body, setting mapped size to logical size (zero).
463+ handler (event_t ::unload_file, table_t ::prevout_body);
464+ ec = prevout_body_.unload ();
465+
466+ if (!ec)
467+ {
468+ // map body, making table usable again.
469+ handler (event_t ::load_file, table_t ::prevout_body);
470+ ec = prevout_body_.load ();
471+ }
472+ }
473+ }
474+ }
475475 }
476476
477477 transactor_mutex_.unlock ();
478478 return ec;
479479}
480480
481481TEMPLATE
482- code CLASS::snapshot (const event_handler& handler) NOEXCEPT
482+ code CLASS::snapshot (const event_handler& handler, bool prune ) NOEXCEPT
483483{
484- while (!transactor_mutex_.try_lock_for (std::chrono::seconds (1 )))
484+ while (!prune && ! transactor_mutex_.try_lock_for (std::chrono::seconds (1 )))
485485 {
486486 handler (event_t ::wait_lock, table_t ::store);
487487 }
@@ -511,16 +511,16 @@ code CLASS::snapshot(const event_handler& handler) NOEXCEPT
511511 flush (ec, strong_tx_body_, table_t ::strong_tx_body);
512512
513513 flush (ec, duplicate_body_, table_t ::duplicate_body);
514- flush (ec, prevout_body_, table_t ::prevout_body);
514+ if (!prune) flush (ec, prevout_body_, table_t ::prevout_body);
515515 flush (ec, validated_bk_body_, table_t ::validated_bk_body);
516516 flush (ec, validated_tx_body_, table_t ::validated_tx_body);
517517
518518 flush (ec, address_body_, table_t ::address_body);
519519 flush (ec, filter_bk_body_, table_t ::filter_bk_body);
520520 flush (ec, filter_tx_body_, table_t ::filter_tx_body);
521521
522- if (!ec) ec = backup (handler);
523- transactor_mutex_.unlock ();
522+ if (!ec) ec = backup (handler, prune );
523+ if (!prune) transactor_mutex_.unlock ();
524524 return ec;
525525}
526526
@@ -863,16 +863,16 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT
863863}
864864
865865TEMPLATE
866- code CLASS::backup (const event_handler& handler) NOEXCEPT
866+ code CLASS::backup (const event_handler& handler, bool prune ) NOEXCEPT
867867{
868868 code ec{ error::success };
869869 const auto backup = [&handler](code& ec, auto & storage,
870- table_t table) NOEXCEPT
870+ table_t table, bool prune= false ) NOEXCEPT
871871 {
872872 if (!ec)
873873 {
874874 handler (event_t ::backup_table, table);
875- if (!storage.backup ())
875+ if (!storage.backup (prune ))
876876 ec = error::backup_table;
877877 }
878878 };
@@ -891,7 +891,7 @@ code CLASS::backup(const event_handler& handler) NOEXCEPT
891891 backup (ec, strong_tx, table_t ::strong_tx_table);
892892
893893 backup (ec, duplicate, table_t ::duplicate_table);
894- backup (ec, prevout, table_t ::prevout_table);
894+ backup (ec, prevout, table_t ::prevout_table, prune );
895895 backup (ec, validated_bk, table_t ::validated_bk_table);
896896 backup (ec, validated_tx, table_t ::validated_tx_table);
897897
0 commit comments