-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprotocol_feature_manager.cpp
More file actions
779 lines (642 loc) · 34 KB
/
protocol_feature_manager.cpp
File metadata and controls
779 lines (642 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/protocol_state_object.hpp>
#include <eosio/chain/exceptions.hpp>
#include <fc/scoped_exit.hpp>
#include <algorithm>
#include <boost/assign/list_of.hpp>
namespace eosio { namespace chain {
const std::unordered_map<builtin_protocol_feature_t, builtin_protocol_feature_spec, enum_hash<builtin_protocol_feature_t>>
builtin_protocol_feature_codenames =
boost::assign::map_list_of<builtin_protocol_feature_t, builtin_protocol_feature_spec>
( builtin_protocol_feature_t::preactivate_feature, builtin_protocol_feature_spec{
"PREACTIVATE_FEATURE",
fc::variant("64fe7df32e9b86be2b296b3f81dfd527f84e82b98e363bc97e40bc7a83733310").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: PREACTIVATE_FEATURE
Adds privileged intrinsic to enable a contract to pre-activate a protocol feature specified by its digest.
Pre-activated protocol features must be activated in the next block.
*/
{},
{time_point{}, false, true} // enabled without preactivation and ready to go at any time
} )
( builtin_protocol_feature_t::only_link_to_existing_permission, builtin_protocol_feature_spec{
"ONLY_LINK_TO_EXISTING_PERMISSION",
fc::variant("f3c3d91c4603cde2397268bfed4e662465293aab10cd9416db0d442b8cec2949").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: ONLY_LINK_TO_EXISTING_PERMISSION
Disallows linking an action to a non-existing permission.
*/
{}
} )
( builtin_protocol_feature_t::replace_deferred, builtin_protocol_feature_spec{
"REPLACE_DEFERRED",
fc::variant("9908b3f8413c8474ab2a6be149d3f4f6d0421d37886033f27d4759c47a26d944").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: REPLACE_DEFERRED
Fix the problems associated with replacing an existing deferred transaction.
Also corrects the RAM usage of accounts affected by the replace deferred transaction bug.
*/
{}
} )
( builtin_protocol_feature_t::no_duplicate_deferred_id, builtin_protocol_feature_spec{
"NO_DUPLICATE_DEFERRED_ID",
fc::variant("45967387ee92da70171efd9fefd1ca8061b5efe6f124d269cd2468b47f1575a0").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: NO_DUPLICATE_DEFERRED_ID
Depends on: REPLACE_DEFERRED
Ensures transactions generated by contracts for deferred execution are adjusted to avoid transaction ID conflicts.
Also allows a contract to send a deferred transaction in a manner that enables the contract to know the transaction ID ahead of time.
*/
{builtin_protocol_feature_t::replace_deferred}
} )
( builtin_protocol_feature_t::fix_linkauth_restriction, builtin_protocol_feature_spec{
"FIX_LINKAUTH_RESTRICTION",
fc::variant("a98241c83511dc86c857221b9372b4aa7cea3aaebc567a48604e1d3db3557050").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: FIX_LINKAUTH_RESTRICTION
Removes the restriction on eosio::linkauth for non-native actions named one of the five special action names:
updateauth, deleteauth, linkauth, unlinkauth, or canceldelay.
*/
{}
} )
( builtin_protocol_feature_t::disallow_empty_producer_schedule, builtin_protocol_feature_spec{
"DISALLOW_EMPTY_PRODUCER_SCHEDULE",
fc::variant("2853617cec3eabd41881eb48882e6fc5e81a0db917d375057864b3befbe29acd").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: DISALLOW_EMPTY_PRODUCER_SCHEDULE
Disallows proposing an empty producer schedule.
*/
{}
} )
( builtin_protocol_feature_t::restrict_action_to_self, builtin_protocol_feature_spec{
"RESTRICT_ACTION_TO_SELF",
fc::variant("e71b6712188391994c78d8c722c1d42c477cf091e5601b5cf1befd05721a57f3").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: RESTRICT_ACTION_TO_SELF
Disallows bypass of authorization checks by unprivileged contracts when sending inline actions or deferred transactions.
The original protocol rules allow a bypass of authorization checks for actions sent by a contract to itself.
This protocol feature removes that bypass.
*/
{}
} )
( builtin_protocol_feature_t::only_bill_first_authorizer, builtin_protocol_feature_spec{
"ONLY_BILL_FIRST_AUTHORIZER",
fc::variant("2f1f13e291c79da5a2bbad259ed7c1f2d34f697ea460b14b565ac33b063b73e2").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: ONLY_BILL_FIRST_AUTHORIZER
Adds CPU and network bandwidth usage to only the first authorizer of a transaction.
*/
{}
} )
( builtin_protocol_feature_t::forward_setcode, builtin_protocol_feature_spec{
"FORWARD_SETCODE",
fc::variant("898082c59f921d0042e581f00a59d5ceb8be6f1d9c7a45b6f07c0e26eaee0222").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: FORWARD_SETCODE
Forward eosio::setcode actions to the WebAssembly code deployed on the eosio account.
*/
{}
} )
( builtin_protocol_feature_t::get_sender, builtin_protocol_feature_spec{
"GET_SENDER",
fc::variant("1eab748b95a2e6f4d7cb42065bdee5566af8efddf01a55a0a8d831b823f8828a").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: GET_SENDER
Allows contracts to determine which account is the sender of an inline action.
*/
{}
} )
( builtin_protocol_feature_t::ram_restrictions, builtin_protocol_feature_spec{
"RAM_RESTRICTIONS",
fc::variant("1812fdb5096fd854a4958eb9d53b43219d114de0e858ce00255bd46569ad2c68").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: RAM_RESTRICTIONS
Modifies the restrictions on operations within actions that increase RAM usage of accounts other than the receiver.
An unprivileged contract responding to a notification:
is not allowed to schedule a deferred transaction in which the RAM costs are paid by an account other than the receiver;
but is allowed to execute database operations that increase RAM usage of an account other than the receiver as long as
the action's net effect on RAM usage for the account is to not increase it.
An unprivileged contract executing an action (but not as a response to a notification):
is not allowed to schedule a deferred transaction in which the RAM costs are paid by an account other than the receiver
unless that account authorized the action;
but is allowed to execute database operations that increase RAM usage of an account other than the receiver as long as
either the account authorized the action or the action's net effect on RAM usage for the account is to not increase it.
*/
{}
} )
( builtin_protocol_feature_t::webauthn_key, builtin_protocol_feature_spec{
"WEBAUTHN_KEY",
fc::variant("927fdf78c51e77a899f2db938249fb1f8bb38f4e43d9c1f75b190492080cbc34").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: WEBAUTHN_KEY
Enables usage of WebAuthn keys and signatures.
*/
{}
} )
( builtin_protocol_feature_t::wtmsig_block_signatures, builtin_protocol_feature_spec{
"WTMSIG_BLOCK_SIGNATURES",
fc::variant("ab76031cad7a457f4fd5f5fca97a3f03b8a635278e0416f77dcc91eb99a48e10").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: WTMSIG_BLOCK_SIGNATURES
Allows producers to specify a multisig of weighted keys as the authority for signing blocks.
A valid block header:
is no longer allowed to have a non-empty `new_producers` field;
must announce new producer schedules using a block header extension with ID `1`.
A valid signed block:
must continue to have exactly one signature in its `signatures` field;
and may have additional signatures in a block extension with ID `2`.
Privileged Contracts:
may continue to use `set_proposed_producers` as they have;
may use a new `set_proposed_producers_ex` intrinsic to access extended features.
*/
{}
} )
( builtin_protocol_feature_t::action_return_value, builtin_protocol_feature_spec{
"ACTION_RETURN_VALUE",
fc::variant("69b064c5178e2738e144ed6caa9349a3995370d78db29e494b3126ebd9111966").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: ACTION_RETURN_VALUE
Enables new `set_action_return_value` intrinsic which sets a value that is included in action_receipt.
*/
{}
} )
( builtin_protocol_feature_t::kv_database, builtin_protocol_feature_spec{
"KV_DATABASE",
fc::variant("14cfb3252a5fa3ae4c764929e0bbc467528990c9cc46aefcc7f16367f28b6278").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: KV_DATABASE
Enables usage of key-value database intrinsics.
*/
{}
} )
( builtin_protocol_feature_t::configurable_wasm_limits, builtin_protocol_feature_spec{
"CONFIGURABLE_WASM_LIMITS",
fc::variant("67f5f1e92cbf6f7276e7b3fc8c2ad23e63448e657641a1e5de69bccd114542d6").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: CONFIGURABLE_WASM_LIMITS
Allows privileged contracts to set the constraints on WebAssembly code.
*/
{}
} )
( builtin_protocol_feature_t::blockchain_parameters, builtin_protocol_feature_spec{
"BLOCKCHAIN_PARAMETERS",
fc::variant("70787548dcea1a2c52c913a37f74ce99e6caae79110d7ca7b859936a0075b314").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: BLOCKCHAIN_PARAMETERS
Allows privileged contracts to get and set subsets of blockchain parameters.
*/
{}
} )
( builtin_protocol_feature_t::event_generation, builtin_protocol_feature_spec{
"EVENT_GENERATION",
fc::variant("35ecd1df24ba3e00c37a5572d2284e4a895233f6981ad3dd91e5ff68664b122a").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: EVENT_GENERATION
Enables `push_event` host function which provides event data to host.
*/
{}
} )
( builtin_protocol_feature_t::verify_rsa_sha256_sig, builtin_protocol_feature_spec{
"VERIFY_RSA_SHA256_SIG",
fc::variant("46c74376222421ef2827512e88ed7ccfa59e0fba00c9b0b7b5cf35315d079411").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: VERIFY_RSA_SHA256_SIG
Enables verification of an RSA signed message.
*/
{}
} )
( builtin_protocol_feature_t::verify_ecdsa_sig, builtin_protocol_feature_spec{
"VERIFY_ECDSA_SIG",
fc::variant("d05fe0811d2bce3ff737f351aa2ddd3ad2411c4c40f90b03a67577dbd9347ecf").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: VERIFY_ECDSA_SIG
Enables verification of an ECDSA signed message.
*/
{}
} )
;
const char* builtin_protocol_feature_codename( builtin_protocol_feature_t codename ) {
auto itr = builtin_protocol_feature_codenames.find( codename );
EOS_ASSERT( itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
"Unsupported builtin_protocol_feature_t passed to builtin_protocol_feature_codename: {codename}",
("codename", static_cast<uint32_t>(codename)) );
return itr->second.codename;
}
protocol_feature_base::protocol_feature_base( protocol_feature_t feature_type,
const digest_type& description_digest,
flat_set<digest_type>&& dependencies,
const protocol_feature_subjective_restrictions& restrictions )
:description_digest( description_digest )
,dependencies( std::move(dependencies) )
,subjective_restrictions( restrictions )
,_type( feature_type )
{
switch( feature_type ) {
case protocol_feature_t::builtin:
protocol_feature_type = builtin_protocol_feature::feature_type_string;
break;
default:
{
EOS_THROW( protocol_feature_validation_exception,
"Unsupported protocol_feature_t passed to constructor: {type}",
("type", static_cast<uint32_t>(feature_type)) );
}
break;
}
}
void protocol_feature_base::reflector_init() {
static_assert( fc::raw::has_feature_reflector_init_on_unpacked_reflected_types,
"protocol_feature_activation expects FC to support reflector_init" );
if( protocol_feature_type == builtin_protocol_feature::feature_type_string ) {
_type = protocol_feature_t::builtin;
} else {
EOS_THROW( protocol_feature_validation_exception,
"Unsupported protocol feature type: {type}", ("type", protocol_feature_type) );
}
}
const char* builtin_protocol_feature::feature_type_string = "builtin";
builtin_protocol_feature::builtin_protocol_feature( builtin_protocol_feature_t codename,
const digest_type& description_digest,
flat_set<digest_type>&& dependencies,
const protocol_feature_subjective_restrictions& restrictions )
:protocol_feature_base( protocol_feature_t::builtin, description_digest, std::move(dependencies), restrictions )
,_codename(codename)
{
auto itr = builtin_protocol_feature_codenames.find( codename );
EOS_ASSERT( itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
"Unsupported builtin_protocol_feature_t passed to constructor: {codename}",
("codename", static_cast<uint32_t>(codename)) );
builtin_feature_codename = itr->second.codename;
}
void builtin_protocol_feature::reflector_init() {
protocol_feature_base::reflector_init();
for( const auto& p : builtin_protocol_feature_codenames ) {
if( builtin_feature_codename.compare( p.second.codename ) == 0 ) {
_codename = p.first;
return;
}
}
EOS_THROW( protocol_feature_validation_exception,
"Unsupported builtin protocol feature codename: {codename}",
("codename", builtin_feature_codename) );
}
digest_type builtin_protocol_feature::digest()const {
digest_type::encoder enc;
fc::raw::pack( enc, _type );
fc::raw::pack( enc, description_digest );
fc::raw::pack( enc, dependencies );
fc::raw::pack( enc, _codename );
return enc.result();
}
fc::variant protocol_feature::to_variant( bool include_subjective_restrictions,
fc::mutable_variant_object* additional_fields )const
{
EOS_ASSERT( builtin_feature, protocol_feature_exception, "not a builtin protocol feature" );
fc::mutable_variant_object mvo;
mvo( "feature_digest", feature_digest );
if( additional_fields ) {
for( const auto& e : *additional_fields ) {
if( e.key().compare( "feature_digest" ) != 0 )
mvo( e.key(), e.value() );
}
}
if( include_subjective_restrictions ) {
fc::mutable_variant_object subjective_restrictions;
subjective_restrictions( "enabled", enabled );
subjective_restrictions( "preactivation_required", preactivation_required );
subjective_restrictions( "earliest_allowed_activation_time", earliest_allowed_activation_time );
mvo( "subjective_restrictions", std::move( subjective_restrictions ) );
}
mvo( "description_digest", description_digest );
mvo( "dependencies", dependencies );
mvo( "protocol_feature_type", builtin_protocol_feature::feature_type_string );
fc::variants specification;
auto add_to_specification = [&specification]( const char* key_name, auto&& value ) {
fc::mutable_variant_object obj;
obj( "name", key_name );
obj( "value", std::forward<decltype(value)>( value ) );
specification.emplace_back( std::move(obj) );
};
add_to_specification( "builtin_feature_codename", builtin_protocol_feature_codename( *builtin_feature ) );
mvo( "specification", std::move( specification ) );
return fc::variant( std::move(mvo) );
}
protocol_feature_set::protocol_feature_set()
{
_recognized_builtin_protocol_features.reserve( builtin_protocol_feature_codenames.size() );
}
protocol_feature_set::recognized_t
protocol_feature_set::is_recognized( const digest_type& feature_digest, time_point now )const {
auto itr = _recognized_protocol_features.find( feature_digest );
if( itr == _recognized_protocol_features.end() )
return recognized_t::unrecognized;
if( !itr->enabled )
return recognized_t::disabled;
if( itr->earliest_allowed_activation_time > now )
return recognized_t::too_early;
return recognized_t::ready;
}
std::optional<digest_type> protocol_feature_set::get_builtin_digest( builtin_protocol_feature_t feature_codename )const {
uint32_t indx = static_cast<uint32_t>( feature_codename );
if( indx >= _recognized_builtin_protocol_features.size() )
return {};
if( _recognized_builtin_protocol_features[indx] == _recognized_protocol_features.end() )
return {};
return _recognized_builtin_protocol_features[indx]->feature_digest;
}
const protocol_feature& protocol_feature_set::get_protocol_feature( const digest_type& feature_digest )const {
auto itr = _recognized_protocol_features.find( feature_digest );
EOS_ASSERT( itr != _recognized_protocol_features.end(), protocol_feature_exception,
"unrecognized protocol feature with digest: {digest}",
("digest", feature_digest)
);
return *itr;
}
bool protocol_feature_set::validate_dependencies(
const digest_type& feature_digest,
const std::function<bool(const digest_type&)>& validator
)const {
auto itr = _recognized_protocol_features.find( feature_digest );
if( itr == _recognized_protocol_features.end() ) return false;
for( const auto& d : itr->dependencies ) {
if( !validator(d) ) return false;
}
return true;
}
builtin_protocol_feature
protocol_feature_set::make_default_builtin_protocol_feature(
builtin_protocol_feature_t codename,
const std::function<digest_type(builtin_protocol_feature_t dependency)>& handle_dependency
) {
auto itr = builtin_protocol_feature_codenames.find( codename );
EOS_ASSERT( itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
"Unsupported builtin_protocol_feature_t: {codename}",
("codename", static_cast<uint32_t>(codename)) );
flat_set<digest_type> dependencies;
dependencies.reserve( itr->second.builtin_dependencies.size() );
for( const auto& d : itr->second.builtin_dependencies ) {
dependencies.insert( handle_dependency( d ) );
}
return {itr->first, itr->second.description_digest, std::move(dependencies), itr->second.subjective_restrictions};
}
const protocol_feature& protocol_feature_set::add_feature( const builtin_protocol_feature& f ) {
auto builtin_itr = builtin_protocol_feature_codenames.find( f._codename );
EOS_ASSERT( builtin_itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
"Builtin protocol feature has unsupported builtin_protocol_feature_t: {codename}",
("codename", static_cast<uint32_t>( f._codename )) );
uint32_t indx = static_cast<uint32_t>( f._codename );
if( indx < _recognized_builtin_protocol_features.size() ) {
EOS_ASSERT( _recognized_builtin_protocol_features[indx] == _recognized_protocol_features.end(),
protocol_feature_exception,
"builtin protocol feature with codename '{codename}' already added",
("codename", f.builtin_feature_codename) );
}
auto feature_digest = f.digest();
const auto& expected_builtin_dependencies = builtin_itr->second.builtin_dependencies;
flat_set<builtin_protocol_feature_t> satisfied_builtin_dependencies;
satisfied_builtin_dependencies.reserve( expected_builtin_dependencies.size() );
for( const auto& d : f.dependencies ) {
auto itr = _recognized_protocol_features.find( d );
EOS_ASSERT( itr != _recognized_protocol_features.end(), protocol_feature_exception,
"builtin protocol feature with codename '{codename}' and digest of {digest} has a dependency on a protocol feature with digest {dependency_digest} that is not recognized",
("codename", f.builtin_feature_codename)
("digest", feature_digest)
("dependency_digest", d )
);
if( itr->builtin_feature
&& expected_builtin_dependencies.find( *itr->builtin_feature )
!= expected_builtin_dependencies.end() )
{
satisfied_builtin_dependencies.insert( *itr->builtin_feature );
}
}
if( expected_builtin_dependencies.size() > satisfied_builtin_dependencies.size() ) {
flat_set<builtin_protocol_feature_t> missing_builtins;
missing_builtins.reserve( expected_builtin_dependencies.size() - satisfied_builtin_dependencies.size() );
std::set_difference( expected_builtin_dependencies.begin(), expected_builtin_dependencies.end(),
satisfied_builtin_dependencies.begin(), satisfied_builtin_dependencies.end(),
end_inserter( missing_builtins )
);
vector<string> missing_builtins_with_names;
missing_builtins_with_names.reserve( missing_builtins.size() );
for( const auto& builtin_codename : missing_builtins ) {
auto itr = builtin_protocol_feature_codenames.find( builtin_codename );
EOS_ASSERT( itr != builtin_protocol_feature_codenames.end(),
protocol_feature_exception,
"Unexpected error"
);
missing_builtins_with_names.emplace_back( itr->second.codename );
}
EOS_THROW( protocol_feature_validation_exception,
"Not all the builtin dependencies of the builtin protocol feature with codename '{codename}' and digest of {digest} were satisfied.",
("missing_dependencies", missing_builtins_with_names)
);
}
auto res = _recognized_protocol_features.insert( protocol_feature{
feature_digest,
f.description_digest,
f.dependencies,
f.subjective_restrictions.earliest_allowed_activation_time,
f.subjective_restrictions.preactivation_required,
f.subjective_restrictions.enabled,
f._codename
} );
EOS_ASSERT( res.second, protocol_feature_exception,
"builtin protocol feature with codename '{codename}' has a digest of {digest} but another protocol feature with the same digest has already been added",
("codename", f.builtin_feature_codename)("digest", feature_digest) );
if( indx >= _recognized_builtin_protocol_features.size() ) {
for( auto i =_recognized_builtin_protocol_features.size(); i <= indx; ++i ) {
_recognized_builtin_protocol_features.push_back( _recognized_protocol_features.end() );
}
}
_recognized_builtin_protocol_features[indx] = res.first;
return *res.first;
}
protocol_feature_manager::protocol_feature_manager(
protocol_feature_set&& pfs
):_protocol_feature_set( std::move(pfs) )
{
_builtin_protocol_features.resize( _protocol_feature_set._recognized_builtin_protocol_features.size() );
}
void protocol_feature_manager::init( chainbase::database& db ) {
EOS_ASSERT( !is_initialized(), protocol_feature_exception, "cannot initialize protocol_feature_manager twice" );
auto reset_initialized = fc::make_scoped_exit( [this]() { _initialized = false; } );
_initialized = true;
for( const auto& f : db.get<protocol_state_object>().activated_protocol_features ) {
activate_feature( f.feature_digest, f.activation_block_num );
}
reset_initialized.cancel();
}
const protocol_feature* protocol_feature_manager::const_iterator::get_pointer()const {
//EOS_ASSERT( _pfm, protocol_feature_iterator_exception, "cannot dereference singular iterator" );
//EOS_ASSERT( _index != end_index, protocol_feature_iterator_exception, "cannot dereference end iterator" );
return &*(_pfm->_activated_protocol_features[_index].iterator_to_protocol_feature);
}
uint32_t protocol_feature_manager::const_iterator::activation_ordinal()const {
EOS_ASSERT( _pfm,
protocol_feature_iterator_exception,
"called activation_ordinal() on singular iterator"
);
EOS_ASSERT( _index != end_index,
protocol_feature_iterator_exception,
"called activation_ordinal() on end iterator"
);
return _index;
}
uint32_t protocol_feature_manager::const_iterator::activation_block_num()const {
EOS_ASSERT( _pfm,
protocol_feature_iterator_exception,
"called activation_block_num() on singular iterator"
);
EOS_ASSERT( _index != end_index,
protocol_feature_iterator_exception,
"called activation_block_num() on end iterator"
);
return _pfm->_activated_protocol_features[_index].activation_block_num;
}
protocol_feature_manager::const_iterator& protocol_feature_manager::const_iterator::operator++() {
EOS_ASSERT( _pfm, protocol_feature_iterator_exception, "cannot increment singular iterator" );
EOS_ASSERT( _index != end_index, protocol_feature_iterator_exception, "cannot increment end iterator" );
++_index;
if( _index >= _pfm->_activated_protocol_features.size() ) {
_index = end_index;
}
return *this;
}
protocol_feature_manager::const_iterator& protocol_feature_manager::const_iterator::operator--() {
EOS_ASSERT( _pfm, protocol_feature_iterator_exception, "cannot decrement singular iterator" );
if( _index == end_index ) {
EOS_ASSERT( _pfm->_activated_protocol_features.size() > 0,
protocol_feature_iterator_exception,
"cannot decrement end iterator when no protocol features have been activated"
);
_index = _pfm->_activated_protocol_features.size() - 1;
} else {
EOS_ASSERT( _index > 0,
protocol_feature_iterator_exception,
"cannot decrement iterator at the beginning of protocol feature activation list" )
;
--_index;
}
return *this;
}
protocol_feature_manager::const_iterator protocol_feature_manager::cbegin()const {
if( _activated_protocol_features.size() == 0 ) {
return cend();
} else {
return const_iterator( this, 0 );
}
}
protocol_feature_manager::const_iterator
protocol_feature_manager::at_activation_ordinal( uint32_t activation_ordinal )const {
if( activation_ordinal >= _activated_protocol_features.size() ) {
return cend();
}
return const_iterator{this, static_cast<std::size_t>(activation_ordinal)};
}
protocol_feature_manager::const_iterator
protocol_feature_manager::lower_bound( uint32_t block_num )const {
const auto begin = _activated_protocol_features.cbegin();
const auto end = _activated_protocol_features.cend();
auto itr = std::lower_bound( begin, end, block_num, []( const protocol_feature_entry& lhs, uint32_t rhs ) {
return lhs.activation_block_num < rhs;
} );
if( itr == end ) {
return cend();
}
return const_iterator{this, static_cast<std::size_t>(itr - begin)};
}
protocol_feature_manager::const_iterator
protocol_feature_manager::upper_bound( uint32_t block_num )const {
const auto begin = _activated_protocol_features.cbegin();
const auto end = _activated_protocol_features.cend();
auto itr = std::upper_bound( begin, end, block_num, []( uint32_t lhs, const protocol_feature_entry& rhs ) {
return lhs < rhs.activation_block_num;
} );
if( itr == end ) {
return cend();
}
return const_iterator{this, static_cast<std::size_t>(itr - begin)};
}
bool protocol_feature_manager::is_builtin_activated( builtin_protocol_feature_t feature_codename,
uint32_t current_block_num )const
{
uint32_t indx = static_cast<uint32_t>( feature_codename );
if( indx >= _builtin_protocol_features.size() ) return false;
return (_builtin_protocol_features[indx].activation_block_num <= current_block_num);
}
void protocol_feature_manager::activate_feature( const digest_type& feature_digest,
uint32_t current_block_num )
{
EOS_ASSERT( is_initialized(), protocol_feature_exception, "protocol_feature_manager is not yet initialized" );
auto itr = _protocol_feature_set.find( feature_digest );
EOS_ASSERT( itr != _protocol_feature_set.end(), protocol_feature_exception,
"unrecognized protocol feature digest: {digest}", ("digest", feature_digest) );
if( _activated_protocol_features.size() > 0 ) {
const auto& last = _activated_protocol_features.back();
EOS_ASSERT( last.activation_block_num <= current_block_num,
protocol_feature_exception,
"last protocol feature activation block num is {last_activation_block_num} yet "
"attempting to activate protocol feature with a current block num of {current_block_num}"
"protocol features is {last_activation_block_num}",
("current_block_num", current_block_num)
("last_activation_block_num", last.activation_block_num)
);
}
EOS_ASSERT( itr->builtin_feature,
protocol_feature_exception,
"invariant failure: encountered non-builtin protocol feature which is not yet supported"
);
uint32_t indx = static_cast<uint32_t>( *itr->builtin_feature );
EOS_ASSERT( indx < _builtin_protocol_features.size(), protocol_feature_exception,
"invariant failure while trying to activate feature with digest '{digest}': "
"unsupported builtin_protocol_feature_t {codename}",
("digest", feature_digest)
("codename", indx)
);
EOS_ASSERT( _builtin_protocol_features[indx].activation_block_num == builtin_protocol_feature_entry::not_active,
protocol_feature_exception,
"cannot activate already activated builtin feature with digest: {digest}",
("digest", feature_digest)
);
_activated_protocol_features.push_back( protocol_feature_entry{itr, current_block_num} );
_builtin_protocol_features[indx].previous = _head_of_builtin_activation_list;
_builtin_protocol_features[indx].activation_block_num = current_block_num;
_head_of_builtin_activation_list = indx;
}
void protocol_feature_manager::popped_blocks_to( uint32_t block_num ) {
EOS_ASSERT( is_initialized(), protocol_feature_exception, "protocol_feature_manager is not yet initialized" );
while( _head_of_builtin_activation_list != builtin_protocol_feature_entry::no_previous ) {
auto& e = _builtin_protocol_features[_head_of_builtin_activation_list];
if( e.activation_block_num <= block_num ) break;
_head_of_builtin_activation_list = e.previous;
e.previous = builtin_protocol_feature_entry::no_previous;
e.activation_block_num = builtin_protocol_feature_entry::not_active;
}
while( _activated_protocol_features.size() > 0
&& block_num < _activated_protocol_features.back().activation_block_num )
{
_activated_protocol_features.pop_back();
}
}
} } // eosio::chain