Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
privileged.cpp
Go to the documentation of this file.
7
8#include <vector>
9#include <set>
10
11namespace sysio { namespace chain { namespace webassembly {
12
13 int interface::is_feature_active( int64_t feature_name ) const { return false; }
14
15 void interface::activate_feature( int64_t feature_name ) const {
16 SYS_ASSERT( false, unsupported_feature, "Unsupported Hardfork Detected" );
17 }
18
20 context.control.preactivate_feature( *feature_digest );
21 }
22
23 void interface::set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight ) {
24 SYS_ASSERT(ram_bytes >= -1, wasm_execution_error, "invalid value for ram resource limit expected [-1,INT64_MAX]");
25 SYS_ASSERT(net_weight >= -1, wasm_execution_error, "invalid value for net resource weight expected [-1,INT64_MAX]");
26 SYS_ASSERT(cpu_weight >= -1, wasm_execution_error, "invalid value for cpu resource weight expected [-1,INT64_MAX]");
27 if( context.control.get_mutable_resource_limits_manager().set_account_limits(account, ram_bytes, net_weight, cpu_weight) ) {
28 context.trx_context.validate_ram_usage.insert( account );
29 }
30 }
31
33 context.control.get_resource_limits_manager().get_account_limits( account, *ram_bytes, *net_weight, *cpu_weight);
34 (void)legacy_ptr<int64_t>(std::move(ram_bytes));
35 (void)legacy_ptr<int64_t>(std::move(net_weight));
36 (void)legacy_ptr<int64_t>(std::move(cpu_weight));
37 }
38
40 SYS_ASSERT(producers.size() <= config::max_producers, wasm_execution_error, "Producer schedule exceeds the maximum producer count for this chain");
41 SYS_ASSERT( producers.size() > 0
43 wasm_execution_error,
44 "Producer schedule cannot be empty"
45 );
46
47 const size_t num_supported_key_types = context.db.get<protocol_state_object>().num_supported_key_types;
48
49 // check that producers are unique
50 std::set<account_name> unique_producers;
51 for (const auto& p: producers) {
52 SYS_ASSERT( context.is_account(p.producer_name), wasm_execution_error, "producer schedule includes a nonexisting account" );
53 std::visit([&p, num_supported_key_types, validate_keys](const auto& a) {
54 uint32_t sum_weights = 0;
55 std::set<public_key_type> unique_keys;
56 for (const auto& kw: a.keys ) {
57 SYS_ASSERT( kw.key.which() < num_supported_key_types, unactivated_key_type,
58 "Unactivated key type used in proposed producer schedule");
59
60 if( validate_keys ) {
61 SYS_ASSERT( kw.key.valid(), wasm_execution_error, "producer schedule includes an invalid key" );
62 }
63
64 if (std::numeric_limits<uint32_t>::max() - sum_weights <= kw.weight) {
65 sum_weights = std::numeric_limits<uint32_t>::max();
66 } else {
67 sum_weights += kw.weight;
68 }
69
70 unique_keys.insert(kw.key);
71 }
72
73 SYS_ASSERT( a.keys.size() == unique_keys.size(), wasm_execution_error, "producer schedule includes a duplicated key for ${account}", ("account", p.producer_name));
74 SYS_ASSERT( a.threshold > 0, wasm_execution_error, "producer schedule includes an authority with a threshold of 0 for ${account}", ("account", p.producer_name));
75 SYS_ASSERT( sum_weights >= a.threshold, wasm_execution_error, "producer schedule includes an unsatisfiable authority for ${account}", ("account", p.producer_name));
76 }, p.authority);
77
78 unique_producers.insert(p.producer_name);
79 }
80 SYS_ASSERT( producers.size() == unique_producers.size(), wasm_execution_error, "duplicate producer name in producer schedule" );
81
82 return context.control.set_proposed_producers( std::move(producers) );
83 }
84
85 uint32_t interface::get_wasm_parameters_packed( span<char> packed_parameters, uint32_t max_version ) const {
86 auto& gpo = context.control.get_global_properties();
87 auto& params = gpo.wasm_configuration;
88 uint32_t version = std::min( max_version, uint32_t(0) );
89
90 auto s = fc::raw::pack_size( version ) + fc::raw::pack_size( params );
91 if ( packed_parameters.size() == 0 )
92 return s;
93
94 if ( s <= packed_parameters.size() ) {
95 datastream<char*> ds( packed_parameters.data(), s );
96 fc::raw::pack(ds, version);
98 }
99 return s;
100 }
102 datastream<const char*> ds( packed_parameters.data(), packed_parameters.size() );
103 uint32_t version;
105 fc::raw::unpack(ds, version);
106 SYS_ASSERT(version == 0, wasm_config_unknown_version, "set_wasm_parameters_packed: Unknown version: ${version}", ("version", version));
107 fc::raw::unpack(ds, cfg);
108 cfg.validate();
109 context.db.modify( context.control.get_global_properties(),
110 [&]( auto& gprops ) {
111 gprops.wasm_configuration = cfg;
112 }
113 );
114 }
116 datastream<const char*> ds( packed_producer_schedule.data(), packed_producer_schedule.size() );
117 std::vector<producer_authority> producers;
118 std::vector<legacy::producer_key> old_version;
119 fc::raw::unpack(ds, old_version);
120
121 /*
122 * Up-convert the producers
123 */
124 for ( const auto& p : old_version ) {
125 producers.emplace_back( producer_authority{ p.producer_name, block_signing_authority_v0{ 1, {{p.block_signing_key, 1}} } } );
126 }
127
128 return set_proposed_producers_common( context, std::move(producers), true );
129 }
130
131 int64_t interface::set_proposed_producers_ex( uint64_t packed_producer_format, legacy_span<const char> packed_producer_schedule) {
132 if (packed_producer_format == 0) {
133 return set_proposed_producers(std::move(packed_producer_schedule));
134 } else if (packed_producer_format == 1) {
135 datastream<const char*> ds( packed_producer_schedule.data(), packed_producer_schedule.size() );
137
139 return set_proposed_producers_common( context, std::move(producers), false);
140 } else {
141 SYS_THROW(wasm_execution_error, "Producer schedule is in an unknown format!");
142 }
143 }
144
146 auto& gpo = context.control.get_global_properties();
147
148 auto s = fc::raw::pack_size( gpo.configuration.v0() );
149 if( packed_blockchain_parameters.size() == 0 ) return s;
150
151 if ( s <= packed_blockchain_parameters.size() ) {
152 datastream<char*> ds( packed_blockchain_parameters.data(), s );
153 fc::raw::pack(ds, gpo.configuration.v0());
154 return s;
155 }
156 return 0;
157 }
158
160 datastream<const char*> ds( packed_blockchain_parameters.data(), packed_blockchain_parameters.size() );
162 fc::raw::unpack(ds, cfg);
163 cfg.validate();
164 context.db.modify( context.control.get_global_properties(),
165 [&]( auto& gprops ) {
166 gprops.configuration = cfg;
167 });
168 }
169
170 uint32_t interface::get_parameters_packed( span<const char> packed_parameter_ids, span<char> packed_parameters) const{
171 datastream<const char*> ds_ids( packed_parameter_ids.data(), packed_parameter_ids.size() );
172
173 chain::chain_config cfg = context.control.get_global_properties().configuration;
174 std::vector<fc::unsigned_int> ids;
175 fc::raw::unpack(ds_ids, ids);
176 const config_range config_range(cfg, std::move(ids), {context.control});
177
178 auto size = fc::raw::pack_size( config_range );
179 if( packed_parameters.size() == 0 ) return size;
180
181 SYS_ASSERT(size <= packed_parameters.size(),
182 chain::config_parse_error,
183 "get_parameters_packed: buffer size is smaller than ${size}", ("size", size));
184
185 datastream<char*> ds( packed_parameters.data(), size );
187 return size;
188 }
189
191 datastream<const char*> ds( packed_parameters.data(), packed_parameters.size() );
192
193 chain::chain_config cfg = context.control.get_global_properties().configuration;
194 config_range config_range(cfg, {context.control});
195
197
198 config_range.config.validate();
199 context.db.modify( context.control.get_global_properties(),
200 [&]( auto& gprops ) {
201 gprops.configuration = config_range.config;
202 });
203 }
204
206 return context.db.get<account_metadata_object, by_name>( n ).is_privileged();
207 }
208
209 void interface::set_privileged( account_name n, bool is_priv ) {
210 const auto& a = context.db.get<account_metadata_object, by_name>( n );
211 context.db.modify( a, [&]( auto& ma ){
212 ma.set_privileged( is_priv );
213 });
214 }
215}}} // ns sysio::chain::webassembly
const mie::Vuint & p
Definition bn.cpp:27
#define SYS_THROW(exc_type, FORMAT,...)
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
Maintains global state information about consensus protocol rules.
uint32_t get_blockchain_parameters_packed(legacy_span< char > packed_blockchain_parameters) const
int32_t is_feature_active(int64_t feature_name) const
void set_privileged(account_name account, bool is_priv)
int64_t set_proposed_producers_ex(uint64_t packed_producer_format, legacy_span< const char > packed_producer_schedule)
void activate_feature(int64_t feature_name) const
void set_parameters_packed(span< const char > packed_parameters)
Set the blockchain parameters in a flexible manner.
void set_wasm_parameters_packed(span< const char > packed_parameters)
void set_blockchain_parameters_packed(legacy_span< const char > packed_blockchain_parameters)
uint32_t get_wasm_parameters_packed(span< char > packed_parameters, uint32_t max_version) const
void get_resource_limits(account_name account, legacy_ptr< int64_t, 8 > ram_bytes, legacy_ptr< int64_t, 8 > net_weight, legacy_ptr< int64_t, 8 > cpu_weight) const
uint32_t get_parameters_packed(span< const char > packed_parameter_ids, span< char > packed_parameters) const
Retrieve the blockchain config parameters.
void set_resource_limits(account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight)
bool is_privileged(account_name account) const
void preactivate_feature(legacy_ptr< const digest_type > feature_digest)
int64_t set_proposed_producers(legacy_span< const char > packed_producer_schedule)
constexpr std::size_t size() const noexcept
Definition span.hpp:73
constexpr T * data() const noexcept
Definition span.hpp:72
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
size_t pack_size(const T &v)
Definition raw.hpp:671
int64_t set_proposed_producers_common(apply_context &context, vector< producer_authority > &&producers, bool validate_keys)
data_range< chain_config, config_entry_validator > config_range
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers producers(dont_start)) FC_REFLECT(testnet_def
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Producer-voted blockchain configuration parameters.
v1 Producer-voted blockchain configuration parameters
Immutable except for fc::from_variant.
Definition name.hpp:43
char * s