alexbosworth / lightning

Lightning client methods
MIT License
126 stars 32 forks source link

Inconsistent `commit_transaction_fee` #144

Closed vindard closed 1 year ago

vindard commented 1 year ago

Description

In listchannels on lnd I get a commit_fee of 2810 whereas for the same channel fetched via getChannels method I get a commit_transaction_fee of 3240. Are these supposed to be equivalent values? And if yes, why are they different? Json blobs below.

listchannels from lnd:

{
    "active": true,
    "remote_pubkey": "039341ef13e776dc1611502cf510110d9ac5cdc252141f5997adcfd72cef34c3a7",
    "channel_point": "3252171149db503e175ea0cf12ae0abe06101135b56f2cbbedd350fca8469be1:0",
    "chan_id": "468391953498112",
    "capacity": "500000",
    "local_balance": "250000",
    "remote_balance": "246530",
    "commit_fee": "2810",
    "commit_weight": "1116",
    "fee_per_kw": "2500",
    "unsettled_balance": "0",
    "total_satoshis_sent": "246530",
    "total_satoshis_received": "0",
    "num_updates": "4",
    "pending_htlcs": [
    ],
    "csv_delay": 144,
    "private": false,
    "initiator": true,
    "chan_status_flags": "ChanStatusDefault",
    "local_chan_reserve_sat": "5000",
    "remote_chan_reserve_sat": "5000",
    "static_remote_key": false,
    "commitment_type": "ANCHORS",
    "lifetime": "58",
    "uptime": "58",
    "close_address": "",
    "push_amount_sat": "0",
    "thaw_height": 0,
    "local_constraints": {
        "csv_delay": 144,
        "chan_reserve_sat": "5000",
        "dust_limit_sat": "354",
        "max_pending_amt_msat": "495000000",
        "min_htlc_msat": "1",
        "max_accepted_htlcs": 50
    },
    "remote_constraints": {
        "csv_delay": 144,
        "chan_reserve_sat": "5000",
        "dust_limit_sat": "354",
        "max_pending_amt_msat": "495000000",
        "min_htlc_msat": "1",
        "max_accepted_htlcs": 50
    },
    "alias_scids": [
    ],
    "zero_conf": false,
    "zero_conf_confirmed_scid": "0",
    "peer_alias": "039341ef13e776dc1611",
    "peer_scid_alias": "0"
}

getChannels method in the library:

{
  "capacity": 500000,
  "commit_transaction_fee": 3240,
  "commit_transaction_weight": 1116,
  "id": "426x1x0",
  "is_active": true,
  "is_closing": false,
  "is_opening": false,
  "is_partner_initiated": false,
  "is_private": false,
  "local_balance": 249570,
  "local_csv": 144,
  "local_dust": 354,
  "local_given": 0,
  "local_max_htlcs": 50,
  "local_max_pending_mtokens": "495000000",
  "local_min_htlc_mtokens": "1",
  "local_reserve": 5000,
  "other_ids": [],
  "partner_public_key": "039341ef13e776dc1611502cf510110d9ac5cdc252141f5997adcfd72cef34c3a7",
  "past_states": 3,
  "pending_payments": [
    {
      "id": "bb71bd4d3e0bd5315c400b2676eb5d451d7121c72ac02e61a27562265fcbce16",
      "is_outgoing": true,
      "payment": 1,
      "timeout": 581,
      "tokens": 246530
    }
  ],
  "received": 0,
  "remote_balance": 0,
  "remote_csv": 144,
  "remote_dust": 354,
  "remote_given": 0,
  "remote_max_htlcs": 50,
  "remote_max_pending_mtokens": "495000000",
  "remote_min_htlc_mtokens": "1",
  "remote_reserve": 5000,
  "sent": 0,
  "time_offline": 0,
  "time_online": 6000,
  "transaction_id": "3252171149db503e175ea0cf12ae0abe06101135b56f2cbbedd350fca8469be1",
  "transaction_vout": 0,
  "type": "anchor",
  "unsettled_balance": 246530
}
alexbosworth commented 1 year ago

Looks like those two samples were taken at different time periods, can you do the same but at the same time?

vindard commented 1 year ago

Ah you're right, from getChannels now the commit fee matches from lnd (see below). What would cause this fee to change over time?

{
    capacity: 500000,
    commit_transaction_fee: 2810,
    commit_transaction_weight: 1116,
    cooperative_close_address: undefined,
    cooperative_close_delay_height: undefined,
    description: undefined,
    id: '426x1x0',
    is_active: true,
    is_closing: false,
    is_opening: false,
    is_partner_initiated: false,
    is_private: false,
    is_trusted_funding: undefined,
    local_balance: 250000,
    local_csv: 144,
    local_dust: 354,
    local_given: 0,
    local_max_htlcs: 50,
    local_max_pending_mtokens: '495000000',
    local_min_htlc_mtokens: '1',
    local_reserve: 5000,
    other_ids: [],
    partner_public_key: '039341ef13e776dc1611502cf510110d9ac5cdc252141f5997adcfd72cef34c3a7',
    past_states: 4,
    pending_payments: [],
    received: 0,
    remote_balance: 246530,
    remote_csv: 144,
    remote_dust: 354,
    remote_given: 0,
    remote_max_htlcs: 50,
    remote_max_pending_mtokens: '495000000',
    remote_min_htlc_mtokens: '1',
    remote_reserve: 5000,
    sent: 246530,
    time_offline: 0,
    time_online: 1702000,
    transaction_id: '3252171149db503e175ea0cf12ae0abe06101135b56f2cbbedd350fca8469be1',
    transaction_vout: 0,
    type: 'anchor',
    unsettled_balance: 0
  }
alexbosworth commented 1 year ago

More pending HTLCs that are above the dust value will increase the size of the commitment transaction and with the size increase comes a fee increase

vindard commented 1 year ago

Ok gotcha thanks. Closing this one now then

Making a note that having a remote balance of 0 also affects how many anchor outputs there are and the commit_fee by extension