TARAXA
gas_pricer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/circular_buffer.hpp>
4 #include <shared_mutex>
5 
6 #include "config/genesis.hpp"
8 
9 namespace taraxa {
10 
11 class DbStorage;
12 
22 class GasPricer {
23  public:
24  GasPricer(const GasPriceConfig &config, bool is_light_node = false, std::shared_ptr<DbStorage> db = {});
25  ~GasPricer();
26 
27  GasPricer(const GasPricer &) = delete;
28  GasPricer(GasPricer &&) = delete;
29  GasPricer &operator=(const GasPricer &) = delete;
30  GasPricer &operator=(GasPricer &&) = delete;
31 
37  u256 bid() const;
38 
44  void update(const SharedTransactions &trxs);
45 
46  private:
52  void init(const std::shared_ptr<DbStorage> &db);
53 
54  const uint64_t kPercentile;
56  const bool kIsLightNode;
57 
58  mutable std::shared_mutex mutex_;
60  boost::circular_buffer<u256> price_list_;
61 
62  std::unique_ptr<std::thread> init_daemon_;
63 };
64 
67 } // namespace taraxa
GasPricer(const GasPriceConfig &config, bool is_light_node=false, std::shared_ptr< DbStorage > db={})
Definition: gas_pricer.cpp:7
std::shared_mutex mutex_
Definition: gas_pricer.hpp:58
GasPricer & operator=(const GasPricer &)=delete
void update(const SharedTransactions &trxs)
updates gas price after each executed block
Definition: gas_pricer.cpp:72
boost::circular_buffer< u256 > price_list_
Definition: gas_pricer.hpp:60
const u256 kMinimumPrice
Definition: gas_pricer.hpp:55
GasPricer(const GasPricer &)=delete
void init(const std::shared_ptr< DbStorage > &db)
initialize values on start from blocks in DB
Definition: gas_pricer.cpp:28
u256 bid() const
returns current gas price
Definition: gas_pricer.cpp:23
std::unique_ptr< std::thread > init_daemon_
Definition: gas_pricer.hpp:62
const bool kIsLightNode
Definition: gas_pricer.hpp:56
u256 latest_price_
Definition: gas_pricer.hpp:59
~GasPricer()
Definition: gas_pricer.cpp:19
GasPricer(GasPricer &&)=delete
const uint64_t kPercentile
Definition: gas_pricer.hpp:54
GasPricer & operator=(GasPricer &&)=delete
Basic gas price calculator. We calculate the gas price based on the lowest price in last number_of_bl...
Definition: gas_pricer.hpp:22
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:98
Definition: config.hpp:8
std::vector< SharedTransaction > SharedTransactions
Definition: transaction.hpp:81
Definition: genesis.hpp:12