From b97bc70edcb71b38f12deab614599ea3a1ace740 Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:16:32 -0400 Subject: [PATCH] mine script --- devnet/eth-devnet.yaml | 7 +- devnet/eth-devnet2.yaml | 8 +- ethereum/mine.js | 36 ------ ethereum/mine.ts | 37 ++++++ ethereum/package-lock.json | 236 +++++++++++++++++-------------------- ethereum/package.json | 7 +- 6 files changed, 164 insertions(+), 167 deletions(-) delete mode 100644 ethereum/mine.js create mode 100644 ethereum/mine.ts diff --git a/devnet/eth-devnet.yaml b/devnet/eth-devnet.yaml index c2ff2ed2df..0fe8568d20 100644 --- a/devnet/eth-devnet.yaml +++ b/devnet/eth-devnet.yaml @@ -40,7 +40,6 @@ spec: - --chain-id=1 - --silent - --mnemonic=myth like bonus scare over problem client lizard pioneer submit female collect - - --block-time=1 ports: - containerPort: 8545 name: rpc @@ -61,5 +60,11 @@ spec: initialDelaySeconds: 90 tcpSocket: port: 2000 + - name: mine + image: eth-node + command: + - /bin/sh + - -c + - "npm run mine" --- diff --git a/devnet/eth-devnet2.yaml b/devnet/eth-devnet2.yaml index 2944fb85ae..1a133d25ff 100644 --- a/devnet/eth-devnet2.yaml +++ b/devnet/eth-devnet2.yaml @@ -41,8 +41,6 @@ spec: - --chain-id=1397 - --silent - --mnemonic=myth like bonus scare over problem client lizard pioneer submit female collect - - --block-time=1 - ports: - containerPort: 8545 name: rpc @@ -63,3 +61,9 @@ spec: initialDelaySeconds: 90 tcpSocket: port: 2000 + - name: mine + image: eth-node + command: + - /bin/sh + - -c + - "npm run mine" diff --git a/ethereum/mine.js b/ethereum/mine.js deleted file mode 100644 index dfe428fbac..0000000000 --- a/ethereum/mine.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - This script advances Ganache network state. It runs as a sidecar pod alongside the devnet and - ensures that manual token transfers triggered through the web UI will be able to be confirmed. - */ - -advanceBlock = () => { - return new Promise((resolve, reject) => { - web3.currentProvider.send({ - jsonrpc: "2.0", - method: "evm_mine", - id: new Date().getTime() - }, (err, result) => { - if (err) { - return reject(err); - } - const newBlockHash = web3.eth.getBlock('latest').hash; - - return resolve(newBlockHash) - }); - }); -} - -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -module.exports = function(callback) { - const fn = async () => { - while (true) { - await advanceBlock(); - await sleep(1000); - } - } - - fn().catch(reason => console.error(reason)) -} diff --git a/ethereum/mine.ts b/ethereum/mine.ts new file mode 100644 index 0000000000..c42c7ba14f --- /dev/null +++ b/ethereum/mine.ts @@ -0,0 +1,37 @@ +/* + This script advances Anvil network state. It runs as a sidecar pod alongside the devnet and + ensures that manual token transfers triggered through the web UI will be able to be confirmed. + */ + +import fetch from "node-fetch" + +const RPC_URL = 'http://localhost:8545' + +const advanceBlock = () => { + return new Promise((resolve, reject) => { + fetch(RPC_URL, { + method: 'POST', + headers: {'content-type': 'application/json'}, + body: JSON.stringify({ + jsonrpc: '2.0', + id: new Date().getTime(), + method: "evm_mine", + }) + }).then(() => { + resolve(0); + }) + }); +} + +function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +const fn = async () => { + while (true) { + await advanceBlock(); + await sleep(1000); + } +} + +fn().catch(reason => console.error(reason)) \ No newline at end of file diff --git a/ethereum/package-lock.json b/ethereum/package-lock.json index b9e9d40fb3..c3b284c331 100644 --- a/ethereum/package-lock.json +++ b/ethereum/package-lock.json @@ -14,6 +14,7 @@ "dotenv": "^10.0.0", "elliptic": "^6.5.2", "jsonfile": "^4.0.0", + "node-fetch": "^2.7.0", "truffle-hdwallet-provider-klaytn": "^1.4.2", "typechain": "^8.1.1" }, @@ -22,6 +23,7 @@ "@openzeppelin/cli": "^2.8.2", "@openzeppelin/contracts": "^4.3.1", "@truffle/hdwallet-provider": "^1.7.0", + "@types/node-fetch": "^2.6.6", "chai": "^4.3.7", "mocha": "^8.4.0", "truffle": "5.8.4", @@ -3933,25 +3935,6 @@ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" }, - "node_modules/@solana/web3.js/node_modules/node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/@solana/web3.js/node_modules/rpc-websockets": { "version": "7.5.1", "resolved": "https://registry.npmjs.org/rpc-websockets/-/rpc-websockets-7.5.1.tgz", @@ -7444,6 +7427,30 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==" }, + "node_modules/@types/node-fetch": { + "version": "2.6.6", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.6.tgz", + "integrity": "sha512-95X8guJYhfqiuVVhRFxVQcf4hW/2bCuoPwDasMf/531STFoNoWTT7YDnWdXHEZKqAGUigmpG31r2FE70LwnzJw==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/node-fetch/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/@types/npm": { "version": "2.0.31", "resolved": "https://registry.npmjs.org/@types/npm/-/npm-2.0.31.tgz", @@ -8323,27 +8330,6 @@ "node": ">=12.0" } }, - "node_modules/apollo-server-env/node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", - "dev": true, - "optional": true, - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/apollo-server-errors": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/apollo-server-errors/-/apollo-server-errors-3.3.1.tgz", @@ -13305,6 +13291,15 @@ "node-fetch": "~1.7.1" } }, + "node_modules/fetch-ponyfill/node_modules/node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dependencies": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, "node_modules/figgy-pudding": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz", @@ -13939,7 +13934,6 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.5.tgz", "integrity": "sha512-HTm14iMQKK2FjFLRTM5lAVcyaUzOnqbPtesFIvREgXpJHdQm8bWS+GkQgIkfaBYRHuCnea7w8UVNfwiAQhlr9A==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -14297,7 +14291,6 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz", "integrity": "sha512-vLt1O5Pp+flcArHGIyKEQq883nBt8nN8tVBcoL0qUXj2XT1n7p70yGIq2VK98I5FdZ1YHc0wk/koOnHjnXWk1Q==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -15167,25 +15160,6 @@ "node": ">= 0.12" } }, - "node_modules/ipfs-http-client-lite/node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/is-accessor-descriptor": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz", @@ -15612,6 +15586,16 @@ "whatwg-fetch": ">=0.10.0" } }, + "node_modules/isomorphic-fetch/node_modules/node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dev": true, + "dependencies": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, "node_modules/isomorphic-ws": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz", @@ -17754,25 +17738,6 @@ "node": ">= 0.8" } }, - "node_modules/near-api-js/node_modules/node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/near-api-js/node_modules/tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", @@ -17824,12 +17789,22 @@ "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" }, "node_modules/node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } } }, "node_modules/node-gyp-build": { @@ -31280,14 +31255,6 @@ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" }, - "node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", - "requires": { - "whatwg-url": "^5.0.0" - } - }, "rpc-websockets": { "version": "7.5.1", "resolved": "https://registry.npmjs.org/rpc-websockets/-/rpc-websockets-7.5.1.tgz", @@ -34180,6 +34147,29 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==" }, + "@types/node-fetch": { + "version": "2.6.6", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.6.tgz", + "integrity": "sha512-95X8guJYhfqiuVVhRFxVQcf4hW/2bCuoPwDasMf/531STFoNoWTT7YDnWdXHEZKqAGUigmpG31r2FE70LwnzJw==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^4.0.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "@types/npm": { "version": "2.0.31", "resolved": "https://registry.npmjs.org/@types/npm/-/npm-2.0.31.tgz", @@ -34901,18 +34891,6 @@ "optional": true, "requires": { "node-fetch": "^2.6.7" - }, - "dependencies": { - "node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", - "dev": true, - "optional": true, - "requires": { - "whatwg-url": "^5.0.0" - } - } } }, "apollo-server-errors": { @@ -39003,6 +38981,17 @@ "integrity": "sha1-rjzl9zLGReq4fkroeTQUcJsjmJM=", "requires": { "node-fetch": "~1.7.1" + }, + "dependencies": { + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + } } }, "figgy-pudding": { @@ -40453,14 +40442,6 @@ "combined-stream": "^1.0.6", "mime-types": "^2.1.12" } - }, - "node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "requires": { - "whatwg-url": "^5.0.0" - } } } }, @@ -40750,6 +40731,18 @@ "requires": { "node-fetch": "^1.0.1", "whatwg-fetch": ">=0.10.0" + }, + "dependencies": { + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dev": true, + "requires": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + } } }, "isomorphic-ws": { @@ -42531,14 +42524,6 @@ "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" }, - "node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", - "requires": { - "whatwg-url": "^5.0.0" - } - }, "tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", @@ -42589,12 +42574,11 @@ "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" }, "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" + "whatwg-url": "^5.0.0" } }, "node-gyp-build": { diff --git a/ethereum/package.json b/ethereum/package.json index ac963880e6..90dc76b111 100644 --- a/ethereum/package.json +++ b/ethereum/package.json @@ -8,6 +8,7 @@ "@openzeppelin/cli": "^2.8.2", "@openzeppelin/contracts": "^4.3.1", "@truffle/hdwallet-provider": "^1.7.0", + "@types/node-fetch": "^2.6.6", "chai": "^4.3.7", "mocha": "^8.4.0", "truffle": "5.8.4", @@ -27,8 +28,9 @@ "deploy_weth9": "npm run build:core && mkdir -p build/contracts && cp node_modules/@openzeppelin/contracts/build/contracts/* build/contracts/ && truffle migrate --f 9 --compile-none", "deploy-relayers-evm1": "CONTAINER=evm1 bash ./ts-scripts/relayer/shell/deployInContainer.sh", "deploy-relayers-evm2": "CONTAINER=evm2 bash ./ts-scripts/relayer/shell/deployInContainer.sh", - "typecheck": "tsc --noEmit --skipLibCheck" - }, + "typecheck": "tsc --noEmit --skipLibCheck", + "mine": "ts-node ./mine.ts" + }, "author": "", "license": "ISC", "dependencies": { @@ -37,6 +39,7 @@ "dotenv": "^10.0.0", "elliptic": "^6.5.2", "jsonfile": "^4.0.0", + "node-fetch": "^2.7.0", "truffle-hdwallet-provider-klaytn": "^1.4.2", "typechain": "^8.1.1" }