Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4c8d1d91f | ||
|
|
517afc2d19 | ||
|
|
a4b3fae15c | ||
|
|
011d3a51a5 |
14 changed files with 465 additions and 4 deletions
|
|
@ -350,6 +350,7 @@ processed_transaction database::push_proposal(const proposal_object& proposal)
|
||||||
auto session = _undo_db.start_undo_session(true);
|
auto session = _undo_db.start_undo_session(true);
|
||||||
for( auto& op : proposal.proposed_transaction.operations )
|
for( auto& op : proposal.proposed_transaction.operations )
|
||||||
eval_state.operation_results.emplace_back(apply_operation(eval_state, op));
|
eval_state.operation_results.emplace_back(apply_operation(eval_state, op));
|
||||||
|
remove_son_proposal(proposal);
|
||||||
remove(proposal);
|
remove(proposal);
|
||||||
session.merge();
|
session.merge();
|
||||||
} catch ( const fc::exception& e ) {
|
} catch ( const fc::exception& e ) {
|
||||||
|
|
@ -426,6 +427,34 @@ signed_block database::_generate_block(
|
||||||
_pending_tx_session.reset();
|
_pending_tx_session.reset();
|
||||||
_pending_tx_session = _undo_db.start_undo_session();
|
_pending_tx_session = _undo_db.start_undo_session();
|
||||||
|
|
||||||
|
if( head_block_time() > HARDFORK_SON_TIME )
|
||||||
|
{
|
||||||
|
// Approve proposals raised by me in previous schedule or before
|
||||||
|
process_son_proposals( witness_obj, block_signing_private_key );
|
||||||
|
// Check for new SON Deregistration Proposals to be raised
|
||||||
|
std::set<son_id_type> sons_to_be_dereg = get_sons_to_be_deregistered();
|
||||||
|
if(sons_to_be_dereg.size() > 0)
|
||||||
|
{
|
||||||
|
// We shouldn't raise proposals for the SONs for which a de-reg
|
||||||
|
// proposal is already raised.
|
||||||
|
std::set<son_id_type> sons_being_dereg = get_sons_being_deregistered();
|
||||||
|
for( auto& son : sons_to_be_dereg)
|
||||||
|
{
|
||||||
|
// New SON to be deregistered
|
||||||
|
if(sons_being_dereg.find(son) == sons_being_dereg.end())
|
||||||
|
{
|
||||||
|
// Creating the de-reg proposal
|
||||||
|
auto op = create_son_deregister_proposal(son, witness_obj);
|
||||||
|
if(op.valid())
|
||||||
|
{
|
||||||
|
// Signing and pushing into the txs to be included in the block
|
||||||
|
_pending_tx.insert( _pending_tx.begin(), create_signed_transaction( block_signing_private_key, *op ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t postponed_tx_count = 0;
|
uint64_t postponed_tx_count = 0;
|
||||||
// pop pending state (reset to head block state)
|
// pop pending state (reset to head block state)
|
||||||
for( const processed_transaction& tx : _pending_tx )
|
for( const processed_transaction& tx : _pending_tx )
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/chain_property_object.hpp>
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
|
#include <graphene/chain/son_object.hpp>
|
||||||
|
#include <graphene/chain/son_proposal_object.hpp>
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
@ -141,4 +142,118 @@ const std::vector<uint32_t> database::get_winner_numbers( asset_id_type for_asse
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<son_id_type> database::get_sons_being_deregistered()
|
||||||
|
{
|
||||||
|
std::set<son_id_type> ret;
|
||||||
|
const auto& son_proposal_idx = get_index_type<son_proposal_index>().indices().get< by_id >();
|
||||||
|
|
||||||
|
for( auto& son_proposal : son_proposal_idx )
|
||||||
|
{
|
||||||
|
if(son_proposal.proposal_type == son_proposal_type::son_deregister_proposal)
|
||||||
|
{
|
||||||
|
ret.insert(son_proposal.son_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<son_id_type> database::get_sons_to_be_deregistered()
|
||||||
|
{
|
||||||
|
std::set<son_id_type> ret;
|
||||||
|
const auto& son_idx = get_index_type<son_index>().indices().get< by_id >();
|
||||||
|
|
||||||
|
for( auto& son : son_idx )
|
||||||
|
{
|
||||||
|
if(son.status == son_status::in_maintenance)
|
||||||
|
{
|
||||||
|
auto stats = son.statistics(*this);
|
||||||
|
// TODO : We need to add a function that returns if we can deregister SON
|
||||||
|
// i.e. with introduction of PW code, we have to make a decision if the SON
|
||||||
|
// is needed for release of funds from the PW
|
||||||
|
if(head_block_time() - stats.last_down_timestamp >= fc::hours(SON_DEREGISTER_TIME))
|
||||||
|
{
|
||||||
|
ret.insert(son.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
fc::optional<operation> database::create_son_deregister_proposal(const son_id_type& son_id, const witness_object& current_witness )
|
||||||
|
{
|
||||||
|
son_delete_operation son_dereg_op;
|
||||||
|
son_dereg_op.payer = current_witness.witness_account;
|
||||||
|
son_dereg_op.son_id = son_id;
|
||||||
|
|
||||||
|
proposal_create_operation proposal_op;
|
||||||
|
proposal_op.fee_paying_account = current_witness.witness_account;
|
||||||
|
proposal_op.proposed_ops.push_back( op_wrapper( son_dereg_op ) );
|
||||||
|
uint32_t lifetime = ( get_global_properties().parameters.block_interval * get_global_properties().active_witnesses.size() ) * 3;
|
||||||
|
proposal_op.expiration_time = time_point_sec( head_block_time().sec_since_epoch() + lifetime );
|
||||||
|
return proposal_op;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed_transaction database::create_signed_transaction( const fc::ecc::private_key& signing_private_key, const operation& op )
|
||||||
|
{
|
||||||
|
signed_transaction processed_trx;
|
||||||
|
auto dyn_props = get_dynamic_global_properties();
|
||||||
|
processed_trx.set_reference_block( dyn_props.head_block_id );
|
||||||
|
processed_trx.set_expiration( head_block_time() + get_global_properties().parameters.maximum_time_until_expiration );
|
||||||
|
processed_trx.operations.push_back( op );
|
||||||
|
current_fee_schedule().set_fee( processed_trx.operations.back() );
|
||||||
|
|
||||||
|
processed_trx.sign( signing_private_key, get_chain_id() );
|
||||||
|
|
||||||
|
return processed_trx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void database::process_son_proposals( const witness_object& current_witness, const fc::ecc::private_key& private_key )
|
||||||
|
{
|
||||||
|
const auto& son_proposal_idx = get_index_type<son_proposal_index>().indices().get< by_id >();
|
||||||
|
const auto& proposal_idx = get_index_type<proposal_index>().indices().get< by_id >();
|
||||||
|
|
||||||
|
auto approve_proposal = [ & ]( const proposal_id_type& id )
|
||||||
|
{
|
||||||
|
proposal_update_operation puo;
|
||||||
|
puo.fee_paying_account = current_witness.witness_account;
|
||||||
|
puo.proposal = id;
|
||||||
|
puo.active_approvals_to_add = { current_witness.witness_account };
|
||||||
|
_pending_tx.insert( _pending_tx.begin(), create_signed_transaction( private_key, puo ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
for( auto& son_proposal : son_proposal_idx )
|
||||||
|
{
|
||||||
|
const auto& proposal = proposal_idx.find( son_proposal.proposal_id );
|
||||||
|
FC_ASSERT( proposal != proposal_idx.end() );
|
||||||
|
if( proposal->proposer == current_witness.witness_account)
|
||||||
|
{
|
||||||
|
approve_proposal( proposal->id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void database::remove_son_proposal( const proposal_object& proposal )
|
||||||
|
{ try {
|
||||||
|
if( proposal.proposed_transaction.operations.size() == 1 &&
|
||||||
|
( proposal.proposed_transaction.operations.back().which() == operation::tag<son_delete_operation>::value) )
|
||||||
|
{
|
||||||
|
const auto& son_proposal_idx = get_index_type<son_proposal_index>().indices().get<by_proposal>();
|
||||||
|
auto son_proposal_itr = son_proposal_idx.find( proposal.id );
|
||||||
|
if( son_proposal_itr == son_proposal_idx.end() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
remove( *son_proposal_itr );
|
||||||
|
}
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (proposal) ) }
|
||||||
|
|
||||||
|
bool database::is_son_dereg_valid( const son_id_type& son_id )
|
||||||
|
{
|
||||||
|
const auto& son_idx = get_index_type<son_index>().indices().get< by_id >();
|
||||||
|
auto son = son_idx.find( son_id );
|
||||||
|
FC_ASSERT( son != son_idx.end() );
|
||||||
|
bool ret = ( son->status == son_status::in_maintenance &&
|
||||||
|
(head_block_time() - son->statistics(*this).last_down_timestamp >= fc::hours(SON_DEREGISTER_TIME)));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@
|
||||||
#include <graphene/chain/betting_market_object.hpp>
|
#include <graphene/chain/betting_market_object.hpp>
|
||||||
#include <graphene/chain/global_betting_statistics_object.hpp>
|
#include <graphene/chain/global_betting_statistics_object.hpp>
|
||||||
#include <graphene/chain/son_object.hpp>
|
#include <graphene/chain/son_object.hpp>
|
||||||
|
#include <graphene/chain/son_proposal_object.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/account_evaluator.hpp>
|
#include <graphene/chain/account_evaluator.hpp>
|
||||||
#include <graphene/chain/asset_evaluator.hpp>
|
#include <graphene/chain/asset_evaluator.hpp>
|
||||||
|
|
@ -288,6 +289,7 @@ void database::initialize_indexes()
|
||||||
tournament_details_idx->add_secondary_index<tournament_players_index>();
|
tournament_details_idx->add_secondary_index<tournament_players_index>();
|
||||||
add_index< primary_index<match_index> >();
|
add_index< primary_index<match_index> >();
|
||||||
add_index< primary_index<game_index> >();
|
add_index< primary_index<game_index> >();
|
||||||
|
add_index< primary_index<son_proposal_index> >();
|
||||||
|
|
||||||
//Implementation object indexes
|
//Implementation object indexes
|
||||||
add_index< primary_index<transaction_index > >();
|
add_index< primary_index<transaction_index > >();
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,8 @@
|
||||||
#define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week
|
#define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week
|
||||||
#define MIN_SON_MEMBER_COUNT 15
|
#define MIN_SON_MEMBER_COUNT 15
|
||||||
#define SON_VESTING_AMOUNT (50*GRAPHENE_BLOCKCHAIN_PRECISION) // 50 PPY
|
#define SON_VESTING_AMOUNT (50*GRAPHENE_BLOCKCHAIN_PRECISION) // 50 PPY
|
||||||
#define SON_VESTING_PERIOD (60*60*24*30) // 2 days
|
#define SON_VESTING_PERIOD (60*60*24*2) // 2 days
|
||||||
|
#define SON_DEREGISTER_TIME (12) // 12 Hours
|
||||||
#define MIN_SON_PAY_DAILY_MAX (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(200))
|
#define MIN_SON_PAY_DAILY_MAX (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(200))
|
||||||
#define SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE (2*GRAPHENE_1_PERCENT)
|
#define SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE (2*GRAPHENE_1_PERCENT)
|
||||||
#define SWEEPS_DEFAULT_DISTRIBUTION_ASSET (graphene::chain::asset_id_type(0))
|
#define SWEEPS_DEFAULT_DISTRIBUTION_ASSET (graphene::chain::asset_id_type(0))
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,13 @@ namespace graphene { namespace chain {
|
||||||
const std::vector<uint32_t> get_winner_numbers( asset_id_type for_asset, uint32_t count_members, uint8_t count_winners ) const;
|
const std::vector<uint32_t> get_winner_numbers( asset_id_type for_asset, uint32_t count_members, uint8_t count_winners ) const;
|
||||||
std::vector<uint32_t> get_seeds( asset_id_type for_asset, uint8_t count_winners )const;
|
std::vector<uint32_t> get_seeds( asset_id_type for_asset, uint8_t count_winners )const;
|
||||||
uint64_t get_random_bits( uint64_t bound );
|
uint64_t get_random_bits( uint64_t bound );
|
||||||
|
std::set<son_id_type> get_sons_being_deregistered();
|
||||||
|
std::set<son_id_type> get_sons_to_be_deregistered();
|
||||||
|
fc::optional<operation> create_son_deregister_proposal(const son_id_type& son_id, const witness_object& current_witness );
|
||||||
|
signed_transaction create_signed_transaction( const fc::ecc::private_key& signing_private_key, const operation& op );
|
||||||
|
void process_son_proposals( const witness_object& current_witness, const fc::ecc::private_key& private_key );
|
||||||
|
void remove_son_proposal( const proposal_object& proposal );
|
||||||
|
bool is_son_dereg_valid( const son_id_type& son_id );
|
||||||
|
|
||||||
time_point_sec head_block_time()const;
|
time_point_sec head_block_time()const;
|
||||||
uint32_t head_block_num()const;
|
uint32_t head_block_num()const;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,21 @@
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
class son_hardfork_visitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void result_type;
|
||||||
|
database& db;
|
||||||
|
proposal_id_type prop_id;
|
||||||
|
|
||||||
|
son_hardfork_visitor( database& _db, const proposal_id_type& _prop_id ) : db( _db ), prop_id( _prop_id ) {}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void operator()( const T &v ) const {}
|
||||||
|
|
||||||
|
void operator()( const son_delete_operation &v );
|
||||||
|
};
|
||||||
|
|
||||||
class proposal_create_evaluator : public evaluator<proposal_create_evaluator>
|
class proposal_create_evaluator : public evaluator<proposal_create_evaluator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,10 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
asset fee;
|
asset fee;
|
||||||
son_id_type son_id;
|
son_id_type son_id;
|
||||||
|
account_id_type payer;
|
||||||
account_id_type owner_account;
|
account_id_type owner_account;
|
||||||
|
|
||||||
account_id_type fee_payer()const { return owner_account; }
|
account_id_type fee_payer()const { return payer; }
|
||||||
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ namespace graphene { namespace chain {
|
||||||
betting_market_object_type,
|
betting_market_object_type,
|
||||||
bet_object_type,
|
bet_object_type,
|
||||||
son_object_type,
|
son_object_type,
|
||||||
|
son_proposal_object_type,
|
||||||
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -207,6 +208,7 @@ namespace graphene { namespace chain {
|
||||||
class betting_market_object;
|
class betting_market_object;
|
||||||
class bet_object;
|
class bet_object;
|
||||||
class son_object;
|
class son_object;
|
||||||
|
class son_proposal_object;
|
||||||
|
|
||||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||||
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
||||||
|
|
@ -234,6 +236,7 @@ namespace graphene { namespace chain {
|
||||||
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
||||||
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
||||||
typedef object_id< protocol_ids, son_object_type, son_object> son_id_type;
|
typedef object_id< protocol_ids, son_object_type, son_object> son_id_type;
|
||||||
|
typedef object_id< protocol_ids, son_proposal_object_type, son_proposal_object> son_proposal_id_type;
|
||||||
|
|
||||||
// implementation types
|
// implementation types
|
||||||
class global_property_object;
|
class global_property_object;
|
||||||
|
|
@ -417,6 +420,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
||||||
(betting_market_object_type)
|
(betting_market_object_type)
|
||||||
(bet_object_type)
|
(bet_object_type)
|
||||||
(son_object_type)
|
(son_object_type)
|
||||||
|
(son_proposal_object_type)
|
||||||
(OBJECT_TYPE_COUNT)
|
(OBJECT_TYPE_COUNT)
|
||||||
)
|
)
|
||||||
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
||||||
|
|
@ -488,6 +492,7 @@ FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::son_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::son_id_type )
|
||||||
|
FC_REFLECT_TYPENAME( graphene::chain::son_proposal_id_type )
|
||||||
|
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_t, )
|
FC_REFLECT( graphene::chain::void_t, )
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,12 @@
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
using namespace graphene::db;
|
using namespace graphene::db;
|
||||||
|
|
||||||
|
enum class son_status
|
||||||
|
{
|
||||||
|
inactive,
|
||||||
|
active,
|
||||||
|
in_maintenance
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* @class son_statistics_object
|
* @class son_statistics_object
|
||||||
* @ingroup object
|
* @ingroup object
|
||||||
|
|
@ -23,6 +29,10 @@ namespace graphene { namespace chain {
|
||||||
son_id_type owner;
|
son_id_type owner;
|
||||||
// Transactions signed since the last son payouts
|
// Transactions signed since the last son payouts
|
||||||
uint64_t txs_signed = 0;
|
uint64_t txs_signed = 0;
|
||||||
|
// Total Downtime barring the current down time in seconds, used for stats to present to user
|
||||||
|
uint64_t total_downtime = 0;
|
||||||
|
// Down timestamp, if son status is in_maintenance use this
|
||||||
|
fc::time_point_sec last_down_timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,6 +54,7 @@ namespace graphene { namespace chain {
|
||||||
public_key_type signing_key;
|
public_key_type signing_key;
|
||||||
vesting_balance_id_type pay_vb;
|
vesting_balance_id_type pay_vb;
|
||||||
son_statistics_id_type statistics;
|
son_statistics_id_type statistics;
|
||||||
|
son_status status = son_status::inactive;
|
||||||
|
|
||||||
void pay_son_fee(share_type pay, database& db);
|
void pay_son_fee(share_type pay, database& db);
|
||||||
};
|
};
|
||||||
|
|
@ -76,6 +87,8 @@ namespace graphene { namespace chain {
|
||||||
using son_stats_index = generic_index<son_statistics_object, son_stats_multi_index_type>;
|
using son_stats_index = generic_index<son_statistics_object, son_stats_multi_index_type>;
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(in_maintenance) )
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
|
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
|
||||||
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb) )
|
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb) )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
#include <graphene/db/object.hpp>
|
||||||
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
enum class son_proposal_type
|
||||||
|
{
|
||||||
|
son_deregister_proposal
|
||||||
|
};
|
||||||
|
|
||||||
|
class son_proposal_object : public abstract_object<son_proposal_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = son_proposal_object_type;
|
||||||
|
|
||||||
|
son_proposal_id_type get_id()const { return id; }
|
||||||
|
|
||||||
|
proposal_id_type proposal_id;
|
||||||
|
son_id_type son_id;
|
||||||
|
son_proposal_type proposal_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_proposal;
|
||||||
|
using son_proposal_multi_index_container = multi_index_container<
|
||||||
|
son_proposal_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_unique< tag< by_proposal >, member< son_proposal_object, proposal_id_type, &son_proposal_object::proposal_id > >
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
using son_proposal_index = generic_index<son_proposal_object, son_proposal_multi_index_container>;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_ENUM(graphene::chain::son_proposal_type, (son_deregister_proposal) )
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::son_proposal_object, (graphene::chain::object), (proposal_id)(son_id)(proposal_type) )
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include <graphene/chain/proposal_evaluator.hpp>
|
#include <graphene/chain/proposal_evaluator.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
|
#include <graphene/chain/son_proposal_object.hpp>
|
||||||
#include <graphene/chain/protocol/account.hpp>
|
#include <graphene/chain/protocol/account.hpp>
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
#include <graphene/chain/protocol/tournament.hpp>
|
#include <graphene/chain/protocol/tournament.hpp>
|
||||||
|
|
@ -154,6 +155,15 @@ struct proposal_operation_hardfork_visitor
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void son_hardfork_visitor::operator()( const son_delete_operation &v )
|
||||||
|
{
|
||||||
|
db.create<son_proposal_object>([&]( son_proposal_object& son_prop ) {
|
||||||
|
son_prop.proposal_type = son_proposal_type::son_deregister_proposal;
|
||||||
|
son_prop.proposal_id = prop_id;
|
||||||
|
son_prop.son_id = v.son_id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void_result proposal_create_evaluator::do_evaluate(const proposal_create_operation& o)
|
void_result proposal_create_evaluator::do_evaluate(const proposal_create_operation& o)
|
||||||
{ try {
|
{ try {
|
||||||
const database& d = db();
|
const database& d = db();
|
||||||
|
|
@ -232,6 +242,12 @@ object_id_type proposal_create_evaluator::do_apply(const proposal_create_operati
|
||||||
std::inserter(proposal.required_active_approvals, proposal.required_active_approvals.begin()));
|
std::inserter(proposal.required_active_approvals, proposal.required_active_approvals.begin()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
son_hardfork_visitor son_vtor(d, proposal.id);
|
||||||
|
for(auto& op: o.proposed_ops)
|
||||||
|
{
|
||||||
|
op.op.visit(son_vtor);
|
||||||
|
}
|
||||||
|
|
||||||
return proposal.id;
|
return proposal.id;
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/son_object.hpp>
|
#include <graphene/chain/son_object.hpp>
|
||||||
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
|
|
||||||
|
|
@ -63,7 +64,11 @@ object_id_type update_son_evaluator::do_apply(const son_update_operation& op)
|
||||||
void_result delete_son_evaluator::do_evaluate(const son_delete_operation& op)
|
void_result delete_son_evaluator::do_evaluate(const son_delete_operation& op)
|
||||||
{ try {
|
{ try {
|
||||||
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON_HARDFORK"); // can be removed after HF date pass
|
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON_HARDFORK"); // can be removed after HF date pass
|
||||||
FC_ASSERT(db().get(op.son_id).son_account == op.owner_account);
|
// Get the current block witness signatory
|
||||||
|
witness_id_type wit_id = db().get_scheduled_witness(1);
|
||||||
|
const witness_object& current_witness = wit_id(db());
|
||||||
|
// Either owner can remove or witness
|
||||||
|
FC_ASSERT(db().get(op.son_id).son_account == op.owner_account || (db().is_son_dereg_valid(op.son_id) && op.payer == current_witness.witness_account));
|
||||||
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
|
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
|
||||||
FC_ASSERT( idx.find(op.son_id) != idx.end() );
|
FC_ASSERT( idx.find(op.son_id) != idx.end() );
|
||||||
return void_result();
|
return void_result();
|
||||||
|
|
|
||||||
|
|
@ -1918,6 +1918,7 @@ public:
|
||||||
son_delete_operation son_delete_op;
|
son_delete_operation son_delete_op;
|
||||||
son_delete_op.son_id = son.id;
|
son_delete_op.son_id = son.id;
|
||||||
son_delete_op.owner_account = son.son_account;
|
son_delete_op.owner_account = son.son_account;
|
||||||
|
son_delete_op.payer = son.son_account;
|
||||||
|
|
||||||
signed_transaction tx;
|
signed_transaction tx;
|
||||||
tx.operations.push_back( son_delete_op );
|
tx.operations.push_back( son_delete_op );
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/son_object.hpp>
|
#include <graphene/chain/son_object.hpp>
|
||||||
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
|
#include <graphene/chain/son_proposal_object.hpp>
|
||||||
#include <graphene/chain/son_evaluator.hpp>
|
#include <graphene/chain/son_evaluator.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
|
|
||||||
|
|
@ -142,6 +144,7 @@ try {
|
||||||
son_delete_operation op;
|
son_delete_operation op;
|
||||||
op.owner_account = alice_id;
|
op.owner_account = alice_id;
|
||||||
op.son_id = son_id_type(0);
|
op.son_id = son_id_type(0);
|
||||||
|
op.payer = alice_id;
|
||||||
|
|
||||||
trx.operations.push_back(op);
|
trx.operations.push_back(op);
|
||||||
sign(trx, alice_private_key);
|
sign(trx, alice_private_key);
|
||||||
|
|
@ -205,6 +208,7 @@ try {
|
||||||
son_delete_operation op;
|
son_delete_operation op;
|
||||||
op.owner_account = bob_id;
|
op.owner_account = bob_id;
|
||||||
op.son_id = son_id_type(0);
|
op.son_id = son_id_type(0);
|
||||||
|
op.payer = bob_id;
|
||||||
|
|
||||||
trx.operations.push_back(op);
|
trx.operations.push_back(op);
|
||||||
sign(trx, bob_private_key);
|
sign(trx, bob_private_key);
|
||||||
|
|
@ -442,4 +446,210 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
|
||||||
BOOST_CHECK( dpo.witness_budget.value == 0);
|
BOOST_CHECK( dpo.witness_budget.value == 0);
|
||||||
}FC_LOG_AND_RETHROW()
|
}FC_LOG_AND_RETHROW()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( son_witness_proposal_test )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const dynamic_global_property_object& dpo = db.get_dynamic_global_properties();
|
||||||
|
generate_blocks(HARDFORK_SON_TIME);
|
||||||
|
generate_block();
|
||||||
|
generate_block();
|
||||||
|
set_expiration(db, trx);
|
||||||
|
|
||||||
|
ACTORS((alice)(bob));
|
||||||
|
|
||||||
|
upgrade_to_lifetime_member(alice);
|
||||||
|
upgrade_to_lifetime_member(bob);
|
||||||
|
|
||||||
|
transfer( committee_account, alice_id, asset( 1000*GRAPHENE_BLOCKCHAIN_PRECISION ) );
|
||||||
|
transfer( committee_account, bob_id, asset( 1000*GRAPHENE_BLOCKCHAIN_PRECISION ) );
|
||||||
|
|
||||||
|
set_expiration(db, trx);
|
||||||
|
generate_block();
|
||||||
|
// Now create SONs
|
||||||
|
std::string test_url1 = "https://create_son_test1";
|
||||||
|
std::string test_url2 = "https://create_son_test2";
|
||||||
|
|
||||||
|
// create deposit vesting
|
||||||
|
vesting_balance_id_type deposit1;
|
||||||
|
{
|
||||||
|
vesting_balance_create_operation op;
|
||||||
|
op.creator = alice_id;
|
||||||
|
op.owner = alice_id;
|
||||||
|
op.amount = asset(50*GRAPHENE_BLOCKCHAIN_PRECISION);
|
||||||
|
op.balance_type = vesting_balance_type::son;
|
||||||
|
op.policy = dormant_vesting_policy_initializer {};
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
set_expiration(db, trx);
|
||||||
|
processed_transaction ptx = PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
deposit1 = ptx.operation_results[0].get<object_id_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create payment vesting
|
||||||
|
vesting_balance_id_type payment1;
|
||||||
|
{
|
||||||
|
vesting_balance_create_operation op;
|
||||||
|
op.creator = alice_id;
|
||||||
|
op.owner = alice_id;
|
||||||
|
op.amount = asset(1*GRAPHENE_BLOCKCHAIN_PRECISION);
|
||||||
|
op.balance_type = vesting_balance_type::normal;
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
set_expiration(db, trx);
|
||||||
|
processed_transaction ptx = PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
payment1 = ptx.operation_results[0].get<object_id_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create deposit vesting
|
||||||
|
vesting_balance_id_type deposit2;
|
||||||
|
{
|
||||||
|
vesting_balance_create_operation op;
|
||||||
|
op.creator = bob_id;
|
||||||
|
op.owner = bob_id;
|
||||||
|
op.amount = asset(50*GRAPHENE_BLOCKCHAIN_PRECISION);
|
||||||
|
op.balance_type = vesting_balance_type::son;
|
||||||
|
op.policy = dormant_vesting_policy_initializer {};
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
set_expiration(db, trx);
|
||||||
|
processed_transaction ptx = PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
deposit2 = ptx.operation_results[0].get<object_id_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create payment vesting
|
||||||
|
vesting_balance_id_type payment2;
|
||||||
|
{
|
||||||
|
vesting_balance_create_operation op;
|
||||||
|
op.creator = bob_id;
|
||||||
|
op.owner = bob_id;
|
||||||
|
op.amount = asset(1*GRAPHENE_BLOCKCHAIN_PRECISION);
|
||||||
|
op.balance_type = vesting_balance_type::normal;
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
set_expiration(db, trx);
|
||||||
|
processed_transaction ptx = PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
payment2 = ptx.operation_results[0].get<object_id_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// alice becomes son
|
||||||
|
{
|
||||||
|
son_create_operation op;
|
||||||
|
op.owner_account = alice_id;
|
||||||
|
op.url = test_url1;
|
||||||
|
op.deposit = deposit1;
|
||||||
|
op.pay_vb = payment1;
|
||||||
|
op.fee = asset(0);
|
||||||
|
op.signing_key = alice_public_key;
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
sign(trx, alice_private_key);
|
||||||
|
PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// bob becomes son
|
||||||
|
{
|
||||||
|
son_create_operation op;
|
||||||
|
op.owner_account = bob_id;
|
||||||
|
op.url = test_url2;
|
||||||
|
op.deposit = deposit2;
|
||||||
|
op.pay_vb = payment2;
|
||||||
|
op.fee = asset(0);
|
||||||
|
op.signing_key = bob_public_key;
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
||||||
|
sign(trx, bob_private_key);
|
||||||
|
PUSH_TX(db, trx, ~0);
|
||||||
|
trx.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_block();
|
||||||
|
// Check if SONs are created properly
|
||||||
|
const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
|
||||||
|
BOOST_REQUIRE( idx.size() == 2 );
|
||||||
|
// Alice's SON
|
||||||
|
auto obj1 = idx.find( alice_id );
|
||||||
|
BOOST_REQUIRE( obj1 != idx.end() );
|
||||||
|
BOOST_CHECK( obj1->url == test_url1 );
|
||||||
|
BOOST_CHECK( obj1->signing_key == alice_public_key );
|
||||||
|
BOOST_CHECK( obj1->deposit.instance == deposit1.instance.value );
|
||||||
|
BOOST_CHECK( obj1->pay_vb.instance == payment1.instance.value );
|
||||||
|
// Bob's SON
|
||||||
|
auto obj2 = idx.find( bob_id );
|
||||||
|
BOOST_REQUIRE( obj2 != idx.end() );
|
||||||
|
BOOST_CHECK( obj2->url == test_url2 );
|
||||||
|
BOOST_CHECK( obj2->signing_key == bob_public_key );
|
||||||
|
BOOST_CHECK( obj2->deposit.instance == deposit2.instance.value );
|
||||||
|
BOOST_CHECK( obj2->pay_vb.instance == payment2.instance.value );
|
||||||
|
// Get the statistics object for the SONs
|
||||||
|
const auto& sidx = db.get_index_type<son_stats_index>().indices().get<by_id>();
|
||||||
|
BOOST_REQUIRE( sidx.size() == 2 );
|
||||||
|
auto son_stats_obj1 = sidx.find( obj1->statistics );
|
||||||
|
auto son_stats_obj2 = sidx.find( obj2->statistics );
|
||||||
|
BOOST_REQUIRE( son_stats_obj1 != sidx.end() );
|
||||||
|
BOOST_REQUIRE( son_stats_obj2 != sidx.end() );
|
||||||
|
|
||||||
|
|
||||||
|
// Modify SON's status to in_maintenance
|
||||||
|
db.modify( *obj1, [&]( son_object& _s)
|
||||||
|
{
|
||||||
|
_s.status = son_status::in_maintenance;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Modify the Alice's SON down timestamp to now-12 hours
|
||||||
|
db.modify( *son_stats_obj1, [&]( son_statistics_object& _s)
|
||||||
|
{
|
||||||
|
_s.last_down_timestamp = fc::time_point_sec(db.head_block_time() - fc::hours(12));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Modify SON's status to in_maintenance
|
||||||
|
db.modify( *obj2, [&]( son_object& _s)
|
||||||
|
{
|
||||||
|
_s.status = son_status::in_maintenance;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Modify the Bob's SON down timestamp to now-12 hours
|
||||||
|
db.modify( *son_stats_obj2, [&]( son_statistics_object& _s)
|
||||||
|
{
|
||||||
|
_s.last_down_timestamp = fc::time_point_sec(db.head_block_time() - fc::hours(12));
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto& son_proposal_idx = db.get_index_type<son_proposal_index>().indices().get<by_id>();
|
||||||
|
const auto& proposal_idx = db.get_index_type<proposal_index>().indices().get<by_id>();
|
||||||
|
|
||||||
|
BOOST_CHECK( son_proposal_idx.size() == 0 && proposal_idx.size() == 0 );
|
||||||
|
|
||||||
|
generate_block();
|
||||||
|
witness_id_type proposal_initiator = dpo.current_witness;
|
||||||
|
|
||||||
|
BOOST_CHECK( son_proposal_idx.size() == 2 && proposal_idx.size() == 2 );
|
||||||
|
|
||||||
|
for(size_t i = 0 ; i < 3 * db.get_global_properties().active_witnesses.size() ; i++ )
|
||||||
|
{
|
||||||
|
generate_block();
|
||||||
|
if( dpo.current_witness != proposal_initiator)
|
||||||
|
{
|
||||||
|
BOOST_CHECK( son_proposal_idx.size() == 2 && proposal_idx.size() == 2 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOST_CHECK( son_proposal_idx.size() == 0 && proposal_idx.size() == 0 );
|
||||||
|
BOOST_REQUIRE( idx.size() == 0 );
|
||||||
|
generate_block();
|
||||||
|
} FC_LOG_AND_RETHROW()
|
||||||
|
|
||||||
} BOOST_AUTO_TEST_SUITE_END()
|
} BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue