Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class BCN_API chaser_block

private:
void set_prevout(const system::chain::input& input) const NOEXCEPT;
bool populate(const system::chain::block& block,
const system::chain::context& ctx) const NOEXCEPT;
bool populate(const system::chain::block& block) const NOEXCEPT;
};

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ enum error_t : uint8_t
validate5,
validate6,
validate7,
validate8,
validate9,
////validate8,
////validate9,
confirm1,
confirm2,
confirm3,
Expand Down
26 changes: 12 additions & 14 deletions src/chasers/chaser_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ code chaser_block::validate(const block& block,
return ec;
}

// Populate prevouts from self/tree (metadata not required).
if (!populate(block, ctx))
return system::error::relative_time_locked;
// Populate prevouts from self/tree (no metadata for accept/connect).
populate(block);

// Populate prevouts from store (metadata not required).
if (!archive().populate(block))
// Populate prevouts from store (no metadata for accept/connect).
if (!archive().populate_without_metadata(block))
return network::error::protocol_violation;

if ((ec = block.accept(ctx,
Expand Down Expand Up @@ -156,6 +155,8 @@ void chaser_block::update_milestone(const header&, size_t, size_t) NOEXCEPT
void chaser_block::set_prevout(const input& input) const NOEXCEPT
{
const auto& point = input.point();
if (input.prevout || point.is_null())
return;

// Scan all tree blocks for matching tx (linear :/ but legacy scenario)
std::for_each(tree().begin(), tree().end(), [&](const auto& item) NOEXCEPT
Expand All @@ -173,25 +174,22 @@ void chaser_block::set_prevout(const input& input) const NOEXCEPT
const outputs_cptr outs{ tx->outputs_ptr() };
if (point.index() < outs->size())
{
// prevout is mutable so can be set on a const object.
input.prevout = outs->at(point.index());
return;
}
}
});
}

// metadata is mutable so can be set on a const object.
bool chaser_block::populate(const block& block,
const system::chain::context& ctx) const NOEXCEPT
bool chaser_block::populate(const block& block) const NOEXCEPT
{
if (!block.populate(ctx))
return false;
block.populate();

const inputs_cptr ins{ block.inputs_ptr() };
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
const auto& ins = *block.inputs_ptr();
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
{
if (!in->prevout && !in->point().is_null())
set_prevout(*in);
set_prevout(*in);
});

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT

// TODO: This is simplified single thread variant of full implementation below.
// This variant doesn't implement the relative work check and instead confirms
// one block at a time, just like validation.
// one block at a time, just like validation though sequentially.
void chaser_confirm::do_bump(height_t) NOEXCEPT
{
BC_ASSERT(stranded());
Expand Down Expand Up @@ -229,7 +229,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
return;
}

// Set after if using prevout table.
// Set after block_confirmable when using the prevout table.
if (!query.set_strong(link))
{
fault(error::confirm6);
Expand Down
20 changes: 12 additions & 8 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,21 @@ code chaser_validate::populate(bool bypass, const chain::block& block,
{
const auto& query = archive();

// Relative locktime check is unnecessary under bypass, but cheap.
if (!block.populate(ctx))
return system::error::relative_time_locked;

if (bypass)
{
block.populate();
if (!query.populate_without_metadata(block))
return system::error::missing_previous_output;
}
else
{
if (!query.populate(block))
// Internal maturity and time locks are verified here because they are
// the only necessary confirmation checks for internal spends.
if (const auto ec = block.populate_with_metadata(ctx))
return ec;

// Metadata identifies internal spends alowing confirmation bypass.
if (!query.populate_with_metadata(block))
return system::error::missing_previous_output;
}

Expand All @@ -271,11 +274,11 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
if ((ec = block.connect(ctx)))
return ec;

if ((ec = query.set_prevouts(link, block)))
return ec;
if (!query.set_prevouts(link, block))
return error::validate6;

if (!query.set_block_valid(link, block.fees()))
return error::validate6;
return error::validate7;

return ec;
}
Expand All @@ -286,6 +289,7 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
{
if (ec)
{
// Node errors are fatal.
if (node::error::error_category::contains(ec))
{
LOGR("Validate fault [" << height << "] " << ec.message());
Expand Down
4 changes: 2 additions & 2 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ validate5, "validate5" },
{ validate6, "validate6" },
{ validate7, "validate7" },
{ validate8, "validate8" },
{ validate9, "validate9" },
////{ validate8, "validate8" },
////{ validate9, "validate9" },
{ confirm1, "confirm1" },
{ confirm2, "confirm2" },
{ confirm3, "confirm3" },
Expand Down
Loading