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

Transaction fails for the last validator in native-to-erc20 mode #111

Closed
akolotov opened this issue Oct 30, 2018 · 2 comments
Closed

Transaction fails for the last validator in native-to-erc20 mode #111

akolotov opened this issue Oct 30, 2018 · 2 comments
Assignees

Comments

@akolotov
Copy link
Collaborator

Consider the following scenario:

Pre-requisites:

  1. The bridge is set up in native-to-erc20 mode
  2. There are three validators. The number of required signatures is 3.
  3. The bridge has X coins locked on the Home side and X tokens minted on the Foreign side.
  4. The account A owns Y (X>Y) tokens on the Foreign side.
  5. There is the account B which has no incoming transactions and that's why it has zero balance in the Home network. The account B has some funds in the Foreign network.

Actions:

  1. The account A sends Y tokens to the account B.
  2. The account B sends Y tokens to the Foreign Bridge address.
  3. The affirmation event it is emitted by the bridge contract, 3 validators sings the transaction with confirmation and send them to the Home network.

Results:
When the third validator's transaction included in the block, it is running out of gas.

Analysis:
Most probably all three transactions are being prepared by the validators in the same time - for the same state of the blockchain. So, when all three token bridge instances estimate the gas usage for the transaction to send the confirmation they use the same state which assumes that no confirmations are sent yet that is why gas estimation returns a value which is less than a value which could be received for the case when 2 of 3 confirmations are already sent.
Even if we increase gas limit on some value in https://github.com/poanetwork/token-bridge/blob/7069ef9fb20cf9959057737af5666915ec837787/src/sender.js#L116, it is still not enough.
It is due to the fact that value returned by gas estimation method is around 100000 gas. When the value is increased by the formula above it will be near to 125000. Whereas the transaction to unlock funds requires much more.
And the situation is even worse for the case when the account to receive funds does not exist yet - to create this account 25000 gas is required additionally.

Soluttion:
One of possible solution is to increase EXTRA_GAS_PERCENTAGE.
Another solution could be to take values from the gas consumption report and integrate them into the token bridge code to make sure that the estimated gas value is less or equal of possible maximum identified during the tests.

@akolotov
Copy link
Collaborator Author

I suggest the following solution:
At this moment we close the issue by increasing EXTRA_GAS_PERCENTAGE up to 2.0.

We create another issue in the contracts and the token bride repos to improve the functionality:

  1. Measure the gas usage for all scenarios for every bridge mode.
  2. Introduce new methods in the contracts returning maximum gas consumption. The values in the methods should be updated every time the code of the contracts is modified. Every bridge mode will return its own set of values.
  3. The token bridge will read these values when it is started. The gas consumption values read from the contracts will be used to submit corresponding transactions to the chain.

@patitonar patitonar self-assigned this Oct 31, 2018
@ghost ghost added the review label Oct 31, 2018
@akolotov
Copy link
Collaborator Author

akolotov commented Nov 6, 2018

Addressed in #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants