提交 fc82a83d 编写于 作者: M Matias Romeo

Change producers account active authority threshold to 2/3 of active set

Replace hardcoded strings (active/owner) with global constants in config.hpp
Change char* constants to specific types and use N() macro for initialization
上级 29de3ca9
......@@ -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<permission_object, by_owner>( boost::make_tuple(config::ProducersAccountName, "active") );
auto po = _db.get<permission_object, by_owner>( boost::make_tuple(config::ProducersAccountName, config::ActiveName) );
_db.modify(po,[active_producers_authority] (permission_object& po) {
po.auth = active_producers_authority;
});
......
......@@ -22,8 +22,7 @@
* 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;
......@@ -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;
......
......@@ -145,19 +145,19 @@ std::vector<chain::Message> 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<account_object>([this, &name](account_object& a) {
a.name = name;
a.creation_date = genesis.initial_timestamp;
});
const auto& owner_permission = db.create<permission_object>([&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<permission_object>([&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<chain::Message> 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;
}
......
......@@ -18,6 +18,8 @@
#include <fc/reflect/reflect.hpp>
#define N(X) eos::types::string_to_name(#X)
namespace eos { namespace types {
using namespace boost::multiprecision;
......@@ -56,6 +58,32 @@ namespace eos { namespace types {
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" );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册