Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liquid: ct discount #304

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

liquid: ct discount #304

wants to merge 4 commits into from

Conversation

YusukeShimizu
Copy link
Contributor

@YusukeShimizu YusukeShimizu commented Aug 2, 2024

elements releases have the mempool policy patch.
To apply ct discount on peerswap, we uses an "Ask forgiveness not permission" approach, where we attempt to broadcast with the discounted fee, and if that fails, we retry with the non-discounted fee.

The discount is achieved by calculating the fee based on a discounted vsize(equivalent to 1/4 of the original tx size).

https://github.com/ElementsProject/elements/releases/tag/elements-23.2.2

@YusukeShimizu YusukeShimizu marked this pull request as draft August 2, 2024 09:09
@YusukeShimizu YusukeShimizu changed the title liquid: drop the flat fee for mempool policy patch liquid: ct discount Aug 20, 2024
@YusukeShimizu YusukeShimizu force-pushed the ct-discount branch 4 times, most recently from d53b5af to 6ff417c Compare August 21, 2024 00:51
@YusukeShimizu
Copy link
Contributor Author

YusukeShimizu commented Aug 21, 2024

Observations

log ## lwk ### CT discount disabled
./bin/pscli peerswap1 listswaps
{
  "swaps":  [
    {
      "id":  "e9e20a40740fd0526d039ea2e63f80a412521a1d0ebc329cb16174561412ae7c",
      "created_at":  "1724205066",
      "asset":  "lbtc",
      "type":  "swap-out",
      "role":  "sender",
      "state":  "State_ClaimedPreimage",
      "initiator_node_id":  "02a83a702e5de47ee26e22af40f6a9c80b66e4d3d1097954c95239ac4c86837f6c",
      "peer_node_id":  "030bc3217c0a1aa8c63a4e2b891152180ca24de8722b49602ae975699c831fc7aa",
      "amount":  "1000000",
      "channel_id":  "116:1:1",
      "opening_tx_id":  "8956084b56cd6ffa9b8ffd93ef3e26b68d2ffa06fc17a5455899cbcc220f3e94",
      "claim_tx_id":  "71a026a6c8b5490c234393d840850cb5cb3e77fed56162a1066b63282b4b884a",
      "cancel_message":  "",
      "lnd_chan_id":  "127543348887553"
    }
  ]
}
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction 8956084b56cd6ffa9b8ffd93ef3e26b68d2ffa06fc17a5455899cbcc220f3e94 true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .10 sat/vB
Fee: 251.0000000000 sat
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction 71a026a6c8b5490c234393d840850cb5cb3e77fed56162a1066b63282b4b884a true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .10 sat/vB
Fee: 135.0000000000 sat

CT discount enabled (acceptdiscountct=1, creatediscountct=1)

./bin/pscli peerswap1 listswaps
{
  "swaps":  [
    {
      "id":  "7a0dc61c5ed005b70464b697c42ccfee75e892c42008a89874aedab6ac2640ef",
      "created_at":  "1724205348",
      "asset":  "lbtc",
      "type":  "swap-out",
      "role":  "sender",
      "state":  "State_ClaimedPreimage",
      "initiator_node_id":  "03ba550c3ce73929457fe0f922d70f8826c08f34fd5ee18911f8100e08747d438c",
      "peer_node_id":  "03afeb34a773e610ee7c7b8d1f2404644a7334dd3408338293cc5718a7c63b3113",
      "amount":  "1000000",
      "channel_id":  "116:1:1",
      "opening_tx_id":  "d88af0cc81b112c5ea3f8bcc5b949e63feece092cb24d46469ed6096d281e84a",
      "claim_tx_id":  "9aca63d63dd4b1a24afe694da08b26882bf88de58c4cd8ea96f284046750b934",
      "cancel_message":  "",
      "lnd_chan_id":  "127543348887553"
    }
  ]
}
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction d88af0cc81b112c5ea3f8bcc5b949e63feece092cb24d46469ed6096d281e84a true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .10 sat/vB
Fee: 251.0000000000 sat
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction 9aca63d63dd4b1a24afe694da08b26882bf88de58c4cd8ea96f284046750b934 true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .02 sat/vB
Fee: 33.0000000000 sat

liquid

CT discount disabled

