From a4b3fae15cb8afb97b5e1182e00599474eae52ab Mon Sep 17 00:00:00 2001 From: satyakoneru Date: Tue, 22 Oct 2019 15:42:07 +0000 Subject: [PATCH] SON126 - Approval by witness, removal of son_proposal_object, commenting --- libraries/chain/db_block.cpp | 9 +++++ libraries/chain/db_getter.cpp | 39 +++++++++++++++++++ .../chain/include/graphene/chain/database.hpp | 2 + .../graphene/chain/son_proposal_object.hpp | 8 ++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 8ee2e023..dafdc3ff 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -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 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 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 ) ); } } diff --git a/libraries/chain/db_getter.cpp b/libraries/chain/db_getter.cpp index 8e4130d0..232a73ff 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -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().indices().get< by_id >(); + const auto& proposal_idx = get_index_type().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::value) ) + { + const auto& son_proposal_idx = get_index_type().indices().get(); + 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) ) } + } } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index b5a46022..a368ce7a 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -283,6 +283,8 @@ namespace graphene { namespace chain { std::set get_sons_to_be_deregistered(); fc::optional 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; diff --git a/libraries/chain/include/graphene/chain/son_proposal_object.hpp b/libraries/chain/include/graphene/chain/son_proposal_object.hpp index 344ed2e3..a8eb5384 100644 --- a/libraries/chain/include/graphene/chain/son_proposal_object.hpp +++ b/libraries/chain/include/graphene/chain/son_proposal_object.hpp @@ -24,12 +24,12 @@ class son_proposal_object : public abstract_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; @@ -38,4 +38,4 @@ using son_proposal_index = generic_index