omgnetwork / omg-js

JavaScript Library for communication with OMG network
Apache License 2.0
42 stars 15 forks source link

Need a better example strategy to confirm a transaction is complete. #328

Open snowkidind opened 3 years ago

snowkidind commented 3 years ago

Regarding: https://github.com/omgnetwork/omg-js/blob/master/packages/omg-js-util/src/waitForChildchainBalance.js

After playing with this in my integration I've concluded that there are a lot of problems with this, but I will bring forth a couple:

  1. If the recipient address automatically combines UTXO's it might timeout
  2. If the recipient address receives another deposit, withdraw, anything really, during the waiting period the function will timeout.

Suggested fixes:

  1. Allow for polling of pending transactions.
  2. Improve upon this strategy to handle failure cases by checking for other recent transactions, and reacting accordingly.
nicholasmueller commented 3 years ago

You should not rely on this method to wait for transaction confirmation. This helper is really there to aid in some of the testing the library does when the transactions are triggered in a controlled manner in a private chain. This would be very fragile in a public environment due to the reasons you stated.

The current approach for waiting for transaction confirmation in some of the client integrations is to poll transaction.all and wait for a known sent transaction to show up there. There is work being done on the Watcher side to have pending state returned so we don't have to rely on these kinds of workarounds. Hopefuly we can remove this function in the future for something more robust.