diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index d10cef879288814231c235a105ec722f5bee776c..0882a6c32e9fd1c6b512b54639bcc972649651b4 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -719,12 +719,12 @@ void chain_controller::update_global_properties(const signed_block& b) { gpo.configuration = std::move(config); }); - auto active_producers_authority = types::Authority(gpo.active_producers.size(), {}, {}); + auto active_producers_authority = types::Authority(uint32_t(gpo.active_producers.size()*config::ProducersAuthorityThreshold), {}, {}); for(auto& name : gpo.active_producers) { - active_producers_authority.accounts.push_back({{name,"active"}, 1}); + active_producers_authority.accounts.push_back({{name, config::ActiveName}, 1}); } - auto po = _db.get( boost::make_tuple(config::ProducersAccountName, "active") ); + auto po = _db.get( boost::make_tuple(config::ProducersAccountName, config::ActiveName) ); _db.modify(po,[active_producers_authority] (permission_object& po) { po.auth = active_producers_authority; }); diff --git a/libraries/chain/include/eos/chain/config.hpp b/libraries/chain/include/eos/chain/config.hpp index e938038945151ddbe1b4546e04cb953d94f7a422..7f7739639b8212bfff1149b1f496bfd97272884a 100644 --- a/libraries/chain/include/eos/chain/config.hpp +++ b/libraries/chain/include/eos/chain/config.hpp @@ -22,8 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include namespace eos { namespace config { using types::UInt32; @@ -31,16 +30,21 @@ 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 char NobodyAccountName[] = "nobody"; -const static char AnybodyAccountName[] = "anybody"; -const static char ProducersAccountName[] = "producers"; +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; @@ -57,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; const static int BlocksPerRound = 21; const static int VotedProducersPerRound = 20; diff --git a/libraries/native_contract/native_contract_chain_initializer.cpp b/libraries/native_contract/native_contract_chain_initializer.cpp index d89a819dc735a317083df901e2937826d8f12432..16d049731c1bbc88bf8a3dde98d28ef1e543cd18 100644 --- a/libraries/native_contract/native_contract_chain_initializer.cpp +++ b/libraries/native_contract/native_contract_chain_initializer.cpp @@ -145,19 +145,19 @@ std::vector native_contract_chain_initializer::prepare_database( boost::copy(genesis.initial_producers | CreateProducer, std::back_inserter(messages_to_process)); // Create special accounts - auto CreateSpecialAccount = [this, &db](Name name, const auto& owner, const auto& active) { + auto create_special_account = [this, &db](Name name, const auto& owner, const auto& active) { db.create([this, &name](account_object& a) { a.name = name; a.creation_date = genesis.initial_timestamp; }); const auto& owner_permission = db.create([&owner, &name](permission_object& p) { - p.name = "owner"; + p.name = config::OwnerName; p.parent = 0; p.owner = name; p.auth = std::move(owner); }); db.create([&active, &owner_permission](permission_object& p) { - p.name = "active"; + p.name = config::ActiveName; p.parent = owner_permission.id; p.owner = owner_permission.owner; p.auth = std::move(active); @@ -165,14 +165,14 @@ std::vector native_contract_chain_initializer::prepare_database( }; auto empty_authority = types::Authority(0, {}, {}); - auto active_producers_authority = types::Authority(genesis.initial_producers.size(), {}, {}); + auto active_producers_authority = types::Authority(uint32_t(genesis.initial_producers.size()*config::ProducersAuthorityThreshold), {}, {}); for(auto& p : genesis.initial_producers) { - active_producers_authority.accounts.push_back({{p.owner_name,"active"}, 1}); + active_producers_authority.accounts.push_back({{p.owner_name, config::ActiveName}, 1}); } //CreateNativeAccount(config::AnybodyAccountName, 0); - CreateSpecialAccount(config::NobodyAccountName, empty_authority, empty_authority); - CreateSpecialAccount(config::ProducersAccountName, empty_authority, active_producers_authority); + create_special_account(config::NobodyAccountName, empty_authority, empty_authority); + create_special_account(config::ProducersAccountName, empty_authority, active_producers_authority); return messages_to_process; } diff --git a/libraries/types/include/eos/types/native.hpp b/libraries/types/include/eos/types/native.hpp index 5853360c3c900d4f3112198431a45d4e04d67fa8..4f495f7aba63d93fc2aac31c2a56158cae4e5efb 100644 --- a/libraries/types/include/eos/types/native.hpp +++ b/libraries/types/include/eos/types/native.hpp @@ -18,6 +18,8 @@ #include +#define N(X) eos::types::string_to_name(#X) + namespace eos { namespace types { using namespace boost::multiprecision; @@ -55,7 +57,33 @@ namespace eos { namespace types { using Int128 = boost::multiprecision::int128_t; using Int256 = boost::multiprecision::int256_t; using uint128_t = unsigned __int128; /// native clang/gcc 128 intrinisic + + static constexpr char char_to_symbol( char c ) { + if( c >= 'a' && c <= 'z' ) + return (c - 'a') + 1; + if( c >= '1' && c <= '5' ) + return (c - '1') + 26; + return 0; + } + + static constexpr uint64_t string_to_name( const char* str ) { + uint32_t len = 0; + while( str[len] ) ++len; + + uint64_t value = 0; + + for( uint32_t i = 0; i <= 12 && i < len; ++i ) { + value <<= 5; + value |= char_to_symbol( str[ len -1 - i ] ); + } + if( len == 13 ) { + value <<= 4; + value |= 0x0f & char_to_symbol( str[ 12 ] ); + } + return value; + } + struct Name { uint64_t value = 0; bool valid()const { return 0 == (value >> 60); } @@ -80,16 +108,6 @@ namespace eos { namespace types { } }FC_CAPTURE_AND_RETHROW( (str) ) } - - char char_to_symbol( char c ) const { - if( c >= 'a' && c <= 'z' ) - return (c - 'a') + 1; - if( c >= '1' && c <= '5' ) - return (c - '1') + 27; - //FC_ASSERT( c == '.', "invalid character '${c}' (${i}) in Name string", ("c", String(&c,1))("i",int(c)) ); - return 0; - } - Name( uint64_t v = 0 ):value(v){ // FC_ASSERT( !(v>>(5*12)), "invalid name id" ); }