monorepo
monorepo copied to clipboard
[node] Weird state struct mutations
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 torpcRouter
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,
});
https://github.com/counterfactual/monorepo/pull/2060 will fix the addresses issue but the struct change issue still remains.
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 🎉