./bin/pscli peerswap1 listswaps
{
  "swaps":  [
    {
      "id":  "3ffa01b929572ed84a680e9174843a7242f8749682740077fbc6b6f009fd0735",
      "created_at":  "1724217608",
      "asset":  "lbtc",
      "type":  "swap-out",
      "role":  "sender",
      "state":  "State_ClaimedPreimage",
      "initiator_node_id":  "022c258412a47ad40aee3dc986a8341a28bff86bdcd1ed01aee253b9af58e8ec09",
      "peer_node_id":  "02cbf985fcb9d54d65a77bdd10ea11f932508c1a1c2eca7691b43213e2756f79fc",
      "amount":  "1000000",
      "channel_id":  "110:1:1",
      "opening_tx_id":  "ffad8ef755740488087beccf11f61f6eb966b0431079ee0e87284341de9e1c28",
      "claim_tx_id":  "ac452246c1caf4dd04a72b85bae57fcd696f681b06fae1eaffb642341d1a5ed6",
      "cancel_message":  "",
      "lnd_chan_id":  "120946279120897"
    }
  ]
}
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction ffad8ef755740488087beccf11f61f6eb966b0431079ee0e87284341de9e1c28 true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .10 sat/vB
Fee: 248.0000000000 sat

CT discount enabled (acceptdiscountct=1, creatediscountct=1)

./bin/pscli peerswap1 listswaps
{
  "swaps":  [
    {
      "id":  "af4ea2bbc89ed256f5d5bf08882860825239b205d588866a9cc6ec9b6152cee2",
      "created_at":  "1724207197",
      "asset":  "lbtc",
      "type":  "swap-out",
      "role":  "sender",
      "state":  "State_ClaimedPreimage",
      "initiator_node_id":  "02e02ebe7cf636f346c77d4f8427553cf73bc8c71f74b6dca60aca1016e78cdf61",
      "peer_node_id":  "0269081b618447d0a08680cb987b3ec7bb2907cfeb4f8f14d6a0cd2a853589a304",
      "amount":  "1000000",
      "channel_id":  "110:1:1",
      "opening_tx_id":  "e984679d7f929d6f1676ad678f5134db7847432060a6f7e5028efe8a21bc1bbb",
      "claim_tx_id":  "6fc74f0cbd12e9546e00e189073318f54e5fe940b4338249df83bb44976c35c6",
      "cancel_message":  "",
      "lnd_chan_id":  "120946279120897"
    }
  ]
}
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction e984679d7f929d6f1676ad678f5134db7847432060a6f7e5028efe8a21bc1bbb true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .01 sat/vB
Fee: 33.0000000000 sat
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction 6fc74f0cbd12e9546e00e189073318f54e5fe940b4338249df83bb44976c35c6 true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .02 sat/vB
Fee: 33.0000000000 sat

@Impa10r
Copy link
Contributor

Impa10r commented Aug 21, 2024

Testing it on liquidtestnet with Elements 23.2.2. Swap out does not work when swapAmount == PeerLBTCbalance - 75:

Initiator log:

2024/08/21 15:40:46 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] Start new swap-out: peer: 020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854 chanId: 2543197:37:1 initiator: 02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29 amount 662891
2024/08/21 15:40:51 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] Paid Feeinvoice of 75 sats
2024/08/21 15:40:51 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] Swap canceled. Reason: -4:Insufficient funds
2024/08/21 15:40:51 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] Warning: Paid swap-out prepayment, but swap canceled before receiving opening transaction

Receiver log:

2024/08/21 15:40:47 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] swap-out request received: peer: 02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29 chanId: 2543197:37:1 initiator: 02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29 amount 662891
2024/08/21 15:40:51 [INFO] [FSM] Action failure -4:Insufficient funds
2024/08/21 15:40:51 [INFO] [Swap:8b8420769aa12f288366b2057590903aa9498f7ffe5e9317a5fb17f726ac6107] Swap canceled. Reason: -4:Insufficient funds

PeerLBTCbalance -100 and -150 also did not work. -200 worked, but caused the recipient pay an excessive opening fee of 200. Cannot find what returns the Insufficient funds error.

@grubles
Copy link
Collaborator

grubles commented Aug 21, 2024

LND as LBTC swap-out sender results in:

2024/08/21 15:48:43 rpc error: code = Unknown desc = Fee is too damn high. Max expected: 225 Received 300
2024/08/21 19:48:42 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_OnSwapOutStarted on 
2024/08/21 19:48:42 [INFO] [Swap:a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d] Start new swap-out: peer: 036e680823a129ac9a2eeb8c43514a5b6cb09ae28e3e698a0e34aaa8865d6cc344 chanId: 194668:21:0 initiator: 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923 amount 100000000
2024/08/21 19:48:42 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_ActionSucceeded on State_SwapOutSender_CreateSwap
2024/08/21 19:48:42 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_ActionSucceeded on State_SwapOutSender_SendRequest
2024/08/21 19:48:42 [DEBUG] [Messenger] From: 036e680823a129ac9a2eeb8c43514a5b6cb09ae28e3e698a0e34aaa8865d6cc344 got msgtype: a45b for swap: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d
2024/08/21 19:48:42 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_OnFeeInvoiceReceived on State_SwapOutSender_AwaitAgreement
2024/08/21 19:48:43 [INFO] [FSM] Action failure Fee is too damn high. Max expected: 225 Received 300
2024/08/21 19:48:43 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_ActionFailed on State_SwapOutSender_PayFeeInvoice
2024/08/21 19:48:43 [DEBUG] [FSM] Canceling because of Fee is too damn high. Max expected: 225 Received 300
2024/08/21 19:48:43 [DEBUG] [FSM] event:id: a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d, Event_ActionSucceeded on State_SendCancel
2024/08/21 19:48:43 [INFO] [Swap:a8099a5544b6745f725a726c86af81b074e73ad2681449370dd766b81dd3894d] Swap canceled. Reason: Fee is too damn high. Max expected: 225 Received 300

@YusukeShimizu
Copy link
Contributor Author

#304 (comment)

Thank you for your confirmation.
It seems that the issue is caused by elements itself.
The Insufficient funds errors occur when the fee falls below a certain value (200 satoshis, as far as I can tell).
It is possible that the CT discount is not being taken into account.

Normally, the CT discount is applied

./bin/elements-cli -rpcwallet=peerswap1 getbalance
{
  "bitcoin": 10.00000000
}
./bin/elements-cli -rpcwallet=peerswap1 sendtoaddress "el1qqwk83ycg9lwrlj8ccvar3n62xak8rkyxvk20w63p2f40jx8k2244yvxgawe30l9glsj5835nwcj5xnz0st65knhtcs3se2xt6" 9
267a5cf0c22515811f7a9f3acc0248b5ddfa21afdb2ec701c61ddecc623a48fc
./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction 267a5cf0c22515811f7a9f3acc0248b5ddfa21afdb2ec701c61ddecc623a48fc true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: .01 sat/vB
Fee: 32.0000000000 sat

However, Insufficient funds occurs when trying to send almost the entire balance

Even though the balance should be sufficient with the CT discount, an error occurs.

./bin/elements-cli -rpcwallet=peerswap1 getbalance
{
  "bitcoin": 10.00000000
}

Subtract 100 sat

./bin/elements-cli -rpcwallet=peerswap1 getbalance | jq '.bitcoin | tonumber | (. * 100000000 - 100) / 100000000'
9.999999
./bin/elements-cli -rpcwallet=peerswap1 sendtoaddress "el1qq0phvvcs6r4td0hlhs8rgjrghz368k4w33trkxjtlmu9ltylum0p6gekdtvs6af69hca2hsj4tf42wf6z76nunctzxnupq47f" 9.999999
error code: -6
error message:
Insufficient funds

However, if you leave about 200 satoshis in the balance, the transfer succeeds, and the entire amount becomes the fee.

./bin/elements-cli -rpcwallet=peerswap1 sendtoaddress "el1qq0phvvcs6r4td0hlhs8rgjrghz368k4w33trkxjtlmu9ltylum0p6gekdtvs6af69hca2hsj4tf42wf6z76nunctzxnupq47f" 9.999998
a2c3d15bb91b77b8923afbc03dab9f85895f56f82d1e21a7a2781639cfa7ef17

