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
7 changes: 6 additions & 1 deletion include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class BCN_API chaser_transaction
std::vector<size_t> sigops_of{};
std::unordered_set<system::hash_digest> held{};
query::pool_graph graph{};
uint64_t bytes{};
uint64_t weight{};
uint64_t sigops{};
size_t given{};
size_t first{};
Expand All @@ -215,6 +215,10 @@ class BCN_API chaser_transaction
static size_t to_rate(const system::chain::transaction& tx) NOEXCEPT;
system::pool::algorithm::totals_t block_limit() const NOEXCEPT;

/// Chain state of top, the held state advanced by top, else from store.
system::chain::chain_state::cptr top_state(const database::header_link& top,
size_t height) NOEXCEPT;

/// Submission steps.
void hold(submission& set) NOEXCEPT;
bool spends_held(const submission& set,
Expand Down Expand Up @@ -313,6 +317,7 @@ class BCN_API chaser_transaction
// These are protected by strand.
pool_subscriber subscriber_{};
system::chain::context pool_{};
system::chain::chain_state::cptr state_{};
system::hash_digest previous_{};
database::header_link top_{};
size_t floor_{};
Expand Down
32 changes: 27 additions & 5 deletions src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ void chaser_transaction::do_bump() NOEXCEPT
return;
}

const auto state = query.get_confirmed_chain_state(system_settings(),
top, height);

const auto state = top_state(top, height);
if (!state)
{
fault(error::transaction1);
Expand All @@ -216,7 +214,7 @@ void chaser_transaction::do_bump() NOEXCEPT
// The context of the next block, in which a pool tx would confirm.
const auto previous = pool_;
pool_ = chain_state{ *state, system_settings() }.context();
previous_ = query.get_header_key(top);
previous_ = state->hash();

// Row holds unless a flag changes or height or median time past falls.
due_ = due_ || pool_.flags != previous.flags ||
Expand Down Expand Up @@ -265,6 +263,30 @@ void chaser_transaction::do_bump() NOEXCEPT
start_scan(true);
}

// private
chain_state::cptr chaser_transaction::top_state(
const database::header_link& top, size_t height) NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();
if (state_ && height == state_->height() &&
query.get_header_key(top) == state_->hash())
return state_;

if (state_ && height == add1(state_->height()))
{
const auto header = query.get_header(top);
if (header && header->previous_block_hash() == state_->hash())
{
state_ = to_shared<chain_state>(*state_, *header, system_settings());
return state_;
}
}

state_ = query.get_confirmed_chain_state(system_settings(), top, height);
return state_;
}

bool chaser_transaction::is_indexing() const NOEXCEPT
{
return network_settings().enable_relay && archive().is_pooling();
Expand Down Expand Up @@ -715,7 +737,7 @@ pool::algorithm::totals_t chaser_transaction::block_limit() const NOEXCEPT
return
{
{},
possible_narrow_cast<uint32_t>(weight / light_weight_factor),
possible_narrow_cast<uint32_t>(weight),
possible_narrow_cast<uint32_t>(sigops)
};
}
Expand Down
8 changes: 5 additions & 3 deletions src/chasers/chaser_transaction_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ void chaser_transaction::do_estimate(size_t target, estimate_mode mode,
};

using algorithm = pool::algorithm;
const auto space = limit.size;
const auto rate = algorithm::estimate(projection_, count, space,
settings.estimate_room, arrive);
const auto space = limit.weight;
const auto room = ceilinged_multiply<uint64_t>(settings.estimate_room,
light_weight_factor);
const auto rate = algorithm::estimate(projection_, count, space, room,
arrive);
if (rate == max_uint64)
{
handler(error::estimate_false, {});
Expand Down
16 changes: 7 additions & 9 deletions src/chasers/chaser_transaction_relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,34 @@ bool chaser_transaction::relay(const database::tx_links& links,
if (archive().get_pooled_ancestry(rows, links))
return false;

const auto limit = block_limit().size;
const auto limit = block_limit().weight;
const auto bytes_per_sigop = node_settings().pool.bytes_per_sigop;
std::array<uint64_t, relay_slots> fees{};
std::array<uint64_t, relay_slots> sizes{};
std::array<uint64_t, relay_slots> weights{};
for (const auto& row: rows)
{
auto& mark = marks(row.row);
if (origin < relay_slots)
set_right_into(mark, origin);

const auto lacking = bit_and(slots, bit_not(mark));
const auto size = algorithm::chargeable(row.totals, bytes_per_sigop);
const auto weight = algorithm::chargeable(row.totals, bytes_per_sigop);
for (size_t slot{}; slot < relay_slots; ++slot)
{
if (get_right(lacking, slot))
{
fees.at(slot) = ceilinged_add(fees.at(slot), row.totals.fee);
sizes.at(slot) = ceilinged_add(sizes.at(slot), size);
weights.at(slot) = ceilinged_add(weights.at(slot), weight);
}
}
}

// Compared in satoshis per virtual kilobyte.
uint64_t clears{};
for (size_t slot{}; slot < relay_slots; ++slot)
{
const auto size = sizes.at(slot);
const auto paid = ceilinged_multiply(fees.at(slot), 1'000_u64);
const auto owed = ceilinged_multiply(rates_.at(slot), size);
if (!is_zero(size) && size <= limit && paid >= owed)
const auto weight = weights.at(slot);
if (!is_zero(weight) && weight <= limit &&
algorithm::covered(fees.at(slot), weight, rates_.at(slot)))
set_right_into(clears, slot);
}

Expand Down
10 changes: 5 additions & 5 deletions src/chasers/chaser_transaction_submit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static std::string describe_limit(const node::query& query,
out << "candidate " << at << (ancestry ? " outcomes " :
" ancestry ") << "members " << component.count
<< " contests " << component.contests << " outcomes "
<< outcomes << " size " << sum.size << " sigops "
<< outcomes << " weight " << sum.weight << " sigops "
<< sum.sigops << ":" << members(component);
return out.str();
}
Expand Down Expand Up @@ -300,7 +300,7 @@ void chaser_transaction::count(submission& set, size_t index) const NOEXCEPT
using algorithm = pool::algorithm;
const auto totals = algorithm::from_column(set.graph.totals.back());
set.sigops_of.at(index) = totals.sigops;
set.bytes = ceilinged_add<uint64_t>(set.bytes, totals.size);
set.weight = ceilinged_add<uint64_t>(set.weight, totals.weight);
set.sigops = ceilinged_add<uint64_t>(set.sigops, totals.sigops);
}

Expand All @@ -323,7 +323,7 @@ code chaser_transaction::extend(bool& covered, submission& set,
count(set, index);

const auto limit = block_limit();
if (set.bytes > limit.size || set.sigops > limit.sigops)
if (set.weight > limit.weight || set.sigops > limit.sigops)
{
LOGN("Pool limit [" << encode_hash(tx.get_hash(false))
<< "] running set over a block");
Expand Down Expand Up @@ -361,7 +361,7 @@ code chaser_transaction::restore(submission& set, size_t index) NOEXCEPT
auto& query = archive();
const auto ctx = database::context::from(pool_);
set.graph = {};
set.bytes = set.sigops = zero;
set.weight = set.sigops = zero;
set.running = false;
for (auto at = set.first; at < index; ++at)
{
Expand Down Expand Up @@ -426,7 +426,7 @@ code chaser_transaction::clear(size_t& at, submission& set,
}

set.running = false;
set.bytes = set.sigops = zero;
set.weight = set.sigops = zero;
return error::success;
}

Expand Down
Loading