Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rainbow on Binance Smart Chain #604

Merged
merged 4 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
help:
@echo Deploy rainbow bridge
@echo 1 run "make init" first time only and one time.
@echo 2 run "make start-bsc" or "make start-ethash"
@echo 3 run "make gen-contarcts"
@echo 4 run "make deploy-contarcts"
@echo 5 run "make start-relayer"
@echo 6 run "stop-all"

init: yarn-init gen-contracts

yarn-init:
yarn
yarn install

# generate ether contracts
gen-contracts:
cd contracts/eth/nearbridge/ && yarn && yarn build
cd contracts/eth/nearprover/ && yarn && yarn build

# start near blockchain and connect with ganache.
start-ethash:
cli/index.js clean
cli/index.js prepare
cli/index.js start near-node
cli/index.js start ganache

# start near blockchain and connect with binance test net.
start-bsc:
cli/index.js clean
cli/index.js prepare
cli/index.js start near-node
cli/index.js start binance-smart-chain \
--eth-node-url https://data-seed-prebsc-1-s1.binance.org:8545 \
--eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200

# deploy contracts
full-contracts:
cli/index.js init-near-contracts
cli/index.js init-eth-ed25519
cli/index.js init-eth-client --eth-client-lock-eth-amount 1000 --eth-client-lock-duration 10
cli/index.js init-eth-prover
cli/index.js init-eth-erc20
cli/index.js init-eth-locker
cli/index.js init-near-token-factory

# deploy contracts
light-bsc-contracts:
cli/index.js init-near-contracts
cli/index.js init-near-token-factory

# start-relayer eth2near-relay, near2eth-relay and bridge-watchdog
start-relayer:
cli/index.js start eth2near-relay
cli/index.js start near2eth-relay
cli/index.js start bridge-watchdog
pm2 logs

stop-all:
cli/index.js stop all

build-eth-client:
cd contracts/near/eth-client && sudo ./build.sh

test-eth-client:
cd contracts/near/eth-client && sudo ./test.sh

.PHONY: help init yarn-init gen-contracts start-bsc light-bsc-contracts start-relayer stop-all build-eth-client test-eth-client start-ethash
25 changes: 25 additions & 0 deletions cli/commands/start/binance-smart-chain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Binance Smart chain configurations to connect with testnet
class StartBinanceSmartChainNodeCommand {
static async execute ({ ethNodeUrl, ethMasterSk, nearClientValidateHeader }) {
if (nearClientValidateHeader !== 'true' && nearClientValidateHeader !== 'false') {
nearClientValidateHeader = 'true'
}

if (ethNodeUrl === '') {
throw new Error('--eth-node-url not set')
}

if (ethMasterSk === '') {
throw new Error('--eth-master-sk not set')
}

return {
ethNodeUrl: ethNodeUrl,
ethMasterSk: ethMasterSk,
nearClientValidateHeader: nearClientValidateHeader,
nearClientValidateHeaderMode: 'bsc'
}
}
}

exports.StartBinanceSmartChainNodeCommand = StartBinanceSmartChainNodeCommand
7 changes: 4 additions & 3 deletions cli/commands/start/eth2near-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { nearAPI } = require('rainbow-bridge-utils')
const path = require('path')

