Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
transaction_context.hpp
Go to the documentation of this file.
1#pragma once
5#include <signal.h>
6
7namespace sysio { namespace chain {
8
10 public:
16
17 void start(fc::time_point tp);
18 void stop();
19
20 /* Sets a callback for when timer expires. Be aware this could might fire from a signal handling context and/or
21 on any particular thread. Only a single callback can be registered at once; trying to register more will
22 result in an exception. Use nullptr to disable a previously set callback. */
23 void set_expiration_callback(void(*func)(void*), void* user);
24
25 std::atomic_bool& expired;
26 private:
27 platform_timer& _timer;
28
29 friend controller_impl;
30 };
31
33 private:
34 void init( uint64_t initial_net_usage);
35
36 public:
37
39 const packed_transaction& t,
42 bool read_only=false);
44
45 void init_for_implicit_trx( uint64_t initial_net_usage = 0 );
46
47 void init_for_input_trx( uint64_t packed_trx_unprunable_size,
48 uint64_t packed_trx_prunable_size );
49
51
52 void exec();
53 void finalize();
54 void squash();
55 void undo();
56
57 inline void add_net_usage( uint64_t u ) { net_usage += u; check_net_usage(); }
58
59 void check_net_usage()const;
60
61 void checktime()const;
62
63 template <typename DigestType>
64 inline DigestType hash_with_checktime( const char* data, uint32_t datalen )const {
65 const size_t bs = sysio::chain::config::hashing_checktime_block_size;
66 typename DigestType::encoder enc;
67 while ( datalen > bs ) {
68 enc.write( data, bs );
69 data += bs;
70 datalen -= bs;
71 checktime();
72 }
73 enc.write( data, datalen );
74 return enc.result();
75 }
76
79
81
82 std::tuple<int64_t, int64_t, bool, bool> max_bandwidth_billed_accounts_can_pay( bool force_elastic_limits = false )const;
83
84 void validate_referenced_accounts( const transaction& trx, bool enforce_actor_whitelist_blacklist )const;
85
86 private:
87
88 friend struct controller_impl;
89 friend class apply_context;
90
91 void add_ram_usage( account_name account, int64_t ram_delta );
92
93 action_trace& get_action_trace( uint32_t action_ordinal );
94 const action_trace& get_action_trace( uint32_t action_ordinal )const;
95
97 uint32_t schedule_action( const action& act, account_name receiver, bool context_free,
98 uint32_t creator_action_ordinal, uint32_t closest_unnotified_ancestor_action_ordinal );
99
101 uint32_t schedule_action( action&& act, account_name receiver, bool context_free,
102 uint32_t creator_action_ordinal, uint32_t closest_unnotified_ancestor_action_ordinal );
103
105 uint32_t schedule_action( uint32_t action_ordinal, account_name receiver, bool context_free,
106 uint32_t creator_action_ordinal, uint32_t closest_unnotified_ancestor_action_ordinal );
107
108 void execute_action( uint32_t action_ordinal, uint32_t recurse_depth );
109
110 void schedule_transaction();
111 void record_transaction( const transaction_id_type& id, fc::time_point_sec expire );
112
113 void validate_cpu_usage_to_bill( int64_t billed_us, int64_t account_cpu_limit, bool check_minimum )const;
114 void validate_account_cpu_usage( int64_t billed_us, int64_t account_cpu_limit )const;
115 void validate_account_cpu_usage_estimate( int64_t billed_us, int64_t account_cpu_limit )const;
116
117 void disallow_transaction_extensions( const char* error_msg )const;
118
120 public:
121
124 std::optional<chainbase::database::session> undo_session;
127
129
130
132 flat_set<account_name> bill_to_accounts;
133 flat_set<account_name> validate_ram_usage;
134
137
139 bool is_input = false;
142
144 fc::microseconds leeway = fc::microseconds( config::default_subjective_cpu_leeway_us );
148
150
151 const bool is_read_only;
152 private:
153 bool is_initialized = false;
154
155 uint64_t net_limit = 0;
156 bool net_limit_due_to_block = true;
157 bool net_limit_due_to_greylist = false;
158 uint64_t eager_net_limit = 0;
159 uint64_t& net_usage;
160
161 bool cpu_limit_due_to_greylist = false;
162
163 fc::microseconds max_transaction_time_subjective;
164 fc::time_point paused_time;
165 fc::microseconds initial_objective_duration_limit;
166 fc::microseconds objective_duration_limit;
167 fc::time_point _deadline = fc::time_point::maximum(); // calculated deadline
168 int64_t deadline_exception_code = block_cpu_usage_exceeded::code_value;
169 int64_t billing_timer_exception_code = block_cpu_usage_exceeded::code_value;
170 fc::time_point pseudo_start;
171 fc::microseconds billed_time;
172 };
173
174} }
static time_point now()
Definition time.cpp:14
static constexpr time_point maximum()
Definition time.hpp:46
void init_for_deferred_trx(fc::time_point published)
const packed_transaction & packed_trx
uint64_t initial_max_billable_cpu
the maximum number of virtual CPU instructions of the transaction that can be safely billed to the bi...
uint32_t update_billed_cpu_time(fc::time_point now)
transaction_checktime_timer transaction_timer
flat_set< account_name > validate_ram_usage
void init_for_implicit_trx(uint64_t initial_net_usage=0)
transaction_context(controller &c, const packed_transaction &t, transaction_checktime_timer &&timer, fc::time_point start=fc::time_point::now(), bool read_only=false)
void validate_referenced_accounts(const transaction &trx, bool enforce_actor_whitelist_blacklist) const
record_transaction
std::optional< chainbase::database::session > undo_session
vector< digest_type > executed_action_receipt_digests
DigestType hash_with_checktime(const char *data, uint32_t datalen) const
flat_set< account_name > bill_to_accounts
std::tuple< int64_t, int64_t, bool, bool > max_bandwidth_billed_accounts_can_pay(bool force_elastic_limits=false) const
void init_for_input_trx(uint64_t packed_trx_unprunable_size, uint64_t packed_trx_prunable_size)
void init()
Definition lib_test.cpp:3
@ read_only
std::shared_ptr< transaction_trace > transaction_trace_ptr
Definition trace.hpp:20
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Immutable except for fc::from_variant.
Definition name.hpp:43
transaction_checktime_timer(transaction_checktime_timer &&)=default
transaction_checktime_timer(const transaction_checktime_timer &)=delete
void set_expiration_callback(void(*func)(void *), void *user)
CK_ULONG datalen