Skip to content

Commit

Permalink
Merge branch 'default_tester' into GH-170-savanna-protocol-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner authored May 28, 2024
2 parents d4b2431 + c2c7f44 commit a99ca87
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .cicd/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"prerelease":true
},
"referencecontracts":{
"ref":"main"
"ref":"fix_failures_by_default_tester"
}
}
58 changes: 26 additions & 32 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4253,44 +4253,38 @@ struct controller_impl {
}

void update_producers_authority() {
// this is not called when hotstuff is activated
auto& bb = std::get<building_block>(pending->_block_stage);
bb.apply_l<void>([this](building_block::building_block_legacy& legacy_header) {
pending_block_header_state_legacy& pbhs = legacy_header.pending_block_header_state;
const auto& producers = pbhs.active_schedule.producers;

auto update_permission = [&](auto& permission, auto threshold) {
auto auth = authority(threshold, {}, {});
for (auto& p : producers) {
auth.accounts.push_back({
{p.producer_name, config::active_name},
1
});
}

if (permission.auth != auth) {
db.modify(permission, [&](auto& po) { po.auth = auth; });
}
};
const auto& producers = bb.active_producers().producers;

auto update_permission = [&](auto& permission, auto threshold) {
auto auth = authority(threshold, {}, {});
for (auto& p : producers) {
auth.accounts.push_back({
{p.producer_name, config::active_name},
1
});
}

uint32_t num_producers = producers.size();
auto calculate_threshold = [=](uint32_t numerator, uint32_t denominator) {
return ((num_producers * numerator) / denominator) + 1;
};
if (permission.auth != auth) {
db.modify(permission, [&](auto& po) { po.auth = auth; });
}
};

update_permission(authorization.get_permission({config::producers_account_name, config::active_name}),
calculate_threshold(2, 3) /* more than two-thirds */);
uint32_t num_producers = producers.size();
auto calculate_threshold = [=](uint32_t numerator, uint32_t denominator) {
return ((num_producers * numerator) / denominator) + 1;
};

update_permission(
authorization.get_permission({config::producers_account_name, config::majority_producers_permission_name}),
calculate_threshold(1, 2) /* more than one-half */);
update_permission(authorization.get_permission({config::producers_account_name, config::active_name}),
calculate_threshold(2, 3) /* more than two-thirds */);

update_permission(
authorization.get_permission({config::producers_account_name, config::minority_producers_permission_name}),
calculate_threshold(1, 3) /* more than one-third */);
update_permission(
authorization.get_permission({config::producers_account_name, config::majority_producers_permission_name}),
calculate_threshold(1, 2) /* more than one-half */);

// TODO: Add tests
});
update_permission(
authorization.get_permission({config::producers_account_name, config::minority_producers_permission_name}),
calculate_threshold(1, 3) /* more than one-third */);
}

void create_block_summary(const block_id_type& id) {
Expand Down
1 change: 1 addition & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
set_tests_properties(api_part3_unit_test_${RUNTIME} PROPERTIES COST 5000)
set_tests_properties(wasm_part1_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_part2_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_part3_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part1_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part2_unit_test_${RUNTIME} PROPERTIES COST 4000)
set_tests_properties(wasm_config_part3_unit_test_${RUNTIME} PROPERTIES COST 4000)
Expand Down
20 changes: 17 additions & 3 deletions unittests/producer_schedule_if_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <eosio/chain/global_property_object.hpp>
#include <eosio/chain/authorization_manager.hpp>
#include <eosio/testing/tester.hpp>

#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -26,19 +27,32 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat
const uint32_t check_duration = 100; // number of blocks
bool scheduled_changed_to_new = false;
for (uint32_t i = 0; i < check_duration; ++i) {
const auto current_schedule = control->active_producers();
if (new_prod_schd == current_schedule.producers) {
const auto current_schedule = control->active_producers().producers;
if (new_prod_schd == current_schedule) {
scheduled_changed_to_new = true;
if (expected_block_num != 0)
BOOST_TEST(control->head_block_num() == expected_block_num);

// verify eosio.prods updated
const name usr = config::producers_account_name;
const name active_permission = config::active_name;
const auto* perm = control->db().template find<permission_object, by_owner>(boost::make_tuple(usr, active_permission));
for (auto account : perm->auth.accounts) {
auto act = account.permission.actor;
auto itr = std::find_if( current_schedule.begin(), current_schedule.end(), [&](const auto& p) {
return p.producer_name == act;
});
bool found = itr != current_schedule.end();
BOOST_TEST(found);
}
}

auto b = produce_block();
BOOST_TEST( b->confirmed == 0); // must be 0 after instant finality is enabled

// Check if the producer is the same as what we expect
const auto block_time = control->head_block_time();
const auto& expected_producer = get_expected_producer(current_schedule.producers, block_time);
const auto& expected_producer = get_expected_producer(current_schedule, block_time);
BOOST_TEST(control->head_block_producer() == expected_producer);

if (scheduled_changed_to_new)
Expand Down
13 changes: 13 additions & 0 deletions unittests/producer_schedule_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <eosio/chain/global_property_object.hpp>
#include <eosio/chain/authorization_manager.hpp>
#include <eosio/testing/tester.hpp>

#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -31,6 +32,18 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule, legacy_validating_tester ) tr
const auto current_schedule = control->active_producers().producers;
if (new_prod_schd == current_schedule) {
scheduled_changed_to_new = true;
// verify eosio.prods updated
const name usr = config::producers_account_name;
const name active_permission = config::active_name;
const auto* perm = control->db().template find<permission_object, by_owner>(boost::make_tuple(usr, active_permission));
for (auto account : perm->auth.accounts) {
auto act = account.permission.actor;
auto itr = std::find_if( current_schedule.begin(), current_schedule.end(), [&](const auto& p) {
return p.producer_name == act;
});
bool found = itr != current_schedule.end();
BOOST_TEST(found);
}
}

// Produce block
Expand Down
2 changes: 1 addition & 1 deletion unittests/svnn_ibc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)

// since heavy_proof_4 requires finalizer policy generation #2, we cannot prove it yet.
try {
cluster.node0.push_action("ibc"_n, "checkproof"_n, "ibc"_n, heavy_proof_4)->action_traces[0];
cluster.node0.push_action("ibc"_n, "checkproof"_n, "ibc"_n, heavy_proof_4);
}
catch(const eosio_assert_message_exception& e){
last_action_failed = true;
Expand Down
12 changes: 8 additions & 4 deletions unittests/wasm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( table_init_oob, T, validating_testers ) try {

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_part2_tests)

BOOST_AUTO_TEST_CASE_TEMPLATE( memory_init_border, T, validating_testers ) try {
T chain;

Expand Down Expand Up @@ -1270,10 +1274,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( check_big_deserialization, T, validating_testers

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_part2_tests)

BOOST_AUTO_TEST_CASE_TEMPLATE( check_table_maximum, T, validating_testers ) try {
T chain;

Expand Down Expand Up @@ -1755,6 +1755,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fuzz, T, validating_testers ) try {
chain.produce_blocks(1);
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(wasm_part3_tests)

BOOST_AUTO_TEST_CASE_TEMPLATE( big_maligned_host_ptr, T, validating_testers ) try {
T chain;

Expand Down

0 comments on commit a99ca87

Please sign in to comment.