Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

[node] Weird state struct mutations #2059

Open
LayneHaber opened this issue Jul 29, 2019 · 2 comments
Open

[node] Weird state struct mutations #2059

LayneHaber opened this issue Jul 29, 2019 · 2 comments

Comments

@LayneHaber
Copy link
Collaborator

LayneHaber commented Jul 29, 2019

When creating a payment via the UnidirectionalTransferApp, the app successfully installs, updates, and uninstalls. However, on uninstall the recipient's freeBalance does not correctly increment.

After installing, I get the following result from calling getAppState:

{
  "state": {
    "finalized": false,
    "stage": 0,
    "transfers": [
      {
        "amount": "10000000000000000",
        "to": "0xDd03b9De95078c6109D46Ccb6a46357059BfA057"
      },
      {
        "amount": "0",
        "to": "0x7D745b331737765515749D5724b220C0Ac4cFA2A"
      }
    ],
    "turnNum": {
      "_hex": "0x00"
    }
  }
}

I then call takeAction twice, once to transfer the entire balance to the receiver (0 starting balance), and once to finalize the state. After these actions, I get the following response from getAppState:

{
  "state": {
    "finalized": true,
    "stage": 2,
    "transfers": [
      [
        "0xDd03b9De95078c6109D46Ccb6a46357059BfA057",
        "0"
      ],
      [
        "0xDd03b9De95078c6109D46Ccb6a46357059BfA057",
        "10000000000000000"
      ]
    ],
    "turnNum": {
      "_hex": "0x02"
    }
  }
}

Notice the second call delivers a state with the wrong structure, and drops the receiver's address 0x7D745....

Once the app is uninstalled, which does not throw an error, the sender's free balance decrements appropriately as does the hub's in its channel with the receiver. However, no balances are incremented.

Note: Balances displayed were manually converted to strings for easier to read logs.

Other helpful information for debugging:

  • actionEncoding:
tuple(
  uint8 actionType,
  uint256 amount
)
  • stateEncoding:
tuple(
  uint8 stage,
  tuple(address to, uint256 amount)[2] transfers,
  uint256 turnNum,
  bool finalized
)
  • takeAction call to rpcRouter
const actionResponse = await this.cfModule.rpcRouter.dispatch(
    jsonRpcDeserialize({
      id: Date.now(),
      jsonrpc: "2.0",
      method: NodeTypes.RpcMethodName.TAKE_ACTION,
      params: {
        action,
        appInstanceId,
      } as NodeTypes.TakeActionParams,
    }),
);
  • actions taken by client:
// send balance
await this.connext.takeAction(this.appId, {
    actionType: UnidirectionalTransferAppActionType.SEND_MONEY,
    amount,
});

// finalize state
await this.connext.takeAction(appId, {
    actionType: UnidirectionalTransferAppActionType.END_CHANNEL,
    amount: Zero,
});
@cf19drofxots
Copy link
Member

#2060 will fix the addresses issue but the struct change issue still remains.

@LayneHaber
Copy link
Collaborator Author

Results from after #2060 fix:

  • transfers object now has correct addresses in both structs, but the object is still mutating form:
app state installed: {
  "state": {
    "finalized": false,
    "stage": 0,
    "transfers": [
      {
        "amount": "10000000000000000",
        "to": "0xDd03b9De95078c6109D46Ccb6a46357059BfA057"
      },
      {
        "amount": "0",
        "to": "0x7D745b331737765515749D5724b220C0Ac4cFA2A"
      }
    ],
    "turnNum": {
      "_hex": "0x00"
    }
  }
}

app state finalized: {
  "state": {
    "finalized": true,
    "stage": 2,
    "transfers": [
      [
        "0xDd03b9De95078c6109D46Ccb6a46357059BfA057",
        "0"
      ],
      [
        "0x7D745b331737765515749D5724b220C0Ac4cFA2A",
        "10000000000000000"
      ]
    ],
    "turnNum": {
      "_hex": "0x02"
    }
  }
}
  • balances are correctly incremented after uninstalling the application 🎉

@cf19drofxots cf19drofxots changed the title [node] Receiver free balance not increasing on uninstall, weird state mutations. [node] Weird state struct mutations Jul 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants