keep-network / local-setup

Allow to easily set up tBTC and Keep locally for development and test purposes.
MIT License
8 stars 16 forks source link

Bring local-setup into the V2 era #156

Open beaurancourt opened 1 year ago

beaurancourt commented 1 year ago

refs:https://github.com/keep-network/keep-core/issues/3617

Features

It's pretty tough to run all of the moving pieces of v2, so this PR is the first half of being able to build everything in docker!

Implemented:

geth with all the contracts deployed, exposed at the default port (localhost:8545) • a local ethereum block explorer (localhost:8095) • bitcoind exposed at the default port (localhost:18332) • this interacts out of the box with our bitcoind-walletelectrs exposed at the default port (localhost:3002) • a local bitcoin block explorer (localhost:8094)

The bitcoin block explorer works great:

image

image

the ethereum block explorer sometimes works:

image image image image

but sometimes does not: image


Next step is getting the UI hooked up!

Testing

clone the repo

git submodule update --init --recursive

then

docker-compose build
docker-compose up

• You should be able to see block explorers running at http://localhost:8094 and http://localhost:8095 • The log output should be talking about mining blocks and sometimes deploying contracts • If you see a message that says "Contract Deployment completed!" then deployment is done. If you tear down the dockers (ctrl+c) and then bring them back up (docker-compose up), then it should skip deployment. • The ethereum block explorer has a lot of noisy error logs but is useful enough to keep in its current state imo.

Tagging @michalinacienciala @nkuba @pdyraga for review. I'm not a docker expert so any help reformatting this stuff or on better idioms would be appreciated!

michalinacienciala commented 1 year ago

A couple of notes:

  1. Not necessarily in this PR, but we should remember about updating README.
  2. As I didn't work with submodules in a long time, I didn't remember initially to execute git submodule init and git submodule update in the root folder. We could add those commands to the Testing section in the PR description.
  3. My first run of docker-compose build after getting submodules sorted out have failed, with the following error:
    => [stage-1 22/45] RUN yarn link @threshold-network/solidity-contracts                                                                                                                                                                                               1.0s
    => ERROR [stage-1 23/45] RUN yarn build                                                                                                                                                                                                                            128.9s
    ------
    > [stage-1 23/45] RUN yarn build:
    #29 0.688 yarn run v1.22.19
    #29 0.888 $ hardhat compile
    #29 10.80 Solidity 0.8.17 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.
    #29 10.80 
    #29 10.80 Learn more at https://hardhat.org/hardhat-runner/docs/reference/solidity-support
    #29 10.80 
    #29 15.92 Downloading compiler 0.8.17
    #29 77.31 Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
    #29 77.31 --> @keep-network/sortition-pools/contracts/Branch.sol
    [...]
    #29 77.31 
    #29 77.31 Warning: Contract code size is 24991 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
    #29 77.31   --> contracts/test/RandomBeaconStub.sol:11:1:
    #29 77.31    |
    #29 77.31 11 | contract RandomBeaconStub is RandomBeacon {
    #29 77.31    | ^ (Relevant source part starts here and spans across multiple lines).
    #29 77.31 
    #29 77.31 
    #29 128.7 An unexpected error occurred:
    #29 128.7 
    #29 128.7 Error: Lock is already released
    #29 128.7     at /keep-core/solidity/random-beacon/node_modules/proper-lockfile/lib/lockfile.js:257:60
    #29 128.7     at /keep-core/solidity/random-beacon/node_modules/proper-lockfile/lib/adapter.js:39:9
    #29 128.7     at new Promise (<anonymous>)
    #29 128.7     at /keep-core/solidity/random-beacon/node_modules/proper-lockfile/lib/adapter.js:30:25
    #29 128.7     at writeValidations (/keep-core/solidity/random-beacon/node_modules/@openzeppelin/hardhat-upgrades/src/utils/validations.ts:35:24)
    #29 128.7     at async OverriddenTaskDefinition._action (/keep-core/solidity/random-beacon/node_modules/@openzeppelin/hardhat-upgrades/src/index.ts:82:5)
    #29 128.7     at async Environment._runTaskDefinition (/keep-core/solidity/random-beacon/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    #29 128.7     at async Environment.run (/keep-core/solidity/random-beacon/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    #29 128.7     at async SimpleTaskDefinition.action (/keep-core/solidity/random-beacon/node_modules/hardhat/src/builtin-tasks/compile.ts:989:37)
    #29 128.7     at async Environment._runTaskDefinition (/keep-core/solidity/random-beacon/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14) {
    #29 128.7   code: 'ERELEASED'
    #29 128.7 }
    #29 128.9 error Command failed with exit code 1.
    #29 128.9 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

    Once I re-run, the build have passed.

  4. For me, I was getting error 500 in the ethereum block explorer in details of every block except of block 0.
  5. When I was trying to reproduce the issue from point 4, by executing docker-compose build --no-cache, I got a different issue, on an earlier stage:
    => [stage-1 11/45] WORKDIR /solidity-contracts                                                                       0.0s 
    => [stage-1 12/45] RUN git init                                                                                      0.2s 
    => [stage-1 13/45] RUN yarn install                                                                                103.4s 
    => [stage-1 14/45] RUN yarn build                                                                                   88.9s 
    => [stage-1 15/45] RUN yarn link                                                                                     0.6s 
    => ERROR [stage-1 16/45] RUN yarn prepack                                                                           18.2s 
    ------                                                                                                                     
    > [stage-1 16/45] RUN yarn prepack:                                                                                       
    #22 0.507 yarn run v1.22.19                                                                                                
    #22 0.676 $ tsc -p tsconfig.export.json && hardhat export-artifacts export/artifacts
    #22 18.02 An unexpected error occurred:
    #22 18.02 
    #22 18.10 SyntaxError: Unexpected token g in JSON at position 1092
    #22 18.10     at JSON.parse (<anonymous>)
    #22 18.10     at readValidations (/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/utils/validations.ts:34:23)
    #22 18.10     at async OverriddenTaskDefinition._action (/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/index.ts:49:5)
    #22 18.10     at async Environment._runTaskDefinition (/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    #22 18.10     at async Environment.run (/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    #22 18.10     at async SimpleTaskDefinition.action (/solidity-contracts/node_modules/hardhat/src/builtin-tasks/compile.ts:1438:7)
    #22 18.10     at async Environment._runTaskDefinition (/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    #22 18.10     at async OverriddenTaskDefinition._action (/solidity-contracts/node_modules/hardhat-contract-sizer/tasks/compile.js:8:3)
    #22 18.10     at async Environment._runTaskDefinition (/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    #22 18.10     at async Environment.run (/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    #22 18.18 error Command failed with exit code 1.
    #22 18.18 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

    I run docker-compose build --no-cache again and didn't get any errors this time.

beaurancourt commented 1 year ago

Not necessarily in this PR, but we should remember about updating README.

:100:

As I didn't work with submodules in a long time, I didn't remember initially to execute git submodule init and git submodule update in the root folder. We could add those commands to the Testing section in the PR description.

Added!

Error: Lock is already released

I see this too sometimes, totally unclear as to why; it goes away if i just rebuild

For me, I was getting error 500 in the ethereum block explorer in details of every block except of block 0.

The ethereum block explorer is definitely inconsistent. It works for me sometimes. I'm down to take it out or leave it in. I also might try to adopt the code one weekend and make it actually work

SyntaxError: Unexpected token g in JSON at position 1092

this also happened to me a handful of times while building; very inconsistently though

beaurancourt commented 1 year ago

What do we plan to do about the failed CI jobs? Are they still relevant or should we remove them?

Nuking them: 8c71a0e570f80eda9334431c60add11ead2b4115

michalinacienciala commented 1 year ago

BTW, @nkuba / @pdyraga, before merging this PR we'll need to turn off the branch protection rules related to the checks.