Why my State Channel didn't go further with JSON-RPC?

I used websocket client to build my state channel(ROMA 1.4 in Ubuntu 18.04 which is running in Virtualbox with NAT network, host is Windows 10 Home in Thinkpad X280 8G RAM, i5 CPU), following the instructions:https://github.com/aeternity/protocol/blob/master/node/api/examples/aehttp_integration_SUITE/json-rpc/channel_websocket.basic_open_close.md

Everything worked fine at the beginning, but did not return channel id which is listed here:

https://github.com/aeternity/protocol/blob/master/node/api/examples/aehttp_integration_SUITE/json-rpc/channel_websocket.basic_open_close.md#responder-----2018-10-24-125314397

The event "event": "own_funding_locked" didn’t happen.

And can not use the method channels.update.new to transfer, just no response. Anything wrong with my json data?

My initiator console log:
Press Ctrl+C to stop. Start success.

  1. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:null,“data”:{“event”:“channel_accept”}},“version”:1}
  2. <: {“jsonrpc”:“2.0”,“method”:“channels.sign.initiator_sign”,“params”:{“channel_id”:null,“data”:{“tx”:“tx_+HUyAaEBlH/aXhLUvUIyJDf/2pcqQhmgP7u6eh+bMD0rlZ5dgP6CAryhAYwtD6vGcEx6vNpPAA6v7kAJUl0sqbDtG3PdZdMFqKnrggGQAgoAgk4gwKATOTvNIiN9LYhe7q4MbRo8Orr6SU0YDXc7aP1iTe7kTEMP/rSd”}},“version”:1}
  3. {“jsonrpc”: “2.0”, “method”: “channels.initiator_sign”, “params”: {“tx”: “tx_+L8LAfhCuEA/wLjsmPwuezkNa3wp3Mp/wE17ZmsIFgdRUb9z1Llr7L8h79Hm2dHRhp0ga85ikKTdpLm+rSuGHG+D+iqi/gkDuHf4dTIBoQGUf9peEtS9QjIkN//alypCGaA/u7p6H5swPSuVnl2A/oICvKEBjC0Pq8ZwTHq82k8ADq/uQAlSXSypsO0bc91l0wWoqeuCAZACCgCCTiDAoBM5O80iI30tiF7urgxtGjw6uvpJTRgNdzto/WJN7uRMQzC6kUo=”}}

  4. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:null,“data”:{“event”:“funding_signed”}},“version”:1}
  5. <: {“jsonrpc”:“2.0”,“method”:“channels.on_chain_tx”,“params”:{“channel_id”:null,“data”:{“tx”:“tx_+QEBCwH4hLhAP8C47Jj8Lns5DWt8KdzKf8BNe2ZrCBYHUVG/c9S5a+y/Ie/R5tnR0YadIGvOYpCk3aS5vq0rhhxvg/oqov4JA7hAdXUEdAY75q3cZgkSke4MW8L0fidfJ45Ow4xhSi8GrMhn73ijGSLZGICEyIjhmU8MR8TZiAqL4E00B6qt3pmRDbh3+HUyAaEBlH/aXhLUvUIyJDf/2pcqQhmgP7u6eh+bMD0rlZ5dgP6CAryhAYwtD6vGcEx6vNpPAA6v7kAJUl0sqbDtG3PdZdMFqKnrggGQAgoAgk4gwKATOTvNIiN9LYhe7q4MbRo8Orr6SU0YDXc7aP1iTe7kTEMZUqhH”}},“version”:1}
  6. {“id”:-576460752303423482,“jsonrpc”: “2.0”,“method”:“channels.get.balances”,“params”: {“accounts”: [“ak_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh”,“ak_24jcHLTZQfsou7NvomRJ1hKEnjyNqbYSq2Az7DmyrAyUHPq8uR” ]}}

  7. <: {“channel_id”:null,“id”:-576460752303423482,“jsonrpc”:“2.0”,“result”:[{“account”:“ak_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh”,“balance”:699},{“account”:“ak_24jcHLTZQfsou7NvomRJ1hKEnjyNqbYSq2Az7DmyrAyUHPq8uR”,“balance”:401}],“version”:1}
  8. connection closed