./bin/elements-cli -rpcwallet=peerswap1 getrawtransaction a2c3d15bb91b77b8923afbc03dab9f85895f56f82d1e21a7a2781639cfa7ef17 true | jq -r '.vsize, .fee["5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"]' | {
read -r vsize
read -r fee

fee=$(printf "%.10f" "$fee")

fee_satoshi=$(echo "$fee * 100000000" | bc)
feerate=$(echo "scale=2; $fee_satoshi / $vsize" | bc)

echo "Fee Rate: $feerate sat/vB"
echo "Fee: $fee_satoshi sat"
}
Fee Rate: 1.23 sat/vB
Fee: 200.0000000000 sat

This behavior seems to result in unnecessary losses.
It might be necessary to consider the CT discount when determining Insufficient funds.

@YusukeShimizu
Copy link
Contributor Author

YusukeShimizu commented Aug 22, 2024

#304 (comment)

Thank you for your feedback.
It's likely that this issue is occurring because the peer doesn't support CT discounts.

In the peerswap implementation, when a swapout request is received, the amount of the fee invoice is verified.
We calculate three times the expectedFee (normal transaction fee) and set this as the maximum acceptable fee. (We allow some margin to account for situations where the fee might be higher than usual due to network congestion, etc.)
In this case, the error is occurring because the fee exceeds 225 sat (75 sat * 3), which is three times the expected fee assuming the CT discount is applied.

In this PR, I modified the calculation of expectedFee to assume a CT discount.
This is a conservative approach because we cannot be sure if the connected peer supports CT discounts or not.

However, I've noticed that this is causing frequent failures like this.
I'll investigate the appropriate specifications to address this.

@Impa10r
Copy link
Contributor

Impa10r commented Aug 22, 2024

Thanks, I reported this bug on Elements github, but I think they will tell us to use subtractfeefromamount flag. This is a cleaner solution regardless. Can we implement it?

@grubles
Copy link
Collaborator

grubles commented Aug 22, 2024

In this PR, I modified the calculation of expectedFee to assume a CT discount. This is a conservative approach because we cannot be sure if the connected peer supports CT discounts or not.

However, I've noticed that this is causing frequent failures like this. I'll investigate the appropriate specifications to address this.

In this case, both peers are running PR 304 and using the same elementsd configured to use the CT discount.

@YusukeShimizu
Copy link
Contributor Author

#304 (comment)

I think it's a good idea.
However, the issue is whether the same interface can be provided across various daemons (lnd, bitcoind, lwk).
As far as I've seen, a function similar to subtractfeefromamount may not be currently provided in lnd and lwk.

@Impa10r
Copy link
Contributor

Impa10r commented Aug 23, 2024

uses an "Ask forgiveness not permission" approach, where we attempt to broadcast with the discounted fee, and if that fails, we retry with the non-discounted fee.

I observe persistent situations on liquidtestnet where an opening tx does not fail, but still does not reach https://blockstream.info/liquidtestnet, https://liquid.network/testnet and the swap peer node. There are no errors in peerswap or elements logs. gettxout shows 0 confirmations at first, then nothing at all:

$ ecli gettxout 6775a3fb23b0e0190ba08ef7b88d9a1c91af102b3476cce6f31d5f598ea6ea4a 0
{
  "bestblock": "60b88d6d41a1c6d89e8d61bae9d9912724bc3308c703588a95315cd4304ab726
  "confirmations": 0,
  "valuecommitment": "082a4fa57ae4b37f30438b2a9092b7ff945a44da3936302b482111da4d
  "assetcommitment": "0ab32c036f312ef5cefca2fd29a83cbfdfba131831a68d55984fe97054
  "commitmentnonce": "033c2f1269344680c4059aab3ac5530fe35e683b2d39483881d3cf9f64
  "scriptPubKey": {
    "asm": "0 7787377aabfe8235a6ce8fc784b4c0b32ae57bc9d9b04b198e2d0dacbdb6bc69",
    "desc": "addr(tex1qw7rnw74tl6prtfkw3lrcfdxqkv4w277fmxcykxvw95x6e0dkh35shldc8
    "hex": "00207787377aabfe8235a6ce8fc784b4c0b32ae57bc9d9b04b198e2d0dacbdb6bc69
    "address": "tex1qw7rnw74tl6prtfkw3lrcfdxqkv4w277fmxcykxvw95x6e0dkh35shldc8u"
    "type": "witness_v0_scripthash"
  },
  "coinbase": false
}
$ ecli gettxout 6775a3fb23b0e0190ba08ef7b88d9a1c91af102b3476cce6f31d5f598ea6ea4a 0
$

The swap times out with State_ClaimedCoop.

So we cannot rely on error to retry with a higher fee, we may end up paying twice. I think the only way around this is to add some third node that definitely runs v23.2.2 as addnode to both peers' elements.conf.

@YusukeShimizu
Copy link
Contributor Author

YusukeShimizu commented Aug 26, 2024

How about give up the current approach and add a configuration item related to Confidential Transaction discounts?
The reasons are as follows:

Problems

  1. Cannot determine whether to apply CT discount when calculating fee invoice amount during swapout

    • lwk cannot know whether the connected backend daemon supports CT discounts, which may cause problems like liquid: ct discount #304 (comment).
    • (Currently, CT discounts are temporarily always enabled)
  2. CT discounts may require the connected peer to also support CT discounts

Solution

  • Add a configuration item to peerswap's config to enable or disable the use of CT discounts
    • If enabled, always operate on the assumption of CT discounts
    • If disabled, behave as before
  • The allowable fee invoice check in swapout will also be performed on the assumption that the other party also uses CT discounts if you have enabled CT discounts

peerswap.conf sample

  • lwk
lwk.signername=s1
lwk.walletname=w1
lwk.liquidswaps=true
lwk.ctdiscount=true # default false
  • elementsd
elementsd.liquidswaps=true
elementsd.ctdiscount=true # default false

drawback

It's true that this would require users to configure an additional setting, adding some inconvenience.
However, for the reasons mentioned above, I think that automatically determining whether or not to apply CT discounts has some problems.

@YusukeShimizu
Copy link
Contributor Author

YusukeShimizu commented Aug 26, 2024

Regarding #304 (comment),
As mentioned in ElementsProject/elements#1358 (comment), it seems appropriate to utilize sendall and add swapall to peerswap as well.

@grubles
Copy link
Collaborator

grubles commented Aug 26, 2024

How will you know when your peer finally supports the CT discount and then be able to enable it on your local end?

@YusukeShimizu
Copy link
Contributor Author

Currently, the only ways I know are to either try some method to confirm that the ct discount is incorporated into the block, or to find a peer that supports the ct discount and add it.

@Impa10r
Copy link
Contributor

Impa10r commented Aug 27, 2024

Why not ask the peer via a custom message before initiating a swap-out, whether they support the CT discount?

If not, don't make it a config parameter, make it an option for each individual swap out.

@wtogami
Copy link
Contributor

wtogami commented Aug 27, 2024

How will you know when your peer finally supports the CT discount and then be able to enable it on your local end?

Simplest

  • Increase minimum elements version and version of LWK
  • Bump protocol version to 4
  • Assume everyone else with protocol version 4 supports CT discount

@wtogami wtogami closed this Aug 27, 2024
@wtogami wtogami reopened this Aug 27, 2024
@YusukeShimizu
Copy link
Contributor Author

YusukeShimizu commented Aug 27, 2024

It seems possible for each user to have their own CT discount settings and include them in custom messages.
Indeed, I agree that upgrading the protocol version and assuming CT discounts is the simplest and good idea.

@Impa10r
Copy link
Contributor

Impa10r commented Sep 3, 2024

testing this pr with cln v24.08. lcli peerswap-listpeers causes this in cln.log:

2024-09-03T11:40:08.679Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"35/cln:listchannels#126\"
2024-09-03T11:40:09.525Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"36/cln:listchannels#127\"
2024-09-03T11:40:10.033Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.046Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.402Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_in INVALID 42083
2024-09-03T11:40:10.709Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"37/cln:listchannels#128\"
2024-09-03T11:40:11.266Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_in INVALID 42083
2024-09-03T11:40:11.446Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.446Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.710Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"42/cln:listchannels#134\"
2024-09-03T11:40:12.199Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_in INVALID 42083
2024-09-03T11:40:12.594Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_in INVALID 42083

@grubles
Copy link
Collaborator

grubles commented Sep 3, 2024

