@@ -418,6 +418,61 @@ code CLASS::open(const event_handler& handler) NOEXCEPT
418418 return ec;
419419}
420420
421+ TEMPLATE
422+ code CLASS::prune (const event_handler& handler) NOEXCEPT
423+ {
424+ while (!transactor_mutex_.try_lock_for (std::chrono::seconds (1 )))
425+ {
426+ handler (event_t ::wait_lock, table_t ::store);
427+ }
428+
429+ code ec{ error::success };
430+ const auto prune = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
431+ {
432+ if (!ec)
433+ {
434+ handler (event_t ::prune_table, table);
435+ if (!storage.reset ())
436+ ec = error::prune_table;
437+ }
438+ };
439+
440+ const auto unload = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
441+ {
442+ if (!ec)
443+ {
444+ handler (event_t ::unload_file, table);
445+ ec = storage.unload ();
446+ }
447+ };
448+
449+ const auto load = [&handler](code& ec, auto & storage, table_t table) NOEXCEPT
450+ {
451+ if (!ec)
452+ {
453+ handler (event_t ::load_file, table);
454+ ec = storage.load ();
455+ }
456+ };
457+
458+ // Prevouts resettable if all candidates confirmed (fork is candidate top).
459+ const query<CLASS> query_{ *this };
460+ if (query_.get_fork () == query_.get_top_candidate ())
461+ {
462+ // zeroize table head, set body logical size to zero.
463+ prune (ec, prevout, table_t ::prevout_table);
464+
465+ // unmap body, setting mapped size to logical size (zero).
466+ unload (ec, prevout_body_, table_t ::prevout_body);
467+
468+ // map body, making table usable again.
469+ load (ec, prevout_body_, table_t ::prevout_body);
470+ }
471+
472+ transactor_mutex_.unlock ();
473+ return ec;
474+ }
475+
421476TEMPLATE
422477code CLASS::snapshot (const event_handler& handler) NOEXCEPT
423478{
0 commit comments