From f3e9273b848e3653eae4c0ce840b2a057402b5e4 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 23 Aug 2023 18:28:57 +0300 Subject: [PATCH 01/17] Add mainnet ABIs publication --- .github/workflows/main.yml | 37 ++++++++++----------- .github/workflows/publish.yml | 62 ++++++++++++++++++++--------------- proxy/scripts/generateAbi.ts | 26 +++++++++++++++ 3 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 proxy/scripts/generateAbi.ts diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d1ed9c604..26df5a39b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,13 +10,18 @@ on: branches-ignore: - 'docs-v*' +env: + NODE_VERSION: 18 + PYTHON_VERSION: 3.8 + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: test-contracts: runs-on: ubuntu-latest - env: - working-directory: ./proxy + defaults: + run: + working-directory: proxy steps: - uses: actions/checkout@v2 @@ -43,47 +48,41 @@ jobs: - name: Install PYTHON uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Install NODE JS uses: actions/setup-node@v2 with: - node-version: 16 + node-version: ${{ env.NODE_VERSION }} - name: Install project - working-directory: ${{env.working-directory}} - run: | - yarn install + run: yarn install - name: Install slither - working-directory: ${{env.working-directory}} run: pip3 install -r scripts/requirements.txt - name: Lint solidity - working-directory: ${{env.working-directory}} run: yarn lint - name: Compile typescript - working-directory: ${{env.working-directory}} run: yarn tsc - name: Lint typescript - working-directory: ${{env.working-directory}} run: yarn eslint - name: Slither checks - working-directory: ${{env.working-directory}} run: yarn slither + - name: Test ABI generation + run: npx hardhat run scripts/generateAbi.ts + - name: Gas calculation test - working-directory: ${{env.working-directory}} run: npx hardhat test gas/calculateGas.ts - name: Test upgrade - run: bash ./proxy/scripts/test_upgrade.sh + run: bash scripts/test_upgrade.sh - name: Run tests - working-directory: ${{env.working-directory}} run: | npx hardhat coverage --solcoverjs .solcover.js bash <(curl -s https://codecov.io/bash) -f coverage/lcov.info -t $CODECOV_TOKEN || echo "Codecov did not collect coverage reports" @@ -120,12 +119,12 @@ jobs: - name: Install PYTHON uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ env. PYTHON_VERSION }} - name: Install NODE JS uses: actions/setup-node@v2 with: - node-version: 16 + node-version: ${{ env.NODE_VERSION }} - name: Install project run: | @@ -329,12 +328,12 @@ jobs: - name: Set up Node uses: actions/setup-node@v2 with: - node-version: '16' + node-version: ${{ env.NODE_VERSION }} - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Compile contracts working-directory: ./proxy diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 98159f5af..94c5e3c44 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,15 +12,21 @@ on: tags: - 'custom-release-*' +env: + NODE_VERSION: 18 + PYTHON_VERSION: 3.8 + jobs: build: runs-on: ubuntu-latest env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - PROXY_DIR: "proxy" + defaults: + run: + working-directory: proxy steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get yarn cache directory path id: yarn-cache-dir-path @@ -44,28 +50,28 @@ jobs: - name: Install NODE JS uses: actions/setup-node@v2 with: - node-version: '16' + node-version: ${{ env.NODE_VERSION }} - - name: Set up Python 3.8 + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Build and publish container run: | export BRANCH=${GITHUB_REF##*/} echo "Branch $BRANCH" - export VERSION=$(bash ./scripts/calculate_version.sh) + export VERSION=$(bash ../scripts/calculate_version.sh) echo "VERSION=$VERSION" >> $GITHUB_ENV echo "Version $VERSION" ( test $BRANCH = "stable" && export PRERELEASE=false ) || export PRERELEASE=true echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV echo ------------ download binaries - LIB_BLS_RELEASE_TAG=${{ secrets.LIB_BLS_RELEASE_TAG }} bash ./scripts/download_binaries.sh + LIB_BLS_RELEASE_TAG=${{ secrets.LIB_BLS_RELEASE_TAG }} bash ../scripts/download_binaries.sh export RELEASE=true echo "RELEASE=$RELEASE" >> $GITHUB_ENV echo ------------ docker image - bash ./scripts/build_image.sh ${{ secrets.DOCKER_USERNAME }} ${{ secrets.DOCKER_PASSWORD }} #|| echo "----> Looks like deploy failed" + bash ../scripts/build_image.sh ${{ secrets.DOCKER_USERNAME }} ${{ secrets.DOCKER_PASSWORD }} #|| echo "----> Looks like deploy failed" - name: Prepare for pip package building run: | @@ -73,35 +79,31 @@ jobs: python3 -m pip install --user --upgrade twine - name: Install project - working-directory: ${{env.PROXY_DIR}} - run: | - yarn install + run: yarn install - name: Generate Manifest - working-directory: ${{env.PROXY_DIR}} - run: | - npx hardhat run migrations/generateManifest.ts + run: npx hardhat run migrations/generateManifest.ts - name: Install python testing staff - working-directory: ${{env.PROXY_DIR}} run: pip3 install -r predeployed/test/requirements.txt - name: Build predeployed pip package - working-directory: ${{env.PROXY_DIR}} env: VERSION: ${{ env.VERSION }} - run: | - ./predeployed/scripts/build_package.sh + run: ./predeployed/scripts/build_package.sh - name: Publish predeployed pip package - working-directory: ${{env.PROXY_DIR}} env: PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} - run: | - ./predeployed/scripts/publish_package.sh + run: ./predeployed/scripts/publish_package.sh + + - name: Generate mainnet ABIs + env: + VERSION: ${{ env.VERSION }} + run: npx hardhat run scripts/generateAbi.ts - - name: Generate ABIs - working-directory: ${{env.PROXY_DIR}}/predeployed + - name: Generate predeployed ABIs + working-directory: proxy/predeployed env: VERSION: ${{ env.VERSION }} run: | @@ -129,7 +131,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ steps.create_release.outputs.id }} - assets_path: proxy/predeployed/dist/ + assets_path: predeployed/dist/ - name: Upload Release Assets id: upload-static-data @@ -138,7 +140,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ steps.create_release.outputs.id }} - assets_path: proxy/predeployed/data/ + assets_path: predeployed/data/ - name: Upload Release Assets id: upload-manifest-data @@ -147,4 +149,12 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ steps.create_release.outputs.id }} - assets_path: proxy/data/ima-schain-*-manifest.json + assets_path: data/ima-schain-*-manifest.json + + - name: Upload Release Assets + uses: dwenegar/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} + assets_path: data/*-abi.json diff --git a/proxy/scripts/generateAbi.ts b/proxy/scripts/generateAbi.ts new file mode 100644 index 000000000..ae8d5e4cc --- /dev/null +++ b/proxy/scripts/generateAbi.ts @@ -0,0 +1,26 @@ +import { promises as fs } from 'fs'; +import { contracts } from "../migrations/deployMainnet"; +import { ethers } from "hardhat"; +import { getAbi, getVersion } from '@skalenetwork/upgrade-tools'; + +async function main() { + const abi: {[name: string]: []} = {}; + for (const contractName of contracts) { + console.log(`Load ABI of ${contractName}`); + const factory = await ethers.getContractFactory(contractName); + abi[contractName] = getAbi(factory.interface); + } + const version = await getVersion(); + const filename = `data/mainnet-ima-${version}-abi.json`; + console.log(`Save to ${filename}`) + await fs.writeFile(filename, JSON.stringify(abi, null, 4)); +} + +if (require.main === module) { + main() + .then(() => process.exit(0)) + .catch(error => { + console.error(error); + process.exit(1); + }); +} From 90c84de2d27a5aff8cca3ce1fb457a4d07a9edd6 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 4 Sep 2023 17:52:58 +0300 Subject: [PATCH 02/17] Set version --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26df5a39b..b2d6cf39d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,6 +74,8 @@ jobs: run: yarn slither - name: Test ABI generation + env: + VERSION: "0.0.0" run: npx hardhat run scripts/generateAbi.ts - name: Gas calculation test From 397405f4a1ed011f7f0820a0495af69934e90bfb Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 4 Sep 2023 18:01:29 +0300 Subject: [PATCH 03/17] Set deposit boxes addresses to ContractManager during deployment --- proxy/migrations/deployMainnet.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proxy/migrations/deployMainnet.ts b/proxy/migrations/deployMainnet.ts index 668506f2c..db2fe6b45 100644 --- a/proxy/migrations/deployMainnet.ts +++ b/proxy/migrations/deployMainnet.ts @@ -219,6 +219,13 @@ async function main() { try { await contractManagerInst.setContractsAddress( "MessageProxyForMainnet", deployed.get( "MessageProxyForMainnet" )?.address); await contractManagerInst.setContractsAddress( "CommunityPool", deployed.get( "CommunityPool" )?.address); + for (const contractName of contractsToDeploy) { + const contractAddress = deployed.get(contractName); + if (contractAddress === undefined) { + throw new Error(`${contractName} was not found`); + } + await contractManagerInst.setContractsAddress( contractName, contractAddress); + } console.log( "Successfully registered MessageProxy in ContractManager" ); } catch ( error ) { console.log( "Registration of MessageProxy is failed on ContractManager. Please redo it by yourself!\nError:", error ); From f0323cb9b1ac1c3dfe418640ff3820f467af2378 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 4 Sep 2023 18:44:23 +0300 Subject: [PATCH 04/17] Set deposit boxes addresses to ContractManager during upgrade --- proxy/migrations/upgradeMainnet.ts | 68 +++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/proxy/migrations/upgradeMainnet.ts b/proxy/migrations/upgradeMainnet.ts index 30819c9b1..b08fccdaa 100644 --- a/proxy/migrations/upgradeMainnet.ts +++ b/proxy/migrations/upgradeMainnet.ts @@ -3,9 +3,11 @@ import { ethers } from "hardhat"; import { promises as fs } from "fs"; import { AutoSubmitter, Upgrader } from "@skalenetwork/upgrade-tools"; import { SkaleABIFile } from "@skalenetwork/upgrade-tools/dist/src/types/SkaleABIFile"; -import { contracts } from "./deployMainnet"; +import { contracts, contractsToDeploy, getContractKeyInAbiFile } from "./deployMainnet"; import { manifestSetup } from "./generateManifest"; import { MessageProxyForMainnet } from "../typechain"; +import { Interface } from "@ethersproject/abi"; + class ImaMainnetUpgrader extends Upgrader { @@ -45,7 +47,69 @@ class ImaMainnetUpgrader extends Upgrader { // deployNewContracts = () => { }; - // initialize = async () => { }; + initialize = async () => { + const contractManagerAddress = await (await this.getMessageProxyForMainnet()).contractManagerOfSkaleManager(); + const contractManagerInterface = new Interface([{ + "type": "function", + "name": "getContract", + "constant": true, + "stateMutability": "view", + "payable": false, + "inputs": [ + { + "type": "string", + "name": "name" + } + ], + "outputs": [ + { + "type": "address", + "name": "contractAddress" + } + ] + }, + { + "type": "function", + "name": "setContractsAddress", + "constant": false, + "payable": false, + "inputs": [ + { + "type": "string", + "name": "contractsName" + }, + { + "type": "address", + "name": "newContractsAddress" + } + ], + "outputs": [] + }]); + const contractManager = new ethers.Contract( + contractManagerAddress, + contractManagerInterface, + ethers.provider + ) + for (const contractName of contractsToDeploy) { + try { + const contractAddress = await contractManager.getContract(contractName); + console.log(`Address of ${contractName} is set to ${contractAddress}`); + } catch { + // getContract failed because the contract is not set + const contractAddress = this.abi[`${getContractKeyInAbiFile(contractName)}_address`] as string; + this.transactions.push( + { + to: contractManager.address, + data: contractManager.interface.encodeFunctionData( + "setContractsAddress", + [contractAddress] + ) + } + ) + console.log(`Set ${contractName} address to ${contractAddress}`); + } + } + }; _getContractKeyInAbiFile(contract: string) { if (contract === "MessageProxyForMainnet") { From ef120b7694ababd4b8b45b9bd240121e7b5820c0 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 4 Sep 2023 19:06:07 +0300 Subject: [PATCH 05/17] Update ganache arguments --- proxy/scripts/test_upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/scripts/test_upgrade.sh b/proxy/scripts/test_upgrade.sh index 3711481ce..7c81929e6 100755 --- a/proxy/scripts/test_upgrade.sh +++ b/proxy/scripts/test_upgrade.sh @@ -22,7 +22,7 @@ DEPLOYED_DIR=$GITHUB_WORKSPACE/deployed-IMA/ git clone --branch "$DEPLOYED_TAG" "https://github.com/$GITHUB_REPOSITORY.git" "$DEPLOYED_DIR" ACCOUNTS_FILENAME="$DEPLOYED_DIR/proxy/generatedAccounts.json" -npx ganache-cli --gasLimit 9000000 --quiet --allowUnlimitedContractSize --account_keys_path "$ACCOUNTS_FILENAME" & +npx ganache --miner.blockGasLimit 9000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.accountKeysPath "$ACCOUNTS_FILENAME" & cd "$DEPLOYED_DIR" yarn install From 0ce764b83ffae820301328a913fccf65b6d509fa Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 16:42:06 +0300 Subject: [PATCH 06/17] Upgrade ganache --- proxy/package.json | 2 +- proxy/scripts/test_upgrade.sh | 3 +- proxy/yarn.lock | 78 ++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/proxy/package.json b/proxy/package.json index 47856ccf3..cfbcfce23 100644 --- a/proxy/package.json +++ b/proxy/package.json @@ -58,7 +58,7 @@ "codecov": "^3.7.1", "eslint": "^8.46.0", "ethereum-waffle": "^4.0.10", - "ganache": "7.4.3", + "ganache": "7.9.1", "kill-port": "^1.6.1", "solhint": "3.3.6", "solidity-coverage": "^0.8.4", diff --git a/proxy/scripts/test_upgrade.sh b/proxy/scripts/test_upgrade.sh index 7c81929e6..90117d98c 100755 --- a/proxy/scripts/test_upgrade.sh +++ b/proxy/scripts/test_upgrade.sh @@ -24,9 +24,8 @@ git clone --branch "$DEPLOYED_TAG" "https://github.com/$GITHUB_REPOSITORY.git" " ACCOUNTS_FILENAME="$DEPLOYED_DIR/proxy/generatedAccounts.json" npx ganache --miner.blockGasLimit 9000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.accountKeysPath "$ACCOUNTS_FILENAME" & -cd "$DEPLOYED_DIR" +cd "$DEPLOYED_DIR/proxy" yarn install -cd proxy PRIVATE_KEY_FOR_ETHEREUM=$(cat "$ACCOUNTS_FILENAME" | jq -r '.private_keys | to_entries | .[8].value') PRIVATE_KEY_FOR_SCHAIN=$(cat "$ACCOUNTS_FILENAME" | jq -r '.private_keys | to_entries | .[9].value') CHAIN_NAME_SCHAIN="Test" VERSION="$DEPLOYED_VERSION" PRIVATE_KEY_FOR_ETHEREUM="$PRIVATE_KEY_FOR_ETHEREUM" PRIVATE_KEY_FOR_SCHAIN="$PRIVATE_KEY_FOR_SCHAIN" npx hardhat run migrations/deploySkaleManagerComponents.ts --network localhost diff --git a/proxy/yarn.lock b/proxy/yarn.lock index 3ec75951f..e9baa1126 100644 --- a/proxy/yarn.lock +++ b/proxy/yarn.lock @@ -1455,6 +1455,16 @@ dependencies: node-gyp-build "4.3.0" +"@trufflesuite/uws-js-unofficial@20.30.0-unofficial.0": + version "20.30.0-unofficial.0" + resolved "https://registry.yarnpkg.com/@trufflesuite/uws-js-unofficial/-/uws-js-unofficial-20.30.0-unofficial.0.tgz#2fbc2f8ef7e82fbeea6abaf7e8a9d42a02b479d3" + integrity sha512-r5X0aOQcuT6pLwTRLD+mPnAM/nlKtvIK4Z+My++A8tTOR0qTjNRx8UB8jzRj3D+p9PMAp5LnpCUUGmz7/TppwA== + dependencies: + ws "8.13.0" + optionalDependencies: + bufferutil "4.0.7" + utf-8-validate "6.0.3" + "@typechain/ethers-v5@^10.0.0": version "10.2.1" resolved "https://registry.yarnpkg.com/@typechain/ethers-v5/-/ethers-v5-10.2.1.tgz#50241e6957683281ecfa03fb5a6724d8a3ce2391" @@ -1774,7 +1784,7 @@ abortcontroller-polyfill@^1.7.3: resolved "https://registry.yarnpkg.com/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.5.tgz#6738495f4e901fbb57b6c0611d0c75f76c485bed" integrity sha512-JMJ5soJWP18htbbxJjG7bG6yuI6pRhgJ0scHHTfkUjf6wjP912xZWvM+A4sJK3gqd9E8fcPbDnOefbA9Th/FIQ== -abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3: +abstract-level@1.0.3, abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/abstract-level/-/abstract-level-1.0.3.tgz#78a67d3d84da55ee15201486ab44c09560070741" integrity sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA== @@ -1787,18 +1797,7 @@ abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3: module-error "^1.0.1" queue-microtask "^1.2.3" -abstract-leveldown@^6.2.1: - version "6.3.0" - resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.3.0.tgz#d25221d1e6612f820c35963ba4bd739928f6026a" - integrity sha512-TU5nlYgta8YrBMNpc9FwQzRbiXsj49gsALsXadbGHt9CROPzX5fB0rWDR5mtdpOOKa5XqRFpbj1QroPAoPzVjQ== - dependencies: - buffer "^5.5.0" - immediate "^3.2.3" - level-concat-iterator "~2.0.0" - level-supports "~1.0.0" - xtend "~4.0.0" - -abstract-leveldown@^7.2.0: +abstract-leveldown@7.2.0, abstract-leveldown@^7.2.0: version "7.2.0" resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-7.2.0.tgz#08d19d4e26fb5be426f7a57004851b39e1795a2e" integrity sha512-DnhQwcFEaYsvYDnACLZhMmCWd3rkOeEvglpa4q5i/5Jlm3UIsWaxVzuXvDLFCSCWRO3yy2/+V/G7FusFgejnfQ== @@ -1810,6 +1809,17 @@ abstract-leveldown@^7.2.0: level-supports "^2.0.1" queue-microtask "^1.2.3" +abstract-leveldown@^6.2.1: + version "6.3.0" + resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.3.0.tgz#d25221d1e6612f820c35963ba4bd739928f6026a" + integrity sha512-TU5nlYgta8YrBMNpc9FwQzRbiXsj49gsALsXadbGHt9CROPzX5fB0rWDR5mtdpOOKa5XqRFpbj1QroPAoPzVjQ== + dependencies: + buffer "^5.5.0" + immediate "^3.2.3" + level-concat-iterator "~2.0.0" + level-supports "~1.0.0" + xtend "~4.0.0" + abstract-leveldown@~6.2.1: version "6.2.3" resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz#036543d87e3710f2528e47040bc3261b77a9a8eb" @@ -2079,7 +2089,7 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== -async-eventemitter@^0.2.4: +async-eventemitter@0.2.4, async-eventemitter@^0.2.4: version "0.2.4" resolved "https://registry.yarnpkg.com/async-eventemitter/-/async-eventemitter-0.2.4.tgz#f5e7c8ca7d3e46aab9ec40a292baf686a0bafaca" integrity sha512-pd20BwL7Yt1zwDFy+8MX8F1+WCT8aQeKj0kQnTrH9WaeRETlRamVhD0JtRPmrV4GfOJ2F9CvdQkZeZhnh2TuHw== @@ -2347,6 +2357,13 @@ bufferutil@4.0.5: dependencies: node-gyp-build "^4.3.0" +bufferutil@4.0.7: + version "4.0.7" + resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.7.tgz#60c0d19ba2c992dd8273d3f73772ffc894c153ad" + integrity sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw== + dependencies: + node-gyp-build "^4.3.0" + bufferutil@^4.0.1: version "4.0.4" resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.4.tgz#ab81373d313a6ead0d734e98c448c722734ae7bb" @@ -3907,6 +3924,27 @@ ganache@7.4.3: bufferutil "4.0.5" utf-8-validate "5.0.7" +ganache@7.9.1: + version "7.9.1" + resolved "https://registry.yarnpkg.com/ganache/-/ganache-7.9.1.tgz#94f8518215c7989ff5fd542db80bd47d7c7da786" + integrity sha512-Tqhd4J3cpiLeYTD6ek/zlchSB107IVPMIm4ypyg+xz1sdkeALUnYYZnmY4Bdjqj3i6QwtlZPCu7U4qKy7HlWTA== + dependencies: + "@trufflesuite/bigint-buffer" "1.1.10" + "@trufflesuite/uws-js-unofficial" "20.30.0-unofficial.0" + "@types/bn.js" "^5.1.0" + "@types/lru-cache" "5.1.1" + "@types/seedrandom" "3.0.1" + abstract-level "1.0.3" + abstract-leveldown "7.2.0" + async-eventemitter "0.2.4" + emittery "0.10.0" + keccak "3.0.2" + leveldown "6.1.0" + secp256k1 "4.0.3" + optionalDependencies: + bufferutil "4.0.5" + utf-8-validate "5.0.7" + get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" @@ -6991,6 +7029,13 @@ utf-8-validate@5.0.7: dependencies: node-gyp-build "^4.3.0" +utf-8-validate@6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-6.0.3.tgz#7d8c936d854e86b24d1d655f138ee27d2636d777" + integrity sha512-uIuGf9TWQ/y+0Lp+KGZCMuJWc3N9BHA+l/UmHd/oUHwJJDeysyTRxNQVkbzsIWfGFbRe3OcgML/i0mvVRPOyDA== + dependencies: + node-gyp-build "^4.3.0" + utf-8-validate@^5.0.2: version "5.0.6" resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.6.tgz#e1b3e0a5cc8648a3b44c1799fbb170d1aaaffe80" @@ -7294,6 +7339,11 @@ ws@7.4.6: resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A== +ws@8.13.0: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== + ws@^7.4.6: version "7.5.5" resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.5.tgz#8b4bc4af518cfabd0473ae4f99144287b33eb881" From 6d514fba55db111a15655d2911a62fc8eb654200 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 18:18:13 +0300 Subject: [PATCH 07/17] Change host name --- test/tools/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tools/config.py b/test/tools/config.py index 763e2e795..168f7b8d3 100644 --- a/test/tools/config.py +++ b/test/tools/config.py @@ -29,9 +29,9 @@ class Config: network_for_mainnet = 'mainnet' network_for_schain = 'schain' mainnet_key='' - mainnet_rpc_url='http://localhost:8545' + mainnet_rpc_url='http://127.0.0.1:8545' schain_key = '' - schain_rpc_url = 'http://localhost:8545' + schain_rpc_url = 'http://127.0.0.1:8545' schain_name = 'd2' schain_name_2 = 'd3' abi_mainnet = 'data/proxyMainnet.json' From 93db0e9e479f7045eaa72c2eb81bb30fbb3e77bf Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 18:31:31 +0300 Subject: [PATCH 08/17] Run ganache in deamon mode --- .github/workflows/main.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2d6cf39d..834e75e32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -350,9 +350,11 @@ jobs: yarn install - name: Start background ganache + working-directory: proxy run: | - cd proxy - npx ganache --miner.blockGasLimit 12000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.defaultBalance 2000000 --wallet.accountKeysPath ../test/accounts.json & + INSTANCE=$(npx ganache --😈 --miner.blockGasLimit 12000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.defaultBalance 2000000 --wallet.accountKeysPath ../test/accounts.json) + echo "INSTANCE=$INSTANCE" >> "$GITHUB_ENV" + - name: Prepare test (PY part) working-directory: ${{env.working-directory}} @@ -374,3 +376,11 @@ jobs: working-directory: ${{env.working-directory}} run: | yarn test + + - name: Stop ganache + working-directory: proxy + env: + INSTANCE: ${{ env.INSTANCE }} + run: npx ganache instances stop $INSTANCE + + From 03d1a2b9bf05231de7bf48f1ec4f3c0cc6f8d476 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 18:48:44 +0300 Subject: [PATCH 09/17] Remove workaround --- proxy/migrations/deploySchain.ts | 36 +++----------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/proxy/migrations/deploySchain.ts b/proxy/migrations/deploySchain.ts index 0fd0a32fa..e0162a8c8 100644 --- a/proxy/migrations/deploySchain.ts +++ b/proxy/migrations/deploySchain.ts @@ -194,38 +194,8 @@ async function main() { deployed.set( "TokenManagerERC20", { address: tokenManagerERC20.address, interface: tokenManagerERC20.interface } ); console.log("Contract TokenManagerERC20 deployed to", tokenManagerERC20.address); - /* - In the moment of this code was written - ganache had a bug - that prevented proper execution - of estimateGas function - during deployment of smart contract - that exceed 24KB limit. - - In addition to this problem - upgrade-hardhat library - did not supported - manual gas limit configuration. - - TODO: in case of any one or both issues fixed - please remove this crazy workaround below - */ - if (network.config.gas === "auto") { - throw Error("Can't use auto because of problems with gas estimations"); - } - if (!process.env.PRIVATE_KEY_FOR_SCHAIN) { - throw Error("PRIVATE_KEY_FOR_SCHAIN is not set"); - } - const key = process.env.PRIVATE_KEY_FOR_SCHAIN; - const signerWithFixedGasEstimation = new ethers.Wallet(key, ethers.provider); - signerWithFixedGasEstimation.estimateGas = async() => { - return ethers.BigNumber.from(network.config.gas as number); - } - - // The end of TODO: - console.log("Deploy TokenManagerERC721"); - const tokenManagerERC721Factory = await ethers.getContractFactory("TokenManagerERC721", signerWithFixedGasEstimation); + const tokenManagerERC721Factory = await ethers.getContractFactory("TokenManagerERC721"); const tokenManagerERC721 = await upgrades.deployProxy(tokenManagerERC721Factory, [ schainName, messageProxy.address, @@ -238,7 +208,7 @@ async function main() { console.log("Contract TokenManagerERC721 deployed to", tokenManagerERC721.address); console.log("Deploy TokenManagerERC1155"); - const tokenManagerERC1155Factory = await ethers.getContractFactory("TokenManagerERC1155", signerWithFixedGasEstimation); + const tokenManagerERC1155Factory = await ethers.getContractFactory("TokenManagerERC1155"); const tokenManagerERC1155 = await upgrades.deployProxy(tokenManagerERC1155Factory, [ schainName, messageProxy.address, @@ -251,7 +221,7 @@ async function main() { console.log("Contract TokenManagerERC1155 deployed to", tokenManagerERC1155.address); console.log("Deploy TokenManagerERC721WithMetadata"); - const tokenManagerERC721WithMetadataFactory = await ethers.getContractFactory("TokenManagerERC721WithMetadata", signerWithFixedGasEstimation); + const tokenManagerERC721WithMetadataFactory = await ethers.getContractFactory("TokenManagerERC721WithMetadata"); const tokenManagerERC721WithMetadata = await upgrades.deployProxy(tokenManagerERC721WithMetadataFactory, [ schainName, messageProxy.address, From 71a3e032fe783563cdcad1e43fba3211b3bbdd88 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 18:59:10 +0300 Subject: [PATCH 10/17] Remove unused import --- proxy/migrations/deploySchain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/migrations/deploySchain.ts b/proxy/migrations/deploySchain.ts index e0162a8c8..dcf726a16 100644 --- a/proxy/migrations/deploySchain.ts +++ b/proxy/migrations/deploySchain.ts @@ -24,7 +24,7 @@ */ import { promises as fs } from 'fs'; import { Interface } from "ethers/lib/utils"; -import { ethers, upgrades, network } from "hardhat"; +import { ethers, upgrades } from "hardhat"; import hre from "hardhat"; import { getAbi, getVersion } from '@skalenetwork/upgrade-tools'; import { Manifest } from "@openzeppelin/upgrades-core"; From 0dd66f1f4617224f1675a79a7a2a7ccf6cd70203 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 19:06:57 +0300 Subject: [PATCH 11/17] Run ganache in deamon mode --- proxy/package.json | 1 - proxy/scripts/test_upgrade.sh | 4 ++-- proxy/yarn.lock | 18 ------------------ 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/proxy/package.json b/proxy/package.json index cfbcfce23..1dfd2823c 100644 --- a/proxy/package.json +++ b/proxy/package.json @@ -59,7 +59,6 @@ "eslint": "^8.46.0", "ethereum-waffle": "^4.0.10", "ganache": "7.9.1", - "kill-port": "^1.6.1", "solhint": "3.3.6", "solidity-coverage": "^0.8.4", "ts-generator": "^0.1.1", diff --git a/proxy/scripts/test_upgrade.sh b/proxy/scripts/test_upgrade.sh index 90117d98c..e17d2bb13 100755 --- a/proxy/scripts/test_upgrade.sh +++ b/proxy/scripts/test_upgrade.sh @@ -22,7 +22,7 @@ DEPLOYED_DIR=$GITHUB_WORKSPACE/deployed-IMA/ git clone --branch "$DEPLOYED_TAG" "https://github.com/$GITHUB_REPOSITORY.git" "$DEPLOYED_DIR" ACCOUNTS_FILENAME="$DEPLOYED_DIR/proxy/generatedAccounts.json" -npx ganache --miner.blockGasLimit 9000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.accountKeysPath "$ACCOUNTS_FILENAME" & +GANACHE_INSTANCE=$(npx ganache --😈 --miner.blockGasLimit 9000000 --logging.quiet --chain.allowUnlimitedContractSize --wallet.accountKeysPath "$ACCOUNTS_FILENAME") cd "$DEPLOYED_DIR/proxy" yarn install @@ -65,4 +65,4 @@ ALLOW_NOT_ATOMIC_UPGRADE="OK" \ VERSION=$VERSION_TAG \ npx hardhat run migrations/upgradeSchain.ts --network localhost -npx kill-port 8545 +npx ganache instances stop $GANACHE_INSTANCE diff --git a/proxy/yarn.lock b/proxy/yarn.lock index e9baa1126..cc329c6bf 100644 --- a/proxy/yarn.lock +++ b/proxy/yarn.lock @@ -3982,11 +3982,6 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -get-them-args@1.3.2: - version "1.3.2" - resolved "https://registry.yarnpkg.com/get-them-args/-/get-them-args-1.3.2.tgz#74a20ba8a4abece5ae199ad03f2bcc68fdfc9ba5" - integrity sha1-dKILqKSr7OWuGZrQPyvMaP38m6U= - getpass@^0.1.1: version "0.1.7" resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" @@ -4919,14 +4914,6 @@ keccak@^3.0.0, keccak@^3.0.2: node-gyp-build "^4.2.0" readable-stream "^3.6.0" -kill-port@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/kill-port/-/kill-port-1.6.1.tgz#560fe79484583bdf3a5e908557dae614447618aa" - integrity sha512-un0Y55cOM7JKGaLnGja28T38tDDop0AQ8N0KlAdyh+B1nmMoX8AnNmqPNZbS3mUMgiST51DCVqmbFT1gNJpVNw== - dependencies: - get-them-args "1.3.2" - shell-exec "1.0.2" - kind-of@^6.0.2: version "6.0.3" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" @@ -6295,11 +6282,6 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -shell-exec@1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/shell-exec/-/shell-exec-1.0.2.tgz#2e9361b0fde1d73f476c4b6671fa17785f696756" - integrity sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg== - shelljs@^0.8.3: version "0.8.4" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" From 42bb29047c616ffb8dcbe2f110ac797191a03c6c Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 19:14:10 +0300 Subject: [PATCH 12/17] Remove unused dependencies --- proxy/package.json | 8 +-- proxy/yarn.lock | 123 ++------------------------------------------- 2 files changed, 4 insertions(+), 127 deletions(-) diff --git a/proxy/package.json b/proxy/package.json index 1dfd2823c..93540ae84 100644 --- a/proxy/package.json +++ b/proxy/package.json @@ -30,12 +30,8 @@ "@skalenetwork/upgrade-tools": "^2.0.1", "axios": "^0.21.4", "dotenv": "^16.0.0", - "ethereumjs-tx": "2.1.2", - "ethereumjs-util": "^7.1.5", "ethers": "^5.7.2", - "ethers-eip712": "^0.2.0", - "hardhat": "2.11.0 - 2.16.1", - "path": "^0.12.7" + "hardhat": "2.11.0 - 2.16.1" }, "devDependencies": { "@nomiclabs/hardhat-etherscan": "^3.1.0", @@ -51,11 +47,9 @@ "@types/sinon-chai": "^3.2.5", "@typescript-eslint/eslint-plugin": "^6.2.1", "@typescript-eslint/parser": "^6.2.1", - "bignumber.js": "^9.0.0", "chai": "^4.2.0", "chai-almost": "^1.0.1", "chai-as-promised": "^7.1.1", - "codecov": "^3.7.1", "eslint": "^8.46.0", "ethereum-waffle": "^4.0.10", "ganache": "7.9.1", diff --git a/proxy/yarn.lock b/proxy/yarn.lock index cc329c6bf..5896ec398 100644 --- a/proxy/yarn.lock +++ b/proxy/yarn.lock @@ -1436,11 +1436,6 @@ dependencies: antlr4ts "^0.5.0-alpha.4" -"@tootallnate/once@1": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" - integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== - "@trufflesuite/bigint-buffer@1.1.10": version "1.1.10" resolved "https://registry.yarnpkg.com/@trufflesuite/bigint-buffer/-/bigint-buffer-1.1.10.tgz#a1d9ca22d3cad1a138b78baaf15543637a3e1692" @@ -2006,11 +2001,6 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== -argv@0.0.2: - version "0.0.2" - resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab" - integrity sha1-7L0W+JSbFXGDcRsb2jNPN4QBhas= - array-back@^3.0.1, array-back@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/array-back/-/array-back-3.1.0.tgz#b8859d7a508871c9a7b2cf42f99428f65e96bfb0" @@ -2612,17 +2602,6 @@ cliui@^7.0.2: strip-ansi "^6.0.0" wrap-ansi "^7.0.0" -codecov@^3.7.1: - version "3.8.3" - resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.8.3.tgz#9c3e364b8a700c597346ae98418d09880a3fdbe7" - integrity sha512-Y8Hw+V3HgR7V71xWH2vQ9lyS358CbGCldWlJFR0JirqoGtOoas3R3/OclRTvgUYFK29mmJICDPauVKmpqbwhOA== - dependencies: - argv "0.0.2" - ignore-walk "3.0.4" - js-yaml "3.14.1" - teeny-request "7.1.1" - urlgrey "1.0.0" - color-convert@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" @@ -3425,19 +3404,6 @@ ethereumjs-abi@0.6.8, ethereumjs-abi@^0.6.8: bn.js "^4.11.8" ethereumjs-util "^6.0.0" -ethereumjs-common@^1.5.0: - version "1.5.2" - resolved "https://registry.yarnpkg.com/ethereumjs-common/-/ethereumjs-common-1.5.2.tgz#2065dbe9214e850f2e955a80e650cb6999066979" - integrity sha512-hTfZjwGX52GS2jcVO6E2sx4YuFnf0Fhp5ylo4pEPhEffNln7vS59Hr5sLnp3/QCazFLluuBZ+FZ6J5HTp0EqCA== - -ethereumjs-tx@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ethereumjs-tx/-/ethereumjs-tx-2.1.2.tgz#5dfe7688bf177b45c9a23f86cf9104d47ea35fed" - integrity sha512-zZEK1onCeiORb0wyCXUvg94Ve5It/K6GD1K+26KfFKodiBiS6d9lfCXlUKGBBdQ+bv7Day+JK0tj1K+BeNFRAw== - dependencies: - ethereumjs-common "^1.5.0" - ethereumjs-util "^6.0.0" - ethereumjs-util@7.1.3: version "7.1.3" resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.3.tgz#b55d7b64dde3e3e45749e4c41288238edec32d23" @@ -3496,11 +3462,6 @@ ethereumjs-util@^7.1.4: ethereum-cryptography "^0.1.3" rlp "^2.2.4" -ethers-eip712@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/ethers-eip712/-/ethers-eip712-0.2.0.tgz#52973b3a9a22638f7357283bf66624994c6e91ed" - integrity sha512-fgS196gCIXeiLwhsWycJJuxI9nL/AoUPGSQ+yvd+8wdWR+43G+J1n69LmWVWvAON0M6qNaf2BF4/M159U8fujQ== - ethers@5.7.2, ethers@^5.7.1, ethers@^5.7.2: version "5.7.2" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e" @@ -3654,13 +3615,6 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= -fast-url-parser@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/fast-url-parser/-/fast-url-parser-1.1.3.tgz#f4af3ea9f34d8a271cf58ad2b3759f431f0b318d" - integrity sha1-9K8+qfNNiicc9YrSs3WfQx8LMY0= - dependencies: - punycode "^1.3.2" - fastq@^1.6.0: version "1.13.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c" @@ -4339,15 +4293,6 @@ http-https@^1.0.0: resolved "https://registry.yarnpkg.com/http-https/-/http-https-1.0.0.tgz#2f908dd5f1db4068c058cd6e6d4ce392c913389b" integrity sha1-L5CN1fHbQGjAWM1ubUzjkskTOJs= -http-proxy-agent@^4.0.0: - version "4.0.1" - resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" - integrity sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg== - dependencies: - "@tootallnate/once" "1" - agent-base "6" - debug "4" - http-signature@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1" @@ -4377,13 +4322,6 @@ ieee754@^1.1.13, ieee754@^1.1.4, ieee754@^1.2.1: resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== -ignore-walk@3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.4.tgz#c9a09f69b7c7b479a5d74ac1a3c0d4236d2a6335" - integrity sha512-PY6Ii8o1jMRA1z4F2hRkH/xN59ox43DavKvD3oDpfurRlOJyAHpifIwpbdv1n4jt4ov0jSpw3kQ4GhJnpBL6WQ== - dependencies: - minimatch "^3.0.4" - ignore@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" @@ -4453,11 +4391,6 @@ inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, i resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== -inherits@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" - integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= - ini@^1.3.5: version "1.3.8" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" @@ -4793,7 +4726,7 @@ js-yaml@3.13.1: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@3.14.1, js-yaml@3.x, js-yaml@^3.12.0, js-yaml@^3.13.0, js-yaml@^3.13.1: +js-yaml@3.x, js-yaml@^3.12.0, js-yaml@^3.13.0, js-yaml@^3.13.1: version "3.14.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g== @@ -5745,14 +5678,6 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -path@^0.12.7: - version "0.12.7" - resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f" - integrity sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8= - dependencies: - process "^0.11.1" - util "^0.10.3" - pathval@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d" @@ -5814,11 +5739,6 @@ printj@~1.1.0: resolved "https://registry.yarnpkg.com/printj/-/printj-1.1.2.tgz#d90deb2975a8b9f600fb3a1c94e3f4c53c78a222" integrity sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ== -process@^0.11.1: - version "0.11.10" - resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" - integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= - progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" @@ -5848,7 +5768,7 @@ psl@^1.1.28: resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag== -punycode@^1.3.2, punycode@^1.4.1: +punycode@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" integrity sha1-wNWmOycYgArY4esPpSachN1BhF4= @@ -6461,13 +6381,6 @@ stacktrace-parser@^0.1.10: resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= -stream-events@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/stream-events/-/stream-events-1.0.5.tgz#bbc898ec4df33a4902d892333d47da9bf1c406d5" - integrity sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg== - dependencies: - stubs "^3.0.0" - streamsearch@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" @@ -6592,11 +6505,6 @@ strip-json-comments@3.1.1, strip-json-comments@^3.1.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -stubs@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/stubs/-/stubs-3.0.0.tgz#e8d2ba1fa9c90570303c030b6900f7d5f89abe5b" - integrity sha1-6NK6H6nJBXAwPAMLaQD31fiavls= - supports-color@6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a" @@ -6663,17 +6571,6 @@ table@^6.8.0: string-width "^4.2.3" strip-ansi "^6.0.1" -teeny-request@7.1.1: - version "7.1.1" - resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-7.1.1.tgz#2b0d156f4a8ad81de44303302ba8d7f1f05e20e6" - integrity sha512-iwY6rkW5DDGq8hE2YgNQlKbptYpY5Nn2xecjQiNjOXWbKzPGUfmeUBCSQbbr306d7Z7U2N0TPl+/SwYRfua1Dg== - dependencies: - http-proxy-agent "^4.0.0" - https-proxy-agent "^5.0.0" - node-fetch "^2.6.1" - stream-events "^1.0.5" - uuid "^8.0.0" - text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -6997,13 +6894,6 @@ url@^0.11.0: punycode "^1.4.1" qs "^6.11.0" -urlgrey@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-1.0.0.tgz#72d2f904482d0b602e3c7fa599343d699bbe1017" - integrity sha512-hJfIzMPJmI9IlLkby8QrsCykQ+SXDeO2W5Q9QTW3QpqZVTx4a/K7p8/5q+/isD8vsbVaFgql/gvAoQCRQ2Cb5w== - dependencies: - fast-url-parser "^1.1.3" - utf-8-validate@5.0.7: version "5.0.7" resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.7.tgz#c15a19a6af1f7ad9ec7ddc425747ca28c3644922" @@ -7035,13 +6925,6 @@ util-deprecate@^1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -util@^0.10.3: - version "0.10.4" - resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901" - integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A== - dependencies: - inherits "2.0.3" - util@^0.12.5: version "0.12.5" resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" @@ -7058,7 +6941,7 @@ uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.0.0, uuid@^8.3.2: +uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== From f75936e638dd2d692d4beedf4484701c0b1c4bea Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 5 Sep 2023 19:16:55 +0300 Subject: [PATCH 13/17] Add double quote --- proxy/scripts/test_upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/scripts/test_upgrade.sh b/proxy/scripts/test_upgrade.sh index e17d2bb13..a3f831ab6 100755 --- a/proxy/scripts/test_upgrade.sh +++ b/proxy/scripts/test_upgrade.sh @@ -65,4 +65,4 @@ ALLOW_NOT_ATOMIC_UPGRADE="OK" \ VERSION=$VERSION_TAG \ npx hardhat run migrations/upgradeSchain.ts --network localhost -npx ganache instances stop $GANACHE_INSTANCE +npx ganache instances stop "$GANACHE_INSTANCE" From c66a8545decf2e48140c2ca79458d74ceee01b8d Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 12 Sep 2023 16:11:10 +0100 Subject: [PATCH 14/17] ticket-1584 Fixed own S-chain discovery delays --- agent/bls.mjs | 11 ++-- agent/discoveryTools.mjs | 123 +++++++++++++++++++++++++++------------ agent/main.mjs | 12 +++- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/agent/bls.mjs b/agent/bls.mjs index 0bdf81751..d90d3d175 100644 --- a/agent/bls.mjs +++ b/agent/bls.mjs @@ -136,6 +136,7 @@ function discoverPublicKeyByIndex( nNodeIndex, joSChainNetworkInfo, details, isT const imaState = state.get(); joSChainNetworkInfo = joSChainNetworkInfo || imaState.joSChainNetworkInfo; const jarrNodes = joSChainNetworkInfo.network; + const cntNodes = jarrNodes.length; const joNode = jarrNodes[nNodeIndex]; if( joNode && "imaInfo" in joNode && typeof joNode.imaInfo === "object" && "BLSPublicKey0" in joNode.imaInfo && @@ -159,10 +160,12 @@ function discoverPublicKeyByIndex( nNodeIndex, joSChainNetworkInfo, details, isT }; } details.write( cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " BLS 1/16 public key discovery failed for node #" ) + cc.info( nNodeIndex ) + - cc.error( ", node data is: " ) + cc.j( joNode ) + "\n" ); - if( isThrowException ) - throw new Error( "BLS 1/16 public key discovery failed for node #" + nNodeIndex ); + cc.error( " BLS 1/" + cntNodes + " public key discovery failed for node #" ) + + cc.info( nNodeIndex ) + cc.error( ", node data is: " ) + cc.j( joNode ) + "\n" ); + if( isThrowException ) { + throw new Error( + "BLS 1/" + cntNodes + " public key discovery failed for node #" + nNodeIndex ); + } return null; } diff --git a/agent/discoveryTools.mjs b/agent/discoveryTools.mjs index e5d315453..e248d6d66 100644 --- a/agent/discoveryTools.mjs +++ b/agent/discoveryTools.mjs @@ -165,11 +165,16 @@ export async function waitUntilSChainStarted() { const isSilentReDiscovery = true; // it must be silent during S-Chain sanity check for( ; !bSuccess; ) { try { + if( log.verboseGet() >= log.verboseReversed().information ) { + log.write( cc.attention( "This S-Chain discovery will be done for " ) + + cc.bright( "startup pre-requisite" ) + "\n" ); + } + const nCountToWait = -1; const joSChainNetworkInfo = await discoverSChainNetwork( function( err, joSChainNetworkInfo ) { if( ! err ) bSuccess = true; - }, isSilentReDiscovery, null, -1 ).catch( ( err ) => { + }, isSilentReDiscovery, null, nCountToWait ).catch( ( err ) => { if( log.verboseGet() >= log.verboseReversed().critical ) { const strError = owaspUtils.extractErrorMessage( err ); log.write( cc.fatal( "CRITICAL ERROR:" ) + @@ -211,9 +216,13 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis fnAfter = fnAfter || function() {}; const imaState = state.get(); const cntNodesOnChain = getSChainNodesCount( imaState.joSChainNetworkInfo ); - const cntNodes = Math.min( Math.ceil( cntNodesOnChain * 2 / 3 + 1 ), cntNodesOnChain ); + let nCountToWait = ( cntNodesOnChain > 2 ) + ? Math.ceil( cntNodesOnChain * 2 / 3 + 1 ) + : cntNodesOnChain; + if( nCountToWait > cntNodesOnChain ) + nCountToWait = cntNodesOnChain; const cntDiscovered = getSChainDiscoveredNodesCount( imaState.joSChainNetworkInfo ); - if( cntDiscovered >= cntNodes ) { + if( cntDiscovered >= nCountToWait ) { if( gTimerSChainDiscovery != null ) { clearInterval( gTimerSChainDiscovery ); gTimerSChainDiscovery = null; @@ -237,9 +246,13 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis gFlagIsInSChainDiscovery = true; try { if( log.verboseGet() >= log.verboseReversed().information ) { - log.write( cc.info( "Will re-discover " ) + cc.notice( cntNodes ) + - cc.info( "-node S-Chain network, " ) + cc.notice( cntDiscovered ) + - cc.info( " node(s) already discovered..." ) + "\n" ); + if( ! isSilentReDiscovery ) { + log.write( cc.attention( "This S-Chain discovery will be done for " ) + + cc.bright( "re-discover task" ) + "\n" ); + log.write( cc.info( "Will re-discover " ) + cc.notice( nCountToWait ) + + cc.info( "-node S-Chain network, " ) + cc.notice( cntDiscovered ) + + cc.info( " node(s) already discovered..." ) + "\n" ); + } } await discoverSChainNetwork( function( err, joSChainNetworkInfo ) { if( ! err ) { @@ -251,13 +264,13 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis let strMessage = cc.success( "S-Chain network was re-discovered, " ) + cc.info( cntDiscoveredNew ) + - cc.success( " of " ) + cc.info( cntNodes ) + + cc.success( " of " ) + cc.info( nCountToWait ) + cc.success( " node(s) (" ) + strDiscoveryStatus + cc.success( ")" ); - const cntStillUnknown = cntNodes - cntDiscoveredNew; + const cntStillUnknown = nCountToWait - cntDiscoveredNew; if( cntStillUnknown > 0 ) { strMessage += cc.success( ", " ) + cc.info( cntStillUnknown ) + - cc.success( " of " ) + cc.info( cntNodes ) + + cc.success( " of " ) + cc.info( cntNodesOnChain ) + cc.success( " still unknown (" ); try { const jarrNodes = joSChainNetworkInfo.network; @@ -298,7 +311,7 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis } // fnAfter() will be called here inside async call at beginning continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDiscovery, fnAfter ); - }, isSilentReDiscovery, imaState.joSChainNetworkInfo, cntNodes ).catch( ( err ) => { + }, isSilentReDiscovery, imaState.joSChainNetworkInfo, nCountToWait ).catch( ( err ) => { if( log.verboseGet() >= log.verboseReversed().critical ) { const strError = owaspUtils.extractErrorMessage( err ); log.write( cc.fatal( "CRITICAL ERROR:" ) + @@ -315,7 +328,7 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis if( gFlagIsInSChainDiscovery ) return; fnAsyncHandler(); - }, imaState.joSChainDiscovery.repeatIntervalMilliseconds ); + }, imaState.joSChainDiscovery.periodicDiscoveryInterval ); } async function discoverSChainWalkNodes( optsDiscover ) { @@ -327,6 +340,11 @@ async function discoverSChainWalkNodes( optsDiscover ) { const strNodeDescColorized = cc.notice( "#" ) + cc.info( nCurrentNodeIdx ) + cc.attention( "(" ) + cc.u( strNodeURL ) + cc.attention( ")" ); + if( ! optsDiscover.isSilentReDiscovery ) { + log.write( optsDiscover.strLogPrefix + + cc.attention( "Will try to discover S-Chain node " ) + + strNodeDescColorized + cc.attention( "..." ) + "\n" ); + } try { if( optsDiscover.joPrevSChainNetworkInfo && "network" in optsDiscover.joPrevSChainNetworkInfo && @@ -360,7 +378,7 @@ async function discoverSChainWalkNodes( optsDiscover ) { if( ! optsDiscover.isSilentReDiscovery ) { log.write( optsDiscover.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " JSON RPC call to S-Chain node " ) + + cc.error( " JSON RPC call(creation) to S-Chain node " ) + strNodeDescColorized + cc.error( " failed" ) + "\n" ); } } @@ -383,7 +401,7 @@ async function discoverSChainWalkNodes( optsDiscover ) { if( ! optsDiscover.isSilentReDiscovery ) { log.write( optsDiscover.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " JSON RPC call to S-Chain node " ) + + cc.error( " JSON RPC call(network) to S-Chain node " ) + strNodeDescColorized + cc.error( " failed, error: " ) + cc.warning( strError ) + "\n" ); } @@ -409,7 +427,7 @@ async function discoverSChainWalkNodes( optsDiscover ) { if( ! optsDiscover.isSilentReDiscovery ) { const strError = owaspUtils.extractErrorMessage( err ); log.write( optsDiscover.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " JSON RPC call to S-Chain node " ) + strNodeDescColorized + + cc.error( " JSON RPC call(err) to S-Chain node " ) + strNodeDescColorized + cc.error( " was not created: " ) + cc.warning( strError ) + cc.error( ", stack is: " ) + "\n" + cc.stack( err.stack ) + "\n" ); } @@ -437,15 +455,19 @@ async function discoverSChainWait( optsDiscover ) { cntWaitAttempts = 1; const iv = setInterval( function() { optsDiscover.nCountAvailable = - optsDiscover.cntNodes - optsDiscover.cntFailed; + optsDiscover.cntNodes - optsDiscover.cntFailed; + // notice, below provided up-to-date count of available and fully discovered nodes: + optsDiscover.nCountReceivedImaDescriptions = + getSChainDiscoveredNodesCount( optsDiscover.joSChainNetworkInfo ); if( log.verboseGet() >= log.verboseReversed().debug ) { if( ! optsDiscover.isSilentReDiscovery ) { - log.write( cc.debug( "Waiting attempt " ) + cc.info( nWaitAttempt ) + - cc.debug( " of " ) + cc.info( cntWaitAttempts ) + + log.write( cc.debug( "Waiting (S-Chain discovery) attempt " ) + + cc.info( nWaitAttempt ) + cc.debug( " of " ) + cc.info( cntWaitAttempts ) + cc.debug( " for S-Chain nodes, total " ) + cc.info( optsDiscover.cntNodes ) + cc.debug( ", available " ) + cc.info( optsDiscover.nCountAvailable ) + cc.debug( ", expected at least " ) + - cc.info( optsDiscover.nCountToWait ) + "\n" ); + cc.info( optsDiscover.nCountToWait ) + cc.debug( ", discovered " ) + + cc.info( optsDiscover.nCountReceivedImaDescriptions ) + "\n" ); } } if( log.verboseGet() >= log.verboseReversed().information ) { @@ -457,8 +479,16 @@ async function discoverSChainWait( optsDiscover ) { cc.debug( " node(s)." ) + "\n" ); } } - if( optsDiscover.nCountReceivedImaDescriptions >= - optsDiscover.nCountToWait ) { + if( optsDiscover.nCountReceivedImaDescriptions >= optsDiscover.nCountToWait ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( !optsDiscover.isSilentReDiscovery ) { + log.write( optsDiscover.strLogPrefix + + cc.success( "This S-Chain discovery will finish with " ) + + cc.info( optsDiscover.nCountReceivedImaDescriptions ) + + cc.success( " of " ) + cc.info( optsDiscover.cntNodes ) + + cc.success( " node(s) discovered." ) + "\n" ); + } + } clearInterval( iv ); optsDiscover.fnAfter( null, optsDiscover.joSChainNetworkInfo ); return; @@ -467,12 +497,12 @@ async function discoverSChainWait( optsDiscover ) { if( nWaitAttempt >= cntWaitAttempts ) { clearInterval( iv ); const strErrorDescription = - "S-Chain network discovery wait timeout, " + - "network will be re-discovered"; + "S-Chain network discovery wait timeout, network will be re-discovered later"; if( log.verboseGet() >= log.verboseReversed().warning ) { if( ! optsDiscover.isSilentReDiscovery ) { - log.write( optsDiscover.strLogPrefix + cc.warning( "WARNING:" ) + " " + - cc.warning( strErrorDescription ) + "\n" ); + log.write( optsDiscover.strLogPrefix + + cc.warning( "WARNING: This S-Chain discovery will finish due to: " ) + + cc.error( strErrorDescription ) + "\n" ); } } if( getSChainDiscoveredNodesCount( @@ -484,9 +514,10 @@ async function discoverSChainWait( optsDiscover ) { } if( log.verboseGet() >= log.verboseReversed().debug ) { if( ! optsDiscover.isSilentReDiscovery ) { - log.write( optsDiscover.strLogPrefix + cc.debug( " Waiting attempt " ) + - cc.info( nWaitAttempt ) + cc.debug( " of " ) + cc.info( cntWaitAttempts ) + - cc.debug( " for " ) + cc.notice( optsDiscover.nCountToWait - + log.write( optsDiscover.strLogPrefix + + cc.debug( "S-Chain discovery waiting attempt " ) + cc.info( nWaitAttempt ) + + cc.debug( " of " ) + cc.info( cntWaitAttempts ) + cc.debug( " for " ) + + cc.notice( optsDiscover.nCountToWait - optsDiscover.nCountReceivedImaDescriptions ) + cc.debug( " node answer(s)" ) + "\n" ); } @@ -496,8 +527,7 @@ async function discoverSChainWait( optsDiscover ) { } export async function discoverSChainNetwork( - fnAfter, isSilentReDiscovery, joPrevSChainNetworkInfo, nCountToWait -) { + fnAfter, isSilentReDiscovery, joPrevSChainNetworkInfo, nCountToWait ) { const optsDiscover = { fnAfter: fnAfter, isSilentReDiscovery: ( !!isSilentReDiscovery ), @@ -517,6 +547,12 @@ export async function discoverSChainNetwork( optsDiscover.nCountToWait < 0 ) optsDiscover.nCountToWait = 0; optsDiscover.fnAfter = optsDiscover.fnAfter || function() {}; + if( log.verboseGet() >= log.verboseReversed().information ) { + if( !optsDiscover.isSilentReDiscovery ) { + log.write( optsDiscover.strLogPrefix + + cc.attention( "This S-Chain discovery will start..." ) + "\n" ); + } + } const rpcCallOpts = null; try { await rpcCall.create( optsDiscover.imaState.chainProperties.sc.strURL, rpcCallOpts, @@ -591,13 +627,14 @@ export async function discoverSChainNetwork( } optsDiscover.jarrNodes = optsDiscover.joSChainNetworkInfo.network; optsDiscover.cntNodes = optsDiscover.jarrNodes.length; - if( optsDiscover.nCountToWait <= 0 ) { - optsDiscover.nCountToWait = 0 + optsDiscover.cntNodes; - if( optsDiscover.nCountToWait > 2 ) { - optsDiscover.nCountToWait = - Math.ceil( optsDiscover.nCountToWait * 2 / 3 ); - } - } else if( optsDiscover.nCountToWait > optsDiscover.cntNodes ) + if( optsDiscover.nCountToWait <= 0 || + optsDiscover.nCountToWait >= optsDiscover.cntNodes + ) { + optsDiscover.nCountToWait = ( optsDiscover.cntNodes > 2 ) + ? Math.ceil( optsDiscover.cntNodes * 2 / 3 ) + : optsDiscover.cntNodes; + } + if( optsDiscover.nCountToWait > optsDiscover.cntNodes ) optsDiscover.nCountToWait = optsDiscover.cntNodes; if( log.verboseGet() >= log.verboseReversed().information ) { if( ! optsDiscover.isSilentReDiscovery ) { @@ -706,8 +743,20 @@ export async function doPeriodicSChainNetworkDiscoveryIfNeeded( periodicDiscoveryInterval = 5 * 60 * 1000; fnAfterRediscover = fnAfterRediscover || function() { }; gIntervalPeriodicDiscovery = setInterval( async function() { + let nCountToWait = ( cntNodesOnChain > 2 ) + ? Math.ceil( cntNodesOnChain * 2 / 3 ) + : cntNodesOnChain; + if( nCountToWait > cntNodesOnChain ) + nCountToWait = cntNodesOnChain; + if( log.verboseGet() >= log.verboseReversed().information ) { + if( !optsDiscover.isSilentReDiscovery ) { + log.write( optsDiscover.strLogPrefix + + cc.attention( "This S-Chain discovery will be done for " ) + + cc.bright( "periodic discovery update" ) + "\n" ); + } + } await discoverSChainNetwork( - null, isSilentReDiscovery, joPrevSChainNetworkInfo, cntNodesOnChain ); + null, isSilentReDiscovery, joPrevSChainNetworkInfo, nCountToWait ); joPrevSChainNetworkInfo = imaState.joSChainNetworkInfo; if( checkPeriodicDiscoveryNoLongerNeeded( joPrevSChainNetworkInfo, isSilentReDiscovery ) ) { diff --git a/agent/main.mjs b/agent/main.mjs index 34df1e481..a70a6ebef 100644 --- a/agent/main.mjs +++ b/agent/main.mjs @@ -517,6 +517,13 @@ async function main() { if( ! imaState.bNoWaitSChainStarted ) { discoveryTools.waitUntilSChainStarted().then( function() { // uses call to discoveryTools.discoverSChainNetwork() + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + log.write( cc.attention( "This S-Chain discovery will be done for " ) + + cc.bright( "command line task handler" ) + "\n" ); + } + } + const nCountToWait = -1; discoveryTools.discoverSChainNetwork( function( err, joSChainNetworkInfo ) { if( err ) { // error information is printed by discoveryTools.discoverSChainNetwork() @@ -531,12 +538,13 @@ async function main() { isSilentReDiscovery, function() { discoveryTools.doPeriodicSChainNetworkDiscoveryIfNeeded( isSilentReDiscovery, fnOnPeriodicDiscoveryResultAvailable ); - doTheJob(); } ); + doTheJob(); // Finish of IMA Agent startup, // everything else is in async calls executed later return 0; - }, isSilentReDiscovery, imaState.joSChainNetworkInfo, -1 ).catch( ( err ) => { + }, isSilentReDiscovery, imaState.joSChainNetworkInfo, nCountToWait + ).catch( ( err ) => { if( log.verboseGet() >= log.verboseReversed().critical ) { const strError = owaspUtils.extractErrorMessage( err ); log.write( cc.fatal( "CRITICAL ERROR:" ) + From 30c447dfcce59b29dc1cd9b0bec7d5f7b926f6a3 Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 12 Sep 2023 17:21:52 +0100 Subject: [PATCH 15/17] ticket-1584 Fixed SNB parallel discovery delays for connected S-chains --- npms/skale-observer/observer.mjs | 16 ++++++++++++++-- npms/skale-observer/observerWorker.mjs | 21 +++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/npms/skale-observer/observer.mjs b/npms/skale-observer/observer.mjs index 300c2ae62..6f70bb0e5 100644 --- a/npms/skale-observer/observer.mjs +++ b/npms/skale-observer/observer.mjs @@ -1255,7 +1255,9 @@ async function parallelPeriodicCachingStart( strChainNameConnectedTo, opts ) { await ensureHaveWorker( opts ); if( log.verboseGet() >= log.verboseReversed().debug ) { log.write( threadInfo.threadDescription() + - cc.debug( " will inform worker thread to start periodic SNB refresh..." ) + "\n" ); + cc.debug( " will inform worker thread to start periodic SNB refresh each " ) + + cc.info( opts.secondsToReDiscoverSkaleNetwork ) + cc.debug( " seconds..." ) + + "\n" ); } const jo = { "method": "periodicCachingStart", @@ -1274,7 +1276,8 @@ async function parallelPeriodicCachingStart( strChainNameConnectedTo, opts ) { gClient.send( jo ); if( log.verboseGet() >= log.verboseReversed().debug ) { log.write( threadInfo.threadDescription() + - cc.debug( " did informed worker thread to start periodic SNB refresh" ) + "\n" ); + cc.debug( " did informed worker thread to start periodic SNB refresh each " ) + + cc.info( opts.secondsToReDiscoverSkaleNetwork ) + cc.debug( " second(s)" ) + "\n" ); } return true; } catch ( err ) { @@ -1308,6 +1311,11 @@ export async function periodicCachingStart( strChainNameConnectedTo, opts ) { export async function periodicCachingStop() { if( gWorker && gClient ) { try { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( threadInfo.threadDescription() + + cc.debug( " will inform worker thread to stop periodic SNB refresh..." ) + + "\n" ); + } const jo = { "method": "periodicCachingStop", "message": { } @@ -1331,6 +1339,10 @@ export async function periodicCachingStop() { } if( gIntervalPeriodicCaching ) { try { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( threadInfo.threadDescription() + + cc.debug( " will stop periodic SNB refresh..." ) + "\n" ); + } clearInterval( gIntervalPeriodicCaching ); gIntervalPeriodicCaching = null; } catch ( err ) { diff --git a/npms/skale-observer/observerWorker.mjs b/npms/skale-observer/observerWorker.mjs index 4a2f911aa..832ab4009 100644 --- a/npms/skale-observer/observerWorker.mjs +++ b/npms/skale-observer/observerWorker.mjs @@ -159,10 +159,8 @@ class ObserverServer extends SocketServer { self.mapApiHandlers.periodicCachingStart = function( joMessage, joAnswer, eventData, socket ) { if( log.verboseGet() >= log.verboseReversed().debug ) { - self.opts.details.write( - threadInfo.threadDescription() + - cc.debug( " will to start periodic SNB refresh ..." ) + - "\n" ); + self.opts.details.write( threadInfo.threadDescription() + + cc.debug( " will start periodic SNB refresh ..." ) + "\n" ); } self.periodicCachingStart( socket, @@ -285,13 +283,21 @@ class ObserverServer extends SocketServer { await self.periodicCachingStop(); if( secondsToReDiscoverSkaleNetwork <= 0 ) return false; + if( log.verboseGet() >= log.verboseReversed().debug ) { + self.opts.details.write( + cc.debug( "SKALE Observer in " ) + threadInfo.threadDescription() + + cc.debug( " will do pre-configured periodic SNB refresh each " ) + + cc.info( secondsToReDiscoverSkaleNetwork ) + cc.debug( " second(s)..." ) + + "\n" ); + } const fnAsyncHandler = async function() { try { if( log.verboseGet() >= log.verboseReversed().debug ) { self.opts.details.write( cc.debug( "SKALE Observer in " ) + threadInfo.threadDescription() + - cc.debug( " will do immediate periodic SNB refresh..." ) + - "\n" ); + cc.debug( " will do immediate periodic SNB refresh" ) + + cc.normal( "(one of each " ) + cc.info( secondsToReDiscoverSkaleNetwork ) + + cc.normal( " second(s))" ) + cc.debug( "..." ) + "\n" ); } while( true ) { const strError = @@ -339,8 +345,7 @@ class ObserverServer extends SocketServer { if( log.verboseGet() >= log.verboseReversed().debug ) { self.opts.details.write( cc.debug( "SKALE Observer in " ) + threadInfo.threadDescription() + - cc.debug( " will to start periodic SNB refresh..." ) + - "\n" ); + cc.debug( " will start periodic SNB refresh..." ) + "\n" ); } self.intervalPeriodicSchainsCaching = setInterval( fnPeriodicCaching, secondsToReDiscoverSkaleNetwork * 1000 ); From 7293aaef67d7eda44ef1526f9a9b9a218d5e3a7b Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 12 Sep 2023 17:59:54 +0100 Subject: [PATCH 16/17] ticket-1584 own S-chain discovery nodes counting fix --- agent/discoveryTools.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/discoveryTools.mjs b/agent/discoveryTools.mjs index e248d6d66..124c8e208 100644 --- a/agent/discoveryTools.mjs +++ b/agent/discoveryTools.mjs @@ -256,17 +256,17 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis } await discoverSChainNetwork( function( err, joSChainNetworkInfo ) { if( ! err ) { - const cntDiscoveredNew = + const cntDiscoveredNow = getSChainDiscoveredNodesCount( joSChainNetworkInfo ); if( log.verboseGet() >= log.verboseReversed().information ) { const strDiscoveryStatus = - cc.info( cntDiscoveredNew ) + cc.success( " nodes known" ); + cc.info( cntDiscoveredNow ) + cc.success( " nodes known" ); let strMessage = cc.success( "S-Chain network was re-discovered, " ) + - cc.info( cntDiscoveredNew ) + + cc.info( cntDiscoveredNow ) + cc.success( " of " ) + cc.info( nCountToWait ) + cc.success( " node(s) (" ) + strDiscoveryStatus + cc.success( ")" ); - const cntStillUnknown = nCountToWait - cntDiscoveredNew; + const cntStillUnknown = cntNodesOnChain - cntDiscoveredNow; if( cntStillUnknown > 0 ) { strMessage += cc.success( ", " ) + cc.info( cntStillUnknown ) + From 862c5ebe2186c58efa45c0d778fbd5ac10fc19ef Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Wed, 13 Sep 2023 16:09:50 +0100 Subject: [PATCH 17/17] ticket-1584 own S-chain discovery nodes periodic continuation fix --- agent/discoveryTools.mjs | 100 +++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 14 deletions(-) diff --git a/agent/discoveryTools.mjs b/agent/discoveryTools.mjs index 124c8e208..22bd61c41 100644 --- a/agent/discoveryTools.mjs +++ b/agent/discoveryTools.mjs @@ -213,38 +213,104 @@ let gTimerSChainDiscovery = null; let gFlagIsInSChainDiscovery = false; export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDiscovery, fnAfter ) { + if( gTimerSChainDiscovery != null ) + return; fnAfter = fnAfter || function() {}; const imaState = state.get(); + if( imaState.joSChainDiscovery.repeatIntervalMilliseconds <= 0 ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) + log.write( cc.warning( "This S-Chain re-discovery will not be preformed" ) + "\n" ); + + } + fnAfter(); + return; // no S-Chain re-discovery, special mode + } const cntNodesOnChain = getSChainNodesCount( imaState.joSChainNetworkInfo ); let nCountToWait = ( cntNodesOnChain > 2 ) ? Math.ceil( cntNodesOnChain * 2 / 3 + 1 ) : cntNodesOnChain; if( nCountToWait > cntNodesOnChain ) nCountToWait = cntNodesOnChain; - const cntDiscovered = getSChainDiscoveredNodesCount( imaState.joSChainNetworkInfo ); - if( cntDiscovered >= nCountToWait ) { + let cntDiscovered = getSChainDiscoveredNodesCount( imaState.joSChainNetworkInfo ); + if( cntDiscovered >= cntNodesOnChain ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + log.write( cc.attention( "Everything is discovered about this S-Chain. " + + "No re-discovery is needed" ) + "\n" ); + } + } if( gTimerSChainDiscovery != null ) { clearInterval( gTimerSChainDiscovery ); gTimerSChainDiscovery = null; + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) + log.write( cc.notice( "This S-Chain re-discovery stopped" ) + "\n" ); + + } } fnAfter(); return; } - if( gTimerSChainDiscovery != null ) - return; - if( imaState.joSChainDiscovery.repeatIntervalMilliseconds <= 0 ) { - fnAfter(); - return; // no S-Chain re-discovery, special mode + if( cntDiscovered < cntNodesOnChain ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + const cntUnDiscoveredYet = cntNodesOnChain - cntDiscovered; + log.write( cc.warning( "Have " ) + cc.info( cntUnDiscoveredYet ) + + cc.warning( " of " ) + cc.info( cntNodesOnChain ) + + cc.warning( " nodes of this S-Chain not discovered yet " + + "before continuing re-discovery." ) + "\n" ); + } + } } const fnAsyncHandler = async function() { if( gFlagIsInSChainDiscovery ) { isInsideAsyncHandler = false; - if( log.verboseGet() >= log.verboseReversed().information ) - log.write( cc.warning( "Notice: long S-Chain discovery is in progress" ) + "\n" ); + if( log.verboseGet() >= log.verboseReversed().information ) { + log.write( cc.warning( "Notice: " + + "long this S-Chain re-discovery is in progress now..." ) + "\n" ); + } return; } gFlagIsInSChainDiscovery = true; try { + nCountToWait = ( cntNodesOnChain > 2 ) + ? Math.ceil( cntNodesOnChain * 2 / 3 + 1 ) + : cntNodesOnChain; + if( nCountToWait > cntNodesOnChain ) + nCountToWait = cntNodesOnChain; + cntDiscovered = getSChainDiscoveredNodesCount( imaState.joSChainNetworkInfo ); + if( cntDiscovered >= cntNodesOnChain ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + log.write( cc.attention( "Everything is discovered about this S-Chain. " + + "No re-discovery is needed" ) + "\n" ); + } + } + if( gTimerSChainDiscovery != null ) { + clearInterval( gTimerSChainDiscovery ); + gTimerSChainDiscovery = null; + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) + log.write( cc.notice( "This S-Chain re-discovery stopped" ) + "\n" ); + + } + } + // fnAfter() will be called here inside async call at beginning + gFlagIsInSChainDiscovery = false; + return; + } + if( cntDiscovered < cntNodesOnChain ) { + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + const cntUnDiscoveredYet = cntNodesOnChain - cntDiscovered; + log.write( cc.warning( "Have " ) + cc.info( cntUnDiscoveredYet ) + + cc.warning( " of " ) + cc.info( cntNodesOnChain ) + + cc.warning( " nodes of this S-Chain not discovered yet " + + "on re-discovery step." ) + "\n" ); + } + } + } if( log.verboseGet() >= log.verboseReversed().information ) { if( ! isSilentReDiscovery ) { log.write( cc.attention( "This S-Chain discovery will be done for " ) + @@ -309,8 +375,8 @@ export async function continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDis } imaState.joSChainNetworkInfo = joSChainNetworkInfo; } - // fnAfter() will be called here inside async call at beginning - continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDiscovery, fnAfter ); + fnAfter(); + continueSChainDiscoveryInBackgroundIfNeeded( isSilentReDiscovery, null ); }, isSilentReDiscovery, imaState.joSChainNetworkInfo, nCountToWait ).catch( ( err ) => { if( log.verboseGet() >= log.verboseReversed().critical ) { const strError = owaspUtils.extractErrorMessage( err ); @@ -732,7 +798,7 @@ export async function doPeriodicSChainNetworkDiscoveryIfNeeded( joPrevSChainNetworkInfo, isSilentReDiscovery ) ) { if( ! isSilentReDiscovery ) { log.write( - cc.debug( "Periodic S-Chain re-discovery is not needed right from startup" ) + + cc.success( "Periodic S-Chain re-discovery is not needed right from startup" ) + "\n" ); } return; // not needed right from very beginning @@ -741,6 +807,12 @@ export async function doPeriodicSChainNetworkDiscoveryIfNeeded( let periodicDiscoveryInterval = imaState.joSChainDiscovery.periodicDiscoveryInterval; if( periodicDiscoveryInterval <= 0 ) periodicDiscoveryInterval = 5 * 60 * 1000; + if( log.verboseGet() >= log.verboseReversed().information ) { + if( ! isSilentReDiscovery ) { + log.write( cc.debug( "Periodic S-Chain re-discovery will be done with " ) + + cc.info( periodicDiscoveryInterval ) + cc.debug( " interval..." ) + "\n" ); + } + } fnAfterRediscover = fnAfterRediscover || function() { }; gIntervalPeriodicDiscovery = setInterval( async function() { let nCountToWait = ( cntNodesOnChain > 2 ) @@ -749,8 +821,8 @@ export async function doPeriodicSChainNetworkDiscoveryIfNeeded( if( nCountToWait > cntNodesOnChain ) nCountToWait = cntNodesOnChain; if( log.verboseGet() >= log.verboseReversed().information ) { - if( !optsDiscover.isSilentReDiscovery ) { - log.write( optsDiscover.strLogPrefix + + if( !isSilentReDiscovery ) { + log.write( cc.attention( "This S-Chain discovery will be done for " ) + cc.bright( "periodic discovery update" ) + "\n" ); }