From 8e0e20eb6fe59a4544b75b107ecb03e2409007ea Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Fri, 17 Mar 2023 11:33:33 +0300 Subject: [PATCH 01/21] #518 - update update_vote_time when voting for SON --- libraries/wallet/wallet.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index e1363b0b..f01e2605 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2773,12 +2773,21 @@ public: FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son)); FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive || sidechain == sidechain_type::ethereum, "Unexpected sidechain type"); + bool update_vote_time = false; if (approve) { FC_ASSERT(son_obj->get_sidechain_vote_id(sidechain).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", sidechain)("son", *son_obj)); + account_id_type stake_account = get_account_id(voting_account); + const auto gpos_info = _remote_db->get_gpos_info(stake_account); + const auto vesting_subperiod = _remote_db->get_global_properties().parameters.gpos_subperiod(); + const auto gpos_start_time = fc::time_point_sec(_remote_db->get_global_properties().parameters.gpos_period_start()); + const auto subperiod_start_time = gpos_start_time.sec_since_epoch() + (gpos_info.current_subperiod - 1) * vesting_subperiod; + auto insert_result = voting_account_object.options.votes.insert(*son_obj->get_sidechain_vote_id(sidechain)); - if (!insert_result.second) - FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain)); + if (!insert_result.second && (gpos_info.last_voted_time.sec_since_epoch() >= subperiod_start_time)) + FC_THROW("Account ${account} was already voting for son ${son} in the current GPOS sub-period", ("account", voting_account)("son", son)); + else + update_vote_time = true; //Allow user to vote in each sub-period(Update voting time, which is reference in calculating VF) } else { @@ -2787,9 +2796,11 @@ public: if (!votes_removed) FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain)); } + account_update_operation account_update_op; account_update_op.account = voting_account_object.id; account_update_op.new_options = voting_account_object.options; + account_update_op.extensions.value.update_last_voting_time = update_vote_time; signed_transaction tx; tx.operations.push_back( account_update_op ); -- 2.45.2 From b21f9c4282f8d000fac2270f3c8ef82b9cbe8edb Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 29 Mar 2023 09:38:54 +0000 Subject: [PATCH 02/21] Bug/524-eth-mainnet-tr --- .../plugins/peerplays_sidechain/ethereum/encoders.cpp | 5 +++-- .../sidechain_net_handler_ethereum.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/ethereum/encoders.cpp b/libraries/plugins/peerplays_sidechain/ethereum/encoders.cpp index 872a5720..19a373de 100644 --- a/libraries/plugins/peerplays_sidechain/ethereum/encoders.cpp +++ b/libraries/plugins/peerplays_sidechain/ethereum/encoders.cpp @@ -137,8 +137,9 @@ std::string rlp_encoder::encode_length(int len, int offset) { std::string rlp_encoder::hex2bytes(const std::string &s) { std::string dest; - dest.resize(s.size() / 2); - hex2bin(s.c_str(), &dest[0]); + const auto s_final = s.size() % 2 == 0 ? s : "0" + s; + dest.resize(s_final.size() / 2); + hex2bin(s_final.c_str(), &dest[0]); return dest; } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp index c4db3266..5ffe1332 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp @@ -684,13 +684,18 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid const ethereum::signature_encoder encoder{function_signature}; #ifdef SEND_RAW_TRANSACTION + const auto data = encoder.encode(transactions); + const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]"; + ethereum::raw_transaction raw_tr; raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key)); raw_tr.gas_price = rpc_client->get_gas_price(); - raw_tr.gas_limit = rpc_client->get_gas_limit(); + raw_tr.gas_limit = rpc_client->get_estimate_gas(params); + if (raw_tr.gas_limit.empty()) + raw_tr.gas_limit = rpc_client->get_gas_limit(); raw_tr.to = wallet_contract_address; raw_tr.value = ""; - raw_tr.data = encoder.encode(transactions); + raw_tr.data = data; raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id)); const auto sign_tr = raw_tr.sign(get_private_key(public_key)); @@ -804,7 +809,7 @@ optional sidechain_net_handler_ethereum::estimate_withdrawal_transaction_ } const auto &public_key = son->sidechain_public_keys.at(sidechain); - const auto data = ethereum::withdrawal_encoder::encode(public_key, boost::multiprecision::uint256_t{1} * boost::multiprecision::uint256_t{10000000000}, son_wallet_withdraw_id_type{0}.operator object_id_type().operator std::string()); + const auto data = ethereum::withdrawal_encoder::encode(public_key, boost::multiprecision::uint256_t{1} * boost::multiprecision::uint256_t{10000000000}, "0"); const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]"; const auto estimate_gas = ethereum::from_hex(rpc_client->get_estimate_gas(params)); -- 2.45.2 From 432876a677a52ce593b13837662718d5463c17fa Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Sun, 16 Apr 2023 23:49:51 +0200 Subject: [PATCH 03/21] Try different approach --- .gitlab-ci.yml | 29 ++++++++++++++++++++++++++++- Dockerfile | 5 ----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61afce6e..08b1025a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,8 +7,9 @@ include: stages: - build - - test - dockerize + - python-test + - test build-mainnet: stage: build @@ -119,3 +120,29 @@ dockerize-testnet: manual timeout: 3h + +test-e2e: + stage: python-test + variables: + IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA + before_script: + - docker info + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git + - cd peerplays-utils/peerplays-qa-environment + - git checkout origin/feature/python-e2e-tests-for-CI + - cd e2e-tests/ + - python3 -m venv venv + - source venv/bin/activate + - pip3 install -r requirements.txt + - python3 start.py --stop + - docker ps -a + - export COMPOSE_SERVICE_PEERPLAYS_BASE_IMAGE=$IMAGE + - python3 start.py --start all + - docker ps -a + - python3 start.py --stop + - deactivate + - docker ps -a + tags: + - python-tests diff --git a/Dockerfile b/Dockerfile index 7a229aa7..43db4a39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -190,8 +190,6 @@ ADD . peerplays RUN \ cd peerplays && \ git submodule update --init --recursive && \ - git symbolic-ref --short HEAD && \ - git log --oneline -n 5 && \ mkdir build && \ cd build && \ cmake -DCMAKE_BUILD_TYPE=Release .. @@ -217,6 +215,3 @@ RUN chown peerplays:root -R /home/peerplays/peerplays-network EXPOSE 8090 # Peerplays P2P: EXPOSE 9777 - -# Peerplays -CMD ["./witness_node", "-d", "./witness_node_data_dir"] -- 2.45.2 From a2ce65e1ef1ed1334e1eda21ce2a0f73b58353e5 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Mon, 17 Apr 2023 08:52:41 +0200 Subject: [PATCH 04/21] Add pull image --- .gitlab-ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08b1025a..08538c83 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -57,8 +57,6 @@ dockerize-mainnet: - docker rmi $IMAGE tags: - builder - when: - manual timeout: 3h @@ -136,12 +134,13 @@ test-e2e: - python3 -m venv venv - source venv/bin/activate - pip3 install -r requirements.txt - - python3 start.py --stop + - python3 main.py --stop - docker ps -a + - docker pull $IMAGE - export COMPOSE_SERVICE_PEERPLAYS_BASE_IMAGE=$IMAGE - - python3 start.py --start all + - python3 main.py --start all - docker ps -a - - python3 start.py --stop + - python3 main.py --stop - deactivate - docker ps -a tags: -- 2.45.2 From 0f375777c246717ec6a3f3e8824b887c99bc1af3 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Mon, 17 Apr 2023 22:37:26 +0200 Subject: [PATCH 05/21] Quick exec --- .gitlab-ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08538c83..75ab1930 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,9 +6,9 @@ include: - template: Secret-Detection.gitlab-ci.yml stages: + - python-test - build - dockerize - - python-test - test build-mainnet: @@ -122,10 +122,7 @@ dockerize-testnet: test-e2e: stage: python-test variables: - IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA - before_script: - - docker info - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + IMAGE: registry.gitlab.com/pbsa/peerplays/mainnet/feature-python-e2e-tests:943e02cdcd9fb8a90137851635b998cf1b4f622c script: - git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git - cd peerplays-utils/peerplays-qa-environment -- 2.45.2 From 1b61016693a037c52fd8842a59b5759b4c03278f Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Mon, 17 Apr 2023 22:45:05 +0200 Subject: [PATCH 06/21] docker login still needed --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 75ab1930..37be02a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,6 +123,9 @@ test-e2e: stage: python-test variables: IMAGE: registry.gitlab.com/pbsa/peerplays/mainnet/feature-python-e2e-tests:943e02cdcd9fb8a90137851635b998cf1b4f622c + before_script: + - docker info + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git - cd peerplays-utils/peerplays-qa-environment -- 2.45.2 From 6f792db52dc5f09ecbdc0697cd16822076cbe7fc Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 00:22:26 +0200 Subject: [PATCH 07/21] Passing locally --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 37be02a5..021e63e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -138,7 +138,8 @@ test-e2e: - docker ps -a - docker pull $IMAGE - export COMPOSE_SERVICE_PEERPLAYS_BASE_IMAGE=$IMAGE - - python3 main.py --start all + - python3 main.py --start btc hive eth + - python3 main.py --start pp - docker ps -a - python3 main.py --stop - deactivate -- 2.45.2 From d2374aeed92e0ed7c438860a78c266a71a622b75 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 08:13:20 +0200 Subject: [PATCH 08/21] Try via command line again --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 021e63e6..5a84bd7e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -139,7 +139,7 @@ test-e2e: - docker pull $IMAGE - export COMPOSE_SERVICE_PEERPLAYS_BASE_IMAGE=$IMAGE - python3 main.py --start btc hive eth - - python3 main.py --start pp + - docker-compose up peerplays01 peerplays02 peerplays03 peerplays04 peerplays05 peerplays06 peerplays07 peerplays08 peerplays09 peerplays10 peerplays11 peerplays12 peerplays13 peerplays14 peerplays15 peerplays16 - docker ps -a - python3 main.py --stop - deactivate -- 2.45.2 From 6fe15f27b076069614725ddab9b18c0d715b7f0a Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 08:44:27 +0200 Subject: [PATCH 09/21] Try with rename --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a84bd7e..565488f1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -137,7 +137,8 @@ test-e2e: - python3 main.py --stop - docker ps -a - docker pull $IMAGE - - export COMPOSE_SERVICE_PEERPLAYS_BASE_IMAGE=$IMAGE + - docker tag $IMAGE peerplays-base:latest + - docker image ls -a - python3 main.py --start btc hive eth - docker-compose up peerplays01 peerplays02 peerplays03 peerplays04 peerplays05 peerplays06 peerplays07 peerplays08 peerplays09 peerplays10 peerplays11 peerplays12 peerplays13 peerplays14 peerplays15 peerplays16 - docker ps -a -- 2.45.2 From 2a6c917e4c72b1ae0e83fdb2717d90d91483d6a4 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 11:14:20 +0200 Subject: [PATCH 10/21] Try through python --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 565488f1..47d2c6c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -139,8 +139,7 @@ test-e2e: - docker pull $IMAGE - docker tag $IMAGE peerplays-base:latest - docker image ls -a - - python3 main.py --start btc hive eth - - docker-compose up peerplays01 peerplays02 peerplays03 peerplays04 peerplays05 peerplays06 peerplays07 peerplays08 peerplays09 peerplays10 peerplays11 peerplays12 peerplays13 peerplays14 peerplays15 peerplays16 + - python3 main.py --start all - docker ps -a - python3 main.py --stop - deactivate -- 2.45.2 From fd492ca19695d45948bb1eff74107f5a904b5a71 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 12:53:12 +0200 Subject: [PATCH 11/21] Run tests in the end --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 47d2c6c0..25ff9b62 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -141,6 +141,7 @@ test-e2e: - docker image ls -a - python3 main.py --start all - docker ps -a + - python3 -m pytest test_btc_init_state.py test_hive_inital_state.py test_pp_inital_state.py - python3 main.py --stop - deactivate - docker ps -a -- 2.45.2 From 0175a7d0ecf4032c928535a9e93639a5676d2bf7 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 13:27:00 +0200 Subject: [PATCH 12/21] Try the full flow --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 25ff9b62..2c3dadaa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,9 +6,9 @@ include: - template: Secret-Detection.gitlab-ci.yml stages: - - python-test - build - dockerize + - python-test - test build-mainnet: @@ -122,7 +122,7 @@ dockerize-testnet: test-e2e: stage: python-test variables: - IMAGE: registry.gitlab.com/pbsa/peerplays/mainnet/feature-python-e2e-tests:943e02cdcd9fb8a90137851635b998cf1b4f622c + IMAGE: $CI_REGISTRY_IMAGE/testnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA before_script: - docker info - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY -- 2.45.2 From 25bbacaa88bc94c21482e1ec1dac88a84d925437 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Tue, 18 Apr 2023 16:17:48 +0200 Subject: [PATCH 13/21] Add docker prune before run --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2c3dadaa..6767b196 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,6 +49,7 @@ dockerize-mainnet: IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA before_script: - docker info + - docker builder prune -a -f - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build --no-cache -t $IMAGE . -- 2.45.2 From cfecfb457b6bb7791fcd170200cbd1f47f51d243 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Wed, 19 Apr 2023 00:23:54 +0200 Subject: [PATCH 14/21] Pull propper image --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6767b196..02e74c0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,7 +123,7 @@ dockerize-testnet: test-e2e: stage: python-test variables: - IMAGE: $CI_REGISTRY_IMAGE/testnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA + IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA before_script: - docker info - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY -- 2.45.2 From 3ee2439d5b8ee3d18bf50fd93edfdc0fe6b2cf46 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Thu, 20 Apr 2023 14:15:30 +0200 Subject: [PATCH 15/21] Revert changes on Dockerfile --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 43db4a39..7a229aa7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -190,6 +190,8 @@ ADD . peerplays RUN \ cd peerplays && \ git submodule update --init --recursive && \ + git symbolic-ref --short HEAD && \ + git log --oneline -n 5 && \ mkdir build && \ cd build && \ cmake -DCMAKE_BUILD_TYPE=Release .. @@ -215,3 +217,6 @@ RUN chown peerplays:root -R /home/peerplays/peerplays-network EXPOSE 8090 # Peerplays P2P: EXPOSE 9777 + +# Peerplays +CMD ["./witness_node", "-d", "./witness_node_data_dir"] -- 2.45.2 From 1f72b4fbd62f5947ddb21cc4bc378f159b817307 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Fri, 21 Apr 2023 00:35:02 +0200 Subject: [PATCH 16/21] Remove symbolic-ref call --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7a229aa7..8e2c76f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -190,7 +190,6 @@ ADD . peerplays RUN \ cd peerplays && \ git submodule update --init --recursive && \ - git symbolic-ref --short HEAD && \ git log --oneline -n 5 && \ mkdir build && \ cd build && \ -- 2.45.2 From dfd3dfae097866e9cec4911dd4b3891748ca69e6 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Fri, 21 Apr 2023 09:21:17 +0300 Subject: [PATCH 17/21] #530 - fix ETH deposit_address --- .../graphene/chain/sidechain_address_object.hpp | 11 ++++++++++- .../sidechain_net_handler_ethereum.cpp | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp index 73be44d5..b808a23c 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp @@ -36,6 +36,15 @@ namespace graphene { namespace chain { deposit_address(""), withdraw_public_key(""), withdraw_address("") {} + + inline string get_deposit_address() const { + if(sidechain_type::ethereum != sidechain) + return deposit_address; + + auto deposit_address_lower = deposit_address; + std::transform(deposit_address_lower.begin(), deposit_address_lower.end(), deposit_address_lower.begin(), ::tolower); + return deposit_address_lower; + } }; struct by_account; @@ -76,7 +85,7 @@ namespace graphene { namespace chain { ordered_non_unique< tag, composite_key, - member, + const_mem_fun, member > > diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp index 5ffe1332..fb21a87c 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp @@ -914,8 +914,9 @@ void sidechain_net_handler_ethereum::handle_event(const std::string &block_numbe const boost::property_tree::ptree tx = tx_child.second; tx_idx = tx_idx + 1; - const std::string from = tx.get("from"); const std::string to = tx.get("to"); + std::string from = tx.get("from"); + std::transform(from.begin(), from.end(), from.begin(), ::tolower); std::string cmp_to = to; std::transform(cmp_to.begin(), cmp_to.end(), cmp_to.begin(), ::toupper); -- 2.45.2 From 838a9820f1873aa30bff59d80ae924fe163a1a74 Mon Sep 17 00:00:00 2001 From: Milos Milosevic Date: Wed, 26 Apr 2023 13:22:19 +0200 Subject: [PATCH 18/21] Right order of the steps --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02e74c0c..0da838fb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,9 +7,9 @@ include: stages: - build + - test - dockerize - python-test - - test build-mainnet: stage: build -- 2.45.2 From 6cf31b107580aff207558e160154a536e7434c18 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Mon, 5 Jun 2023 12:21:45 +0300 Subject: [PATCH 19/21] Add develop branch to build target --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c443fe98..80c8fb23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ build-mainnet: - build/programs/ - build/tests/ rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" + - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" tags: - builder @@ -82,7 +82,7 @@ build-testnet: - build/programs/ - build/tests/ rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" + - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" when: manual tags: - builder -- 2.45.2 From fee7bc99faabf6779f9f2177d052b7318253500c Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Mon, 5 Jun 2023 09:24:04 +0000 Subject: [PATCH 20/21] Fix #549 testnet sync --- .gitlab-ci.yml | 4 ++-- libraries/chain/son_wallet_evaluator.cpp | 28 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c443fe98..80c8fb23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ build-mainnet: - build/programs/ - build/tests/ rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" + - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" tags: - builder @@ -82,7 +82,7 @@ build-testnet: - build/programs/ - build/tests/ rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" + - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" when: manual tags: - builder diff --git a/libraries/chain/son_wallet_evaluator.cpp b/libraries/chain/son_wallet_evaluator.cpp index 138f8e57..03e2edc1 100644 --- a/libraries/chain/son_wallet_evaluator.cpp +++ b/libraries/chain/son_wallet_evaluator.cpp @@ -97,10 +97,18 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); + const son_wallet_id_type son_wallet_id = [&]{ + if(db().head_block_time() >= HARDFORK_SON_FOR_ETHEREUM_TIME) + { + const auto ast = active_sidechain_types(db().head_block_time()); + const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size(); + return son_wallet_id_type{ id }; + } + + return op.son_wallet_id; + }(); + const auto& idx = db().get_index_type().indices().get(); - const auto ast = active_sidechain_types(db().head_block_time()); - const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size(); - const son_wallet_id_type son_wallet_id{ id }; FC_ASSERT( idx.find(son_wallet_id) != idx.end() ); //auto itr = idx.find(op.son_wallet_id); //FC_ASSERT( itr->addresses.find(op.sidechain) == itr->addresses.end() || @@ -110,10 +118,18 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op) { try { + const son_wallet_id_type son_wallet_id = [&]{ + if(db().head_block_time() >= HARDFORK_SON_FOR_ETHEREUM_TIME) + { + const auto ast = active_sidechain_types(db().head_block_time()); + const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size(); + return son_wallet_id_type{ id }; + } + + return op.son_wallet_id; + }(); + const auto& idx = db().get_index_type().indices().get(); - const auto ast = active_sidechain_types(db().head_block_time()); - const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size(); - const son_wallet_id_type son_wallet_id{ id }; auto itr = idx.find(son_wallet_id); if (itr != idx.end()) { -- 2.45.2 From 3a51723e513ca62c44b3cc7a73344856a8e2c194 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 8 Jun 2023 05:28:30 +0000 Subject: [PATCH 21/21] #550 - update schedule for sidechain type --- .gitlab-ci.yml | 6 +- libraries/chain/db_block.cpp | 18 +-- libraries/chain/db_witness_schedule.cpp | 140 ++++++++---------- .../chain/include/graphene/chain/database.hpp | 4 +- 4 files changed, 72 insertions(+), 96 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 80c8fb23..f300e82b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,8 +29,6 @@ build-mainnet: - build/libraries/ - build/programs/ - build/tests/ - rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" tags: - builder @@ -81,9 +79,7 @@ build-testnet: - build/libraries/ - build/programs/ - build/tests/ - rules: - - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "beatrice" || $CI_COMMIT_BRANCH == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "beatrice" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" - when: manual + when: manual tags: - builder diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index adabcffe..79b24464 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -739,13 +739,11 @@ void database::_apply_block( const signed_block& next_block ) if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) { update_witness_schedule(next_block); - bool need_to_update_son_schedule = false; - for(const auto& active_sons : global_props.active_sons){ - if(!active_sons.second.empty()) - need_to_update_son_schedule = true; - } - if(need_to_update_son_schedule) { - update_son_schedule(next_block); + + for(const auto& active_sons : global_props.active_sons) { + if(!active_sons.second.empty()) { + update_son_schedule(active_sons.first, next_block); + } } } @@ -783,15 +781,11 @@ void database::_apply_block( const signed_block& next_block ) if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) { update_witness_schedule(); - bool need_update_son_schedule = false; for(const auto& active_sidechain_type : active_sidechain_types(dynamic_global_props.time)) { if(global_props.active_sons.at(active_sidechain_type).size() > 0) { - need_update_son_schedule = true; + update_son_schedule(active_sidechain_type); } } - if(need_update_son_schedule) { - update_son_schedule(); - } } if( !_node_property_object.debug_updates.empty() ) diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 12d4a6dd..d4874b29 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -200,44 +200,41 @@ void database::update_witness_schedule() } } -void database::update_son_schedule() +void database::update_son_schedule(sidechain_type type) { const global_property_object& gpo = get_global_properties(); - for(const auto& active_sidechain_type : active_sidechain_types(head_block_time())) + const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(type))); + if( gpo.active_sons.at(type).size() != 0 && + head_block_num() % gpo.active_sons.at(type).size() == 0) { - const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(active_sidechain_type))); - if( gpo.active_sons.at(active_sidechain_type).size() != 0 && - head_block_num() % gpo.active_sons.at(active_sidechain_type).size() == 0) + modify( sidechain_sso, [&]( son_schedule_object& _sso ) { - modify( sidechain_sso, [&]( son_schedule_object& _sso ) + _sso.current_shuffled_sons.clear(); + _sso.current_shuffled_sons.reserve( gpo.active_sons.at(type).size() ); + + for ( const auto &w : gpo.active_sons.at(type) ) { + _sso.current_shuffled_sons.push_back(w.son_id); + } + + auto now_hi = uint64_t(head_block_time().sec_since_epoch()) << 32; + + for (uint32_t i = 0; i < _sso.current_shuffled_sons.size(); ++i) { - _sso.current_shuffled_sons.clear(); - _sso.current_shuffled_sons.reserve( gpo.active_sons.at(active_sidechain_type).size() ); + /// High performance random generator + /// http://xorshift.di.unimi.it/ + uint64_t k = now_hi + uint64_t(i) * 2685821657736338717ULL; + k ^= (k >> 12); + k ^= (k << 25); + k ^= (k >> 27); + k *= 2685821657736338717ULL; - for ( const auto &w : gpo.active_sons.at(active_sidechain_type) ) { - _sso.current_shuffled_sons.push_back(w.son_id); - } - - auto now_hi = uint64_t(head_block_time().sec_since_epoch()) << 32; - - for (uint32_t i = 0; i < _sso.current_shuffled_sons.size(); ++i) - { - /// High performance random generator - /// http://xorshift.di.unimi.it/ - uint64_t k = now_hi + uint64_t(i) * 2685821657736338717ULL; - k ^= (k >> 12); - k ^= (k << 25); - k ^= (k >> 27); - k *= 2685821657736338717ULL; - - uint32_t jmax = _sso.current_shuffled_sons.size() - i; - uint32_t j = i + k % jmax; - std::swap(_sso.current_shuffled_sons[i], - _sso.current_shuffled_sons[j]); - } - }); - } + uint32_t jmax = _sso.current_shuffled_sons.size() - i; + uint32_t j = i + k % jmax; + std::swap(_sso.current_shuffled_sons[i], + _sso.current_shuffled_sons[j]); + } + }); } } @@ -321,23 +318,15 @@ void database::update_witness_schedule(const signed_block& next_block) idump( ( double(total_time/1000000.0)/calls) ); } -void database::update_son_schedule(const signed_block& next_block) +void database::update_son_schedule(sidechain_type type, const signed_block& next_block) { auto start = fc::time_point::now(); #ifndef NDEBUG const son_schedule_object& sso = get(son_schedule_id_type()); #endif const global_property_object& gpo = get_global_properties(); - const flat_map schedule_needs_filled = [&gpo]() - { - flat_map schedule_needs_filled; - for(const auto& sidechain_active_sons : gpo.active_sons) - { - schedule_needs_filled[sidechain_active_sons.first] = sidechain_active_sons.second.size(); - } - return schedule_needs_filled; - }(); - uint32_t schedule_slot = get_slot_at_time(next_block.timestamp); + const uint32_t schedule_needs_filled = gpo.active_sons.at(type).size(); + const uint32_t schedule_slot = get_slot_at_time(next_block.timestamp); // We shouldn't be able to generate _pending_block with timestamp // in the past, and incoming blocks from the network with timestamp @@ -351,46 +340,43 @@ void database::update_son_schedule(const signed_block& next_block) assert( dpo.random.data_size() == witness_scheduler_rng::seed_length ); assert( witness_scheduler_rng::seed_length == sso.rng_seed.size() ); - for(const auto& active_sidechain_type : active_sidechain_types(head_block_time())) + const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(type))); + son_id_type first_son; + bool slot_is_near = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son ); + son_id_type son_id; + + modify(sidechain_sso, [&](son_schedule_object& _sso) { - const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(active_sidechain_type))); - son_id_type first_son; - bool slot_is_near = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son ); - son_id_type son_id; + _sso.slots_since_genesis += schedule_slot; + witness_scheduler_rng rng(_sso.rng_seed.data, _sso.slots_since_genesis); - modify(sidechain_sso, [&](son_schedule_object& _sso) - { - _sso.slots_since_genesis += schedule_slot; - witness_scheduler_rng rng(_sso.rng_seed.data, _sso.slots_since_genesis); + _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(type).size()) / 2, 1); - _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(active_sidechain_type).size()) / 2, 1); - - if( slot_is_near ) + if( slot_is_near ) + { + uint32_t drain = schedule_slot; + while( drain > 0 ) { - uint32_t drain = schedule_slot; - while( drain > 0 ) - { - if( _sso.scheduler.size() == 0 ) - break; - _sso.scheduler.consume_schedule(); - --drain; - } + if( _sso.scheduler.size() == 0 ) + break; + _sso.scheduler.consume_schedule(); + --drain; } - else - { - _sso.scheduler.reset_schedule( first_son ); - } - while( !_sso.scheduler.get_slot(schedule_needs_filled.at(active_sidechain_type), son_id) ) - { - if( _sso.scheduler.produce_schedule(rng) & emit_turn ) - memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); - } - _sso.last_scheduling_block = next_block.block_num(); - _sso.recent_slots_filled = ( - (_sso.recent_slots_filled << 1) - + 1) << (schedule_slot - 1); - }); - } + } + else + { + _sso.scheduler.reset_schedule( first_son ); + } + while( !_sso.scheduler.get_slot(schedule_needs_filled, son_id) ) + { + if( _sso.scheduler.produce_schedule(rng) & emit_turn ) + memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); + } + _sso.last_scheduling_block = next_block.block_num(); + _sso.recent_slots_filled = ( + (_sso.recent_slots_filled << 1) + + 1) << (schedule_slot - 1); + }); auto end = fc::time_point::now(); static uint64_t total_time = 0; diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index c8e1f214..48be59f0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -292,8 +292,8 @@ namespace graphene { namespace chain { vector get_near_witness_schedule()const; void update_witness_schedule(); void update_witness_schedule(const signed_block& next_block); - void update_son_schedule(); - void update_son_schedule(const signed_block& next_block); + void update_son_schedule(sidechain_type type); + void update_son_schedule(sidechain_type type, const signed_block& next_block); void check_lottery_end_by_participants( asset_id_type asset_id ); void check_ending_lotteries(); -- 2.45.2