diff --git a/include/bitcoin/database/impl/store.ipp b/include/bitcoin/database/impl/store.ipp index 5c1c4a048..afa7e33c9 100644 --- a/include/bitcoin/database/impl/store.ipp +++ b/include/bitcoin/database/impl/store.ipp @@ -67,21 +67,25 @@ const std::unordered_map CLASS::tables { { table_t::store, "store" }, + // Archives. { table_t::header_table, "header_table" }, { table_t::header_head, "header_head" }, { table_t::header_body, "header_body" }, - { table_t::point_table, "point_table" }, - { table_t::point_head, "point_head" }, - { table_t::point_body, "point_body" }, { table_t::input_table, "input_table" }, { table_t::input_head, "input_head" }, { table_t::input_body, "input_body" }, { table_t::output_table, "output_table" }, { table_t::output_head, "output_head" }, { table_t::output_body, "output_body" }, + { table_t::point_table, "point_table" }, + { table_t::point_head, "point_head" }, + { table_t::point_body, "point_body" }, { table_t::puts_table, "puts_table" }, { table_t::puts_head, "puts_head" }, { table_t::puts_body, "puts_body" }, + { table_t::spend_table, "spend_table" }, + { table_t::spend_head, "spend_head" }, + { table_t::spend_body, "spend_body" }, { table_t::tx_table, "tx_table" }, { table_t::tx_head, "tx_head" }, { table_t::txs_table, "txs_table" }, @@ -89,37 +93,38 @@ const std::unordered_map CLASS::tables { table_t::txs_head, "txs_head" }, { table_t::txs_body, "txs_body" }, - { table_t::address_table, "address_table" }, - { table_t::address_head, "address_head" }, - { table_t::address_body, "address_body" }, + // Indexes. { table_t::candidate_table, "candidate_table" }, { table_t::candidate_head, "candidate_head" }, { table_t::candidate_body, "candidate_body" }, { table_t::confirmed_table, "confirmed_table" }, { table_t::confirmed_head, "confirmed_head" }, { table_t::confirmed_body, "confirmed_body" }, - { table_t::spend_table, "spend_table" }, - { table_t::spend_head, "spend_head" }, - { table_t::spend_body, "spend_body" }, { table_t::strong_tx_table, "strong_tx_table" }, { table_t::strong_tx_head, "strong_tx_head" }, { table_t::strong_tx_body, "strong_tx_body" }, + // Caches. + { table_t::prevout_table, "prevout_table" }, + { table_t::prevout_head, "prevout_head" }, + { table_t::prevout_body, "prevout_body" }, { table_t::validated_bk_table, "validated_bk_table" }, { table_t::validated_bk_head, "validated_bk_head" }, { table_t::validated_bk_body, "validated_bk_body" }, { table_t::validated_tx_table, "validated_tx_table" }, { table_t::validated_tx_head, "validated_tx_head" }, { table_t::validated_tx_body, "validated_tx_body" }, + + // Optionals. + { table_t::address_table, "address_table" }, + { table_t::address_head, "address_head" }, + { table_t::address_body, "address_body" }, { table_t::neutrino_table, "neutrino_table" }, { table_t::neutrino_head, "neutrino_head" }, { table_t::neutrino_body, "neutrino_body" } ////{ table_t::bootstrap_table, "bootstrap_table" }, ////{ table_t::bootstrap_head, "bootstrap_head" }, ////{ table_t::bootstrap_body, "bootstrap_body" }, - ////{ table_t::buffer_table, "buffer_table" }, - ////{ table_t::buffer_head, "buffer_head" }, - ////{ table_t::buffer_body, "buffer_body" } }; TEMPLATE @@ -127,6 +132,7 @@ CLASS::store(const settings& config) NOEXCEPT : configuration_(config), // Archive. + // ------------------------------------------------------------------------ header_head_(head(config.path / schema::dir::heads, schema::archive::header)), header_body_(body(config.path, schema::archive::header), config.header_size, config.header_rate), @@ -161,6 +167,7 @@ CLASS::store(const settings& config) NOEXCEPT txs(txs_head_, txs_body_, std::max(config.txs_buckets, nonzero)), // Indexes. + // ------------------------------------------------------------------------ candidate_head_(head(config.path / schema::dir::heads, schema::indexes::candidate)), candidate_body_(body(config.path, schema::indexes::candidate), config.candidate_size, config.candidate_rate), @@ -175,6 +182,11 @@ CLASS::store(const settings& config) NOEXCEPT strong_tx(strong_tx_head_, strong_tx_body_, std::max(config.strong_tx_buckets, nonzero)), // Caches. + // ------------------------------------------------------------------------ + + prevout_head_(head(config.path / schema::dir::heads, schema::caches::prevout)), + prevout_body_(body(config.path, schema::caches::prevout), config.prevout_size, config.prevout_rate), + prevout(prevout_head_, prevout_body_, std::max(config.prevout_buckets, nonzero)), validated_bk_head_(head(config.path / schema::dir::heads, schema::caches::validated_bk)), validated_bk_body_(body(config.path, schema::caches::validated_bk), config.validated_bk_size, config.validated_bk_rate), @@ -185,6 +197,7 @@ CLASS::store(const settings& config) NOEXCEPT validated_tx(validated_tx_head_, validated_tx_body_, std::max(config.validated_tx_buckets, nonzero)), // Optionals. + // ------------------------------------------------------------------------ address_head_(head(config.path / schema::dir::heads, schema::optionals::address)), address_body_(body(config.path, schema::optionals::address), config.address_size, config.address_rate), @@ -198,11 +211,9 @@ CLASS::store(const settings& config) NOEXCEPT ////bootstrap_body_(body(config.path, schema::optionals::bootstrap), config.bootstrap_size, config.bootstrap_rate), ////bootstrap(bootstrap_head_, bootstrap_body_), - ////buffer_head_(head(config.path / schema::dir::heads, schema::optionals::buffer)), - ////buffer_body_(body(config.path, schema::optionals::buffer), config.buffer_size, config.buffer_rate), - ////buffer(buffer_head_, buffer_body_, std::max(config.buffer_buckets, nonzero)), - // Locks. + // ------------------------------------------------------------------------ + flush_lock_(lock(config.path, schema::locks::flush)), process_lock_(lock(config.path, schema::locks::process)) { @@ -264,6 +275,8 @@ code CLASS::create(const event_handler& handler) NOEXCEPT create(ec, strong_tx_head_, table_t::strong_tx_head); create(ec, strong_tx_body_, table_t::strong_tx_body); + create(ec, prevout_head_, table_t::prevout_head); + create(ec, prevout_body_, table_t::prevout_body); create(ec, validated_bk_head_, table_t::validated_bk_head); create(ec, validated_bk_body_, table_t::validated_bk_body); create(ec, validated_tx_head_, table_t::validated_tx_head); @@ -275,8 +288,6 @@ code CLASS::create(const event_handler& handler) NOEXCEPT create(ec, neutrino_body_, table_t::neutrino_body); ////create(ec, bootstrap_head_, table_t::bootstrap_head); ////create(ec, bootstrap_body_, table_t::bootstrap_body); - ////create(ec, buffer_head_, table_t::buffer_head); - ////create(ec, buffer_body_, table_t::buffer_body); const auto populate = [&handler](code& ec, auto& storage, table_t table) NOEXCEPT @@ -305,13 +316,13 @@ code CLASS::create(const event_handler& handler) NOEXCEPT populate(ec, confirmed, table_t::confirmed_table); populate(ec, strong_tx, table_t::strong_tx_table); + populate(ec, prevout, table_t::prevout_table); populate(ec, validated_bk, table_t::validated_bk_table); populate(ec, validated_tx, table_t::validated_tx_table); populate(ec, address, table_t::address_table); populate(ec, neutrino, table_t::neutrino_table); ////populate(ec, bootstrap, table_t::bootstrap_table); - ////populate(ec, buffer, table_t::buffer_table); if (ec) { @@ -377,13 +388,13 @@ code CLASS::open(const event_handler& handler) NOEXCEPT verify(ec, confirmed, table_t::confirmed_table); verify(ec, strong_tx, table_t::strong_tx_table); + verify(ec, prevout, table_t::prevout_table); verify(ec, validated_bk, table_t::validated_bk_table); verify(ec, validated_tx, table_t::validated_tx_table); verify(ec, address, table_t::address_table); verify(ec, neutrino, table_t::neutrino_table); ////verify(ec, bootstrap, table_t::bootstrap_table); - ////verify(ec, buffer, table_t::buffer_table); if (ec) { @@ -431,13 +442,13 @@ code CLASS::snapshot(const event_handler& handler) NOEXCEPT flush(ec, confirmed_body_, table_t::confirmed_body); flush(ec, strong_tx_body_, table_t::strong_tx_body); + flush(ec, prevout_body_, table_t::prevout_body); flush(ec, validated_bk_body_, table_t::validated_bk_body); flush(ec, validated_tx_body_, table_t::validated_tx_body); flush(ec, address_body_, table_t::address_body); flush(ec, neutrino_body_, table_t::neutrino_body); ////flush(ec, bootstrap_body_, table_t::bootstrap_body); - ////flush(ec, buffer_body_, table_t::buffer_body); if (!ec) ec = backup(handler); transactor_mutex_.unlock(); @@ -491,6 +502,8 @@ code CLASS::reload(const event_handler& handler) NOEXCEPT reload(ec, strong_tx_head_, table_t::strong_tx_head); reload(ec, strong_tx_body_, table_t::strong_tx_body); + reload(ec, prevout_head_, table_t::prevout_head); + reload(ec, prevout_body_, table_t::prevout_body); reload(ec, validated_bk_head_, table_t::validated_bk_head); reload(ec, validated_bk_body_, table_t::validated_bk_body); reload(ec, validated_tx_head_, table_t::validated_tx_head); @@ -502,8 +515,6 @@ code CLASS::reload(const event_handler& handler) NOEXCEPT reload(ec, neutrino_body_, table_t::neutrino_body); ////reload(ec, bootstrap_head_, table_t::bootstrap_head); ////reload(ec, bootstrap_body_, table_t::bootstrap_body); - ////reload(ec, buffer_head_, table_t::buffer_head); - ////reload(ec, buffer_body_, table_t::buffer_body); transactor_mutex_.unlock(); return ec; @@ -542,13 +553,13 @@ code CLASS::close(const event_handler& handler) NOEXCEPT close(ec, confirmed, table_t::confirmed_table); close(ec, strong_tx, table_t::strong_tx_table); + close(ec, prevout, table_t::prevout_table); close(ec, validated_bk, table_t::validated_bk_table); close(ec, validated_tx, table_t::validated_tx_table); close(ec, address, table_t::address_table); close(ec, neutrino, table_t::neutrino_table); ////close(ec, bootstrap, table_t::bootstrap_table); - ////close(ec, buffer, table_t::buffer_table); if (!ec) ec = unload_close(handler); @@ -606,6 +617,8 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT open(ec, strong_tx_head_, table_t::strong_tx_head); open(ec, strong_tx_body_, table_t::strong_tx_body); + open(ec, prevout_head_, table_t::prevout_head); + open(ec, prevout_body_, table_t::prevout_body); open(ec, validated_bk_head_, table_t::validated_bk_head); open(ec, validated_bk_body_, table_t::validated_bk_body); open(ec, validated_tx_head_, table_t::validated_tx_head); @@ -617,8 +630,6 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT open(ec, neutrino_body_, table_t::neutrino_body); ////open(ec, bootstrap_head_, table_t::bootstrap_head); ////open(ec, bootstrap_body_, table_t::bootstrap_body); - ////open(ec, buffer_head_, table_t::buffer_head); - ////open(ec, buffer_body_, table_t::buffer_body); const auto load = [&handler](code& ec, auto& storage, table_t table) NOEXCEPT { @@ -653,6 +664,8 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT load(ec, strong_tx_head_, table_t::strong_tx_head); load(ec, strong_tx_body_, table_t::strong_tx_body); + load(ec, prevout_head_, table_t::prevout_head); + load(ec, prevout_body_, table_t::prevout_body); load(ec, validated_bk_head_, table_t::validated_bk_head); load(ec, validated_bk_body_, table_t::validated_bk_body); load(ec, validated_tx_head_, table_t::validated_tx_head); @@ -664,8 +677,6 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT load(ec, neutrino_body_, table_t::neutrino_body); ////load(ec, bootstrap_head_, table_t::bootstrap_head); ////load(ec, bootstrap_body_, table_t::bootstrap_body); - ////load(ec, buffer_head_, table_t::buffer_head); - ////load(ec, buffer_body_, table_t::buffer_body); return ec; } @@ -707,6 +718,8 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT unload(ec, strong_tx_head_, table_t::strong_tx_head); unload(ec, strong_tx_body_, table_t::strong_tx_body); + unload(ec, prevout_head_, table_t::prevout_head); + unload(ec, prevout_body_, table_t::prevout_body); unload(ec, validated_bk_head_, table_t::validated_bk_head); unload(ec, validated_bk_body_, table_t::validated_bk_body); unload(ec, validated_tx_head_, table_t::validated_tx_head); @@ -718,8 +731,6 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT unload(ec, neutrino_body_, table_t::neutrino_body); ////unload(ec, bootstrap_head_, table_t::bootstrap_head); ////unload(ec, bootstrap_body_, table_t::bootstrap_body); - ////unload(ec, buffer_head_, table_t::buffer_head); - ////unload(ec, buffer_body_, table_t::buffer_body); const auto close = [&handler](code& ec, auto& storage, table_t table) NOEXCEPT { @@ -754,6 +765,8 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT close(ec, strong_tx_head_, table_t::strong_tx_head); close(ec, strong_tx_body_, table_t::strong_tx_body); + close(ec, prevout_head_, table_t::prevout_head); + close(ec, prevout_body_, table_t::prevout_body); close(ec, validated_bk_head_, table_t::validated_bk_head); close(ec, validated_bk_body_, table_t::validated_bk_body); close(ec, validated_tx_head_, table_t::validated_tx_head); @@ -765,8 +778,6 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT close(ec, neutrino_body_, table_t::neutrino_body); ////close(ec, bootstrap_head_, table_t::bootstrap_head); ////close(ec, bootstrap_body_, table_t::bootstrap_body); - ////close(ec, buffer_head_, table_t::buffer_head); - ////close(ec, buffer_body_, table_t::buffer_body); return ec; } @@ -799,13 +810,13 @@ code CLASS::backup(const event_handler& handler) NOEXCEPT backup(ec, confirmed, table_t::confirmed_table); backup(ec, strong_tx, table_t::strong_tx_table); + backup(ec, prevout, table_t::prevout_table); backup(ec, validated_bk, table_t::validated_bk_table); backup(ec, validated_tx, table_t::validated_tx_table); backup(ec, address, table_t::address_table); backup(ec, neutrino, table_t::neutrino_table); ////backup(ec, bootstrap, table_t::bootstrap_table); - ////backup(ec, buffer, table_t::buffer_table); if (ec) return ec; @@ -852,13 +863,13 @@ code CLASS::dump(const path& folder, auto confirmed_buffer = confirmed_head_.get(); auto strong_tx_buffer = strong_tx_head_.get(); + auto prevout_buffer = prevout_head_.get(); auto validated_bk_buffer = validated_bk_head_.get(); auto validated_tx_buffer = validated_tx_head_.get(); auto address_buffer = address_head_.get(); auto neutrino_buffer = neutrino_head_.get(); ////auto bootstrap_buffer = bootstrap_head_.get(); - ////auto buffer_buffer = buffer_head_.get(); if (!header_buffer) return error::unloaded_file; if (!input_buffer) return error::unloaded_file; @@ -873,13 +884,13 @@ code CLASS::dump(const path& folder, if (!confirmed_buffer) return error::unloaded_file; if (!strong_tx_buffer) return error::unloaded_file; + if (!prevout_buffer) return error::unloaded_file; if (!validated_bk_buffer) return error::unloaded_file; if (!validated_tx_buffer) return error::unloaded_file; if (!address_buffer) return error::unloaded_file; if (!neutrino_buffer) return error::unloaded_file; ////if (!bootstrap_buffer) return error::unloaded_file; - ////if (!buffer_buffer) return error::unloaded_file; code ec{ error::success }; const auto dump = [&handler, &folder](code& ec, const auto& storage, @@ -906,13 +917,13 @@ code CLASS::dump(const path& folder, dump(ec, confirmed_buffer, schema::indexes::confirmed, table_t::confirmed_head); dump(ec, strong_tx_buffer, schema::indexes::strong_tx, table_t::strong_tx_head); + dump(ec, prevout_buffer, schema::caches::prevout, table_t::prevout_head); dump(ec, validated_bk_buffer, schema::caches::validated_bk, table_t::validated_bk_head); dump(ec, validated_tx_buffer, schema::caches::validated_tx, table_t::validated_tx_head); dump(ec, address_buffer, schema::optionals::address, table_t::address_head); dump(ec, neutrino_buffer, schema::optionals::neutrino, table_t::neutrino_head); ////dump(ec, bootstrap_buffer, schema::optionals::bootstrap, table_t::bootstrap_head); - ////dump(ec, buffer_buffer, schema::optionals::buffer, table_t::buffer_head); return ec; } @@ -995,13 +1006,13 @@ code CLASS::restore(const event_handler& handler) NOEXCEPT restore(ec, confirmed, table_t::confirmed_table); restore(ec, strong_tx, table_t::strong_tx_table); + restore(ec, prevout, table_t::prevout_table); restore(ec, validated_bk, table_t::validated_bk_table); restore(ec, validated_tx, table_t::validated_tx_table); restore(ec, address, table_t::address_table); restore(ec, neutrino, table_t::neutrino_table); ////restore(ec, bootstrap, table_t::bootstrap_table); - ////restore(ec, buffer, table_t::buffer_table); if (ec) /* code */ unload_close(handler); @@ -1045,12 +1056,12 @@ code CLASS::get_fault() const NOEXCEPT if ((ec = candidate_body_.get_fault())) return ec; if ((ec = confirmed_body_.get_fault())) return ec; if ((ec = strong_tx_body_.get_fault())) return ec; + if ((ec = prevout_body_.get_fault())) return ec; if ((ec = validated_bk_body_.get_fault())) return ec; if ((ec = validated_tx_body_.get_fault())) return ec; if ((ec = address_body_.get_fault())) return ec; if ((ec = neutrino_body_.get_fault())) return ec; ////if ((ec = bootstrap_body_.get_fault())) return ec; - ////if ((ec = buffer_body_.get_fault())) return ec; return ec; } @@ -1074,12 +1085,12 @@ size_t CLASS::get_space() const NOEXCEPT space(candidate_body_); space(confirmed_body_); space(strong_tx_body_); + space(prevout_body_); space(validated_bk_body_); space(validated_tx_body_); space(address_body_); space(neutrino_body_); ////space(bootstrap_body_); - ////space(buffer_body_); return total; } @@ -1107,12 +1118,12 @@ void CLASS::report(const error_handler& handler) const NOEXCEPT report(candidate_body_, table_t::candidate_body); report(confirmed_body_, table_t::confirmed_body); report(strong_tx_body_, table_t::strong_tx_body); + report(prevout_body_, table_t::prevout_body); report(validated_bk_body_, table_t::validated_bk_body); report(validated_tx_body_, table_t::validated_tx_body); report(address_body_, table_t::address_body); report(neutrino_body_, table_t::neutrino_body); ////report(bootstrap_body_, table_t::bootstrap_body); - ////report(buffer_body_, table_t::buffer_body); } TEMPLATE diff --git a/include/bitcoin/database/settings.hpp b/include/bitcoin/database/settings.hpp index 7221490fa..f5f84ce4c 100644 --- a/include/bitcoin/database/settings.hpp +++ b/include/bitcoin/database/settings.hpp @@ -88,6 +88,10 @@ struct BCD_API settings /// Caches. /// ----------------------------------------------------------------------- + uint32_t prevout_buckets; + uint64_t prevout_size; + uint16_t prevout_rate; + uint32_t validated_bk_buckets; uint64_t validated_bk_size; uint16_t validated_bk_rate; @@ -109,10 +113,6 @@ struct BCD_API settings ////uint32_t bootstrap_size; ////uint16_t bootstrap_rate; - - ////uint32_t buffer_buckets; - ////uint64_t buffer_size; - ////uint16_t buffer_rate; }; } // namespace database diff --git a/include/bitcoin/database/store.hpp b/include/bitcoin/database/store.hpp index 763032920..cfd3b96c7 100644 --- a/include/bitcoin/database/store.hpp +++ b/include/bitcoin/database/store.hpp @@ -113,6 +113,7 @@ class store table::strong_tx strong_tx; /// Caches. + table::prevout prevout; table::validated_bk validated_bk; table::validated_tx validated_tx; @@ -120,7 +121,6 @@ class store table::address address; table::neutrino neutrino; ////table::bootstrap bootstrap; - ////table::buffer buffer; protected: code open_load(const event_handler& handler) NOEXCEPT; @@ -185,6 +185,10 @@ class store /// Caches. /// ----------------------------------------------------------------------- + // record arraymap + Storage prevout_head_; + Storage prevout_body_; + // record hashmap Storage validated_bk_head_; Storage validated_bk_body_; @@ -208,10 +212,6 @@ class store ////Storage bootstrap_head_; ////Storage bootstrap_body_; - ////// slab hashmap - ////Storage buffer_head_; - ////Storage buffer_body_; - /// Locks. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index d9402da18..772eb3d5f 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -50,7 +50,7 @@ struct header bits = source.read_little_endian(); nonce = source.read_little_endian(); merkle_root = source.read_hash(); - BC_ASSERT(source.get_read_position() == minrow); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -64,7 +64,7 @@ struct header sink.write_little_endian(bits); sink.write_little_endian(nonce); sink.write_bytes(merkle_root); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } @@ -105,7 +105,7 @@ struct header sink.write_little_endian(header->bits()); sink.write_little_endian(header->nonce()); sink.write_bytes(header->merkle_root()); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } @@ -130,7 +130,7 @@ struct header sink.write_little_endian(header.bits()); sink.write_little_endian(header.nonce()); sink.write_bytes(header.merkle_root()); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } diff --git a/include/bitcoin/database/tables/archives/input.hpp b/include/bitcoin/database/tables/archives/input.hpp index dd0c101ba..49605807b 100644 --- a/include/bitcoin/database/tables/archives/input.hpp +++ b/include/bitcoin/database/tables/archives/input.hpp @@ -54,7 +54,7 @@ struct input { script = system::chain::script{ source, true }; witness = system::chain::witness{ source, true }; - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -62,7 +62,7 @@ struct input { script.to_data(sink, true); witness.to_data(sink, true); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } @@ -105,7 +105,7 @@ struct input { input.script().to_data(sink, true); input.witness().to_data(sink, true); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/archives/output.hpp b/include/bitcoin/database/tables/archives/output.hpp index 0ea2e8c32..01658d7fd 100644 --- a/include/bitcoin/database/tables/archives/output.hpp +++ b/include/bitcoin/database/tables/archives/output.hpp @@ -57,7 +57,7 @@ struct output parent_fk = source.read_little_endian(); value = source.read_variable(); script = chain::script{ source, true }; - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -66,7 +66,7 @@ struct output sink.write_little_endian(parent_fk); sink.write_variable(value); script.to_data(sink, true); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } @@ -143,7 +143,7 @@ struct output sink.write_little_endian(parent_fk); sink.write_variable(output.value()); output.script().to_data(sink, true); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/archives/puts.hpp b/include/bitcoin/database/tables/archives/puts.hpp index 500f4088f..18cc18486 100644 --- a/include/bitcoin/database/tables/archives/puts.hpp +++ b/include/bitcoin/database/tables/archives/puts.hpp @@ -67,7 +67,7 @@ struct puts fk = source.read_little_endian(); }); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -83,7 +83,7 @@ struct puts sink.write_little_endian(fk); }); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/archives/spend.hpp b/include/bitcoin/database/tables/archives/spend.hpp index f2331cc73..6e3f56782 100644 --- a/include/bitcoin/database/tables/archives/spend.hpp +++ b/include/bitcoin/database/tables/archives/spend.hpp @@ -66,7 +66,7 @@ struct spend parent_fk = source.read_little_endian(); sequence = source.read_little_endian(); input_fk = source.read_little_endian(); - BC_ASSERT(source.get_read_position() == minrow); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -75,7 +75,7 @@ struct spend sink.write_little_endian(parent_fk); sink.write_little_endian(sequence); sink.write_little_endian(input_fk); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } @@ -106,7 +106,7 @@ struct spend source.skip_bytes(tx::size); sequence = source.read_little_endian(); input_fk = source.read_little_endian(); - BC_ASSERT(source.get_read_position() == minrow); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } diff --git a/include/bitcoin/database/tables/archives/transaction.hpp b/include/bitcoin/database/tables/archives/transaction.hpp index db4fd8763..59bff6ec5 100644 --- a/include/bitcoin/database/tables/archives/transaction.hpp +++ b/include/bitcoin/database/tables/archives/transaction.hpp @@ -69,7 +69,7 @@ struct transaction ins_count = source.read_little_endian(); outs_count = source.read_little_endian(); puts_fk = source.read_little_endian(); - BC_ASSERT(source.get_read_position() == minrow); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -83,7 +83,7 @@ struct transaction sink.write_little_endian(ins_count); sink.write_little_endian(outs_count); sink.write_little_endian(puts_fk); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } @@ -125,7 +125,7 @@ struct transaction ins_count = source.read_little_endian(); outs_count = source.read_little_endian(); puts_fk = source.read_little_endian(); - BC_ASSERT(source.get_read_position() == minrow); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -152,7 +152,7 @@ struct transaction sink.write_little_endian(ins_count); sink.write_little_endian(outs_count); sink.write_little_endian(puts_fk); - BC_ASSERT(sink.get_write_position() == minrow); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index fa03cd365..6e63707b1 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -58,7 +58,7 @@ struct txs fk = source.read_little_endian(); }); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -74,7 +74,7 @@ struct txs sink.write_little_endian(fk); }); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/caches/prevout.hpp b/include/bitcoin/database/tables/caches/prevout.hpp index b288b35ff..1414760cb 100644 --- a/include/bitcoin/database/tables/caches/prevout.hpp +++ b/include/bitcoin/database/tables/caches/prevout.hpp @@ -44,7 +44,7 @@ struct prevout coinbase = source.read_byte(); spend_fk = source.read_little_endian(); output_tx_fk = source.read_little_endian(); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -53,7 +53,7 @@ struct prevout sink.write_byte(coinbase); sink.write_little_endian(spend_fk); sink.write_little_endian(output_tx_fk); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } diff --git a/include/bitcoin/database/tables/caches/validated_bk.hpp b/include/bitcoin/database/tables/caches/validated_bk.hpp index 0c9ec0a83..b8d6067ad 100644 --- a/include/bitcoin/database/tables/caches/validated_bk.hpp +++ b/include/bitcoin/database/tables/caches/validated_bk.hpp @@ -50,7 +50,7 @@ struct validated_bk { code = source.read_little_endian(); fees = source.read_variable(); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -58,7 +58,7 @@ struct validated_bk { sink.write_little_endian(code); sink.write_variable(fees); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/caches/validated_tx.hpp b/include/bitcoin/database/tables/caches/validated_tx.hpp index a1abef587..8a5bacb3e 100644 --- a/include/bitcoin/database/tables/caches/validated_tx.hpp +++ b/include/bitcoin/database/tables/caches/validated_tx.hpp @@ -58,7 +58,7 @@ struct validated_tx code = source.read_little_endian(); fee = source.read_variable(); sigops = possible_narrow_cast(source.read_variable()); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -68,7 +68,7 @@ struct validated_tx sink.write_little_endian(code); sink.write_variable(fee); sink.write_variable(sigops); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/indexes/height.hpp b/include/bitcoin/database/tables/indexes/height.hpp index 142d9b80d..6f837c9f2 100644 --- a/include/bitcoin/database/tables/indexes/height.hpp +++ b/include/bitcoin/database/tables/indexes/height.hpp @@ -41,12 +41,14 @@ struct height inline bool from_data(reader& source) NOEXCEPT { header_fk = source.read_little_endian(); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } inline bool to_data(flipper& sink) const NOEXCEPT { sink.write_little_endian(header_fk); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } diff --git a/include/bitcoin/database/tables/indexes/strong_tx.hpp b/include/bitcoin/database/tables/indexes/strong_tx.hpp index 28d579ac2..313f0e9ac 100644 --- a/include/bitcoin/database/tables/indexes/strong_tx.hpp +++ b/include/bitcoin/database/tables/indexes/strong_tx.hpp @@ -42,6 +42,7 @@ struct strong_tx { header_fk = source.read_little_endian(); positive = to_bool(source.read_byte()); + BC_ASSERT(!source || source.get_read_position() == minrow); return source; } @@ -49,6 +50,7 @@ struct strong_tx { sink.write_little_endian(header_fk); sink.write_byte(to_int(positive)); + BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; } diff --git a/include/bitcoin/database/tables/optionals/bootstrap.hpp b/include/bitcoin/database/tables/optionals/bootstrap.hpp index 590d0d95e..d9b5e5ef4 100644 --- a/include/bitcoin/database/tables/optionals/bootstrap.hpp +++ b/include/bitcoin/database/tables/optionals/bootstrap.hpp @@ -55,7 +55,7 @@ //// hash = source.read_hash(); //// }); //// -//// BC_ASSERT(source.get_read_position() == count() * schema::hash); +//// BC_ASSERT(!source || source.get_read_position() == count() * schema::hash); //// return source; //// } //// @@ -71,7 +71,7 @@ //// sink.write_bytes(hash); //// }); //// -//// BC_ASSERT(sink.get_write_position() == count() * schema::hash); +//// BC_ASSERT(!sink || sink.get_write_position() == count() * schema::hash); //// return sink; //// } //// diff --git a/include/bitcoin/database/tables/optionals/neutrino.hpp b/include/bitcoin/database/tables/optionals/neutrino.hpp index a6fa84303..6287b63be 100644 --- a/include/bitcoin/database/tables/optionals/neutrino.hpp +++ b/include/bitcoin/database/tables/optionals/neutrino.hpp @@ -49,7 +49,7 @@ struct neutrino { filter_head = source.read_hash(); filter = source.read_bytes(source.read_size()); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -58,7 +58,7 @@ struct neutrino sink.write_bytes(filter_head); sink.write_variable(filter.size()); sink.write_bytes(filter); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } @@ -87,7 +87,7 @@ struct neutrino { source.skip_bytes(schema::hash); filter = source.read_bytes(source.read_size()); - BC_ASSERT(source.get_read_position() == count()); + BC_ASSERT(!source || source.get_read_position() == count()); return source; } @@ -122,7 +122,7 @@ struct neutrino sink.write_bytes(filter_head); sink.write_variable(filter.size()); sink.write_bytes(filter); - BC_ASSERT(sink.get_write_position() == count()); + BC_ASSERT(!sink || sink.get_write_position() == count()); return sink; } diff --git a/include/bitcoin/database/tables/table.hpp b/include/bitcoin/database/tables/table.hpp index 4866cca9d..6df5e7071 100644 --- a/include/bitcoin/database/tables/table.hpp +++ b/include/bitcoin/database/tables/table.hpp @@ -64,6 +64,9 @@ enum class table_t strong_tx_body, /// Caches. + prevout_table, + prevout_head, + prevout_body, validated_bk_table, validated_bk_head, validated_bk_body, @@ -77,13 +80,10 @@ enum class table_t address_body, neutrino_table, neutrino_head, - neutrino_body, + neutrino_body ////bootstrap_table, ////bootstrap_head, - ////bootstrap_body, - ////buffer_table, - ////buffer_head, - ////buffer_body, + ////bootstrap_body }; } // namespace database diff --git a/include/bitcoin/database/tables/tables.hpp b/include/bitcoin/database/tables/tables.hpp index 28d3fab9e..d405943e2 100644 --- a/include/bitcoin/database/tables/tables.hpp +++ b/include/bitcoin/database/tables/tables.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -37,7 +38,6 @@ #include #include ////#include - ////#include #include #include diff --git a/src/settings.cpp b/src/settings.cpp index 8857335ee..869dbb2e2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -75,6 +75,10 @@ settings::settings() NOEXCEPT // Caches. + prevout_buckets{ 100 }, + prevout_size{ 1 }, + prevout_rate{ 50 }, + validated_bk_buckets{ 100 }, validated_bk_size{ 1 }, validated_bk_rate{ 50 }, @@ -93,14 +97,8 @@ settings::settings() NOEXCEPT neutrino_size{ 1 }, neutrino_rate{ 50 } - // Caches. - ////bootstrap_size{ 1 }, - ////bootstrap_rate{ 50 }, - - ////buffer_buckets{ 100 }, - ////buffer_size{ 1 }, - ////buffer_rate{ 50 } + ////bootstrap_rate{ 50 } { } diff --git a/test/mocks/map_store.hpp b/test/mocks/map_store.hpp index 9207ea19b..af9e6f5be 100644 --- a/test/mocks/map_store.hpp +++ b/test/mocks/map_store.hpp @@ -68,16 +68,6 @@ class map_store return header_body_.file(); } - inline const path& point_head_file() const NOEXCEPT - { - return point_head_.file(); - } - - inline const path& point_body_file() const NOEXCEPT - { - return point_body_.file(); - } - inline const path& input_head_file() const NOEXCEPT { return input_head_.file(); @@ -98,6 +88,16 @@ class map_store return output_body_.file(); } + inline const path& point_head_file() const NOEXCEPT + { + return point_head_.file(); + } + + inline const path& point_body_file() const NOEXCEPT + { + return point_body_.file(); + } + inline const path& puts_head_file() const NOEXCEPT { return puts_head_.file(); @@ -108,6 +108,16 @@ class map_store return puts_body_.file(); } + inline const path& spend_head_file() const NOEXCEPT + { + return spend_head_.file(); + } + + inline const path& spend_body_file() const NOEXCEPT + { + return spend_body_.file(); + } + inline const path& tx_head_file() const NOEXCEPT { return tx_head_.file(); @@ -130,16 +140,6 @@ class map_store // Indexes. - inline const path& address_head_file() const NOEXCEPT - { - return address_head_.file(); - } - - inline const path& address_body_file() const NOEXCEPT - { - return address_body_.file(); - } - inline const path& candidate_head_file() const NOEXCEPT { return candidate_head_.file(); @@ -160,16 +160,6 @@ class map_store return confirmed_body_.file(); } - inline const path& spend_head_file() const NOEXCEPT - { - return spend_head_.file(); - } - - inline const path& spend_body_file() const NOEXCEPT - { - return spend_body_.file(); - } - inline const path& strong_tx_head_file() const NOEXCEPT { return strong_tx_head_.file(); @@ -182,6 +172,16 @@ class map_store // Caches. + inline const path& prevout_head_file() const NOEXCEPT + { + return prevout_head_.file(); + } + + inline const path& prevout_body_file() const NOEXCEPT + { + return prevout_body_.file(); + } + inline const path& validated_bk_head_file() const NOEXCEPT { return validated_bk_head_.file(); @@ -202,6 +202,18 @@ class map_store return validated_tx_body_.file(); } + // Optionals. + + inline const path& address_head_file() const NOEXCEPT + { + return address_head_.file(); + } + + inline const path& address_body_file() const NOEXCEPT + { + return address_body_.file(); + } + inline const path& neutrino_head_file() const NOEXCEPT { return neutrino_head_.file(); @@ -222,16 +234,6 @@ class map_store //// return bootstrap_body_.file(); ////} - ////inline const path& buffer_head_file() const NOEXCEPT - ////{ - //// return buffer_head_.file(); - ////} - - ////inline const path& buffer_body_file() const NOEXCEPT - ////{ - //// return buffer_body_.file(); - ////} - // Locks. inline const path& flush_lock_file() const NOEXCEPT diff --git a/test/settings.cpp b/test/settings.cpp index c46ec6763..ac8f443c1 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -39,6 +39,9 @@ BOOST_AUTO_TEST_CASE(settings__construct__default__expected) BOOST_REQUIRE_EQUAL(configuration.output_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.puts_size, 1u); BOOST_REQUIRE_EQUAL(configuration.puts_rate, 50u); + BOOST_REQUIRE_EQUAL(configuration.spend_buckets, 100u); + BOOST_REQUIRE_EQUAL(configuration.spend_size, 1u); + BOOST_REQUIRE_EQUAL(configuration.spend_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.tx_buckets, 100u); BOOST_REQUIRE_EQUAL(configuration.tx_size, 1u); BOOST_REQUIRE_EQUAL(configuration.tx_rate, 50u); @@ -47,35 +50,34 @@ BOOST_AUTO_TEST_CASE(settings__construct__default__expected) BOOST_REQUIRE_EQUAL(configuration.txs_rate, 50u); // Indexes. - BOOST_REQUIRE_EQUAL(configuration.address_buckets, 100u); - BOOST_REQUIRE_EQUAL(configuration.address_size, 1u); - BOOST_REQUIRE_EQUAL(configuration.address_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.candidate_size, 1u); BOOST_REQUIRE_EQUAL(configuration.candidate_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.confirmed_size, 1u); BOOST_REQUIRE_EQUAL(configuration.confirmed_rate, 50u); - BOOST_REQUIRE_EQUAL(configuration.spend_buckets, 100u); - BOOST_REQUIRE_EQUAL(configuration.spend_size, 1u); - BOOST_REQUIRE_EQUAL(configuration.spend_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.strong_tx_buckets, 100u); BOOST_REQUIRE_EQUAL(configuration.strong_tx_size, 1u); BOOST_REQUIRE_EQUAL(configuration.strong_tx_rate, 50u); // Caches. + BOOST_REQUIRE_EQUAL(configuration.prevout_buckets, 100u); + BOOST_REQUIRE_EQUAL(configuration.prevout_size, 1u); + BOOST_REQUIRE_EQUAL(configuration.prevout_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.validated_bk_buckets, 100u); BOOST_REQUIRE_EQUAL(configuration.validated_bk_size, 1u); BOOST_REQUIRE_EQUAL(configuration.validated_bk_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.validated_tx_buckets, 100u); BOOST_REQUIRE_EQUAL(configuration.validated_tx_size, 1u); BOOST_REQUIRE_EQUAL(configuration.validated_tx_rate, 50u); + + // Optionals. + BOOST_REQUIRE_EQUAL(configuration.address_buckets, 100u); + BOOST_REQUIRE_EQUAL(configuration.address_size, 1u); + BOOST_REQUIRE_EQUAL(configuration.address_rate, 50u); BOOST_REQUIRE_EQUAL(configuration.neutrino_buckets, 100u); BOOST_REQUIRE_EQUAL(configuration.neutrino_size, 1u); BOOST_REQUIRE_EQUAL(configuration.neutrino_rate, 50u); ////BOOST_REQUIRE_EQUAL(configuration.bootstrap_size, 1u); ////BOOST_REQUIRE_EQUAL(configuration.bootstrap_rate, 50u); - ////BOOST_REQUIRE_EQUAL(configuration.buffer_buckets, 100u); - ////BOOST_REQUIRE_EQUAL(configuration.buffer_size, 1u); - ////BOOST_REQUIRE_EQUAL(configuration.buffer_rate, 50u); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/store.cpp b/test/store.cpp index 66d887369..89bd162a8 100644 --- a/test/store.cpp +++ b/test/store.cpp @@ -70,42 +70,41 @@ BOOST_AUTO_TEST_CASE(store__paths__default_configuration__expected) /// Archive. BOOST_REQUIRE_EQUAL(instance.header_head_file(), "bitcoin/heads/archive_header.head"); BOOST_REQUIRE_EQUAL(instance.header_body_file(), "bitcoin/archive_header.data"); - BOOST_REQUIRE_EQUAL(instance.point_head_file(), "bitcoin/heads/archive_point.head"); - BOOST_REQUIRE_EQUAL(instance.point_body_file(), "bitcoin/archive_point.data"); BOOST_REQUIRE_EQUAL(instance.input_head_file(), "bitcoin/heads/archive_input.head"); BOOST_REQUIRE_EQUAL(instance.input_body_file(), "bitcoin/archive_input.data"); BOOST_REQUIRE_EQUAL(instance.output_head_file(), "bitcoin/heads/archive_output.head"); BOOST_REQUIRE_EQUAL(instance.output_body_file(), "bitcoin/archive_output.data"); + BOOST_REQUIRE_EQUAL(instance.point_head_file(), "bitcoin/heads/archive_point.head"); + BOOST_REQUIRE_EQUAL(instance.point_body_file(), "bitcoin/archive_point.data"); BOOST_REQUIRE_EQUAL(instance.puts_head_file(), "bitcoin/heads/archive_puts.head"); BOOST_REQUIRE_EQUAL(instance.puts_body_file(), "bitcoin/archive_puts.data"); + BOOST_REQUIRE_EQUAL(instance.spend_head_file(), "bitcoin/heads/archive_spend.head"); + BOOST_REQUIRE_EQUAL(instance.spend_body_file(), "bitcoin/archive_spend.data"); BOOST_REQUIRE_EQUAL(instance.tx_head_file(), "bitcoin/heads/archive_tx.head"); BOOST_REQUIRE_EQUAL(instance.tx_body_file(), "bitcoin/archive_tx.data"); BOOST_REQUIRE_EQUAL(instance.txs_head_file(), "bitcoin/heads/archive_txs.head"); BOOST_REQUIRE_EQUAL(instance.txs_body_file(), "bitcoin/archive_txs.data"); /// Index. - BOOST_REQUIRE_EQUAL(instance.address_head_file(), "bitcoin/heads/address.head"); - BOOST_REQUIRE_EQUAL(instance.address_body_file(), "bitcoin/address.data"); BOOST_REQUIRE_EQUAL(instance.candidate_head_file(), "bitcoin/heads/candidate.head"); BOOST_REQUIRE_EQUAL(instance.candidate_body_file(), "bitcoin/candidate.data"); BOOST_REQUIRE_EQUAL(instance.confirmed_head_file(), "bitcoin/heads/confirmed.head"); BOOST_REQUIRE_EQUAL(instance.confirmed_body_file(), "bitcoin/confirmed.data"); - BOOST_REQUIRE_EQUAL(instance.spend_head_file(), "bitcoin/heads/archive_spend.head"); - BOOST_REQUIRE_EQUAL(instance.spend_body_file(), "bitcoin/archive_spend.data"); BOOST_REQUIRE_EQUAL(instance.strong_tx_head_file(), "bitcoin/heads/strong_tx.head"); BOOST_REQUIRE_EQUAL(instance.strong_tx_body_file(), "bitcoin/strong_tx.data"); /// Caches. - BOOST_REQUIRE_EQUAL(instance.validated_bk_head_file(), "bitcoin/heads/validated_bk.head"); - BOOST_REQUIRE_EQUAL(instance.validated_bk_body_file(), "bitcoin/validated_bk.data"); + BOOST_REQUIRE_EQUAL(instance.prevout_head_file(), "bitcoin/heads/prevout.head"); + BOOST_REQUIRE_EQUAL(instance.prevout_body_file(), "bitcoin/prevout.data"); BOOST_REQUIRE_EQUAL(instance.validated_tx_head_file(), "bitcoin/heads/validated_tx.head"); BOOST_REQUIRE_EQUAL(instance.validated_tx_body_file(), "bitcoin/validated_tx.data"); + + BOOST_REQUIRE_EQUAL(instance.address_head_file(), "bitcoin/heads/address.head"); + BOOST_REQUIRE_EQUAL(instance.address_body_file(), "bitcoin/address.data"); BOOST_REQUIRE_EQUAL(instance.neutrino_head_file(), "bitcoin/heads/neutrino.head"); BOOST_REQUIRE_EQUAL(instance.neutrino_body_file(), "bitcoin/neutrino.data"); ////BOOST_REQUIRE_EQUAL(instance.bootstrap_head_file(), "bitcoin/heads/bootstrap.head"); ////BOOST_REQUIRE_EQUAL(instance.bootstrap_body_file(), "bitcoin/bootstrap.data"); - ////BOOST_REQUIRE_EQUAL(instance.buffer_head_file(), "bitcoin/heads/buffer.head"); - ////BOOST_REQUIRE_EQUAL(instance.buffer_body_file(), "bitcoin/buffer.data"); /// Locks. BOOST_REQUIRE_EQUAL(instance.flush_lock_file(), "bitcoin/flush.lock"); diff --git a/test/tables/caches/prevout.cpp b/test/tables/caches/prevout.cpp index 1d64afd6a..99c70580c 100644 --- a/test/tables/caches/prevout.cpp +++ b/test/tables/caches/prevout.cpp @@ -22,5 +22,83 @@ BOOST_AUTO_TEST_SUITE(prevout_tests) using namespace system; +constexpr table::prevout::record record1{ {}, true, 0x01020304, 0xbaadf00d }; +constexpr table::prevout::record record2{ {}, false, 0xbaadf00d, 0x01020304 }; + +BOOST_AUTO_TEST_CASE(header__put__at1__expected) +{ + table::prevout::record element{}; + test::chunk_storage head_store{}; + test::chunk_storage body_store{}; + table::prevout instance{ head_store, body_store, 5 }; + BOOST_REQUIRE(instance.create()); + + // Put at key. + BOOST_REQUIRE(instance.put(3, record1)); + BOOST_REQUIRE(instance.put(42, record2)); + + // Dereference at key to get link. + BOOST_REQUIRE(instance.at(0).is_terminal()); + BOOST_REQUIRE_EQUAL(instance.at(3), 0u); + BOOST_REQUIRE_EQUAL(instance.at(42), 1u); +} + +BOOST_AUTO_TEST_CASE(header__put__at2__expected) +{ + table::prevout::record element{}; + test::chunk_storage head_store{}; + test::chunk_storage body_store{}; + table::prevout instance{ head_store, body_store, 5 }; + BOOST_REQUIRE(instance.create()); + + // Put at key. + BOOST_REQUIRE(instance.put(3, record1)); + BOOST_REQUIRE(instance.put(42, record2)); + + // Dereference at key to get element. + BOOST_REQUIRE(!instance.at(0, element)); + BOOST_REQUIRE(instance.at(3, element)); + BOOST_REQUIRE(element == record1); + BOOST_REQUIRE(instance.at(42, element)); + BOOST_REQUIRE(element == record2); +} + +BOOST_AUTO_TEST_CASE(header__put__exists__expected) +{ + table::prevout::record element{}; + test::chunk_storage head_store{}; + test::chunk_storage body_store{}; + table::prevout instance{ head_store, body_store, 5 }; + BOOST_REQUIRE(instance.create()); + + // Put at key. + BOOST_REQUIRE(instance.put(3, record1)); + BOOST_REQUIRE(instance.put(42, record2)); + + // Exists at key. + BOOST_REQUIRE(!instance.exists(0)); + BOOST_REQUIRE(instance.exists(3)); + BOOST_REQUIRE(instance.exists(42)); +} + +BOOST_AUTO_TEST_CASE(header__put__get__expected) +{ + table::prevout::record element{}; + test::chunk_storage head_store{}; + test::chunk_storage body_store{}; + table::prevout instance{ head_store, body_store, 5 }; + BOOST_REQUIRE(instance.create()); + + // Put at key. + BOOST_REQUIRE(instance.put(3, record1)); + BOOST_REQUIRE(instance.put(42, record2)); + + // Get at link. + BOOST_REQUIRE(!instance.get(2, element)); + BOOST_REQUIRE(instance.get(0, element)); + BOOST_REQUIRE(element == record1); + BOOST_REQUIRE(instance.get(1, element)); + BOOST_REQUIRE(element == record2); +} BOOST_AUTO_TEST_SUITE_END()