Resolve #40
This commit is contained in:
parent
a14500a364
commit
ec76179b0b
3 changed files with 50 additions and 11 deletions
|
|
@ -515,6 +515,7 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
|
||||||
|
|
||||||
eval_state.operation_results.reserve( trx.operations.size() );
|
eval_state.operation_results.reserve( trx.operations.size() );
|
||||||
|
|
||||||
|
//Finally process the operations
|
||||||
processed_transaction ptrx(trx);
|
processed_transaction ptrx(trx);
|
||||||
_current_op_in_trx = 0;
|
_current_op_in_trx = 0;
|
||||||
for( const auto& op : ptrx.operations )
|
for( const auto& op : ptrx.operations )
|
||||||
|
|
@ -524,6 +525,11 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
|
||||||
}
|
}
|
||||||
ptrx.operation_results = std::move( eval_state.operation_results );
|
ptrx.operation_results = std::move( eval_state.operation_results );
|
||||||
|
|
||||||
|
//Make sure the temp account has no non-zero balances
|
||||||
|
const auto& index = get_index_type<account_balance_index>().indices().get<by_account>();
|
||||||
|
auto range = index.equal_range(GRAPHENE_TEMP_ACCOUNT);
|
||||||
|
std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); });
|
||||||
|
|
||||||
return ptrx;
|
return ptrx;
|
||||||
} FC_CAPTURE_AND_RETHROW( (trx) ) }
|
} FC_CAPTURE_AND_RETHROW( (trx) ) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,9 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
n.membership_expiration_date = time_point_sec::maximum();
|
n.membership_expiration_date = time_point_sec::maximum();
|
||||||
n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
||||||
n.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
n.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
||||||
|
n.owner.weight_threshold = 1;
|
||||||
|
n.active.weight_threshold = 1;
|
||||||
n.name = "committee-account";
|
n.name = "committee-account";
|
||||||
n.active = n.owner;
|
|
||||||
n.statistics = create<account_statistics_object>( [&](account_statistics_object& b){}).id;
|
n.statistics = create<account_statistics_object>( [&](account_statistics_object& b){}).id;
|
||||||
});
|
});
|
||||||
FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT);
|
FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT);
|
||||||
|
|
@ -183,8 +184,8 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
FC_ASSERT(create<account_object>([this](account_object& a) {
|
FC_ASSERT(create<account_object>([this](account_object& a) {
|
||||||
a.name = "null-account";
|
a.name = "null-account";
|
||||||
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
||||||
a.owner.weight_threshold = 0;
|
a.owner.weight_threshold = 1;
|
||||||
a.active.weight_threshold = 0;
|
a.active.weight_threshold = 1;
|
||||||
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT;
|
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT;
|
||||||
a.membership_expiration_date = time_point_sec::maximum();
|
a.membership_expiration_date = time_point_sec::maximum();
|
||||||
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,34 @@ void database::update_active_witnesses()
|
||||||
auto wits = sort_votable_objects<witness_object>(std::max(witness_count*2+1, GRAPHENE_MIN_WITNESS_COUNT));
|
auto wits = sort_votable_objects<witness_object>(std::max(witness_count*2+1, GRAPHENE_MIN_WITNESS_COUNT));
|
||||||
const global_property_object& gpo = get_global_properties();
|
const global_property_object& gpo = get_global_properties();
|
||||||
|
|
||||||
|
// Update witness authority
|
||||||
|
modify( get(GRAPHENE_WITNESS_ACCOUNT), [&]( account_object& a ) {
|
||||||
|
uint64_t total_votes = 0;
|
||||||
|
map<account_id_type, uint64_t> weights;
|
||||||
|
a.active.weight_threshold = 0;
|
||||||
|
a.active.auths.clear();
|
||||||
|
|
||||||
|
for( const witness_object& wit : wits )
|
||||||
|
{
|
||||||
|
weights.emplace(wit.witness_account, _vote_tally_buffer[wit.vote_id]);
|
||||||
|
total_votes += _vote_tally_buffer[wit.vote_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
// total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits,
|
||||||
|
// then I want to keep the most significant 16 bits of what's left.
|
||||||
|
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
||||||
|
for( const auto& weight : weights )
|
||||||
|
{
|
||||||
|
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
|
||||||
|
uint16_t votes = std::max((weight.second >> bits_to_drop), uint64_t(1) );
|
||||||
|
a.active.auths[weight.first] += votes;
|
||||||
|
a.active.weight_threshold += votes;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.active.weight_threshold /= 2;
|
||||||
|
a.active.weight_threshold += 1;
|
||||||
|
});
|
||||||
|
|
||||||
modify( gpo, [&]( global_property_object& gp ){
|
modify( gpo, [&]( global_property_object& gp ){
|
||||||
gp.active_witnesses.clear();
|
gp.active_witnesses.clear();
|
||||||
gp.active_witnesses.reserve( wits.size() );
|
gp.active_witnesses.reserve( wits.size() );
|
||||||
|
|
@ -139,11 +167,12 @@ void database::update_active_delegates()
|
||||||
|
|
||||||
// Update genesis authorities
|
// Update genesis authorities
|
||||||
if( !delegates.empty() )
|
if( !delegates.empty() )
|
||||||
modify( get(account_id_type()), [&]( account_object& a ) {
|
{
|
||||||
|
modify( get(GRAPHENE_COMMITTEE_ACCOUNT), [&]( account_object& a ) {
|
||||||
uint64_t total_votes = 0;
|
uint64_t total_votes = 0;
|
||||||
map<account_id_type, uint64_t> weights;
|
map<account_id_type, uint64_t> weights;
|
||||||
a.owner.weight_threshold = 0;
|
a.active.weight_threshold = 0;
|
||||||
a.owner.auths.clear();
|
a.active.auths.clear();
|
||||||
|
|
||||||
for( const delegate_object& del : delegates )
|
for( const delegate_object& del : delegates )
|
||||||
{
|
{
|
||||||
|
|
@ -158,14 +187,17 @@ void database::update_active_delegates()
|
||||||
{
|
{
|
||||||
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
|
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
|
||||||
uint16_t votes = std::max((weight.second >> bits_to_drop), uint64_t(1) );
|
uint16_t votes = std::max((weight.second >> bits_to_drop), uint64_t(1) );
|
||||||
a.owner.auths[weight.first] += votes;
|
a.active.auths[weight.first] += votes;
|
||||||
a.owner.weight_threshold += votes;
|
a.active.weight_threshold += votes;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.owner.weight_threshold /= 2;
|
a.active.weight_threshold /= 2;
|
||||||
a.owner.weight_threshold += 1;
|
a.active.weight_threshold += 1;
|
||||||
a.active = a.owner;
|
|
||||||
});
|
});
|
||||||
|
modify( get(GRAPHENE_RELAXED_COMMITTEE_ACCOUNT), [&](account_object& a) {
|
||||||
|
a.active = get(GRAPHENE_COMMITTEE_ACCOUNT).active;
|
||||||
|
});
|
||||||
|
}
|
||||||
modify( get_global_properties(), [&]( global_property_object& gp ) {
|
modify( get_global_properties(), [&]( global_property_object& gp ) {
|
||||||
gp.active_delegates.clear();
|
gp.active_delegates.clear();
|
||||||
std::transform(delegates.begin(), delegates.end(),
|
std::transform(delegates.begin(), delegates.end(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue