connext / indra

[LEGACY] Monorepo containing everything related to the core Connext protocols and network.
MIT License
84 stars 38 forks source link

Link payment is redeemed before restoring state if necessary #502

Closed bohendo closed 4 years ago

bohendo commented 4 years ago

Describe the bug FYI yall I have a daicard that's broken. It's recieved a link payment and redemption fails with:

Uncaught (in promise) Error: Call to getStateChannel failed when searching for multisig address: 0x576D73C78f19F34BCC71d44bDC5e882D79f02C74. This probably means that the StateChannel does not exist yet.

This error is kinda handled but it's handled after my card tries to redeem the payment (and crashes) so it never reaches the logic branch that'll fix it To Reproduce Steps to reproduce the behavior:

  1. Rm or corrupt or upgrade state channel stuff in local storage
  2. Try to redeem a link payment
  3. refresh & watch it crash

Expected behavior State should be restored if necessary before doing that other fancy stuff at the end of the client's connect function

Your Environment

rinkeby.daicard

bohendo commented 4 years ago

And while we're at it, how about we either wait to return the channel client until the channel is available or expose a promise that'll resolve once it is.

This boiler plate is going to be required by every single connext app otherwise: https://github.com/ConnextProject/indra/blob/master/modules/daicard/src/App.js#L253

    // Wait for channel to be available
    const channelIsAvailable = async channel => {
      const chan = await channel.getChannel();
      return chan && chan.available;
    };

    while (!(await channelIsAvailable(channel))) {
      await new Promise(res => setTimeout(() => res(), 1000));
    }
bohendo commented 4 years ago

Better would be:

const channel = await connext.connect(config)
await channel.isReady()