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

IF: Add needed dependencies to the INSTANT_FINALITY protocol feature #2318

Merged
merged 5 commits into from
Mar 18, 2024
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
2 changes: 1 addition & 1 deletion libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ namespace eosio::chain {

// check that fork_dbs are in a consistent state
if (!legacy_valid && !savanna_valid) {
elog( "fork_database is in a bad state when closing; not writing out '${filename}', legacy_valid=${l}, savanna_valid=${s}",
wlog( "fork_database is in a bad state when closing; not writing out '${filename}', legacy_valid=${l}, savanna_valid=${s}",
("filename", fork_db_file)("l", legacy_valid)("s", savanna_valid) );
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <eosio/chain/types.hpp>
#include <iterator>

namespace eosio { namespace chain {
namespace eosio::chain {

class deep_mind_handler;

Expand Down Expand Up @@ -403,7 +403,7 @@ class protocol_feature_manager {
std::optional<builtin_protocol_feature> read_builtin_protocol_feature( const std::filesystem::path& p );
protocol_feature_set initialize_protocol_features( const std::filesystem::path& p, bool populate_missing_builtins = true );

} } // namespace eosio::chain
} // namespace eosio::chain

FC_REFLECT(eosio::chain::protocol_feature_subjective_restrictions,
(earliest_allowed_activation_time)(preactivation_required)(enabled))
Expand Down
32 changes: 22 additions & 10 deletions libraries/chain/protocol_feature_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,23 @@ retires a deferred transaction is invalid.
} )
( builtin_protocol_feature_t::instant_finality, builtin_protocol_feature_spec{
"INSTANT_FINALITY",
fc::variant("bc726a24928ea2d71ba294b70c5c9efc515c1542139bcf9e42f8bc174f2e72ff").as<digest_type>(),
fc::variant("bd496b9e85ce61dcddeee4576ea185add87844238da992a9ee6df2a2bdb357c2").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: INSTANT_FINALITY
Depends on: DISALLOW_EMPTY_PRODUCER_SCHEDULE
WTMSIG_BLOCK_SIGNATURES
ACTION_RETURN_VALUE
BLS_PRIMITIVES2

Once this protocol feature is activated, the first subsequent block including a `set_finalizers`
host function call will trigger a switch to the Savanna consensus algorithm.
*/
{}
{ builtin_protocol_feature_t::disallow_empty_producer_schedule,
builtin_protocol_feature_t::wtmsig_block_signatures,
builtin_protocol_feature_t::action_return_value,
builtin_protocol_feature_t::bls_primitives
}
} )
;

Expand Down Expand Up @@ -592,8 +603,8 @@ Builtin protocol feature: INSTANT_FINALITY
}

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)
"Not all the builtin dependencies of the builtin protocol feature with codename '${codename}' and digest of ${digest} were satisfied. Missing dependencies: ${missing_dependencies}",
("codename", f.builtin_feature_codename)("digest",feature_digest)("missing_dependencies", missing_builtins_with_names)
);
}

Expand Down Expand Up @@ -973,22 +984,23 @@ Builtin protocol feature: INSTANT_FINALITY
auto file_path = p / filename;

EOS_ASSERT( !std::filesystem::exists( file_path ), plugin_exception,
"Could not save builtin protocol feature with codename '${codename}' because a file at the following path already exists: ${path}",
"Could not save builtin protocol feature with codename '${codename}' because a file at "
"the following path already exists: ${path}",
("codename", builtin_protocol_feature_codename( f.get_codename() ))
("path", file_path)
("path", file_path)
);

