This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Create special accounts #79
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d2bccfd
Create special accounts (nobody, producers)
elmato 29de3ca
Update "producers" account authority on every new round
elmato fc82a83
Change producers account active authority threshold to 2/3 of active set
elmato 2b15938
Add test to check for producers/nobody accounts in genesis
elmato a0dbe29
Fix error getting permission_object from db
elmato 4756d36
Add test to check producers account authority when a new set of produ…
elmato 1265a87
Change ProducersAuthorityThreshold type to UInt32
elmato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,21 +22,29 @@ | |
* THE SOFTWARE. | ||
*/ | ||
#pragma once | ||
#include <eos/types/native.hpp> | ||
#include <eos/types/Asset.hpp> | ||
#include <eos/types/types.hpp> | ||
|
||
namespace eos { namespace config { | ||
using types::UInt32; | ||
using types::UInt64; | ||
using types::UInt128; | ||
using types::ShareType; | ||
using types::Asset; | ||
using types::AccountName; | ||
using types::PermissionName; | ||
|
||
const static char KeyPrefix[] = "EOS"; | ||
|
||
const static char SystemContractName[] = "system"; | ||
const static char EosContractName[] = "eos"; | ||
const static char StakedBalanceContractName[] = "staked"; | ||
const static AccountName SystemContractName = N(system); | ||
const static AccountName EosContractName = N(eos); | ||
const static AccountName StakedBalanceContractName = N(staked); | ||
|
||
const static AccountName NobodyAccountName = N(nobody); | ||
const static AccountName AnybodyAccountName = N(anybody); | ||
const static AccountName ProducersAccountName = N(producers); | ||
|
||
const static PermissionName ActiveName = N(active); | ||
const static PermissionName OwnerName = N(owner); | ||
|
||
const static ShareType InitialTokenSupply = Asset::fromString("90000000.00000000 EOS").amount; | ||
|
||
|
@@ -53,6 +61,7 @@ const static ShareType DefaultElectedPay = Asset(100).amount; | |
const static ShareType DefaultRunnerUpPay = Asset(75).amount; | ||
const static ShareType DefaultMinEosBalance = Asset(100).amount; | ||
const static UInt32 DefaultMaxTrxLifetime = 60*60; | ||
const static double ProducersAuthorityThreshold = 2.0/3.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should never use double's in our code, especially any logic that is run as part of consensus. |
||
|
||
const static int BlocksPerRound = 21; | ||
const static int VotedProducersPerRound = 20; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include <algorithm> | ||
#include <vector> | ||
#include <iterator> | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <eos/chain/chain_controller.hpp> | ||
#include <eos/chain/exceptions.hpp> | ||
#include <eos/chain/permission_object.hpp> | ||
#include <eos/chain/key_value_object.hpp> | ||
|
||
#include <eos/native_contract/producer_objects.hpp> | ||
|
||
#include <eos/utilities/tempdir.hpp> | ||
|
||
#include <fc/crypto/digest.hpp> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <boost/range/algorithm/find.hpp> | ||
#include <boost/range/algorithm/find_if.hpp> | ||
#include <boost/range/algorithm/permutation.hpp> | ||
|
||
#include "../common/database_fixture.hpp" | ||
|
||
using namespace eos; | ||
using namespace chain; | ||
|
||
BOOST_AUTO_TEST_SUITE(special_account_tests) | ||
|
||
//Check special accounts exits in genesis | ||
BOOST_FIXTURE_TEST_CASE(accounts_exists, testing_fixture) | ||
{ try { | ||
|
||
Make_Blockchain(chain); | ||
|
||
auto nobody = chain_db.find<account_object, by_name>(config::NobodyAccountName); | ||
BOOST_CHECK(nobody != nullptr); | ||
const auto& nobody_active_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::NobodyAccountName, config::ActiveName)); | ||
BOOST_CHECK_EQUAL(nobody_active_authority.auth.threshold, 0); | ||
BOOST_CHECK_EQUAL(nobody_active_authority.auth.accounts.size(), 0); | ||
BOOST_CHECK_EQUAL(nobody_active_authority.auth.keys.size(), 0); | ||
|
||
const auto& nobody_owner_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::NobodyAccountName, config::OwnerName)); | ||
BOOST_CHECK_EQUAL(nobody_owner_authority.auth.threshold, 0); | ||
BOOST_CHECK_EQUAL(nobody_owner_authority.auth.accounts.size(), 0); | ||
BOOST_CHECK_EQUAL(nobody_owner_authority.auth.keys.size(), 0); | ||
|
||
// TODO: check for anybody account | ||
//auto anybody = chain_db.find<account_object, by_name>(config::AnybodyAccountName); | ||
//BOOST_CHECK(anybody == nullptr); | ||
|
||
auto producers = chain_db.find<account_object, by_name>(config::ProducersAccountName); | ||
BOOST_CHECK(producers != nullptr); | ||
|
||
auto& gpo = chain_db.get<global_property_object>(); | ||
auto threshold = uint32_t(gpo.active_producers.size()*config::ProducersAuthorityThreshold); | ||
|
||
const auto& producers_active_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::ProducersAccountName, config::ActiveName)); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.threshold, threshold); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.accounts.size(), gpo.active_producers.size()); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.keys.size(), 0); | ||
|
||
std::vector<AccountName> active_auth; | ||
for(auto& apw : producers_active_authority.auth.accounts) { | ||
active_auth.emplace_back(apw.permission.account); | ||
} | ||
|
||
std::vector<AccountName> diff; | ||
std::set_difference( | ||
active_auth.begin(), | ||
active_auth.end(), | ||
gpo.active_producers.begin(), | ||
gpo.active_producers.end(), | ||
std::inserter(diff, diff.begin()) | ||
); | ||
|
||
BOOST_CHECK_EQUAL(diff.size(), 0); | ||
|
||
const auto& producers_owner_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::ProducersAccountName, config::OwnerName)); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.threshold, 0); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.accounts.size(), 0); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.keys.size(), 0); | ||
|
||
} FC_LOG_AND_RETHROW() } | ||
|
||
//Check correct authority when new set of producers are elected | ||
BOOST_FIXTURE_TEST_CASE(producers_authority, testing_fixture) | ||
{ try { | ||
|
||
Make_Blockchain(chain) | ||
chain.produce_blocks(); | ||
|
||
Make_Account(chain, alice); | ||
Make_Account(chain, bob); | ||
Make_Account(chain, charlie); | ||
|
||
Make_Account(chain, newproducer1); Make_Producer(chain, newproducer1); | ||
Make_Account(chain, newproducer2); Make_Producer(chain, newproducer2); | ||
Make_Account(chain, newproducer3); Make_Producer(chain, newproducer3); | ||
|
||
Approve_Producer(chain, alice, newproducer1, true); | ||
Approve_Producer(chain, bob, newproducer2, true); | ||
Approve_Producer(chain, charlie, newproducer3, true); | ||
|
||
chain.produce_blocks(config::BlocksPerRound - chain.head_block_num() ); | ||
|
||
auto& gpo = chain_db.get<global_property_object>(); | ||
|
||
BOOST_REQUIRE(boost::find(gpo.active_producers, "newproducer1") != gpo.active_producers.end()); | ||
BOOST_REQUIRE(boost::find(gpo.active_producers, "newproducer2") != gpo.active_producers.end()); | ||
BOOST_REQUIRE(boost::find(gpo.active_producers, "newproducer3") != gpo.active_producers.end()); | ||
|
||
auto threshold = uint32_t(gpo.active_producers.size()*config::ProducersAuthorityThreshold); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will also break when constant changed. |
||
|
||
const auto& producers_active_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::ProducersAccountName, config::ActiveName)); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.threshold, threshold); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.accounts.size(), gpo.active_producers.size()); | ||
BOOST_CHECK_EQUAL(producers_active_authority.auth.keys.size(), 0); | ||
|
||
std::vector<AccountName> active_auth; | ||
for(auto& apw : producers_active_authority.auth.accounts) { | ||
active_auth.emplace_back(apw.permission.account); | ||
} | ||
|
||
std::vector<AccountName> diff; | ||
std::set_difference( | ||
active_auth.begin(), | ||
active_auth.end(), | ||
gpo.active_producers.begin(), | ||
gpo.active_producers.end(), | ||
std::inserter(diff, diff.begin()) | ||
); | ||
|
||
BOOST_CHECK_EQUAL(diff.size(), 0); | ||
|
||
const auto& producers_owner_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple(config::ProducersAccountName, config::OwnerName)); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.threshold, 0); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.accounts.size(), 0); | ||
BOOST_CHECK_EQUAL(producers_owner_authority.auth.keys.size(), 0); | ||
|
||
} FC_LOG_AND_RETHROW() } | ||
|
||
|
||
BOOST_AUTO_TEST_SUITE_END() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This like will break once you replace the double constant with a constant number of producers threshold.
The active producers size should always be 21.