testing this pr with cln v24.08. lcli peerswap-listpeers causes this in cln.log:

2024-09-03T11:40:08.679Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"35/cln:listchannels#126\"
2024-09-03T11:40:09.525Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"36/cln:listchannels#127\"
2024-09-03T11:40:10.033Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.046Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.402Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_in INVALID 42083
2024-09-03T11:40:10.709Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"37/cln:listchannels#128\"
2024-09-03T11:40:11.266Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_in INVALID 42083
2024-09-03T11:40:11.446Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.446Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.710Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"42/cln:listchannels#134\"
2024-09-03T11:40:12.199Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_in INVALID 42083
2024-09-03T11:40:12.594Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_in INVALID 42083

Looks like that field was deprecated (though not removed yet) in v24.02. https://github.com/ElementsProject/lightning/blob/master/CHANGELOG.md#deprecated-2

It appears we will need to use listpeerchannels for that field eventually once it's removed from listchannels.

@Impa10r
Copy link
Contributor

Impa10r commented Sep 4, 2024

testing this pr with cln v24.08. lcli peerswap-listpeers causes this in cln.log:

2024-09-03T11:40:08.679Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"35/cln:listchannels#126\"
2024-09-03T11:40:09.525Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"36/cln:listchannels#127\"
2024-09-03T11:40:10.033Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.046Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_out INVALID 42085
2024-09-03T11:40:10.402Z DEBUG   020ed4ea09c56c3e398190ae5ac60504fe4e56d6989d49e2f7845f14608c546854-connectd: peer_in INVALID 42083
2024-09-03T11:40:10.709Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"37/cln:listchannels#128\"
2024-09-03T11:40:11.266Z DEBUG   02e74acffd6375fa71a038e780064ae1765ebaf520bf7b9a5681e8ff9bfe36ce29-connectd: peer_in INVALID 42083
2024-09-03T11:40:11.446Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.446Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_out INVALID 42085
2024-09-03T11:40:11.710Z **BROKEN** plugin-topology: DEPRECATED API USED: listchannels.include_private by \"42/cln:listchannels#134\"
2024-09-03T11:40:12.199Z DEBUG   0246ec6dc79d422a2945037afe7d0b9511a3abc6f78adae7f7419c132145381990-connectd: peer_in INVALID 42083
2024-09-03T11:40:12.594Z DEBUG   020a654db4feba771ba2f82b9e97297d6c5294ddd40f167c6538149c162e4aa63c-connectd: peer_in INVALID 42083

Looks like that field was deprecated (though not removed yet) in v24.02. https://github.com/ElementsProject/lightning/blob/master/CHANGELOG.md#deprecated-2

It appears we will need to use listpeerchannels for that field eventually once it's removed from listchannels.

I PRd listpeerchannels to glightning, still being reviewed. But it does not have include_private...

@YusukeShimizu
Copy link
Contributor Author

Thank you for creating the PR for glightning.
I will use that change to add support for peerswap.
I also plan to update the nix version for testing purposes.

As this is a separate requirement, I will address it in a separate PR.

elements releases have the mempool policy patch.
To apply ct discount on peerswap, we uses An
"Ask forgiveness not permission" approach,
where we attempt to broadcast with the discounted fee,
and if that fails, we retry with the non-discounted fee.

The discount is achieved by calculating the fee
based on a discounted vsize
(equivalent to 1/4 of the original tx size).
Assume support for all peerswap CT discounts with protocol version up.
Remove the previous Ask forgiveness not permission approach,
and return an error if CT discount is not supported.
@YusukeShimizu
Copy link
Contributor Author

I have added an implementation that ensures the CT discount mechanism works correctly in the latest version of lwk. Currently, it only functions on the master branch of lwk, so I plan to officially determine the supported version after a release tag is created.

Additionally, the Liquid setup process has been changed, and we will update nix when a new version becomes available.

Update the supported CLI version to 0.8.0.

This change ensures that lwkwallet is compatible with
the latest version of the command-line interface.

Adds tests to ensure that the CT discount
mechanism functions correctly with the latest version
of lwk.
@YusukeShimizu
Copy link
Contributor Author

The draft status has been removed because the CT discount was released in LWK and Peerswap has also been updated to support it.

@grubles
Copy link
Collaborator

grubles commented Oct 28, 2024

@nepet can you please review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants