-
Notifications
You must be signed in to change notification settings - Fork 40
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
base: master
Are you sure you want to change the base?
liquid: ct discount #304
Conversation
6bab96a
to
269df55
Compare
d53b5af
to
6ff417c
Compare
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 liquidCT 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 |
Testing it on liquidtestnet with Elements 23.2.2. Swap out does not work when swapAmount == PeerLBTCbalance - 75: Initiator log:
Receiver log:
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 |
LND as LBTC swap-out sender results in:
|
Thank you for your confirmation. 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,
|
Thank you for your feedback. In the peerswap implementation, when a swapout request is received, the amount of the fee invoice is verified. In this PR, I modified the calculation of expectedFee to assume a CT discount. However, I've noticed that this is causing frequent failures like this. |
Thanks, I reported this bug on Elements github, but I think they will tell us to use |
In this case, both peers are running PR 304 and using the same |
I think it's a good idea. |
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.
The swap times out with 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 |
How about give up the current approach and add a configuration item related to Confidential Transaction discounts? Problems
Solution
peerswap.conf sample
drawbackIt's true that this would require users to configure an additional setting, adding some inconvenience. |
Regarding #304 (comment), |
How will you know when your peer finally supports the CT discount and then be able to enable it on your local end? |
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. |
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. |
Simplest
|
It seems possible for each user to have their own CT discount settings and include them in custom messages. |
testing this pr with cln v24.08.
|
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 |
I PRd listpeerchannels to glightning, still being reviewed. But it does not have include_private... |
Thank you for creating the PR for glightning. 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.
cdc6211
to
d3f07a4
Compare
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.
485dfc8
to
4739346
Compare
The draft status has been removed because the CT discount was released in LWK and Peerswap has also been updated to support it. |
@nepet can you please review? |
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