@@ -65,10 +65,10 @@ bool CLASS::set(const transaction& tx) NOEXCEPT
6565}
6666
6767TEMPLATE
68- bool CLASS::set (const block& block, bool strong) NOEXCEPT
68+ bool CLASS::set (const block& block, bool strong, bool bypass ) NOEXCEPT
6969{
7070 // This sets only the txs of a block with header/context already archived.
71- return !set_code (block, strong);
71+ return !set_code (block, strong, bypass );
7272}
7373
7474// set transaction
@@ -84,11 +84,12 @@ code CLASS::set_code(const transaction& tx) NOEXCEPT
8484 if (tx_fk.is_terminal ())
8585 return error::tx_tx_allocate;
8686
87- return set_code (tx_fk, tx);
87+ return set_code (tx_fk, tx, false );
8888}
8989
9090TEMPLATE
91- code CLASS::set_code (const tx_link& tx_fk, const transaction& tx) NOEXCEPT
91+ code CLASS::set_code (const tx_link& tx_fk, const transaction& tx,
92+ bool bypass) NOEXCEPT
9293{
9394 // This is the only multitable write query (except initialize/genesis).
9495
@@ -106,9 +107,6 @@ code CLASS::set_code(const tx_link& tx_fk, const transaction& tx) NOEXCEPT
106107 // ========================================================================
107108 const auto scope = store_.get_transactor ();
108109
109- // If dirty we must guard against duplicates.
110- const auto dirty = store_.is_dirty ();
111-
112110 // Allocate contiguously and store inputs.
113111 input_link in_fk{};
114112 if (!store_.input .put_link (in_fk,
@@ -167,9 +165,13 @@ code CLASS::set_code(const tx_link& tx_fk, const transaction& tx) NOEXCEPT
167165 if (!store_.point .expand (ins_fk + inputs))
168166 return error::tx_point_allocate;
169167
168+ // If dirty we must guard against duplicates.
169+ // Dirty doesn't hold up in the case of an invalidated block, as that
170+ // may result in a duplicated tx. So dirty should be false in the case
171+ // of a non-bypass (valid) block.
170172 // Must be set after tx.set and before tx.commit, since searchable and
171173 // produces association to tx.link, and is also an integral part of tx.
172- if (dirty )
174+ if (store_. is_dirty () || !bypass )
173175 {
174176 // Collect duplicates to store in duplicate table.
175177 std::vector<chain::point> twins{};
@@ -336,7 +338,7 @@ code CLASS::set_code(header_link& out_fk, const block& block,
336338 const context& ctx, bool milestone, bool strong) NOEXCEPT
337339{
338340 const auto ec = set_code (out_fk, block.header (), ctx, milestone);
339- return ec ? ec : set_code (block, out_fk, strong);
341+ return ec ? ec : set_code (block, out_fk, strong, strong || milestone );
340342}
341343
342344// set txs from block
@@ -346,26 +348,26 @@ code CLASS::set_code(header_link& out_fk, const block& block,
346348// releases all memory for parts of itself, due to the custom allocator.
347349
348350TEMPLATE
349- code CLASS::set_code (const block& block, bool strong) NOEXCEPT
351+ code CLASS::set_code (const block& block, bool strong, bool bypass ) NOEXCEPT
350352{
351353 header_link unused{};
352- return set_code (unused, block, strong);
354+ return set_code (unused, block, strong, bypass );
353355}
354356
355357TEMPLATE
356- code CLASS::set_code (header_link& out_fk, const block& block,
357- bool strong ) NOEXCEPT
358+ code CLASS::set_code (header_link& out_fk, const block& block, bool strong,
359+ bool bypass ) NOEXCEPT
358360{
359361 out_fk = to_header (block.get_hash ());
360362 if (out_fk.is_terminal ())
361363 return error::txs_header;
362364
363- return set_code (block, out_fk, strong);
365+ return set_code (block, out_fk, strong, bypass );
364366}
365367
366368TEMPLATE
367369code CLASS::set_code (const block& block, const header_link& key,
368- bool strong) NOEXCEPT
370+ bool strong, bool bypass ) NOEXCEPT
369371{
370372 using namespace system ;
371373 if (key.is_terminal ())
@@ -383,7 +385,7 @@ code CLASS::set_code(const block& block, const header_link& key,
383385 code ec{};
384386 auto fk = tx_fks;
385387 for (const auto & tx: *block.transactions_ptr ())
386- if ((ec = set_code (fk++, *tx)))
388+ if ((ec = set_code (fk++, *tx, bypass )))
387389 return ec;
388390
389391 using bytes = linkage<schema::size>::integer;
0 commit comments