Skip to content

Commit 62bef0e

Browse files
authored
Merge pull request #1222 from AntelopeIO/sync_call_protocol_feature
SC: SYNC_CALL protocol feature definition and registration
2 parents 32b66ca + b52d2d4 commit 62bef0e

File tree

12 files changed

+304
-256
lines changed

12 files changed

+304
-256
lines changed

libraries/chain/include/eosio/chain/protocol_feature_manager.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum class builtin_protocol_feature_t : uint32_t {
3939
disable_deferred_trxs_stage_1 = 22,
4040
disable_deferred_trxs_stage_2 = 23,
4141
savanna = 24,
42+
sync_call = 25,
4243
reserved_private_fork_protocol_features = 500000,
4344
};
4445

libraries/chain/protocol_feature_manager.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ host function call will trigger a transition to the Savanna consensus algorithm.
363363
builtin_protocol_feature_t::disable_deferred_trxs_stage_2
364364
}
365365
} )
366+
( builtin_protocol_feature_t::sync_call, builtin_protocol_feature_spec{
367+
"SYNC_CALL",
368+
fc::variant("49f6fbc4fee045bc5c8b09a96b2b5c096afdc320ac29b54e0f3805c660b88483").as<digest_type>(),
369+
// SHA256 hash of the raw message below within the comment delimiters (exclude newline after /*) (do not modify message below).
370+
/*
371+
Builtin protocol feature: SYNC_CALL
372+
373+
Enables synchronous calls to functions in other and own contracts.
374+
*/
375+
{builtin_protocol_feature_t::savanna}
376+
} )
366377
;
367378

368379

