Skip to content

Commit

Permalink
ethereum: mine ganache blocks in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Nov 18, 2020
1 parent 22368de commit da768a0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 1 addition & 2 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions devnet/eth-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 36 additions & 0 deletions ethereum/mine.js
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit da768a0

Please sign in to comment.