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

Rainbow on Binance Smart Chain #604

merged 4 commits into from
Aug 26, 2021

Conversation

3alpha
Copy link

@3alpha 3alpha commented Jul 1, 2021

New BSC Feature

The new BSC feature allows Rainbow bridge to run on Binance Smart Chain.

Technical

When the Bridge is configured to use bsc mode, the first header has to be an epoch header (block_number%200==0). That is because the epoch header contains the validator set inside the extra_data field. After that, bridge starts to receive and validate the other blocks. If current block at the time of starting the bridge isn't the epoch block, bridge gets initialised at previous epoch block.
Every time Near client gets a new epoch header it saves it and uses the new validator set from it.

New Configurations:

The Bridge handles POW(ethash), POSA(bsc), or POA, by default the POW is used.

To use bsc:

    nearClientValidateHeader: 'true',
    nearClientValidateHeaderMode: 'bsc'

and to use ethash:

    nearClientValidateHeader: 'true',
    nearClientValidateHeaderMode: 'ethash'

here is an example of the new config file ~/.rainbow/config.json:

    {
        "nearNodeUrl": "http://localhost:3030",
        "nearNetworkId": "local",
        "nearMasterAccount": "node0",
        "nearMasterSk": "ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP",
        "ethNodeUrl": "https://data-seed-prebsc-1-s1.binance.org:8545",
        "ethMasterSk": "0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200",
        "nearClientValidateHeader": "true", 
        "nearClientValidateHeaderMode": "bsc",
        "nearClientSk": "ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP",
        "nearProverSk": "ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP",
        "ethEd25519Address": "0x62ff99964d1026bfd3fea2086b9d141917f1a793",
        "ethClientLockEthAmount": "1000",
        "ethClientLockDuration": "10",
        "ethClientAddress": "0x2cdaaa435937ae65705b97fbd01d28f4f6494545",
        "ethProverAddress": "0x5cdc96ce31bdf08ef39d5f65a9fd5e236ce2245f",
        "ethErc20Address": "0x7ef88a3901494435700ccc4c7615903b43ec2dbc",
        "ethLockerAddress": "0x24d718f7d8af7d7a4abaa2b1cb7abbb36a23a00d",
        "ethAdminAddress": "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"
    }

Deploy the bridge locally with BSC Mode

To run the bridge locally with Binance Smart Chain, run the following cmd:

  1. init yarn and generate Ethereum contracts:
make init
  1. Start Near blockchain and connect with Binance testnet.
make start-bsc
  1. Deploy Near and Ethereum contracts
make full-bsc-contracts

or use already deployed contracts (on BSC), first copy past the following parameters inside the ~/.rainbow/config.json file:

    "ethEd25519Address": "0x62ff99964d1026bfd3fea2086b9d141917f1a793",
    "ethClientLockEthAmount": "1000",
    "ethClientLockDuration": "10",
    "ethClientAddress": "0x2cdaaa435937ae65705b97fbd01d28f4f6494545",
    "ethProverAddress": "0x5cdc96ce31bdf08ef39d5f65a9fd5e236ce2245f",
    "ethErc20Address": "0x7ef88a3901494435700ccc4c7615903b43ec2dbc",
    "ethLockerAddress": "0x24d718f7d8af7d7a4abaa2b1cb7abbb36a23a00d",
    "ethAdminAddress": "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"

then run the following command:

make light-bsc-contracts
  1. Start the relayers:
make start-relayer
  1. When you are done you can stop the bridge by running:
make stop-all
  • The bridge uses pm2 tool so you can use it to check logs and list the processes

Copy link
Contributor

@mfornet mfornet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now only reviewed the code affecting the previous setup, will continue reviewing the code introducing the new feature next. I'm making this checkpoint to leave some comments.

cli/commands/start/binance-smart-chain.js Outdated Show resolved Hide resolved
cli/commands/start/binance-smart-chain.js Outdated Show resolved Hide resolved
cli/commands/start/binance-smart-chain.js Outdated Show resolved Hide resolved
contracts/near/eth-client/src/lib.rs Outdated Show resolved Hide resolved
contracts/near/eth-client/src/lib.rs Outdated Show resolved Hide resolved
contracts/near/eth-client/src/lib.rs Outdated Show resolved Hide resolved
contracts/near/eth-client/src/lib.rs Outdated Show resolved Hide resolved
400_000 / 30000,
vec![blocks_with_proofs.first().unwrap().merkle_root],
blocks[0].clone(),
30,
10,
10,
None,
97,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use named ChainId here, to be clear what this number actually means. In this case since we are using ethash let's use chain_id 3, though it is not used anywhere so it makes no real difference.

Just as a note for other reviewing this PR I found a list of chain id from networks supporting EVM: Chainlist.

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

.PHONY: help init yarn-init gen-contracts start-bsc full-bsc-contracts light-bsc-contracts start-relayer stop-all build-eth-client test-eth-client start-ethash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the Makefile, it is a really helpful addition. 🎉

Copy link
Contributor

@mfornet mfornet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract LGTM.

For the BSC code in the client I think we should use rust feature flags so only the intended binary is compiled and deployed.

self.headers.get(&self.epoch_header).unwrap()
}

// check if the auther address is valid and is in the validator set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// check if the auther address is valid and is in the validator set.
// check if the author address is valid and is in the validator set.

[extra_vanity..(epoch_header.extra_data.len() - extra_seal)]
.to_vec();

// Get validator offset postion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Get validator offset postion.
// Get validator offset position.

return true;
}

// verift basic header properties.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// verift basic header properties.
// verify basic header properties.

@mfornet mfornet self-requested a review August 7, 2021 02:01
Copy link
Contributor

@mfornet mfornet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflicts needs to be solved before merging.

@idirall22
Copy link

Hello @mfornet @abacabadabacaba
The conflicts are solved the fork is ready to be merged.

@mfornet
Copy link
Contributor

mfornet commented Aug 18, 2021

@sept-en could you take a look at this PR before merging.

@sept-en sept-en self-requested a review August 19, 2021 01:23
@mfornet mfornet changed the base branch from master to bsc August 26, 2021 22:07
@mfornet
Copy link
Contributor

mfornet commented Aug 26, 2021

I discussed with @sept-en and agreed on merge it to bsc branch for now!

@mfornet mfornet merged commit 8953a6c into Near-One:bsc Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants