Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::subjective_billing Class Reference

#include <subjective_billing.hpp>

Public Member Functions

void remove_subjective_billing (const transaction_id_type &trx_id, uint32_t time_ordinal)
 
void disable ()
 
void disable_account (chain::account_name a)
 
bool is_account_disabled (const account_name &a) const
 
void subjective_bill (const transaction_id_type &id, const fc::time_point &expire, const account_name &first_auth, const fc::microseconds &elapsed, bool in_pending_block)
 
void subjective_bill_failure (const account_name &first_auth, const fc::microseconds &elapsed, const fc::time_point &now)
 
int64_t get_subjective_bill (const account_name &first_auth, const fc::time_point &now) const
 
void abort_block ()
 
void on_block (fc::logger &log, const block_state_ptr &bsp, const fc::time_point &now)
 
template<typename Yield >
bool remove_expired (fc::logger &log, const fc::time_point &pending_block_time, const fc::time_point &now, Yield &&yield)
 
uint32_t get_expired_accumulator_average_window () const
 
void set_expired_accumulator_average_window (fc::microseconds subjective_account_decay_time)
 

Static Public Attributes

static constexpr uint32_t subjective_time_interval_ms = 5'000
 

Detailed Description

Definition at line 25 of file subjective_billing.hpp.

Member Function Documentation

◆ abort_block()

void sysio::subjective_billing::abort_block ( )
inline

Definition at line 171 of file subjective_billing.hpp.

171 {
172 _block_subjective_bill_cache.clear();
173 }
Here is the caller graph for this function:

◆ disable()

void sysio::subjective_billing::disable ( )
inline

Definition at line 115 of file subjective_billing.hpp.

115{ _disabled = true; }

◆ disable_account()

void sysio::subjective_billing::disable_account ( chain::account_name a)
inline

Definition at line 116 of file subjective_billing.hpp.

116{ _disabled_accounts.emplace( a ); }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ get_expired_accumulator_average_window()

uint32_t sysio::subjective_billing::get_expired_accumulator_average_window ( ) const
inline

Definition at line 210 of file subjective_billing.hpp.

210 {
211 return _expired_accumulator_average_window;
212 }

◆ get_subjective_bill()

int64_t sysio::subjective_billing::get_subjective_bill ( const account_name & first_auth,
const fc::time_point & now ) const
inline

Definition at line 148 of file subjective_billing.hpp.