class StartEth2NearRelayCommand {
static async execute({
static async execute ({
daemon,
nearNetworkId,
nearNodeUrl,
Expand All @@ -18,7 +18,8 @@ class StartEth2NearRelayCommand {
totalSubmitBlock,
gasPerTransaction,
ethNodeUrl,
metricsPort
metricsPort,
nearClientValidateHeaderMode
}) {
if (daemon === 'true') {
ProcessManager.connect((err) => {
Expand Down Expand Up @@ -75,7 +76,7 @@ class StartEth2NearRelayCommand {
)
await clientContract.accessKeyInit()
console.log('Initializing eth2near-relay...', { ethNodeUrl, metricsPort })
relay.initialize(clientContract, { ethNodeUrl, totalSubmitBlock, gasPerTransaction, metricsPort, nearNetworkId })
relay.initialize(clientContract, { ethNodeUrl, totalSubmitBlock, gasPerTransaction, metricsPort, nearNetworkId, nearClientValidateHeaderMode })
console.log('Starting eth2near-relay...')
await relay.run()
}
Expand Down
3 changes: 2 additions & 1 deletion cli/commands/start/ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class StartGanacheNodeCommand {
return {
ethNodeUrl: 'ws://localhost:9545',
ethMasterSk: '0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200',
nearClientValidateEthash: 'false'
nearClientValidateHeader: 'false',
nearClientValidateHeaderMode: 'ethash'
}
}
}
Expand Down
33 changes: 26 additions & 7 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
} = require('./commands/start/near2eth-relay.js')
const { StartWatchdogCommand } = require('./commands/start/watchdog.js')
const { StartGanacheNodeCommand } = require('./commands/start/ganache.js')
const { StartBinanceSmartChainNodeCommand } = require('./commands/start/binance-smart-chain.js')
const { StartLocalNearNodeCommand } = require('./commands/start/near.js')
const { AddressWatcherCommand } = require('./commands/start/address-watcher.js')
const { StopManagedProcessCommand } = require('./commands/stop/process.js')
Expand Down Expand Up @@ -93,10 +94,16 @@ RainbowConfig.declareOption(
'100000000000000000000000000'
)
RainbowConfig.declareOption(
'near-client-validate-ethash',
'Whether validate ethash of submitted eth block, should set to true on mainnet and false on PoA testnets',
'near-client-validate-header',
'Whether validate header of submitted eth block, should set to true on mainnet(s) and false on PoA testnets',
'true'
)

RainbowConfig.declareOption(
'near-client-validate-header-mode',
'Choose between ethash and bsc',
'ethash'
)
RainbowConfig.declareOption(
'hashes-gc-threshold',
'Events that happen past this threshold cannot be verified by the client.',
Expand Down Expand Up @@ -334,6 +341,16 @@ RainbowConfig.addOptions(
[]
)

RainbowConfig.addOptions(
startCommand.command('binance-smart-chain'),
StartBinanceSmartChainNodeCommand.execute,
[
'eth-node-url',
'eth-master-sk',
'near-client-validate-header'
]
)

RainbowConfig.addOptions(
startCommand.command('eth2near-relay'),
StartEth2NearRelayCommand.execute,
Expand All @@ -347,7 +364,8 @@ RainbowConfig.addOptions(
'total-submit-block',
'gas-per-transaction',
'daemon',
'metrics-port'
'metrics-port',
'near-client-validate-header-mode'
]
)

Expand Down Expand Up @@ -455,7 +473,8 @@ RainbowConfig.addOptions(
'near-client-sk',
'near-client-contract-path',
'near-client-init-balance',
'near-client-validate-ethash',
'near-client-validate-header',
'near-client-validate-header-mode',
'near-client-trusted-signer',
'hashes-gc-threshold',
'finalized-gc-threshold',
Expand Down Expand Up @@ -909,6 +928,6 @@ RainbowConfig.addOptions(
['near-node-url']
)

; (async () => {
await program.parseAsync(process.argv)
})()
; (async () => {
await program.parseAsync(process.argv)
})()
19 changes: 16 additions & 3 deletions cli/init/near-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('rainbow-bridge-eth2near-block-relay')

class InitNearContracts {
static async execute({
static async execute ({
nearMasterAccount,
nearMasterSk,
nearClientAccount,
Expand All @@ -26,7 +26,8 @@ class InitNearContracts {
nearProverInitBalance,
nearNodeUrl,
nearNetworkId,
nearClientValidateEthash,
nearClientValidateHeader,
nearClientValidateHeaderMode,
nearClientTrustedSigner,
ethNodeUrl
}) {
Expand Down Expand Up @@ -97,12 +98,24 @@ class InitNearContracts {
nearClientAccount
)
const robustWeb3 = new RobustWeb3(ethNodeUrl)

// get chain id used only by the bsc verify header.
const chainID = await robustWeb3.web3.eth.net.getId()

// check if the nearClientValidateHeaderMode is either 'ethash' or 'bsc' if not set
// 'ethash' as default
if (nearClientValidateHeaderMode !== 'ethash' && nearClientValidateHeaderMode !== 'bsc') {
nearClientValidateHeaderMode = 'ethash'
}

await clientContract.maybeInitialize(
hashesGcThreshold,
finalizedGcThreshold,
numConfirmations,
nearClientValidateEthash === 'true',
nearClientValidateHeader === 'true',
nearClientValidateHeaderMode,
nearClientTrustedSigner || null,
chainID,
robustWeb3,
nearNetworkId
)
Expand Down
Loading