ソースを参照

ethereum: mine ganache blocks in the background

Fixes #75.
Leo 5 年 前
コミット
da768a09c4
3 ファイル変更43 行追加2 行削除
  1. 1 2
      DEVELOP.md
  2. 6 0
      devnet/eth-devnet.yaml
  3. 36 0
      ethereum/mine.js

+ 1 - 2
DEVELOP.md

@@ -95,8 +95,7 @@ Next, send some of them back to Ethereum:
 
 <img src="https://user-images.githubusercontent.com/859697/98734694-a1228400-23a2-11eb-8f39-13000631c839.png" width="66%" />
 
-MetaMask will ask you to confirm the transaction. You have to run send-eth-lockups.sh script in the background to
-force Ganache to mint new blocks such that the bridge can reach its confirmation threshold (https://github.com/certusone/wormhole/issues/75).
+MetaMask will ask you to confirm the transaction.
 
 After a few seconds, the SPL token balance shown below will increase as the VAA gets accepted on Solana.
 

+ 6 - 0
devnet/eth-devnet.yaml

@@ -49,3 +49,9 @@ spec:
             - /bin/sh
             - -c
             - "npm run migrate && sleep infinity"
+        - name: mine
+          image: eth-node
+          command:
+            - /bin/sh
+            - -c
+            - "npx truffle exec mine.js"

+ 36 - 0
ethereum/mine.js

@@ -0,0 +1,36 @@
+/*
+    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) {
+            console.log(await advanceBlock());
+            await sleep(1000);
+        }
+    }
+
+    fn().catch(reason => console.error(reason))
+}