148 {
149 if( _disabled || _disabled_accounts.count( first_auth ) ) return 0;
150 const auto time_ordinal = time_ordinal_for(now);
151 const subjective_billing_info* sub_bill_info = nullptr;
152 auto aitr = _account_subjective_bill_cache.find( first_auth );
153 if( aitr != _account_subjective_bill_cache.end() ) {
154 sub_bill_info = &aitr->second;
155 }
156 uint64_t in_block_pending_cpu_us = 0;
157 auto bitr = _block_subjective_bill_cache.find( first_auth );
158 if( bitr != _block_subjective_bill_cache.end() ) {
159 in_block_pending_cpu_us = bitr->second;
160 }
161
162 if (sub_bill_info) {
163 SYS_ASSERT(sub_bill_info->pending_cpu_us >= in_block_pending_cpu_us, chain::tx_resource_exhaustion, "Logic error subjective billing ${a}", ("a", first_auth) );
164 int64_t sub_bill = sub_bill_info->pending_cpu_us - in_block_pending_cpu_us + sub_bill_info->expired_accumulator.value_at(time_ordinal, _expired_accumulator_average_window );
165 return sub_bill;
166 } else {
167 return 0;
168 }
169 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
signed __int64 int64_t
Definition stdint.h:135
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ is_account_disabled()

bool sysio::subjective_billing::is_account_disabled ( const account_name & a) const
inline

Definition at line 117 of file subjective_billing.hpp.

117{ return _disabled || _disabled_accounts.count( a ); }
Here is the caller graph for this function:

◆ on_block()

void sysio::subjective_billing::on_block ( fc::logger & log,
const block_state_ptr & bsp,
const fc::time_point & now )
inline

Definition at line 175 of file subjective_billing.hpp.

175 {
176 if( bsp == nullptr || _disabled ) return;
177 const auto time_ordinal = time_ordinal_for(now);
178 const auto orig_count = _account_subjective_bill_cache.size();
179 remove_subjective_billing( bsp, time_ordinal );
180 fc_dlog( log, "Subjective billed accounts ${n} removed ${r}", ("n", orig_count)("r", orig_count - _account_subjective_bill_cache.size()) );
181 }
#define fc_dlog(LOGGER, FORMAT,...)
Definition logger.hpp:77
Here is the caller graph for this function:

◆ remove_expired()

template<typename Yield >
bool sysio::subjective_billing::remove_expired ( fc::logger & log,
const fc::time_point & pending_block_time,
const fc::time_point & now,
Yield && yield )
inline

Definition at line 184 of file subjective_billing.hpp.

184 {
185 bool exhausted = false;
186 auto& idx = _trx_cache_index.get<by_expiry>();
187 if( !idx.empty() ) {
188 const auto time_ordinal = time_ordinal_for(now);
189 const auto orig_count = _trx_cache_index.size();
190 uint32_t num_expired = 0;
191
192 while( !idx.empty() ) {
193 if( yield() ) {
194 exhausted = true;
195 break;
196 }
197 auto b = idx.begin();
198 if( b->expiry > pending_block_time ) break;
199 transition_to_expired( *b, time_ordinal );
200 idx.erase( b );
201 num_expired++;
202 }
203
204 fc_dlog( log, "Processed ${n} subjective billed transactions, Expired ${expired}",
205 ("n", orig_count)( "expired", num_expired ) );
206 }
207 return !exhausted;
208 }
thread_local yield_t yield
Definition yield.hpp:52
unsigned int uint32_t
Definition stdint.h:126
Here is the caller graph for this function:

◆ remove_subjective_billing()

void sysio::subjective_billing::remove_subjective_billing ( const transaction_id_type & trx_id,
uint32_t time_ordinal )
inline

Definition at line 105 of file subjective_billing.hpp.

105 {
106 auto& idx = _trx_cache_index.get<by_id>();
107 auto itr = idx.find( trx_id );
108 if( itr != idx.end() ) {
109 remove_subjective_billing( *itr, time_ordinal );
110 idx.erase( itr );
111 }
112 }

◆ set_expired_accumulator_average_window()

void sysio::subjective_billing::set_expired_accumulator_average_window ( fc::microseconds subjective_account_decay_time)
inline

Definition at line 214 of file subjective_billing.hpp.

214 {
215 _expired_accumulator_average_window =
216 subjective_account_decay_time.count() / 1000 / subjective_time_interval_ms;
217 }
constexpr int64_t count() const
Definition time.hpp:26
static constexpr uint32_t subjective_time_interval_ms
Here is the call graph for this function:

◆ subjective_bill()

void sysio::subjective_billing::subjective_bill ( const transaction_id_type & id,
const fc::time_point & expire,
const account_name & first_auth,
const fc::microseconds & elapsed,
bool in_pending_block )
inline
Parameters
in_pending_blockpass true if pt's bill time is accounted for in the pending block

Definition at line 120 of file subjective_billing.hpp.

122 {
123 if( !_disabled && !_disabled_accounts.count( first_auth ) ) {
124 int64_t bill = std::max<int64_t>( 0, elapsed.count() );
125 auto p = _trx_cache_index.emplace(
126 trx_cache_entry{id,
127 first_auth,
128 bill,
129 expire} );
130 if( p.second ) {
131 _account_subjective_bill_cache[first_auth].pending_cpu_us += bill;
132 if( in_pending_block ) {
133 _block_subjective_bill_cache[first_auth] += bill;
134 }
135 }
136 }
137 }
const mie::Vuint & p
Definition bn.cpp:27
uint64_t id
Definition code_cache.cpp:0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ subjective_bill_failure()

void sysio::subjective_billing::subjective_bill_failure ( const account_name & first_auth,
const fc::microseconds & elapsed,
const fc::time_point & now )
inline

Definition at line 139 of file subjective_billing.hpp.

140 {
141 if( !_disabled && !_disabled_accounts.count( first_auth ) ) {
142 int64_t bill = std::max<int64_t>( 0, elapsed.count() );
143 const auto time_ordinal = time_ordinal_for(now);
144 _account_subjective_bill_cache[first_auth].expired_accumulator.add(bill, time_ordinal, _expired_accumulator_average_window);
145 }
146 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ subjective_time_interval_ms

uint32_t sysio::subjective_billing::subjective_time_interval_ms = 5'000
staticconstexpr

Definition at line 103 of file subjective_billing.hpp.


The documentation for this class was generated from the following file: