Skip to content

Commit

Permalink
Fix EOSIO#2140 - Check that producers are unique and corresponding ac…
Browse files Browse the repository at this point in the history
…counts exist
  • Loading branch information
zorba80 committed Apr 5, 2018
1 parent addbe2f commit e311680
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class privileged_api : public context_aware_api {
datastream<const char*> ds( packed_producer_schedule, datalen );
producer_schedule_type psch;
fc::raw::unpack(ds, psch);
// check that producers are unique
std::set<account_name> unique_producers;
for (const auto& p: psch.producers) {
EOS_ASSERT(context.is_account(p.producer_name), wasm_execution_error, "producer schedule includes a nonexisting account");
unique_producers.insert(p.producer_name);
}
EOS_ASSERT(psch.producers.size() == unique_producers.size(), wasm_execution_error, "duplicate producer name in producer schedule");
context.mutable_db.modify( context.controller.get_global_properties(),
[&]( auto& gprops ) {
gprops.new_active_producers = psch;
Expand Down
1 change: 1 addition & 0 deletions tests/chain_tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ BOOST_AUTO_TEST_CASE(missed_blocks)
for (char i = 'a'; i <= 'u'; i++) {
producer_names.emplace_back(std::string("init") + i);
}
chain.create_accounts(producer_names);
chain.set_producers(producer_names);

// Produce blocks until the next block production will use the new set of producers from beginning
Expand Down
25 changes: 25 additions & 0 deletions tests/chain_tests/producer_schedule_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ BOOST_AUTO_TEST_SUITE(producer_schedule_tests)
} FC_LOG_AND_RETHROW()


BOOST_FIXTURE_TEST_CASE( verify_producers, TESTER ) try {

vector<account_name> valid_producers = {
"inita", "initb", "initc", "initd", "inite", "initf", "initg",
"inith", "initi", "initj", "initk", "initl", "initm", "initn",
"inito", "initp", "initq", "initr", "inits", "initt", "initu"
};
create_accounts(valid_producers);
set_producers(valid_producers);

// account initz does not exist
vector<account_name> nonexisting_producer = { "initz" };
BOOST_CHECK_THROW(set_producers(nonexisting_producer), wasm_execution_error);

// replace initg with inita, inita is now duplicate
vector<account_name> invalid_producers = {
"inita", "initb", "initc", "initd", "inite", "initf", "inita",
"inith", "initi", "initj", "initk", "initl", "initm", "initn",
"inito", "initp", "initq", "initr", "inits", "initt", "initu"
};

BOOST_CHECK_THROW(set_producers(invalid_producers), wasm_execution_error);

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( verify_header_schedule_version, TESTER ) try {

// Utility function to ensure that producer schedule version in the header is correct
Expand Down

0 comments on commit e311680

Please sign in to comment.