if( fc::json::save_to_file( f, file_path ) ) {
ilog( "Saved default specification for builtin protocol feature '${codename}' (with digest of '${digest}') to: ${path}",
("codename", builtin_protocol_feature_codename(f.get_codename()))
("digest", feature_digest)
("path", file_path)
("digest", feature_digest)
("path", file_path)
);
} else {
elog( "Error occurred while writing default specification for builtin protocol feature '${codename}' (with digest of '${digest}') to: ${path}",
("codename", builtin_protocol_feature_codename(f.get_codename()))
("digest", feature_digest)
("path", file_path)
("digest", feature_digest)
("path", file_path)
);
}
};
Expand Down
5 changes: 3 additions & 2 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,12 @@ namespace eosio { namespace testing {
return cfg;
}

void schedule_protocol_features_wo_preactivation(const vector<digest_type> feature_digests);
void preactivate_protocol_features(const vector<digest_type> feature_digests);
void schedule_protocol_features_wo_preactivation(const vector<digest_type>& feature_digests);
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_savanna_protocol_features();

static genesis_state default_genesis() {
genesis_state genesis;
Expand Down
17 changes: 15 additions & 2 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,21 +1229,34 @@ namespace eosio { namespace testing {
return tid;
}

void base_tester::schedule_protocol_features_wo_preactivation(const vector<digest_type> feature_digests) {
void base_tester::schedule_protocol_features_wo_preactivation(const vector<digest_type>& feature_digests) {
protocol_features_to_be_activated_wo_preactivation.insert(
protocol_features_to_be_activated_wo_preactivation.end(),
feature_digests.begin(),
feature_digests.end()
);
}

void base_tester::preactivate_protocol_features(const vector<digest_type> feature_digests) {
void base_tester::preactivate_protocol_features(const vector<digest_type>& feature_digests) {
for( const auto& feature_digest: feature_digests ) {
push_action( config::system_account_name, "activate"_n, config::system_account_name,
fc::mutable_variant_object()("feature_digest", feature_digest) );
}
}

void base_tester::preactivate_savanna_protocol_features() {
const auto& pfm = control->get_protocol_feature_manager();
const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::instant_finality);

// dependencies of builtin_protocol_feature_t::instant_finality
const auto& deps = pfm.get_builtin_digest(builtin_protocol_feature_t::disallow_empty_producer_schedule);
const auto& wtm = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures);
const auto& arv = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value);
const auto& bls = pfm.get_builtin_digest(builtin_protocol_feature_t::bls_primitives);

preactivate_protocol_features( {*deps, *wtm, *arv, *bls, *d} );
}

void base_tester::preactivate_builtin_protocol_features(const std::vector<builtin_protocol_feature_t>& builtins) {
const auto& pfm = control->get_protocol_feature_manager();
const auto& pfs = pfm.get_protocol_feature_set();
Expand Down
76 changes: 38 additions & 38 deletions unittests/deep-mind/deep-mind.log

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions unittests/protocol_feature_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,7 @@ BOOST_AUTO_TEST_CASE( get_sender_test ) { try {
BOOST_AUTO_TEST_CASE( protocol_activatation_works_after_transition_to_savanna ) { try {
validating_tester c({}, {}, setup_policy::preactivate_feature_and_new_bios );

const auto& pfm = c.control->get_protocol_feature_manager();
const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::instant_finality);
// needed for bios contract
const auto& dp = pfm.get_builtin_digest(builtin_protocol_feature_t::bls_primitives);
const auto& dw = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures);
const auto& dwk = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key);
c.preactivate_protocol_features( {*d, *dp, *dw, *dwk} );
c.preactivate_savanna_protocol_features();
c.produce_block();

c.set_bios_contract();
Expand Down Expand Up @@ -1143,6 +1137,7 @@ BOOST_AUTO_TEST_CASE( protocol_activatation_works_after_transition_to_savanna )
wasm_exception,
fc_exception_message_is( "env.get_sender unresolveable" ) );

const auto& pfm = c.control->get_protocol_feature_manager();
const auto& d2 = pfm.get_builtin_digest( builtin_protocol_feature_t::get_sender );
BOOST_REQUIRE( d2 );

Expand Down Expand Up @@ -2385,15 +2380,11 @@ BOOST_AUTO_TEST_CASE( set_finalizers_test ) { try {
c.create_accounts( {alice_account} );
c.produce_block();

const auto& pfm = c.control->get_protocol_feature_manager();
const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::instant_finality);
BOOST_REQUIRE(d);

BOOST_CHECK_EXCEPTION( c.set_code( config::system_account_name, import_set_finalizers_wast ),
wasm_exception,
fc_exception_message_is( "env.set_finalizers unresolveable" ) );

c.preactivate_protocol_features( {*d} );
c.preactivate_savanna_protocol_features();
c.produce_block();

// ensure it now resolves
Expand Down
1 change: 1 addition & 0 deletions unittests/test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void activate_protocol_features_set_bios_contract(appbase::scoped_app& app, chai
builtin_protocol_feature_t::webauthn_key,
builtin_protocol_feature_t::wtmsig_block_signatures,
builtin_protocol_feature_t::bls_primitives,
builtin_protocol_feature_t::action_return_value,
builtin_protocol_feature_t::instant_finality};
for (const auto t : pfs) {
auto feature_digest = pfm.get_builtin_digest(t);
Expand Down
Loading