Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

refactor: simplify transfer-eth-erc20/to-near #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chadoh
Copy link

@chadoh chadoh commented Sep 8, 2020

proof_locker and proof were calculated and saved during discrete steps of the transfer process, rather than as-needed when minting. This made it hard to understand where the data was coming from and why it was being calculated while reading through the code.

Additionally, there was a fair bit of indirection and awkward code throughout. This has been cleaned up.

@chadoh chadoh requested review from Kouprin and ailisp September 8, 2020 19:04
@chadoh chadoh self-assigned this Sep 8, 2020
@chadoh chadoh force-pushed the simplify-transfer-to-near branch from faca9bc to 6a7a6b4 Compare September 8, 2020 19:08
@ailisp
Copy link
Member

ailisp commented Sep 8, 2020

Looks it doesn't pass ci:
image

@chadoh
Copy link
Author

chadoh commented Sep 8, 2020

@ailisp the signature of TransferETHERC20ToNear.mint changed. It now requires a lockedEvent, and ignores proof_locker and new_owner_id. It looks like the failing tests are not for this library itself, but in rainbow-bridge-cli, which relies on this library.

How can I update both libraries at the same time?

@ailisp
Copy link
Member

ailisp commented Sep 8, 2020

I see, yeah this is kind of tricky, this is a workflow i used:
https://github.com/near/rainbow-bridge-cli/pull/335/files#diff-04c6e90faac2675aa89e2176d2eec7d8R245

Basically you need to create two PRs, one here one rainbow-bridge-cli, this one can merge with a failed CI, and bump/republish rainbow-bridge-lib. Then in PR in rainbow-bridge-cli use new version of rainbow-bridge-lib and CI there must pass

Copy link
Member

@ailisp ailisp left a comment

Choose a reason for hiding this comment

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

Looks good, need a minor change: increase rainbow-bridge-lib version in package.json since it's an incompatible change

const blockData = await web3.eth.getBlock(block.number)
// is this necessary? how different are these?
// * robustWeb3.getBlock (the passed-in block)
// * robustWeb3.web3.eth.getBlock
Copy link
Author

Choose a reason for hiding this comment

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

@ailisp do you know the answer to this question?

Copy link
Member

Choose a reason for hiding this comment

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

web3.eth.getBlock sometimes failed and crashed because websocket disconnection. robustWeb3 is a wrapper to web3, handle websocket disconnection, reconnect and retry. We should always use robustWeb3 (some usage of web3 hasn't been replaced by robustWeb3, but that's the plan)

// Wait until client accepts this block number.
while (true) {
// @ts-ignore
const last_block_number = (
await ethOnNearClientContract.last_block_number()
).toNumber()
// Why should the client decide what's safe?
// Shouldn't MintableFungibleToken enforce this?
// And a frontend set expectations accordingly?
Copy link
Author

Choose a reason for hiding this comment

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

@ailisp and these questions? To me it seems like we should:

  • set 25 in MintableFungibleToken
  • adjust expectations accordingly here
  • never call ethOnNearClientContract.block_hash_safe

Copy link
Member

Choose a reason for hiding this comment

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

MintableFungibleToken does enforce this, so if frontend doesn't wait block_hash_safe and continue to next step(mint), it will be rejected by MintableFungibleToken. So we also wait in frontend

Copy link
Member

Choose a reason for hiding this comment

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

where is 25 comes from?

Copy link
Author

@chadoh chadoh Sep 10, 2020

Choose a reason for hiding this comment

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

25 is mentioned in the blog post introducing Bridge (https://near.org/blog/eth-near-rainbow-bridge/). I would expect it's part of MintableFungibleToken. I did not expect it to be part of EthOnNearClient, but the existence of ethOnNearClientContract.block_hash_safe indicates otherwise.

Sounds like I could get away with never calling block_hash_safe on the frontend, if the frontend makes the correct assumptions.

Copy link
Author

Choose a reason for hiding this comment

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

However, here in rainbow-bridge-lib, I think it's worth checking both

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like I could get away with never calling block_hash_safe on the frontend, if the frontend makes the correct assumptions.

Yes if contract is configured so. Need to check with @nearmax if it's really 25 in our deployment, it's probably a bigger number.

`proof_locker` and `proof` were calculated and saved during discrete
steps of the transfer process, rather than as-needed when minting. This
made it hard to understand where the data was coming from and why it was
being calculated while reading through the code.

Additionally, there was a fair bit of indirection and awkward code
throughout. This has been cleaned up.
@chadoh chadoh force-pushed the simplify-transfer-to-near branch from 6a7a6b4 to 886a928 Compare September 8, 2020 22:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants