Kagome
Polkadot Runtime Engine in C++17
pool_moderator_impl.cpp
Go to the documentation of this file.
1 
7 
9 
10 namespace kagome::transaction_pool {
11 
13  std::shared_ptr<clock::SystemClock> clock, Params parameters)
14  : clock_{std::move(clock)}, params_{parameters} {}
15 
16  void PoolModeratorImpl::ban(const common::Hash256 &tx_hash) {
17  banned_until_.insert({tx_hash, clock_->now() + params_.ban_for});
18  if (banned_until_.size() > params_.expected_size * 2) {
19  while (banned_until_.size() > params_.expected_size) {
20  banned_until_.erase(banned_until_.begin());
21  }
22  }
23  }
24 
26  const primitives::Transaction &tx) {
27  if (tx.valid_till > current_block) {
28  return false;
29  }
30  ban(tx.hash);
31  return true;
32  }
33 
34  bool PoolModeratorImpl::isBanned(const common::Hash256 &tx_hash) const {
35  auto it = banned_until_.find(tx_hash);
36  if (it == banned_until_.end()) {
37  return false;
38  }
39  // if ban time is exceeded, the transaction will be removed from the list
40  // on next updateBan()
41  return it->second >= clock_->now();
42  }
43 
45  auto now = clock_->now();
46  for (auto it = banned_until_.begin(); it != banned_until_.end();) {
47  if (it->second < now) {
48  it = banned_until_.erase(it);
49  } else {
50  it++;
51  }
52  }
53  }
54 
56  return banned_until_.size();
57  }
58 
59 } // namespace kagome::transaction_pool
bool banIfStale(primitives::BlockNumber current_block, const Transaction &tx) override
void ban(const common::Hash256 &tx_hash) override
bool isBanned(const common::Hash256 &tx_hash) const override
Longevity valid_till
At which block the transaction becomes invalid?
Definition: transaction.hpp:46
uint32_t BlockNumber
Definition: common.hpp:18
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
Definition: buffer.hpp:244
Hash hash
Extrinsic hash (non-unique)
Definition: transaction.hpp:40
std::shared_ptr< clock::SystemClock > clock_
PoolModeratorImpl(std::shared_ptr< clock::SystemClock > clock, Params parameters)