Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SC: SYNC_CALL protocol feature definition and registration #1222

Merged
merged 7 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class builtin_protocol_feature_t : uint32_t {
disable_deferred_trxs_stage_1 = 22,
disable_deferred_trxs_stage_2 = 23,
savanna = 24,
sync_call = 25,
reserved_private_fork_protocol_features = 500000,
};

Expand Down
11 changes: 11 additions & 0 deletions libraries/chain/protocol_feature_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ host function call will trigger a transition to the Savanna consensus algorithm.
builtin_protocol_feature_t::disable_deferred_trxs_stage_2
}
} )
( builtin_protocol_feature_t::sync_call, builtin_protocol_feature_spec{
"SYNC_CALL",
fc::variant("49f6fbc4fee045bc5c8b09a96b2b5c096afdc320ac29b54e0f3805c660b88483").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (exclude newline after /*) (do not modify message below).
/*
Builtin protocol feature: SYNC_CALL
Enables synchronous calls to functions in other and own contracts.
*/
{builtin_protocol_feature_t::savanna}
} )
;


Expand Down
8 changes: 4 additions & 4 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace eosio::testing {
preactivate_feature_only,
preactivate_feature_and_new_bios,
old_wasm_parser,
full_except_do_not_disable_deferred_trx,
full_prior_to_disable_deferred_trx,
full_except_do_not_transition_to_savanna,
full
};
Expand Down Expand Up @@ -475,7 +475,7 @@ namespace eosio::testing {
void preactivate_protocol_features(const vector<digest_type>& feature_digests);
void preactivate_builtin_protocol_features(const std::vector<builtin_protocol_feature_t>& features);
void preactivate_all_builtin_protocol_features();
void preactivate_all_but_disable_deferred_trx();
void preactivate_all_prior_to_disable_deferred_trx();
void preactivate_savanna_protocol_features();

static genesis_state default_genesis() {
Expand Down Expand Up @@ -731,7 +731,7 @@ namespace eosio::testing {

class tester_no_disable_deferred_trx : public tester {
public:
tester_no_disable_deferred_trx(): tester(setup_policy::full_except_do_not_disable_deferred_trx) {
tester_no_disable_deferred_trx(): tester(setup_policy::full_prior_to_disable_deferred_trx) {
}
};

Expand Down Expand Up @@ -861,7 +861,7 @@ namespace eosio::testing {

class validating_tester_no_disable_deferred_trx : public validating_tester {
public:
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_except_do_not_disable_deferred_trx) {
validating_tester_no_disable_deferred_trx(): validating_tester({}, nullptr, setup_policy::full_prior_to_disable_deferred_trx) {
}
};

Expand Down
25 changes: 15 additions & 10 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ namespace eosio::testing {
break;
}
case setup_policy::full:
case setup_policy::full_except_do_not_disable_deferred_trx:
case setup_policy::full_prior_to_disable_deferred_trx:
case setup_policy::full_except_do_not_transition_to_savanna: {
schedule_preactivate_protocol_feature();
produce_block();
set_before_producer_authority_bios_contract();
if( policy == setup_policy::full_except_do_not_disable_deferred_trx ) {
preactivate_all_but_disable_deferred_trx();
if( policy == setup_policy::full_prior_to_disable_deferred_trx ) {
preactivate_all_prior_to_disable_deferred_trx();
} else {
preactivate_all_builtin_protocol_features();
}
Expand All @@ -288,7 +288,7 @@ namespace eosio::testing {
}

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

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

Expand Down
4 changes: 2 additions & 2 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( inline_action_objective_limit, T, testers ) { try

BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
const uint32_t _4k = 4 * 1024;
tester chain(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain(setup_policy::full_prior_to_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
tester chain2(setup_policy::full_prior_to_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
signed_block_ptr block;
for (int n=0; n < 2; ++n) {
block = chain.produce_block();
Expand Down
2 changes: 1 addition & 1 deletion unittests/currency_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ using currency_testers = boost::mpl::list<currency_tester<legacy_validating_test

class pre_disable_deferred_trx_currency_tester : public currency_tester<legacy_validating_tester> {
public:
pre_disable_deferred_trx_currency_tester() : currency_tester(setup_policy::full_except_do_not_disable_deferred_trx) {}
pre_disable_deferred_trx_currency_tester() : currency_tester(setup_policy::full_prior_to_disable_deferred_trx) {}
};

template <typename T>
Expand Down
483 changes: 244 additions & 239 deletions unittests/deep-mind/deep-mind.log

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions unittests/protocol_feature_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2316,4 +2316,30 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(set_finalizers_test, T, testers) { try {
c.error("alice does not have permission to call this API"));
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(sync_call_activation_test) try {
tester c( setup_policy::preactivate_feature_and_new_bios );
const auto& pfm = c.control->get_protocol_feature_manager();

// Ensure SYNC_CALL not yet activated
BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::sync_call ) );

// Activate SYNC_CALL without the dependency met (it depends on SAVANNA).
auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::sync_call );
BOOST_REQUIRE( d );
BOOST_CHECK_EXCEPTION( c.preactivate_protocol_features({ *d }),
protocol_feature_exception,
fc_exception_message_starts_with("not all dependencies of protocol feature with digest") );

// Activate the depending Savanna
c.preactivate_savanna_protocol_features();
c.produce_block();

// Activate SYNC_CALL after the dependency met
c.preactivate_protocol_features({ *d });
c.produce_block();

// Ensure SYNC_CALL is now activated
BOOST_CHECK( c.control->is_builtin_activated( builtin_protocol_feature_t::sync_call ) );
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
Binary file modified unittests/test-data/consensus_blockchain/blocks.index
Binary file not shown.
Binary file modified unittests/test-data/consensus_blockchain/blocks.log
Binary file not shown.
Binary file modified unittests/test-data/consensus_blockchain/id
Binary file not shown.
Binary file modified unittests/test-data/consensus_blockchain/snapshot
Binary file not shown.