SON126 - Approval by witness, removal of son_proposal_object, commenting

This commit is contained in:
satyakoneru 2019-10-22 15:42:07 +00:00
parent 011d3a51a5
commit a4b3fae15c
4 changed files with 54 additions and 4 deletions

View file

@ -350,6 +350,7 @@ processed_transaction database::push_proposal(const proposal_object& proposal)
auto session = _undo_db.start_undo_session(true);
for( auto& op : proposal.proposed_transaction.operations )
eval_state.operation_results.emplace_back(apply_operation(eval_state, op));
remove_son_proposal(proposal);
remove(proposal);
session.merge();
} catch ( const fc::exception& e ) {
@ -428,17 +429,25 @@ signed_block database::_generate_block(
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 ) );
}
}

View file

@ -206,4 +206,43 @@ signed_transaction database::create_signed_transaction( const fc::ecc::private_k
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) ) }
} }

View file

@ -283,6 +283,8 @@ namespace graphene { namespace chain {
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 );
time_point_sec head_block_time()const;
uint32_t head_block_num()const;

View file

@ -24,12 +24,12 @@ class son_proposal_object : public abstract_object<son_proposal_object>
son_proposal_type proposal_type;
};
//struct by_proposal;
//struct by_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_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>;
@ -38,4 +38,4 @@ using son_proposal_index = generic_index<son_proposal_object, son_proposal_multi
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) )
FC_REFLECT_DERIVED( graphene::chain::son_proposal_object, (graphene::chain::object), (proposal_id)(son_id)(proposal_type) )