Skip to content

Commit 18c61a7

Browse files
committed
Fix address index write for > 0th index outputs.
1 parent 33be281 commit 18c61a7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

include/bitcoin/database/impl/query/archive_write.ipp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,19 @@ code CLASS::set_code(const tx_link& tx_fk, const transaction& tx) NOEXCEPT
192192
if (ad_fk.is_terminal())
193193
return error::tx_address_allocate;
194194

195+
constexpr auto value_parent_diff = sizeof(uint64_t) - tx_link::size;
195196
const auto ptr = store_.address.get_memory();
196197
for (const auto& output: *ous)
197198
{
198199
if (!store_.address.put(ptr, ad_fk++, output->script().hash(),
199200
table::address::record{ {}, out_fk }))
200201
return error::tx_address_put;
201202

202-
out_fk.value += output->serialized_size();
203+
// See outs::put_ref.
204+
// Calculate next corresponding output fk from serialized size.
205+
// (variable_size(value) + (value + script)) - (value - parent)
206+
out_fk.value += (variable_size(output->value()) +
207+
output->serialized_size() - value_parent_diff);
203208
}
204209
}
205210

include/bitcoin/database/tables/archives/outs.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ struct outs
106106
{
107107
using namespace system;
108108
static_assert(tx::size <= sizeof(uint64_t));
109-
constexpr auto value_parent_difference = sizeof(uint64_t) -
110-
tx::size;
109+
constexpr auto value_parent_diff = sizeof(uint64_t) - tx::size;
111110

112111
auto out_fk = output_fk;
113112
const auto& outs = *tx_.outputs_ptr();
@@ -118,7 +117,7 @@ struct outs
118117
// Calculate next corresponding output fk from serialized size.
119118
// (variable_size(value) + (value + script)) - (value - parent)
120119
out_fk += (variable_size(out->value()) + out->serialized_size() -
121-
value_parent_difference);
120+
value_parent_diff);
122121
});
123122

124123
BC_ASSERT(!sink || sink.get_write_position() == count() * minrow);

0 commit comments

Comments
 (0)