Mirror SON owner account weights from son-account.active.account_auths to active SONs
This commit is contained in:
parent
aeb201b667
commit
dc9476b2d3
10 changed files with 81 additions and 44 deletions
|
|
@ -616,10 +616,12 @@ void database::update_active_sons()
|
|||
// Compare current and to-be lists of active sons
|
||||
auto cur_active_sons = gpo.active_sons;
|
||||
vector<son_info> new_active_sons;
|
||||
const auto &acc = get(gpo.parameters.son_account());
|
||||
assert(acc != acc_idx.end());
|
||||
for( const son_object& son : sons ) {
|
||||
son_info swi;
|
||||
swi.son_id = son.id;
|
||||
swi.total_votes = son.total_votes;
|
||||
swi.weight = acc.active.account_auths.at(son.son_account);
|
||||
swi.signing_key = son.signing_key;
|
||||
swi.sidechain_public_keys = son.sidechain_public_keys;
|
||||
new_active_sons.push_back(swi);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
namespace graphene { namespace chain {
|
||||
|
||||
enum class sidechain_type {
|
||||
unknown,
|
||||
bitcoin,
|
||||
ethereum,
|
||||
eos,
|
||||
|
|
@ -20,6 +21,7 @@ using sidechain_type = graphene::chain::sidechain_type;
|
|||
} }
|
||||
|
||||
FC_REFLECT_ENUM(graphene::chain::sidechain_type,
|
||||
(unknown)
|
||||
(bitcoin)
|
||||
(ethereum)
|
||||
(eos)
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ namespace graphene { namespace chain {
|
|||
*/
|
||||
struct son_info {
|
||||
son_id_type son_id;
|
||||
uint64_t total_votes = 0;
|
||||
weight_type weight = 0;
|
||||
public_key_type signing_key;
|
||||
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
|
||||
|
||||
bool operator==(const son_info& rhs) {
|
||||
bool son_sets_equal =
|
||||
(son_id == rhs.son_id) &&
|
||||
(total_votes == rhs.total_votes) &&
|
||||
(weight == rhs.weight) &&
|
||||
(signing_key == rhs.signing_key) &&
|
||||
(sidechain_public_keys.size() == rhs.sidechain_public_keys.size());
|
||||
|
||||
|
|
@ -33,4 +33,7 @@ namespace graphene { namespace chain {
|
|||
} }
|
||||
|
||||
FC_REFLECT( graphene::chain::son_info,
|
||||
(son_id)(total_votes)(signing_key)(sidechain_public_keys) )
|
||||
(son_id)
|
||||
(weight)
|
||||
(signing_key)
|
||||
(sidechain_public_keys) )
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = son_wallet_deposit_object_type;
|
||||
|
||||
time_point_sec timestamp;
|
||||
sidechain_type sidechain;
|
||||
sidechain_type sidechain = sidechain_type::unknown;
|
||||
std::string sidechain_uid;
|
||||
std::string sidechain_transaction_id;
|
||||
std::string sidechain_from;
|
||||
|
|
@ -29,34 +29,29 @@ namespace graphene { namespace chain {
|
|||
chain::account_id_type peerplays_to;
|
||||
chain::asset peerplays_asset;
|
||||
|
||||
std::set<son_id_type> expected_reports;
|
||||
std::map<son_id_type, weight_type> expected_reports;
|
||||
std::set<son_id_type> received_reports;
|
||||
|
||||
bool processed;
|
||||
bool confirmed = false;
|
||||
|
||||
bool processed = false;
|
||||
};
|
||||
|
||||
struct by_sidechain;
|
||||
struct by_sidechain_uid;
|
||||
struct by_processed;
|
||||
struct by_sidechain_and_processed;
|
||||
struct by_sidechain_and_confirmed_and_processed;
|
||||
using son_wallet_deposit_multi_index_type = multi_index_container<
|
||||
son_wallet_deposit_object,
|
||||
indexed_by<
|
||||
ordered_unique< tag<by_id>,
|
||||
member<object, object_id_type, &object::id>
|
||||
>,
|
||||
ordered_non_unique< tag<by_sidechain>,
|
||||
member<son_wallet_deposit_object, sidechain_type, &son_wallet_deposit_object::sidechain>
|
||||
>,
|
||||
ordered_unique< tag<by_sidechain_uid>,
|
||||
member<son_wallet_deposit_object, std::string, &son_wallet_deposit_object::sidechain_uid>
|
||||
>,
|
||||
ordered_non_unique< tag<by_processed>,
|
||||
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::processed>
|
||||
>,
|
||||
ordered_non_unique< tag<by_sidechain_and_processed>,
|
||||
ordered_non_unique< tag<by_sidechain_and_confirmed_and_processed>,
|
||||
composite_key<son_wallet_deposit_object,
|
||||
member<son_wallet_deposit_object, sidechain_type, &son_wallet_deposit_object::sidechain>,
|
||||
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::confirmed>,
|
||||
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::processed>
|
||||
>
|
||||
>
|
||||
|
|
@ -70,4 +65,4 @@ FC_REFLECT_DERIVED( graphene::chain::son_wallet_deposit_object, (graphene::db::o
|
|||
(sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount)
|
||||
(peerplays_from) (peerplays_to) (peerplays_asset)
|
||||
(expected_reports) (received_reports)
|
||||
(processed) )
|
||||
(confirmed) (processed) )
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = son_wallet_withdraw_object_type;
|
||||
|
||||
time_point_sec timestamp;
|
||||
sidechain_type sidechain;
|
||||
sidechain_type sidechain = sidechain_type::unknown;
|
||||
std::string peerplays_uid;
|
||||
std::string peerplays_transaction_id;
|
||||
chain::account_id_type peerplays_from;
|
||||
|
|
@ -28,16 +28,16 @@ namespace graphene { namespace chain {
|
|||
std::string withdraw_currency;
|
||||
safe<int64_t> withdraw_amount;
|
||||
|
||||
std::set<son_id_type> expected_reports;
|
||||
std::map<son_id_type, weight_type> expected_reports;
|
||||
std::set<son_id_type> received_reports;
|
||||
|
||||
bool processed;
|
||||
bool confirmed = false;
|
||||
|
||||
bool processed = false;
|
||||
};
|
||||
|
||||
struct by_peerplays_uid;
|
||||
struct by_withdraw_sidechain;
|
||||
struct by_processed;
|
||||
struct by_withdraw_sidechain_and_processed;
|
||||
struct by_withdraw_sidechain_and_confirmed_and_processed;
|
||||
using son_wallet_withdraw_multi_index_type = multi_index_container<
|
||||
son_wallet_withdraw_object,
|
||||
indexed_by<
|
||||
|
|
@ -47,15 +47,10 @@ namespace graphene { namespace chain {
|
|||
ordered_unique< tag<by_peerplays_uid>,
|
||||
member<son_wallet_withdraw_object, std::string, &son_wallet_withdraw_object::peerplays_uid>
|
||||
>,
|
||||
ordered_non_unique< tag<by_withdraw_sidechain>,
|
||||
member<son_wallet_withdraw_object, sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>
|
||||
>,
|
||||
ordered_non_unique< tag<by_processed>,
|
||||
member<son_wallet_withdraw_object, bool, &son_wallet_withdraw_object::processed>
|
||||
>,
|
||||
ordered_non_unique< tag<by_withdraw_sidechain_and_processed>,
|
||||
ordered_non_unique< tag<by_withdraw_sidechain_and_confirmed_and_processed>,
|
||||
composite_key<son_wallet_withdraw_object,
|
||||
member<son_wallet_withdraw_object, sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>,
|
||||
member<son_wallet_withdraw_object, bool, &son_wallet_withdraw_object::confirmed>,
|
||||
member<son_wallet_withdraw_object, bool, &son_wallet_withdraw_object::processed>
|
||||
>
|
||||
>
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_de
|
|||
FC_ASSERT(expected, "Only active SON can create deposit");
|
||||
} else {
|
||||
bool expected = false;
|
||||
for (auto &son_id : swdo->expected_reports) {
|
||||
if (op.son_id == son_id) {
|
||||
for (auto &exp : swdo->expected_reports) {
|
||||
if (op.son_id == exp.first) {
|
||||
expected = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
|
|||
|
||||
auto &gpo = db().get_global_properties();
|
||||
for (auto &si : gpo.active_sons) {
|
||||
swdo.expected_reports.insert(si.son_id);
|
||||
swdo.expected_reports.insert(std::make_pair(si.son_id, si.weight));
|
||||
|
||||
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(si.son_id);
|
||||
db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) {
|
||||
|
|
@ -78,12 +78,32 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
|
|||
|
||||
swdo.received_reports.insert(op.son_id);
|
||||
|
||||
uint64_t total_weight = 0;
|
||||
for (const auto exp : swdo.expected_reports) {
|
||||
total_weight = total_weight + exp.second;
|
||||
}
|
||||
uint64_t current_weight = 0;
|
||||
for (const auto rec : swdo.received_reports) {
|
||||
current_weight = current_weight + swdo.expected_reports.find(rec)->second;
|
||||
}
|
||||
swdo.confirmed = (current_weight > (total_weight * 2 / 3));
|
||||
|
||||
swdo.processed = false;
|
||||
});
|
||||
return new_son_wallet_deposit_object.id;
|
||||
} else {
|
||||
db().modify(*itr, [&op](son_wallet_deposit_object &swdo) {
|
||||
swdo.received_reports.insert(op.son_id);
|
||||
|
||||
uint64_t total_weight = 0;
|
||||
for (const auto exp : swdo.expected_reports) {
|
||||
total_weight = total_weight + exp.second;
|
||||
}
|
||||
uint64_t current_weight = 0;
|
||||
for (const auto rec : swdo.received_reports) {
|
||||
current_weight = current_weight + swdo.expected_reports.find(rec)->second;
|
||||
}
|
||||
swdo.confirmed = (current_weight > (total_weight * 2 / 3));
|
||||
});
|
||||
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(op.son_id);
|
||||
db().modify(*stats_itr, [&op](son_statistics_object &sso) {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_w
|
|||
FC_ASSERT(expected, "Only active SON can create deposit");
|
||||
} else {
|
||||
bool expected = false;
|
||||
for (auto &son_id : swwo->expected_reports) {
|
||||
if (op.son_id == son_id) {
|
||||
for (auto &exp : swwo->expected_reports) {
|
||||
if (op.son_id == exp.first) {
|
||||
expected = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w
|
|||
|
||||
auto &gpo = db().get_global_properties();
|
||||
for (auto &si : gpo.active_sons) {
|
||||
swwo.expected_reports.insert(si.son_id);
|
||||
swwo.expected_reports.insert(std::make_pair(si.son_id, si.weight));
|
||||
|
||||
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(si.son_id);
|
||||
db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) {
|
||||
|
|
@ -78,12 +78,32 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w
|
|||
|
||||
swwo.received_reports.insert(op.son_id);
|
||||
|
||||
uint64_t total_weight = 0;
|
||||
for (const auto exp : swwo.expected_reports) {
|
||||
total_weight = total_weight + exp.second;
|
||||
}
|
||||
uint64_t current_weight = 0;
|
||||
for (const auto rec : swwo.received_reports) {
|
||||
current_weight = current_weight + swwo.expected_reports.find(rec)->second;
|
||||
}
|
||||
swwo.confirmed = (current_weight > (total_weight * 2 / 3));
|
||||
|
||||
swwo.processed = false;
|
||||
});
|
||||
return new_son_wallet_withdraw_object.id;
|
||||
} else {
|
||||
db().modify(*itr, [&op](son_wallet_withdraw_object &swwo) {
|
||||
swwo.received_reports.insert(op.son_id);
|
||||
|
||||
uint64_t total_weight = 0;
|
||||
for (const auto exp : swwo.expected_reports) {
|
||||
total_weight = total_weight + exp.second;
|
||||
}
|
||||
uint64_t current_weight = 0;
|
||||
for (const auto rec : swwo.received_reports) {
|
||||
current_weight = current_weight + swwo.expected_reports.find(rec)->second;
|
||||
}
|
||||
swwo.confirmed = (current_weight > (total_weight * 2 / 3));
|
||||
});
|
||||
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(op.son_id);
|
||||
db().modify(*stats_itr, [&op](son_statistics_object &sso) {
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
|||
config_ready_son = config_ready_son && !sons.empty();
|
||||
|
||||
#ifndef SUPPORT_MULTIPLE_SONS
|
||||
FC_ASSERT(sons.size() == 1, "Multiple SONs not supported");
|
||||
//FC_ASSERT(sons.size() == 1, "Multiple SONs not supported");
|
||||
#endif
|
||||
|
||||
if (options.count("peerplays-private-key")) {
|
||||
|
|
|
|||
|
|
@ -143,8 +143,8 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
|||
}
|
||||
|
||||
void sidechain_net_handler::process_deposits() {
|
||||
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_and_processed>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false));
|
||||
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_and_confirmed_and_processed>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const son_wallet_deposit_object &swdo) {
|
||||
ilog("Deposit to process: ${swdo}", ("swdo", swdo));
|
||||
|
|
@ -188,8 +188,8 @@ void sidechain_net_handler::process_deposits() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler::process_withdrawals() {
|
||||
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_withdraw_sidechain_and_processed>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false));
|
||||
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_withdraw_sidechain_and_confirmed_and_processed>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const son_wallet_withdraw_object &swwo) {
|
||||
ilog("Withdraw to process: ${swwo}", ("swwo", swwo));
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
|
|||
{
|
||||
son_info si;
|
||||
si.son_id = son_id_type(0);
|
||||
si.total_votes = 1000;
|
||||
si.weight = 1000;
|
||||
si.signing_key = alice_public_key;
|
||||
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
|
||||
op.sons.push_back(si);
|
||||
|
|
@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
|
|||
{
|
||||
son_info si;
|
||||
si.son_id = son_id_type(1);
|
||||
si.total_votes = 1000;
|
||||
si.weight = 1000;
|
||||
si.signing_key = bob_public_key;
|
||||
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
|
||||
op.sons.push_back(si);
|
||||
|
|
|
|||
Loading…
Reference in a new issue