omni / poa-bridge

POA <-> Ethereum bridge for self transfers of POA native token to POA20 (ERC20 representation). Not supported. Use TokenBridge instead
https://github.com/poanetwork/token-bridge
GNU General Public License v3.0
79 stars 38 forks source link

Problem: nonce reuse #51

Closed yrashk closed 6 years ago

yrashk commented 6 years ago

Unfortunately, bridge will still reuse nonce very often. Specifically when trying to send more than one transaction at a time, clearly a faulty behaviour.

Solution: chain retrieving a nonce with subsequent sending of the transaction.

However, chaining these is not enough as it'll still fail.

This is happening because bridge module is polling all its components (deposit_relay, withdraw_confirm, withdraw_relay) sequentially, and some of them maybe waiting on their transactions to go through.

However, those transactions are also done as composed futures of nonce retrieval and transaction sending. This means that it is very often that first, these futures will go through the nonce acquisition process, get the same values, and then submit transactions with the same nonce.

This patch makes NonceCheck future check if the transaction failed with this specific issue of nonce reuse and effectively restarts from the beginning in that case, repeating nonce acquisition process... until it succeeeds.