Blockstream / lwk

Liquid Wallet Kit
Other
52 stars 24 forks source link

Check lwk compatibility with confidential transactions discount #48

Open YusukeShimizu opened 1 month ago

YusukeShimizu commented 1 month ago

Description

Elements version 23.2.2 and later introduce a discount for confidential transactions. Would it be possible to add a way for users to check if their lwk version supports the confidential transactions discount?

Background

In peerswap, we're looking to implement a feature that adjusts the default fee rate based on whether confidential transactions are supported.
Having a way to verify lwk compatibility would be very helpful for this.

For your reference, I've attached a link to a pull request that addresses this in the context of elements. https://github.com/ElementsProject/peerswap/pull/304

RCasatta commented 1 month ago

If I understand correctly It doesn't depend on the lwk version but on the version of the consensus node lwk is connected to.

I don't think is currently possible to retrieve the version of the connected elements node without changes on the electrum server because there aren't electrum protocol methods returning information about the elements node they are connected to.

eg.

(echo '{ "id": 0, "method": "server.features", "params": [] }'; sleep 2) | ncat --ssl blockstream.info 995 
{
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
    "genesis_hash": "1466275836220db2944ca059a3a10ef6fd2ea684b0688d2c379296888a206003",
    "hash_function": "sha256",
    "hosts": {
      "electrum.blockstream.info": {
        "ssl_port": 50402,
        "tcp_port": 50401
      },
      "explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion": {
        "ssl_port": null,
        "tcp_port": 195
      }
    },
    "protocol_max": "1.4",
    "protocol_min": "1.4",
    "pruning": null,
    "server_version": "electrs-esplora 0.4.1"
  }
}

Another approach at the user level may be the "Ask forgiveness not permission" one, trying to broadcast with the discounted fee and if the broadcast fail try with the non-discounted one.

RCasatta commented 1 month ago

We should provide a method on the TxBuilder to opt in though...

YusukeShimizu commented 3 weeks ago

@RCasatta My understanding is that transactions created with the current send method do not have the CT discount applied.

In this case, can I expect that a parameter will be added that allows options to be applied?

RCasatta commented 3 weeks ago

Yes, current transactions are created without the discount. There will be an option in the tx builder to enable the discount. Will be default off until the discount isn't deployed in the live network and default on after.

@LeoComandini may work on that in the next days/weeks

YusukeShimizu commented 3 weeks ago

Is it possible in LDK to test without actually broadcasting a tx, similar to the testmempoolaccept for elements?

Background: In peerswap's Negotiation protocol, we need to calculate the estimated tx fee and send it to the peer, and I'm considering using it for that purpose.

LeoComandini commented 3 weeks ago

@YusukeShimizu we have

lwk_cli wallet broadcast -w WALLET_NAME -p PSET --dry-run

however it does not allow you to get the fee out of the transaction.

Instead you should use

lwk_cli wallet pset-details -w WALLET_NAME -p PSET

and get the fee from that.

Note that in Liquid the fee is explicit, so it's not an estimate.

YusukeShimizu commented 3 weeks ago

Thank you.

While I understand that pset-details can confirm the fee of the created transaction, it might be slightly different from my intention.

I'd like to check if the connected elements support ct discount. Is there a way to do this? I believe the approach you suggested below is the way to go, so I think I need something similar to testmempoolaccept.

Another approach at the user level may be the "Ask forgiveness not permission" one, trying to broadcast with the discounted fee and if the broadcast fail try with the non-discounted one.

I'm not familiar with Rust, but from looking at the lwk code, I don't think lwk_cli wallet broadcast -w WALLET_NAME -p PSET --dry-run can tell whether the actually connected elements support ct discount.

YusukeShimizu commented 2 weeks ago

In peerswap, we've decided to enforce CT discount settings by bumping the protocol version.
So, you can disregard the above issue.

I would appreciate it if you could let me know when the CT discount option is added to the send method.