From 1e76a2313375254aae4c71c9363d4d264f7e9fee Mon Sep 17 00:00:00 2001 From: gladcow Date: Mon, 30 Mar 2020 00:19:45 +0300 Subject: [PATCH 1/5] [SON-311] Add try_create_son call without explicit deposit params (#324) Co-authored-by: gladcow --- .../wallet/include/graphene/wallet/wallet.hpp | 20 ++++++++++++ libraries/wallet/wallet.cpp | 31 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index ac7796e1..a32c66db 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1339,6 +1339,25 @@ class wallet_api flat_map sidechain_public_keys, bool broadcast = false); + /** Creates a SON object owned by the given account. + * + * Tries to create a SON object owned by the given account using + * existing vesting balances, fails if can't quess matching + * vesting balance objects. If several vesting balance objects matches + * this function uses the recent one. + * + * @param owner_account the name or id of the account which is creating the SON + * @param url a URL to include in the SON record in the blockchain. Clients may + * display this when showing a list of SONs. May be blank. + * @param sidechain_public_keys The new set of sidechain public keys. + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction registering a SON + */ + signed_transaction try_create_son(string owner_account, + string url, + flat_map sidechain_public_keys, + bool broadcast = false); + /** * Update a SON object owned by the given account. * @@ -2298,6 +2317,7 @@ FC_API( graphene::wallet::wallet_api, (list_witnesses) (list_committee_members) (create_son) + (try_create_son) (update_son) (delete_son) (list_sons) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 112afc1a..1a4d508a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -4727,6 +4727,37 @@ signed_transaction wallet_api::create_son(string owner_account, return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast); } +signed_transaction wallet_api::try_create_son(string owner_account, + string url, + flat_map sidechain_public_keys, + bool broadcast /* = false */) +{ + vesting_balance_id_type deposit_id; + bool deposit_found = false; + vesting_balance_id_type pay_vb_id; + bool pay_vb_found = false; + vector vbs = get_vesting_balances(owner_account); + for(const auto& vb: vbs) + { + if ((vb.balance_type == vesting_balance_type::son) && + (vb.get_asset_amount() >= my->get_global_properties().parameters.son_vesting_amount()) && + (vb.policy.which() == vesting_policy::tag::value)) + { + deposit_found = true; + deposit_id = vb.id; + } + if ((vb.balance_type == vesting_balance_type::normal) && + (vb.policy.which() == vesting_policy::tag::value)) + { + pay_vb_found = true; + pay_vb_id = vb.id; + } + } + if (!deposit_found || !pay_vb_found) + FC_THROW("Failed to find vesting balance objects"); + return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast); +} + signed_transaction wallet_api::update_son(string owner_account, string url, string block_signing_key, From dc5a8da13dcc2e8ab6dc3fb0b04b4b7f3f238197 Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Sun, 29 Mar 2020 23:23:57 +0200 Subject: [PATCH 2/5] Hotfix - Fix build error --- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 +- libraries/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a32c66db..df4bfc3c 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1355,7 +1355,7 @@ class wallet_api */ signed_transaction try_create_son(string owner_account, string url, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast = false); /** diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 1a4d508a..e6cd6291 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -4729,7 +4729,7 @@ signed_transaction wallet_api::create_son(string owner_account, signed_transaction wallet_api::try_create_son(string owner_account, string url, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast /* = false */) { vesting_balance_id_type deposit_id; From bccba7697e303a69a8761c9d2bacef7127ce28b8 Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Mon, 30 Mar 2020 16:59:10 +0200 Subject: [PATCH 3/5] Quickfix - change GPOS and SON hardfork times --- libraries/chain/hardfork.d/GPOS.hf | 5 +++-- libraries/chain/hardfork.d/SON.hf | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index 8e93f80f..991c35ac 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,4 +1,5 @@ -// GPOS HARDFORK Monday, 31 Dec 2019 00:00:00 GMT +// GPOS HARDFORK Monday, 31 Dec 2019 00:00:00 GMT - 1577750400 +// GPOS HARDFORK Monday, March 30, 2020 2:00:00 PM - 1585569600 #ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1577750400 )) +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1585569600 )) #endif diff --git a/libraries/chain/hardfork.d/SON.hf b/libraries/chain/hardfork.d/SON.hf index 5c4e1e76..b3947a75 100644 --- a/libraries/chain/hardfork.d/SON.hf +++ b/libraries/chain/hardfork.d/SON.hf @@ -1,6 +1,7 @@ // SON HARDFORK Wednesday, January 1, 2020 12:00:00 AM - 1577836800 +// SON HARDFORK Monday, March 30, 2020 3:00:00 PM - 1585573200 // SON HARDFORK Monday, September 21, 2020 1:43:11 PM - 1600695791 #ifndef HARDFORK_SON_TIME #include -#define HARDFORK_SON_TIME (fc::time_point_sec( 1577836800 )) +#define HARDFORK_SON_TIME (fc::time_point_sec( 1585573200 )) #endif From f3a0827d5d80f22268d50c0dad0a2430d74bb92b Mon Sep 17 00:00:00 2001 From: obucina <11353193+obucina@users.noreply.github.com> Date: Mon, 30 Mar 2020 22:48:39 +0200 Subject: [PATCH 4/5] [SON-332] Check gitlab building process for dirty build (#327) * Fix failing son test, fix data types and check condition * Very clean build on Gitlab --- .gitlab-ci.yml | 18 +++++++++++------- tests/cli/son.cpp | 10 +++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 530caf2f..f8ff07ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,16 +8,20 @@ stages: build: stage: build script: + - rm -rf .git/modules/* ./docs ./libraries/fc - git submodule sync - git submodule update --init --recursive - - cmake . + - rm -rf build + - mkdir build + - cd build + - cmake .. - make -j$(nproc) artifacts: untracked: true paths: - - libraries/ - - programs/ - - tests/ + - build/libraries/ + - build/programs/ + - build/tests/ tags: - builder @@ -26,9 +30,9 @@ test: dependencies: - build script: - - ./tests/betting_test --log_level=message - - ./tests/chain_test --log_level=message - - ./tests/cli_test --log_level=message + - ./build/tests/betting_test --log_level=message + - ./build/tests/chain_test --log_level=message + - ./build/tests/cli_test --log_level=message tags: - builder diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index f640a1d7..d8eabf7d 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -205,8 +205,8 @@ BOOST_AUTO_TEST_CASE( son_voting ) son_object son2_obj; signed_transaction vote_son1_tx; signed_transaction vote_son2_tx; - int son1_start_votes, son1_end_votes; - int son2_start_votes, son2_end_votes; + uint64_t son1_start_votes, son1_end_votes; + uint64_t son2_start_votes, son2_end_votes; son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_start_votes = son1_obj.total_votes; @@ -436,8 +436,8 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test ) son_object son1_obj; son_object son2_obj; - int son1_start_votes, son1_end_votes; - int son2_start_votes, son2_end_votes; + uint64_t son1_start_votes, son1_end_votes; + uint64_t son2_start_votes, son2_end_votes; // Get votes at start son1_obj = con.wallet_api_ptr->get_son("son1account"); @@ -488,7 +488,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test ) son2_obj = con.wallet_api_ptr->get_son("son2account"); // voice distribution changed, SON2 now has all voices son2_end_votes = son2_obj.total_votes; - BOOST_CHECK(son2_end_votes > son2_start_votes); + BOOST_CHECK((son2_end_votes > 0) && (son2_end_votes <= son2_start_votes)); // nathan spent funds for vb, it has different voting power son2_start_votes = son2_end_votes; // Try to reject incorrect SON From 210e72f843eb50c443371063c9db9a26eaa1e818 Mon Sep 17 00:00:00 2001 From: pbattu123 <43043205+pbattu123@users.noreply.github.com> Date: Mon, 30 Mar 2020 17:49:03 -0300 Subject: [PATCH 5/5] update son-account parameters (#328) --- libraries/chain/db_maint.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 9c146ea9..98f998eb 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -1844,7 +1844,10 @@ void perform_son_tasks(database& db) { const auto& son_account = db.create([&](account_object& a) { a.name = "son-account"; - a.statistics = db.create([&](account_statistics_object& s){s.owner = a.id;}).id; + a.statistics = db.create([&a](account_statistics_object& s){ + s.owner = a.id; + s.name = a.name; + }).id; a.owner.weight_threshold = 1; a.active.weight_threshold = 0; a.registrar = a.lifetime_referrer = a.referrer = a.id;