diff --git a/src/fiber/channel.rs b/src/fiber/channel.rs index 6d11d2332..3ac7bc55b 100644 --- a/src/fiber/channel.rs +++ b/src/fiber/channel.rs @@ -6304,7 +6304,7 @@ impl ChannelActorState { } fn build_init_commitment_tx_signature(&self) -> Result { - let sign_ctx = self.get_sign_context(true); + let sign_ctx = self.get_sign_context(false); let x_only_aggregated_pubkey = sign_ctx.common_ctx.x_only_aggregated_pubkey(); let ([to_local_output, to_remote_output], [to_local_output_data, to_remote_output_data]) = self.build_settlement_transaction_outputs(false); @@ -6334,7 +6334,7 @@ impl ChannelActorState { &self, signature: PartialSignature, ) -> Result { - let sign_ctx = self.get_sign_context(false); + let sign_ctx = self.get_sign_context(true); let x_only_aggregated_pubkey = sign_ctx.common_ctx.x_only_aggregated_pubkey(); let ([to_local_output, to_remote_output], [to_local_output_data, to_remote_output_data]) = @@ -6823,9 +6823,9 @@ impl ChannelActorState { let mut received_fullfilled = 0; for info in pending_tlcs { if info.is_offered() { - offered_pending += info.amount; if (info.outbound_status() == OutboundTlcStatus::RemoveWaitAck - || info.outbound_status() == OutboundTlcStatus::RemoveAckConfirmed) + || info.outbound_status() == OutboundTlcStatus::RemoveAckConfirmed + || (info.outbound_status() == OutboundTlcStatus::RemoteRemoved && !for_remote)) && info .removed_reason .as_ref() @@ -6833,10 +6833,12 @@ impl ChannelActorState { .unwrap_or_default() { offered_fullfilled += info.amount; + } else { + offered_pending += info.amount; } } else { - received_pending += info.amount; - if info.inbound_status() == InboundTlcStatus::RemoveAckConfirmed + if (info.inbound_status() == InboundTlcStatus::RemoveAckConfirmed + || (info.inbound_status() == InboundTlcStatus::LocalRemoved && for_remote)) && info .removed_reason .as_ref() @@ -6844,12 +6846,16 @@ impl ChannelActorState { .unwrap_or_default() { received_fullfilled += info.amount; + } else { + received_pending += info.amount; } } } - let to_local_value = self.to_local_amount + received_fullfilled - offered_pending; - let to_remote_value = self.to_remote_amount + offered_fullfilled - received_pending; + let to_local_value = + self.to_local_amount + received_fullfilled - offered_pending - offered_fullfilled; + let to_remote_value = + self.to_remote_amount + offered_fullfilled - received_pending - received_fullfilled; let commitment_tx_fee = calculate_commitment_tx_fee(self.commitment_fee_rate, &self.funding_udt_type_script); diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/02-open-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/02-open-channel.bru index 2dea0ae56..28701a0d4 100644 --- a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/02-open-channel.bru +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/02-open-channel.bru @@ -1,5 +1,5 @@ meta { - name: Node1 open a channel to Node2 + name: Node1 open a channel to Node2 with amount 99 ckb type: http seq: 2 } @@ -23,9 +23,9 @@ body:json { "params": [ { "peer_id": "{{NODE2_PEERID}}", - "funding_amount": "0xba43b7400", + "funding_amount": "0x24e160300", "shutdown_script": { - "code_hash": "0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", + "code_hash": "0x2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c", "hash_type": "data", "args": "0x42" } @@ -41,4 +41,5 @@ assert { script:post-response { await new Promise(r => setTimeout(r, 2000)); + bru.setVar("N1N2_TEMP_CHANNEL_ID", res.body.result.temporary_channel_id); } diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-accept-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-accept-channel.bru new file mode 100644 index 000000000..bd26b4da1 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-accept-channel.bru @@ -0,0 +1,46 @@ +meta { + name: node2 accept channel + type: http + seq: 3 +} + +post { + url: {{NODE2_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": "42", + "jsonrpc": "2.0", + "method": "accept_channel", + "params": [ + { + "temporary_channel_id": "{{N1N2_TEMP_CHANNEL_ID}}", + "funding_amount": "0x1004ccb00", + "shutdown_script": { + "code_hash": "0x2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d", + "hash_type": "data", + "args": "0x42" + } + } + ] + } +} + +assert { + res.body.error: isUndefined +} + +script:post-response { + // Sleep for sometime to make sure current operation finishes before next request starts. + await new Promise(r => setTimeout(r, 1000)); + console.log("accept channel result: ", res.body); + bru.setVar("CHANNEL_ID", res.body.result.channel_id); +} diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-get-auto-accepted-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-get-auto-accepted-channel.bru deleted file mode 100644 index 1253ec256..000000000 --- a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/03-get-auto-accepted-channel.bru +++ /dev/null @@ -1,40 +0,0 @@ -meta { - name: get auto accepted channel id from Node1 - type: http - seq: 3 -} - -post { - url: {{NODE1_RPC_URL}} - body: json - auth: none -} - -headers { - Content-Type: application/json - Accept: application/json -} - -body:json { - { - "id": "42", - "jsonrpc": "2.0", - "method": "list_channels", - "params": [ - { - "peer_id": "{{NODE2_PEERID}}" - } - ] - } -} - -assert { - res.body.error: isUndefined - res.body.result.channels: isDefined -} - -script:post-response { - await new Promise(r => setTimeout(r, 2000)); - console.log(res.body.result); - bru.setVar("CHANNEL_ID", res.body.result.channels[0].channel_id); -} diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/05-node2-gen-invoice.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/05-node2-gen-invoice.bru index 8235bc169..c629c51e4 100644 --- a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/05-node2-gen-invoice.bru +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/05-node2-gen-invoice.bru @@ -22,7 +22,7 @@ body:json { "method": "new_invoice", "params": [ { - "amount": "0x5d21dba00", + "amount": "0x2dc6c0", "currency": "Fibd", "description": "test invoice generated by node2", "expiry": "0xe10", diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/07-node1-gen-invoice.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/07-node1-gen-invoice.bru index d8699eb48..541fa7a96 100644 --- a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/07-node1-gen-invoice.bru +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/07-node1-gen-invoice.bru @@ -22,7 +22,7 @@ body:json { "method": "new_invoice", "params": [ { - "amount": "0x2e90edd00", + "amount": "0x16e360", "currency": "Fibd", "description": "test invoice generated by node1", "expiry": "0xe10", diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance-node1.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance-node1.bru new file mode 100644 index 000000000..f3ae96641 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance-node1.bru @@ -0,0 +1,42 @@ +meta { + name: check balance, 0x24e160300 - 0x2dc6c0 + 0x16e360 - 0x1c7 (fee) == 0x24dff1dd9 + type: http + seq: 15 +} + +post { + url: {{CKB_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": 42, + "jsonrpc": "2.0", + "method": "get_cells_capacity", + "params": [ + { + "script": { + "code_hash": "0x2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c", + "hash_type": "data", + "args": "0x42" + }, + "script_type": "lock" + } + ] + } +} + +assert { + res.body.result.capacity: eq "0x24dff1dd9" +} + +script:post-response { + console.log("result: ", res.body); +} diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/16-check-balance-node2.bru b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/16-check-balance-node2.bru new file mode 100644 index 000000000..7f5a43bbe --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/16-check-balance-node2.bru @@ -0,0 +1,42 @@ +meta { + name: check balance, 0x1004ccb00 + 0x2dc6c0 - 0x16e360 - 0x1c7 (fee) == 0x10063ac99 + type: http + seq: 16 +} + +post { + url: {{CKB_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": 42, + "jsonrpc": "2.0", + "method": "get_cells_capacity", + "params": [ + { + "script": { + "code_hash": "0x2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d", + "hash_type": "data", + "args": "0x42" + }, + "script_type": "lock" + } + ] + } +} + +assert { + res.body.result.capacity: eq "0x10063ac99" +} + +script:post-response { + console.log("result: ", res.body); +} diff --git a/tests/bruno/e2e/watchtower/force-close-after-open-channel/02-open-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-open-channel/02-open-channel.bru index f2f0f8ff9..c426c9195 100644 --- a/tests/bruno/e2e/watchtower/force-close-after-open-channel/02-open-channel.bru +++ b/tests/bruno/e2e/watchtower/force-close-after-open-channel/02-open-channel.bru @@ -1,5 +1,5 @@ meta { - name: Node1 open a channel to Node2 + name: Node1 open a channel to Node2 with amount 99 ckb type: http seq: 2 } @@ -23,7 +23,12 @@ body:json { "params": [ { "peer_id": "{{NODE2_PEERID}}", - "funding_amount": "0xba43b7400" + "funding_amount": "0x24e160300", + "shutdown_script": { + "code_hash": "0x2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e", + "hash_type": "data", + "args": "0x42" + } } ] } @@ -36,4 +41,5 @@ assert { script:post-response { await new Promise(r => setTimeout(r, 2000)); + bru.setVar("N1N2_TEMP_CHANNEL_ID", res.body.result.temporary_channel_id); } diff --git a/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-accept-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-accept-channel.bru new file mode 100644 index 000000000..bfcbacad6 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-accept-channel.bru @@ -0,0 +1,46 @@ +meta { + name: node2 accept channel + type: http + seq: 3 +} + +post { + url: {{NODE2_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": "42", + "jsonrpc": "2.0", + "method": "accept_channel", + "params": [ + { + "temporary_channel_id": "{{N1N2_TEMP_CHANNEL_ID}}", + "funding_amount": "0x1004ccb00", + "shutdown_script": { + "code_hash": "0x2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f", + "hash_type": "data", + "args": "0x42" + } + } + ] + } +} + +assert { + res.body.error: isUndefined +} + +script:post-response { + // Sleep for sometime to make sure current operation finishes before next request starts. + await new Promise(r => setTimeout(r, 1000)); + console.log("accept channel result: ", res.body); + bru.setVar("CHANNEL_ID", res.body.result.channel_id); +} diff --git a/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-get-auto-accepted-channel.bru b/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-get-auto-accepted-channel.bru deleted file mode 100644 index 1253ec256..000000000 --- a/tests/bruno/e2e/watchtower/force-close-after-open-channel/03-get-auto-accepted-channel.bru +++ /dev/null @@ -1,40 +0,0 @@ -meta { - name: get auto accepted channel id from Node1 - type: http - seq: 3 -} - -post { - url: {{NODE1_RPC_URL}} - body: json - auth: none -} - -headers { - Content-Type: application/json - Accept: application/json -} - -body:json { - { - "id": "42", - "jsonrpc": "2.0", - "method": "list_channels", - "params": [ - { - "peer_id": "{{NODE2_PEERID}}" - } - ] - } -} - -assert { - res.body.error: isUndefined - res.body.result.channels: isDefined -} - -script:post-response { - await new Promise(r => setTimeout(r, 2000)); - console.log(res.body.result); - bru.setVar("CHANNEL_ID", res.body.result.channels[0].channel_id); -} diff --git a/tests/bruno/e2e/watchtower/force-close-after-open-channel/11-check-balance-node1.bru b/tests/bruno/e2e/watchtower/force-close-after-open-channel/11-check-balance-node1.bru new file mode 100644 index 000000000..077d6d2a0 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-open-channel/11-check-balance-node1.bru @@ -0,0 +1,42 @@ +meta { + name: check balance, 0x24e160300 - 0x1c7 (fee) == 0x24e160139 + type: http + seq: 11 +} + +post { + url: {{CKB_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": 42, + "jsonrpc": "2.0", + "method": "get_cells_capacity", + "params": [ + { + "script": { + "code_hash": "0x2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e", + "hash_type": "data", + "args": "0x42" + }, + "script_type": "lock" + } + ] + } +} + +assert { + res.body.result.capacity: eq "0x24e160139" +} + +script:post-response { + console.log("result: ", res.body); +} diff --git a/tests/bruno/e2e/watchtower/force-close-after-open-channel/12-check-balance-node2.bru b/tests/bruno/e2e/watchtower/force-close-after-open-channel/12-check-balance-node2.bru new file mode 100644 index 000000000..722629950 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close-after-open-channel/12-check-balance-node2.bru @@ -0,0 +1,42 @@ +meta { + name: check balance, 0x1004ccb00 - 0x1c7 (fee) == 0x1004cc939 + type: http + seq: 12 +} + +post { + url: {{CKB_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": 42, + "jsonrpc": "2.0", + "method": "get_cells_capacity", + "params": [ + { + "script": { + "code_hash": "0x2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f", + "hash_type": "data", + "args": "0x42" + }, + "script_type": "lock" + } + ] + } +} + +assert { + res.body.result.capacity: eq "0x1004cc939" +} + +script:post-response { + console.log("result: ", res.body); +} diff --git a/tests/bruno/e2e/watchtower/force-close/02-open-channel.bru b/tests/bruno/e2e/watchtower/force-close/02-open-channel.bru index 88deaa12b..3fbfc2c3f 100644 --- a/tests/bruno/e2e/watchtower/force-close/02-open-channel.bru +++ b/tests/bruno/e2e/watchtower/force-close/02-open-channel.bru @@ -1,5 +1,5 @@ meta { - name: Node1 open a channel to Node2 + name: Node1 open a channel to Node2 with amount 99 ckb type: http seq: 2 } @@ -23,7 +23,7 @@ body:json { "params": [ { "peer_id": "{{NODE2_PEERID}}", - "funding_amount": "0xba43b7400", + "funding_amount": "0x24e160300", "shutdown_script": { "code_hash": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", "hash_type": "data", @@ -41,4 +41,5 @@ assert { script:post-response { await new Promise(r => setTimeout(r, 2000)); + bru.setVar("N1N2_TEMP_CHANNEL_ID", res.body.result.temporary_channel_id); } diff --git a/tests/bruno/e2e/watchtower/force-close/03-accept-channel.bru b/tests/bruno/e2e/watchtower/force-close/03-accept-channel.bru new file mode 100644 index 000000000..bce369e62 --- /dev/null +++ b/tests/bruno/e2e/watchtower/force-close/03-accept-channel.bru @@ -0,0 +1,46 @@ +meta { + name: node2 accept channel + type: http + seq: 3 +} + +post { + url: {{NODE2_RPC_URL}} + body: json + auth: none +} + +headers { + Content-Type: application/json + Accept: application/json +} + +body:json { + { + "id": "42", + "jsonrpc": "2.0", + "method": "accept_channel", + "params": [ + { + "temporary_channel_id": "{{N1N2_TEMP_CHANNEL_ID}}", + "funding_amount": "0x1004ccb00", + "shutdown_script": { + "code_hash": "0x2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", + "hash_type": "data", + "args": "0x42" + } + } + ] + } +} + +assert { + res.body.error: isUndefined +} + +script:post-response { + // Sleep for sometime to make sure current operation finishes before next request starts. + await new Promise(r => setTimeout(r, 1000)); + console.log("accept channel result: ", res.body); + bru.setVar("CHANNEL_ID", res.body.result.channel_id); +} diff --git a/tests/bruno/e2e/watchtower/force-close/03-get-auto-accepted-channel.bru b/tests/bruno/e2e/watchtower/force-close/03-get-auto-accepted-channel.bru deleted file mode 100644 index 1253ec256..000000000 --- a/tests/bruno/e2e/watchtower/force-close/03-get-auto-accepted-channel.bru +++ /dev/null @@ -1,40 +0,0 @@ -meta { - name: get auto accepted channel id from Node1 - type: http - seq: 3 -} - -post { - url: {{NODE1_RPC_URL}} - body: json - auth: none -} - -headers { - Content-Type: application/json - Accept: application/json -} - -body:json { - { - "id": "42", - "jsonrpc": "2.0", - "method": "list_channels", - "params": [ - { - "peer_id": "{{NODE2_PEERID}}" - } - ] - } -} - -assert { - res.body.error: isUndefined - res.body.result.channels: isDefined -} - -script:post-response { - await new Promise(r => setTimeout(r, 2000)); - console.log(res.body.result); - bru.setVar("CHANNEL_ID", res.body.result.channels[0].channel_id); -} diff --git a/tests/bruno/e2e/watchtower/force-close/13-check-balance.bru b/tests/bruno/e2e/watchtower/force-close/13-check-balance-node1.bru similarity index 82% rename from tests/bruno/e2e/watchtower/force-close/13-check-balance.bru rename to tests/bruno/e2e/watchtower/force-close/13-check-balance-node1.bru index f0ae82619..020504070 100644 --- a/tests/bruno/e2e/watchtower/force-close/13-check-balance.bru +++ b/tests/bruno/e2e/watchtower/force-close/13-check-balance-node1.bru @@ -1,5 +1,5 @@ meta { - name: check balance, 0xba43b7400 - 0x2dc6c0 - 0x1c7 (fee) == 0xba40dab79 + name: check balance, 0x24e160300 - 0x2dc6c0 - 0x1c7 (fee) == 0x24de83a79 type: http seq: 13 } @@ -34,7 +34,7 @@ body:json { } assert { - res.body.result.capacity: eq "0xba40dab79" + res.body.result.capacity: eq "0x24de83a79" } script:post-response { diff --git a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance.bru b/tests/bruno/e2e/watchtower/force-close/14-check-balance-node2.bru similarity index 79% rename from tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance.bru rename to tests/bruno/e2e/watchtower/force-close/14-check-balance-node2.bru index 406a3fed6..f2f83d53c 100644 --- a/tests/bruno/e2e/watchtower/force-close-after-multiple-payments/15-check-balance.bru +++ b/tests/bruno/e2e/watchtower/force-close/14-check-balance-node2.bru @@ -1,7 +1,7 @@ meta { - name: check balance, 0xba43b7400 - 0x5d21dba00 + 0x2e90edd00 - 0x1c7 (fee) = 0x8bb2c9539 + name: check balance, 0x1004ccb00 + 0x2dc6c0 - 0x1c7 (fee) == 0x1007a8ff9 type: http - seq: 15 + seq: 14 } post { @@ -34,7 +34,7 @@ body:json { } assert { - res.body.result.capacity: eq "0x8bb2c9539" + res.body.result.capacity: eq "0x1007a8ff9" } script:post-response {