libraries/testing/include/eosio/testing/tester.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace eosio::testing {
6767
preactivate_feature_only,
6868
preactivate_feature_and_new_bios,
6969
old_wasm_parser,
70-
full_except_do_not_disable_deferred_trx,
70+
full_prior_to_disable_deferred_trx,
7171
full_except_do_not_transition_to_savanna,
7272
full
7373
};
@@ -475,7 +475,7 @@ namespace eosio::testing {
475475
void preactivate_protocol_features(const vector<digest_type>& feature_digests);
476476
void preactivate_builtin_protocol_features(const std::vector<builtin_protocol_feature_t>& features);
477477
void preactivate_all_builtin_protocol_features();
478-
void preactivate_all_but_disable_deferred_trx();
478+
void preactivate_all_prior_to_disable_deferred_trx();
479479
void preactivate_savanna_protocol_features();
480480

481481
static genesis_state default_genesis() {
@@ -731,7 +731,7 @@ namespace eosio::testing {
731731

732732
class tester_no_disable_deferred_trx : public tester {
733733
public:
734-
tester_no_disable_deferred_trx(): tester(setup_policy::full_except_do_not_disable_deferred_trx) {
734+
tester_no_disable_deferred_trx(): tester(setup_policy::full_prior_to_disable_deferred_trx) {
735735
}
736736
};
737737

@@ -861,7 +861,7 @@ namespace eosio::testing {
861861

862862
class validating_tester_no_disable_deferred_trx : public validating_tester {
863863
public:
864-
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_except_do_not_disable_deferred_trx) {
864+
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_prior_to_disable_deferred_trx) {
865865
}
866866
};
867867

libraries/testing/tester.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ namespace eosio::testing {
272272
break;
273273
}
274274
case setup_policy::full:
275-
case setup_policy::full_except_do_not_disable_deferred_trx:
275+
case setup_policy::full_prior_to_disable_deferred_trx:
276276
case setup_policy::full_except_do_not_transition_to_savanna: {
277277
schedule_preactivate_protocol_feature();
278278
produce_block();
279279
set_before_producer_authority_bios_contract();
280-
if( policy == setup_policy::full_except_do_not_disable_deferred_trx ) {
281-
preactivate_all_but_disable_deferred_trx();
280+
if( policy == setup_policy::full_prior_to_disable_deferred_trx ) {
281+
preactivate_all_prior_to_disable_deferred_trx();
282282
} else {
283283
preactivate_all_builtin_protocol_features();
284284
}
@@ -288,7 +288,7 @@ namespace eosio::testing {
288288
}
289289

290290
// Do not transition to Savanna under full_except_do_not_transition_to_savanna or
291-
// full_except_do_not_disable_deferred_trx
291+
// full_prior_to_disable_deferred_trx
292292
if( policy == setup_policy::full ) {
293293
// BLS voting is slow. Use only 1 finalizer for default testser.
294294
finalizer_keys fin_keys(*this, 1u /* num_keys */, 1u /* finset_size */);
@@ -1475,16 +1475,21 @@ namespace eosio::testing {
14751475
preactivate_builtin_protocol_features( get_all_builtin_protocol_features() );
14761476
}
14771477

1478-
void base_tester::preactivate_all_but_disable_deferred_trx() {
1478+
void base_tester::preactivate_all_prior_to_disable_deferred_trx() {
14791479
std::vector<builtin_protocol_feature_t> builtins;
14801480
for( const auto& f : get_all_builtin_protocol_features() ) {
14811481
// Before deferred trxs feature is fully disabled, existing tests involving
14821482
// deferred trxs need to be exercised to make sure existing behaviors are
1483-
// maintained. Excluding DISABLE_DEFERRED_TRXS_STAGE_1 and DISABLE_DEFERRED_TRXS_STAGE_2
1484-
// from full protocol feature list such that existing tests can run.
1485-
if( f == builtin_protocol_feature_t::disable_deferred_trxs_stage_1
1486-
|| f == builtin_protocol_feature_t::disable_deferred_trxs_stage_2
1487-
|| f == builtin_protocol_feature_t::savanna ) { // savanna depends on disable_deferred_trxs_stage_1 & 2
1483+
// maintained. Excluding DISABLE_DEFERRED_TRXS_STAGE_1 and DISABLE_DEFERRED_TRXS_STAGE_2,
1484+
// and any future protocol features from full protocol feature list such that
1485+
// existing tests can run.
1486+
//
1487+
// Note: We use `f >= builtin_protocol_feature_t::disable_deferred_trxs_stage_1`
1488+
// instead of earlier version of comparing with exact features to make code less
1489+
// fragile when new protocol features are added. Protocol features order can never change.
1490+
// Future protocol features' ID is guaranteed by the protocol to be greater than
1491+
// DISABLE_DEFERRED_TRXS_STAGE_1.
1492+
if( f >= builtin_protocol_feature_t::disable_deferred_trxs_stage_1 ) {
14881493
continue;
14891494
}
14901495

unittests/api_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( inline_action_objective_limit, T, testers ) { try
10831083

10841084
BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
10851085
const uint32_t _4k = 4 * 1024;
1086-
tester chain(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
1087-
tester chain2(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
1086+
tester chain(setup_policy::full_prior_to_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
1087+
tester chain2(setup_policy::full_prior_to_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
10881088
signed_block_ptr block;
10891089
for (int n=0; n < 2; ++n) {
10901090
block = chain.produce_block();

unittests/currency_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ using currency_testers = boost::mpl::list<currency_tester<legacy_validating_test
9797

9898
class pre_disable_deferred_trx_currency_tester : public currency_tester<legacy_validating_tester> {
9999
public:
100-
pre_disable_deferred_trx_currency_tester() : currency_tester(setup_policy::full_except_do_not_disable_deferred_trx) {}
100+
pre_disable_deferred_trx_currency_tester() : currency_tester(setup_policy::full_prior_to_disable_deferred_trx) {}
101101
};
102102

103103
template <typename T>

unittests/deep-mind/deep-mind.log

+244-239
Large diffs are not rendered by default.

unittests/protocol_feature_tests.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -2316,4 +2316,30 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(set_finalizers_test, T, testers) { try {
23162316
c.error("alice does not have permission to call this API"));
23172317
} FC_LOG_AND_RETHROW() }
23182318

2319+
BOOST_AUTO_TEST_CASE(sync_call_activation_test) try {
2320+
tester c( setup_policy::preactivate_feature_and_new_bios );
2321+
const auto& pfm = c.control->get_protocol_feature_manager();
2322+
2323+
// Ensure SYNC_CALL not yet activated
2324+
BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::sync_call ) );
2325+
2326+
// Activate SYNC_CALL without the dependency met (it depends on SAVANNA).
2327+
auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::sync_call );
2328+
BOOST_REQUIRE( d );
2329+
BOOST_CHECK_EXCEPTION( c.preactivate_protocol_features({ *d }),
2330+
protocol_feature_exception,
2331+
fc_exception_message_starts_with("not all dependencies of protocol feature with digest") );
2332+
2333+
// Activate the depending Savanna
2334+
c.preactivate_savanna_protocol_features();
2335+
c.produce_block();
2336+
2337+
// Activate SYNC_CALL after the dependency met
2338+
c.preactivate_protocol_features({ *d });
2339+
c.produce_block();
2340+
2341+
// Ensure SYNC_CALL is now activated
2342+
BOOST_CHECK( c.control->is_builtin_activated( builtin_protocol_feature_t::sync_call ) );
2343+
} FC_LOG_AND_RETHROW()
2344+
23192345
BOOST_AUTO_TEST_SUITE_END()
Binary file not shown.
194 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)