Merge branch 'feature/SON-98' into feature/SON-231

This commit is contained in:
Srdjan Obucina 2020-01-28 16:45:35 +01:00
commit 6055576aa4
6 changed files with 36 additions and 12 deletions

View file

@ -155,7 +155,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// SON wallets
optional<son_wallet_object> get_active_son_wallet();
optional<son_wallet_object> get_son_wallet_by_time_point(time_point_sec time_point);
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit);
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit);
// Sidechain addresses
vector<optional<sidechain_address_object>> get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const;

View file

@ -582,9 +582,14 @@ void database::update_active_sons()
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_info.son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
obj.owner.account_auths[son.son_account] += votes;
obj.owner.weight_threshold += votes;
obj.active.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes;
}
obj.owner.weight_threshold *= 2;
obj.owner.weight_threshold /= 3;
obj.owner.weight_threshold += 1;
obj.active.weight_threshold *= 2;
obj.active.weight_threshold /= 3;
obj.active.weight_threshold += 1;
@ -599,6 +604,10 @@ void database::update_active_sons()
modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj )
{
uint64_t total_votes = 0;
obj.owner.weight_threshold = 0;
obj.owner.account_auths.clear();
obj.active.weight_threshold = 0;
obj.active.account_auths.clear();
for( const auto& son_info : gpo.active_sons )
{
const son_object& son = get(son_info.son_id);
@ -612,9 +621,14 @@ void database::update_active_sons()
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_info.son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
obj.owner.account_auths[son.son_account] += votes;
obj.owner.weight_threshold += votes;
obj.active.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes;
}
obj.owner.weight_threshold *= 2;
obj.owner.weight_threshold /= 3;
obj.owner.weight_threshold += 1;
obj.active.weight_threshold *= 2;
obj.active.weight_threshold /= 3;
obj.active.weight_threshold += 1;

View file

@ -45,6 +45,6 @@ namespace graphene { namespace chain {
FC_REFLECT(graphene::chain::son_wallet_create_operation::fee_parameters_type, (fee) )
FC_REFLECT(graphene::chain::son_wallet_create_operation, (fee)(payer) )
FC_REFLECT(graphene::chain::son_wallet_update_operation::fee_parameters_type, (fee) )
FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer) )
FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer)(son_wallet_id)(sidechain)(address) )
FC_REFLECT(graphene::chain::son_wallet_close_operation::fee_parameters_type, (fee) )
FC_REFLECT(graphene::chain::son_wallet_close_operation, (fee)(payer) )
FC_REFLECT(graphene::chain::son_wallet_close_operation, (fee)(payer)(son_wallet_id) )

View file

@ -97,7 +97,7 @@ namespace graphene { namespace chain {
FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(in_maintenance)(deregistered) )
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb)(status)(sidechain_public_keys) )
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb)(statistics)(status)(sidechain_public_keys) )
FC_REFLECT_DERIVED( graphene::chain::son_statistics_object,
(graphene::db::object),

View file

@ -193,6 +193,7 @@ void peerplays_sidechain_plugin_impl::schedule_heartbeat_loop()
void peerplays_sidechain_plugin_impl::heartbeat_loop()
{
schedule_heartbeat_loop();
chain::database& d = plugin.database();
chain::son_id_type son_id = *(_sons.begin());
const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>();
@ -219,7 +220,8 @@ void peerplays_sidechain_plugin_impl::heartbeat_loop()
fc::future<bool> fut = fc::async( [&](){
try {
d.push_transaction(trx);
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
return true;
} catch(fc::exception e){
ilog("peerplays_sidechain_plugin_impl: sending heartbeat failed with exception ${e}",("e", e.what()));
@ -228,11 +230,10 @@ void peerplays_sidechain_plugin_impl::heartbeat_loop()
});
fut.wait(fc::seconds(10));
}
schedule_heartbeat_loop();
}
void peerplays_sidechain_plugin_impl::create_son_down_proposals() {
void peerplays_sidechain_plugin_impl::create_son_down_proposals()
{
auto create_son_down_proposal = [&](chain::son_id_type son_id, fc::time_point_sec last_active_ts) {
chain::database& d = plugin.database();
chain::son_id_type my_son_id = *(_sons.begin());
@ -256,18 +257,23 @@ void peerplays_sidechain_plugin_impl::create_son_down_proposals() {
chain::database& d = plugin.database();
const chain::global_property_object& gpo = d.get_global_properties();
const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>();
chain::son_id_type my_son_id = *(_sons.begin());
for(auto son_inf: gpo.active_sons) {
if(my_son_id == son_inf.son_id)
continue;
auto son_obj = idx.find( son_inf.son_id );
auto stats = son_obj->statistics(d);
fc::time_point_sec last_active_ts = stats.last_active_timestamp;
int64_t down_threshold = 2*180000000;
if((fc::time_point::now() - last_active_ts) > fc::microseconds(down_threshold)) {
if(son_obj->status == chain::son_status::active && (fc::time_point::now() - last_active_ts) > fc::microseconds(down_threshold)) {
ilog("peerplays_sidechain_plugin: sending son down proposal for ${t} from ${s}",("t",std::string(object_id_type(son_obj->id)))("s",std::string(object_id_type(my_son_id))));
chain::proposal_create_operation op = create_son_down_proposal(son_inf.son_id, last_active_ts);
chain::signed_transaction trx = d.create_signed_transaction(_private_keys.begin()->second, op);
fc::future<bool> fut = fc::async( [&](){
try {
d.push_transaction(trx);
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
return true;
} catch(fc::exception e){
ilog("peerplays_sidechain_plugin_impl: sending son down proposal failed with exception ${e}",("e", e.what()));
@ -308,8 +314,9 @@ void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
chain::database& d = plugin.database();
chain::son_id_type my_son_id = *(_sons.begin());
const chain::global_property_object& gpo = d.get_global_properties();
bool latest_block = ((fc::time_point::now() - b.timestamp) < fc::microseconds(gpo.parameters.block_interval * 1000000));
// Return if there are no active SONs
if(gpo.active_sons.size() <= 0) {
if(gpo.active_sons.size() <= 0 || !latest_block) {
return;
}
@ -349,6 +356,7 @@ void peerplays_sidechain_plugin_impl::on_objects_new(const vector<object_id_type
auto approve_proposal = [ & ]( const chain::proposal_id_type& id )
{
ilog("peerplays_sidechain_plugin: sending approval for ${t} from ${s}",("t",std::string(object_id_type(id)))("s",std::string(object_id_type(my_son_id))));
chain::proposal_update_operation puo;
puo.fee_paying_account = son_obj->son_account;
puo.proposal = id;
@ -357,7 +365,8 @@ void peerplays_sidechain_plugin_impl::on_objects_new(const vector<object_id_type
fc::future<bool> fut = fc::async( [&](){
try {
d.push_transaction(trx);
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
return true;
} catch(fc::exception e){
ilog("peerplays_sidechain_plugin_impl: sending approval failed with exception ${e}",("e", e.what()));

View file

@ -44,6 +44,7 @@
#include <graphene/chain/match_object.hpp>
#include <graphene/chain/game_object.hpp>
#include <graphene/chain/son_object.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <fc/smart_ref_impl.hpp>