@@ -118,7 +118,7 @@ bool CLASS::is_unconfirmable(const header_link& link) const NOEXCEPT
118118TEMPLATE
119119code CLASS::get_header_state (const header_link& link) const NOEXCEPT
120120{
121- table::validated_bk::slab_get_code valid{};
121+ table::validated_bk::record valid{};
122122 if (!store_.validated_bk .at (to_validated_bk (link), valid))
123123 return error::unvalidated;
124124
@@ -133,7 +133,7 @@ code CLASS::get_header_state(const header_link& link) const NOEXCEPT
133133TEMPLATE
134134code CLASS::get_block_state (const header_link& link) const NOEXCEPT
135135{
136- table::validated_bk::slab_get_code valid{};
136+ table::validated_bk::record valid{};
137137 if (!store_.validated_bk .at (to_validated_bk (link), valid))
138138 return is_associated (link) ? error::unvalidated : error::unassociated;
139139
@@ -305,171 +305,92 @@ bool CLASS::get_context(system::chain::context& ctx,
305305 return true ;
306306}
307307
308- // Setters.
308+ // set_block_state
309309// ----------------------------------------------------------------------------
310310
311311TEMPLATE
312- bool CLASS::set_block_valid (const header_link& link, uint64_t fees ) NOEXCEPT
312+ bool CLASS::set_block_valid (const header_link& link) NOEXCEPT
313313{
314- // ========================================================================
315- const auto scope = store_.get_transactor ();
316-
317- // Clean single allocation failure (e.g. disk full).
318- return store_.validated_bk .put (to_validated_bk (link),
319- table::validated_bk::slab
320- {
321- {},
322- schema::block_state::valid,
323- fees
324- });
325- // ========================================================================
314+ return set_block_state (link, schema::block_state::valid);
326315}
327316
328317TEMPLATE
329318bool CLASS::set_block_confirmable (const header_link& link) NOEXCEPT
330319{
331- // ========================================================================
332- const auto scope = store_.get_transactor ();
333-
334- // Clean single allocation failure (e.g. disk full).
335- return store_.validated_bk .put (to_validated_bk (link),
336- table::validated_bk::slab
337- {
338- {},
339- schema::block_state::confirmable,
340- 0 // fees
341- });
342- // ========================================================================
320+ return set_block_state (link, schema::block_state::confirmable);
343321}
344322
345323TEMPLATE
346324bool CLASS::set_block_unconfirmable (const header_link& link) NOEXCEPT
347325{
348- // ========================================================================
349- const auto scope = store_.get_transactor ();
350-
351- // Clean single allocation failure (e.g. disk full).
352- return store_.validated_bk .put (to_validated_bk (link),
353- table::validated_bk::slab
354- {
355- {},
356- schema::block_state::unconfirmable,
357- 0 // fees
358- });
359- // ========================================================================
326+ return set_block_state (link, schema::block_state::unconfirmable);
360327}
361328
362329TEMPLATE
363330bool CLASS::set_block_unknown (const header_link& link) NOEXCEPT
364331{
332+ return set_block_state (link, schema::block_state::block_unknown);
333+ }
334+
335+ // private
336+ TEMPLATE
337+ bool CLASS::set_block_state (const header_link& link,
338+ schema::block_state state) NOEXCEPT
339+ {
340+ const auto record = to_validated_bk (link);
341+
365342 // ========================================================================
366343 const auto scope = store_.get_transactor ();
367344
368345 // Clean single allocation failure (e.g. disk full).
369- return store_.validated_bk .put (to_validated_bk (link),
370- table::validated_bk::slab
371- {
372- {},
373- schema::block_state::block_unknown,
374- 0 // fees
375- });
346+ return store_.validated_bk .put (record,
347+ table::validated_bk::record{ {}, state });
376348 // ========================================================================
377349}
378350
351+ // set_tx_state
352+ // ----------------------------------------------------------------------------
353+
379354TEMPLATE
380355bool CLASS::set_tx_unknown (const tx_link& link) NOEXCEPT
381356{
382- // ========================================================================
383- const auto scope = store_.get_transactor ();
384-
385- // Clean single allocation failure (e.g. disk full).
386- return store_.validated_tx .put (link, table::validated_tx::slab
387- {
388- {},
389- {},
390- schema::tx_state::tx_unknown,
391- 0 , // fee
392- 0 // sigops
393- });
394- // ========================================================================
357+ return set_tx_state (link, {}, {}, {}, schema::tx_state::tx_unknown);
395358}
396359
397360TEMPLATE
398361bool CLASS::set_tx_disconnected (const tx_link& link,
399362 const context& ctx) NOEXCEPT
400363{
401- // ========================================================================
402- const auto scope = store_.get_transactor ();
403-
404- // Clean single allocation failure (e.g. disk full).
405- return store_.validated_tx .put (link, table::validated_tx::slab
406- {
407- {},
408- ctx,
409- schema::tx_state::disconnected,
410- 0 , // fee
411- 0 // sigops
412- });
413- // ========================================================================
364+ return set_tx_state (link, ctx, {}, {}, schema::tx_state::disconnected);
414365}
415366
416367TEMPLATE
417368bool CLASS::set_tx_connected (const tx_link& link, const context& ctx,
418369 uint64_t fee, size_t sigops) NOEXCEPT
370+ {
371+ return set_tx_state (link, ctx, fee, sigops, schema::tx_state::connected);
372+ }
373+
374+ // private
375+ TEMPLATE
376+ bool CLASS::set_tx_state (const tx_link& link, const context& ctx,
377+ uint64_t fee, size_t sigops, schema::tx_state state) NOEXCEPT
419378{
420379 using sigs = linkage<schema::sigops>;
421380 BC_ASSERT (sigops<system::power2<sigs::integer>(to_bits (sigs::size)));
422381
423382 // ========================================================================
424383 const auto scope = store_.get_transactor ();
384+ using namespace system ;
425385
426386 // Clean single allocation failure (e.g. disk full).
427387 return store_.validated_tx .put (link, table::validated_tx::slab
428388 {
429- {},
430- ctx,
431- schema::tx_state::connected,
432- fee,
433- system::possible_narrow_cast<sigs::integer>(sigops)
389+ {}, ctx, state, fee, possible_narrow_cast<sigs::integer>(sigops)
434390 });
435391 // ========================================================================
436392}
437393
438- // //TEMPLATE
439- // //bool CLASS::set_txs_connected(const header_link& link) NOEXCEPT
440- // //{
441- // // context ctx{};
442- // // if (!get_context(ctx, link))
443- // // return false;
444- // //
445- // // const auto txs = to_transactions(link);
446- // // if (txs.empty())
447- // // return false;
448- // //
449- // // // FOR PERFORMANCE EVALUATION ONLY.
450- // // constexpr uint64_t fee = 99;
451- // // constexpr size_t sigops = 42;
452- // // using sigs = linkage<schema::sigops>;
453- // //
454- // // // ========================================================================
455- // // const auto scope = store_.get_transactor();
456- // //
457- // // // Clean single allocation failure (e.g. disk full).
458- // // return std_all_of(bc::seq, txs.begin(), txs.end(),
459- // // [&](const tx_link& fk) NOEXCEPT
460- // // {
461- // // return store_.validated_tx.put(fk, table::validated_tx::slab
462- // // {
463- // // {},
464- // // ctx,
465- // // schema::tx_state::connected,
466- // // fee,
467- // // system::possible_narrow_cast<sigs::integer>(sigops)
468- // // });
469- // // });
470- // // // ========================================================================
471- // //}
472-
473394} // namespace database
474395} // namespace libbitcoin
475396
0 commit comments