My responder console log:
Press Ctrl+C to stop. Start success.

  1. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:null,“data”:{“event”:“channel_open”}},“version”:1}
  2. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:null,“data”:{“event”:“funding_created”}},“version”:1}
  3. <: {“jsonrpc”:“2.0”,“method”:“channels.sign.responder_sign”,“params”:{“channel_id”:null,“data”:{“tx”:“tx_+HUyAaEBlH/aXhLUvUIyJDf/2pcqQhmgP7u6eh+bMD0rlZ5dgP6CAryhAYwtD6vGcEx6vNpPAA6v7kAJUl0sqbDtG3PdZdMFqKnrggGQAgoAgk4gwKATOTvNIiN9LYhe7q4MbRo8Orr6SU0YDXc7aP1iTe7kTEMP/rSd”}},“version”:1}
  4. {“jsonrpc”: “2.0”, “method”: “channels.responder_sign”, “params”: {“tx”: “tx_+L8LAfhCuEB1dQR0BjvmrdxmCRKR7gxbwvR+J18njk7DjGFKLwasyGfveKMZItkYgITIiOGZTwxHxNmICovgTTQHqq3emZENuHf4dTIBoQGUf9peEtS9QjIkN//alypCGaA/u7p6H5swPSuVnl2A/oICvKEBjC0Pq8ZwTHq82k8ADq/uQAlSXSypsO0bc91l0wWoqeuCAZACCgCCTiDAoBM5O80iI30tiF7urgxtGjw6uvpJTRgNdzto/WJN7uRMQ4Q9RMg=”}}

  5. <: {“jsonrpc”:“2.0”,“method”:“channels.on_chain_tx”,“params”:{“channel_id”:null,“data”:{“tx”:“tx_+QEBCwH4hLhAP8C47Jj8Lns5DWt8KdzKf8BNe2ZrCBYHUVG/c9S5a+y/Ie/R5tnR0YadIGvOYpCk3aS5vq0rhhxvg/oqov4JA7hAdXUEdAY75q3cZgkSke4MW8L0fidfJ45Ow4xhSi8GrMhn73ijGSLZGICEyIjhmU8MR8TZiAqL4E00B6qt3pmRDbh3+HUyAaEBlH/aXhLUvUIyJDf/2pcqQhmgP7u6eh+bMD0rlZ5dgP6CAryhAYwtD6vGcEx6vNpPAA6v7kAJUl0sqbDtG3PdZdMFqKnrggGQAgoAgk4gwKATOTvNIiN9LYhe7q4MbRo8Orr6SU0YDXc7aP1iTe7kTEMZUqhH”}},“version”:1}
  6. connection closed

Hi @LiuYang.chain,
This might be a bit difficult to explain as it touches a lot of different subjects, so bear with me as we go deep in the rabbit whole.

From your nice log, I see that the co-signed transaction produced for you by the node was reportedly sent to miners to mine. We will refer to it later on.

I’ve decoded this, so it is human readable and the create tx looks like this:

{  
    "channel_reserve":2,
    "delegate_ids":[],
    "fee":20000,
    "initiator_amount":700,
    "initiator_id":"ak_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh",
    "lock_period":10,
    "nonce":67,
    "responder_amount":400,
    "responder_id":"ak_24jcHLTZQfsou7NvomRJ1hKEnjyNqbYSq2Az7DmyrAyUHPq8uR",
    "state_hash":"st_Ezk7zSIjfS2IXu6uDG0aPDq6+klNGA13O2j9Yk3u5Eyu2Gti",
    "type":"ChannelCreateTx",
    "version":1
}

It has a transaction hash of th_2UvKb5H1ZAyfhmTmk2CnTUxj7TiarGPLEGXvri9UfJtagbUuiX and it had been included in a block - link to AEKnow. This means that what the on-chain is concerned the channel had been succesfully opened :slight_smile:

Now I guess we shall discuss how does our implementation of channels work. Let’s have an Ingrid-Robert interaction - they want to open a channel. Ingrid will be the initator and Robert - the responder. They prenegotiate some opening conditions which include Robert’s exposed port Ingrid’s node can connect to. Then they open an encrypted connection with those params. In your case this had happened succesfully. Ingrid prepares a channel_create_tx locally, executes it to produce the initial state_hash, signs it and sends it to Robert to co-sign it. After receiving it co-signed, Ingrid broadcasts it to the network so it can be included in a block. After this happens, both participants are informed for it with a message with method being channels.on_chain_tx and the channel create tx in the payload. This is part of your logs and everything looks great.

After that both nodes start sniffing for this transaction’s inclusion on-chain and then - waiting for a certain amount of confirmations. Idea is that participants (Ingrid and Robert) are sure that the transaction has enough confirmations and it does not end on a fork. The amount of key-block confirmations is defined in the opening transaction: "lock_period":10 - that would mean that you’re clients are not to receive the own_funding_locked event soon - it will require ~ 30 minutes.

Then comes the timeouts thingy :slight_smile: The node will not wait for this transaction forever, it has a predefined time interval to do so and if the event does not happen - it considers it timouted. This is poorly defined as timeouts parameter in the channel opening. While not clearly documented, those timeouts have default values. For example the timeout parameter you are looking for is called timeout_funding_lock and it has a default value of 6 minutes. So if the funding is not locked in 6 minutes - the channel is considered not created and the handlers that persist the connection die :slight_smile: What I suggest is you either:

  1. Use a lower lock_period, for test purpouses this could be as low as 0, meaning that no keyblock confirmations are needed, the channel_create_tx shall be just included in a microblock (that could later on end up in a micro-fork as well)
  2. Open the channel with a higher timeout_funding_lock. If go down this path, keep in mind that the amount provided is in milliseconds. So timeout_funding_lock=2400000 would be 40 minutes.

PS One thing that I did notice is amounts dedicated to the channel - 700 + 400, so the total channel amount is 1100 aettos. Since a regular channel_close_mutual_tx requires somewhere around 20 000 aettos, those amounts will be quite unsufficant to close the channel with a mutual agreement as the amounts will not be enough to cover the fee :slight_smile: In close mutual transaction it is the channel that pays the fee and participants redistribute the rest amongst themselves in a manner they feel fair.

3 Likes

Thanks so so much for the details!

I need time to understand them all~wait for my good news!

1 Like

@LiuYang.chain if I haven’t explained anything clear enough - please do not hesitate asking :slight_smile: If something is not clear enough - it will be as well for everyone so asking acually helps all of us :slight_smile:

OK!
Thanks so much for your patience!

1 Like

这开发我服了,他回答问题都很详细。赞一个,看了你们的对话,大概出问题就是 锁定资金需要10个块来确认,锁定资金也有个超时参数6分钟,没收到资金锁定的事件就超时了。刘博踩坑了:grin:

1 Like

嗯,防不胜防的坑。。。回头改进下。
最后一个山头!

Finally!

Thanks very much @dimitar.chain!

I’ll dig deeper tomorrow~

  1. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:null,“data”:{“event”:“own_funding_locked”}},“version”:1}
  2. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:“ch_V2NqPj25Lz5bfehVnxVGAjL1PHN5fUJ9i2KLZiGmowUNR4zq”,“data”:{“event”:“funding_locked”}},“version”:1}
  3. <: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:“ch_V2NqPj25Lz5bfehVnxVGAjL1PHN5fUJ9i2KLZiGmowUNR4zq”,“data”:{“event”:“open”}},“version”:1}
  4. <: {“jsonrpc”:“2.0”,“method”:“channels.update”,“params”:{“channel_id”:“ch_V2NqPj25Lz5bfehVnxVGAjL1PHN5fUJ9i2KLZiGmowUNR4zq”,“data”:{“state”:“tx_+QECCwH4hLhAWsC9xbCBZOYuLg+DofbYpzTegs/MUsrZyzOMqQsFXISU/ajdXWnBV+NM1s6Eznnpn8wbkxBKFu+l91jqVPBpB7hAj2ljA6A/UzPeqnszp+vc/morEBLW77Hn/UQTrK4amkuEZeBNZ0ZQ7Vksv+TRrsbHaihlXCiycCe/zZ80cLEWBrh4+HYyAaEBlH/aXhLUvUIyJDf/2pcqQhmgP7u6eh+bMD0rlZ5dgP6DARFwoQGMLQ+rxnBMerzaTwAOr+5ACVJdLKmw7Rtz3WXTBaip64KcQAIBAIJOIMCgvXMuTfUwXzqeVLLdraAoyPy6rEo5g4PJWaaiMl5D8DZqRfh9UQ==”}},“version”:1}
  5. …<: {“jsonrpc”:“2.0”,“method”:“channels.info”,“params”:{“channel_id”:“ch_V2NqPj25Lz5bfehVnxVGAjL1PHN5fUJ9i2KLZiGmowUNR4zq”,“data”:{“event”:“died”}},“version”:1}
  6. connection closed