Skip to content

Commit 2d67f1f

Browse files
authored
Merge pull request #692 from evoskuil/master
Update fee queries to pull whole object.
2 parents 19bfa9c + af7e49c commit 2d67f1f

File tree

7 files changed

+63
-27
lines changed

7 files changed

+63
-27
lines changed

include/bitcoin/database/impl/primitives/hashhead.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ INLINE constexpr CLASS::cell CLASS::next_cell(bool& collision, cell previous,
273273
using namespace system;
274274
const auto prev = to_filter(previous);
275275
const auto next = filter_t::screen(prev, entropy);
276-
collision = filter_t::is_collision(prev, next);
276+
collision = false; //// filter_t::is_collision(prev, next);
277277
return bit_or<cell>(shift_left<cell>(next, link_bits), current);
278278
}
279279
}

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/impl/query/objects.ipp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,41 @@ typename CLASS::output::cptr CLASS::get_output(
304304
return out.output;
305305
}
306306

307+
TEMPLATE
308+
typename CLASS::point CLASS::get_spent(const output_link& link) const NOEXCEPT
309+
{
310+
////const auto tx = to_output_tx(link);
311+
////const auto hash = get_tx_key(tx);
312+
////const auto index = to_output_index(tx, link);
313+
////if (tx.is_terminal())
314+
////{
315+
//// return { {}, 42 };
316+
////}
317+
////else if (hash == system::null_hash && index == point::null_index)
318+
////{
319+
//// return { {}, 96 };
320+
////}
321+
////else if (hash == system::null_hash && index != point::null_index)
322+
////{
323+
//// return { {}, index };
324+
////}
325+
////else if (hash != system::null_hash && index == point::null_index)
326+
////{
327+
//// return { hash, 69 };
328+
////}
329+
////else // if (hash != system::null_hash && index != point::null_index)
330+
////{
331+
//// return { hash, index };
332+
////}
333+
334+
if (const auto tx = to_output_tx(link); !tx.is_terminal())
335+
if (const auto index = to_output_index(tx, link);
336+
index != point::null_index)
337+
return { get_tx_key(tx), index };
338+
339+
return {};
340+
}
341+
307342
TEMPLATE
308343
typename CLASS::point CLASS::get_spender(const point_link& link) const NOEXCEPT
309344
{

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,23 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT
124124
}
125125

126126
TEMPLATE
127-
code CLASS::get_block_state(uint64_t& fees,
128-
const header_link& link) const NOEXCEPT
127+
uint64_t CLASS::get_block_fees(const header_link& link) const NOEXCEPT
129128
{
130-
table::validated_bk::slab valid{};
131-
if (!store_.validated_bk.at(to_validated_bk(link), valid))
132-
return is_associated(link) ? error::unvalidated : error::unassociated;
129+
// TODO: optimize.
130+
const auto block = get_block(link, false);
131+
return block && populate_without_metadata(*block) ? block->fees() :
132+
max_uint64;
133+
}
133134

134-
// TODO: Fees only valid if block_valid is the current state (iterate for valid).
135-
fees = valid.fees;
135+
TEMPLATE
136+
uint64_t CLASS::get_tx_fee(const tx_link& link) const NOEXCEPT
137+
{
138+
// TODO: optimize.
139+
const auto tx = get_transaction(link, false);
140+
if (is_coinbase(link))
141+
return {};
136142

137-
return to_block_code(valid.code);
143+
return tx && populate_without_metadata(*tx) ? tx->fee() : max_uint64;
138144
}
139145

140146
TEMPLATE

include/bitcoin/database/query.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,11 @@ class query
394394
input::cptr get_input(const tx_link& link, uint32_t index,
395395
bool witness) const NOEXCEPT;
396396

397+
point get_spent(const output_link& link) const NOEXCEPT;
398+
point get_spender(const point_link& link) const NOEXCEPT;
397399
script::cptr get_output_script(const output_link& link) const NOEXCEPT;
398400
output::cptr get_output(const output_link& link) const NOEXCEPT;
399401
output::cptr get_output(const tx_link& link, uint32_t index) const NOEXCEPT;
400-
point get_spender(const point_link& link) const NOEXCEPT;
401402
inputs_ptr get_spenders(const output_link& link,
402403
bool witness) const NOEXCEPT;
403404

@@ -473,9 +474,10 @@ class query
473474
/// -----------------------------------------------------------------------
474475

475476
/// States.
476-
code get_header_state(const header_link& link) const NOEXCEPT;
477+
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
478+
uint64_t get_block_fees(const header_link& link) const NOEXCEPT;
477479
code get_block_state(const header_link& link) const NOEXCEPT;
478-
code get_block_state(uint64_t& fees, const header_link& link) const NOEXCEPT;
480+
code get_header_state(const header_link& link) const NOEXCEPT;
479481
code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;
480482
code get_tx_state(uint64_t& fee, size_t& sigops, const tx_link& link,
481483
const context& ctx) const NOEXCEPT;

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);

test/query/validate.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__invalid_link__unassociated
167167
uint64_t fees{};
168168
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
169169
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
170-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
171170
BOOST_REQUIRE_EQUAL(fees, 0u);
172171
}
173172

@@ -185,7 +184,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unassociated_link__unassoc
185184
uint64_t fees{};
186185
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
187186
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
188-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
189187
BOOST_REQUIRE_EQUAL(fees, 0u);
190188
}
191189

@@ -202,7 +200,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unvalidated_link__unvalida
202200
uint64_t fees{};
203201
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
204202
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unvalidated);
205-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unvalidated);
206203
BOOST_REQUIRE_EQUAL(fees, 0u);
207204
}
208205

@@ -219,13 +216,11 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__confirmable__block_confirm
219216
uint64_t fees{};
220217
BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::unvalidated);
221218
BOOST_REQUIRE_EQUAL(query.get_block_state(0), error::unvalidated);
222-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 0), error::unvalidated);
223219
BOOST_REQUIRE_EQUAL(fees, 0u);
224220

225221
BOOST_REQUIRE(query.set_block_confirmable(1));
226222
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_confirmable);
227223
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_confirmable);
228-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_confirmable);
229224
BOOST_REQUIRE_EQUAL(fees, 0u);
230225
}
231226

@@ -239,12 +234,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__valid__block_valid)
239234
BOOST_REQUIRE(query.initialize(test::genesis));
240235
BOOST_REQUIRE(query.set(test::block1, context{}, false, false));
241236

242-
uint64_t fees{};
243237
BOOST_REQUIRE(query.set_block_valid(1, 42));
244238
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_valid);
245239
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_valid);
246-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_valid);
247-
BOOST_REQUIRE_EQUAL(fees, 42u);
248240
}
249241

250242
BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_unconfirmable)
@@ -257,12 +249,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_uncon
257249
BOOST_REQUIRE(query.initialize(test::genesis));
258250
BOOST_REQUIRE(query.set(test::block1, context{}, false, false));
259251

260-
uint64_t fees{};
261252
BOOST_REQUIRE(query.set_block_unconfirmable(1));
262253
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_unconfirmable);
263254
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_unconfirmable);
264-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_unconfirmable);
265-
BOOST_REQUIRE_EQUAL(fees, 0u);
266255
}
267256

268257
BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__invalid_link__unvalidated)

0 commit comments

Comments
 (0)