Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ require (
github.com/jackc/pgtype v1.14.4 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/jackc/pgx/v5 v5.9.2 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jackpal/gateway v1.0.5 // indirect
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad // indirect
Expand All @@ -133,7 +132,7 @@ require (
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/lightning-node-connect/gbn v1.0.2-0.20250610182311-2f1d46ef18b7 // indirect
github.com/lightninglabs/lightning-node-connect/mailbox v1.0.2-0.20250610182311-2f1d46ef18b7 // indirect
github.com/lightninglabs/neutrino v0.16.2 // indirect
github.com/lightninglabs/neutrino v0.16.3-0.20260508212153-0f87fa7c4b36 // indirect
github.com/lightningnetwork/lightning-onion v1.3.0 // indirect
github.com/lightningnetwork/lnd/actor v0.0.6 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.6 // indirect
Expand Down Expand Up @@ -234,3 +233,5 @@ replace github.com/prometheus/common => github.com/prometheus/common v0.26.0
// pre-release by Go modules and would be overridden by the tagged v0.16.17
// required by aperture and lndclient.
replace github.com/btcsuite/btcwallet => github.com/btcsuite/btcwallet v0.16.17-0.20260213031108-70a94ea39e9c

replace github.com/lightningnetwork/lnd => github.com/GeorgeTsagk/lnd v0.0.0-20260515110736-94fdcc7232c5
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GeorgeTsagk/lnd v0.0.0-20260515110736-94fdcc7232c5 h1:13knPomopNLV6VfUWLaf2pLez8gSWSOFG+tPUWVfvCQ=
github.com/GeorgeTsagk/lnd v0.0.0-20260515110736-94fdcc7232c5/go.mod h1:hG4elDX4kx7J967tswRksh2XAmPjPIJ9REToBlle7XU=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
Expand Down Expand Up @@ -1031,7 +1033,6 @@ github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
Expand Down Expand Up @@ -1117,16 +1118,14 @@ github.com/lightninglabs/lndclient v0.20.0-6 h1:sh23eZkOpHxe39c4QRYwhsM7qbnJlS++
github.com/lightninglabs/lndclient v0.20.0-6/go.mod h1:gBtIFPGmC2xIspGIv/G5+HiPSGJsFD8uIow7Oke1HFI=
github.com/lightninglabs/migrate/v4 v4.18.2-9023d66a-fork-pr-2.0.20251211093704-71c1eef09789 h1:7kX7vUgHUazAHcCJ6uzBDa4/2MEGEbMEfa01GtfqmTQ=
github.com/lightninglabs/migrate/v4 v4.18.2-9023d66a-fork-pr-2.0.20251211093704-71c1eef09789/go.mod h1:99BKpIi6ruaaXRM1A77eqZ+FWPQ3cfRa+ZVy5bmWMaY=
github.com/lightninglabs/neutrino v0.16.2 h1:jHMMDLPX8asfwgN0/C4BY8uVaYupFzZYuWQkX8Go3fk=
github.com/lightninglabs/neutrino v0.16.2/go.mod h1:fNjnbuSPw4lRsVAzvjC1JG7IE7rqae/mbek2tNkN/Dw=
github.com/lightninglabs/neutrino v0.16.3-0.20260508212153-0f87fa7c4b36 h1:d6FuJQ6YjWqBdMJ3fmk9BgjyMFyRKecKxoGq//PHdh0=
github.com/lightninglabs/neutrino v0.16.3-0.20260508212153-0f87fa7c4b36/go.mod h1:fNjnbuSPw4lRsVAzvjC1JG7IE7rqae/mbek2tNkN/Dw=
github.com/lightninglabs/neutrino/cache v1.1.3 h1:rgnabC41W+XaPuBTQrdeFjFCCAVKh1yctAgmb3Se9zA=
github.com/lightninglabs/neutrino/cache v1.1.3/go.mod h1:qxkJb+pUxR5p84jl5uIGFCR4dGdFkhNUwMSxw3EUWls=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
github.com/lightningnetwork/lightning-onion v1.3.0 h1:FqILgHjD6euc/Muo1VOzZ4+XDPuFnw6EYROBq0rR/5c=
github.com/lightningnetwork/lightning-onion v1.3.0/go.mod h1:nP85zMHG7c0si/eHBbSQpuDCtnIXfSvFrK3tW6YWzmU=
github.com/lightningnetwork/lnd v0.20.0-beta.rc4.0.20260421084739-a8a3e13120eb h1:qhzjbUJau0bZCUAGlJwjxKLHI0337Z0KR+37aFoLhbg=
github.com/lightningnetwork/lnd v0.20.0-beta.rc4.0.20260421084739-a8a3e13120eb/go.mod h1:hrJPOxkleTu3y3K32ehBziq8y/zqQqCPQKfwktS35aw=
github.com/lightningnetwork/lnd/actor v0.0.6 h1:Ge8N2wivARG+27qJBwTlB0vwsypStZYZy8vk4Zl38sU=
github.com/lightningnetwork/lnd/actor v0.0.6/go.mod h1:YAsoniSbY/cAM9HTVNfZLvt7RI6swDxy6wzPspTcMZg=
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
Expand Down
20 changes: 12 additions & 8 deletions itest/custom_channels/breach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,25 @@ func testCustomChannelsBreach(ctx context.Context,
locateAssetTransfers(t.t, dave, *breachTxid)

// With the breach transaction mined, Charlie should now have a
// transaction in the mempool sweeping *both* commitment outputs.
// We use a generous timeout because Charlie needs to process the
// block, detect the breach, and construct the justice transaction.
charlieJusticeTxid, err := waitForNTxsInMempool(
net.Miner, 1, time.Second*30,
// transaction in the mempool sweeping commitment outputs.
// We wait for at least one tx as other background txns can race in.
charlieJusticeTxid, err := waitForAtLeastNTxsInMempool(
net.Miner, 1, time.Second*60,
)
require.NoError(t.t, err)

t.Logf("Charlie justice txid: %v", charlieJusticeTxid)

// Next, we'll mine a block to confirm Charlie's justice transaction.
mineBlocks(t, net, 1, 1)
// Use the mined txid (not the mempool txid), to avoid RBF mismatch.
justiceBlocks := mineBlocks(t, net, 1, 1)
minedJusticeTxHash := justiceBlocks[0].Transactions[1].TxHash()

t.Logf("Charlie mined justice txid: %v", minedJusticeTxHash)

// Charlie should now have a transfer for his justice transaction.
locateAssetTransfers(t.t, charlie, *charlieJusticeTxid[0])
// Mine additional blocks so all breach-resolution transfers are fully
// confirmed before asserting final balances.
mineBlocks(t, net, 6, 0)

// Charlie's balance should now be the same as before the breach
// attempt: the amount he minted at the very start.
Expand Down
4 changes: 4 additions & 0 deletions itest/custom_channels/custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ var testCases = []*ccTestCase{
name: "force close",
test: testCustomChannelsForceClose,
},
{
name: "immediate close",
test: testCustomChannelsImmediateClose,
},
{
name: "group tranches force close",
test: testCustomChannelsGroupTranchesForceClose,
Expand Down
164 changes: 164 additions & 0 deletions itest/custom_channels/immediate_close_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//go:build itest

package custom_channels

import (
"context"
"fmt"
"slices"

"github.com/lightninglabs/taproot-assets/itest"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
"github.com/lightninglabs/taproot-assets/tapscript"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/port"
"github.com/stretchr/testify/require"
)

// testCustomChannelsImmediateClose tests that an asset channel can be funded
// and then force closed immediately after the funding transaction confirms,
// without any in-channel asset movement.
func testCustomChannelsImmediateClose(ctx context.Context,
net *itest.IntegratedNetworkHarness, t *ccHarnessTest) {

lndArgs := slices.Clone(lndArgsTemplate)
tapdArgs := slices.Clone(tapdArgsTemplate)

// We use Alice as the Universe proof courier and also as the funder, so
// we pin her RPC listen port up front.
alicePort := port.NextAvailablePort()
tapdArgs = append(tapdArgs, fmt.Sprintf(
"--proofcourieraddr=%s://%s",
proof.UniverseRpcCourierType,
fmt.Sprintf(node.ListenerFormat, alicePort),
))

aliceLndArgs := slices.Clone(lndArgs)
aliceLndArgs = append(aliceLndArgs, fmt.Sprintf(
"--rpclisten=127.0.0.1:%d", alicePort,
))
alice := net.NewNode("Alice", aliceLndArgs, tapdArgs)
bob := net.NewNode("Bob", lndArgs, tapdArgs)
charlie := net.NewNode("Charlie", lndArgs, tapdArgs)

nodes := []*itest.IntegratedNode{alice, bob, charlie}
connectAllNodes(t.t, net, nodes)
fundAllNodes(t.t, net, nodes)

mintedAssets := itest.MintAssetsConfirmBatch(
t.t, net.Miner, asTapd(alice),
[]*mintrpc.MintAssetRequest{
{
Asset: ccItestAsset,
},
},
)
cents := mintedAssets[0]
assetID := cents.AssetGenesis.AssetId

t.Logf("Minted %d lightning cents, syncing universes...", cents.Amount)
syncUniverses(t.t, alice, bob)
syncUniverses(t.t, alice, charlie)

t.Logf("Opening asset channel...")
fundResp, err := asTapd(alice).FundChannel(
ctx, &tchrpc.FundChannelRequest{
AssetAmount: fundingAmount,
AssetId: assetID,
PeerPubkey: bob.PubKey[:],
FeeRateSatPerVbyte: 5,
},
)
require.NoError(t.t, err)

chanPoint := &lnrpc.ChannelPoint{
OutputIndex: uint32(fundResp.OutputIndex),
FundingTxid: &lnrpc.ChannelPoint_FundingTxidStr{
FundingTxidStr: fundResp.Txid,
},
}

mineBlocks(t, net, 6, 1)

fundingScriptTree := tapscript.NewChannelFundingScriptTree()
fundingScriptKey := fundingScriptTree.TaprootKey
assertUniverseProofExists(
t.t, alice, assetID, nil,
fundingScriptKey.SerializeCompressed(),
fmt.Sprintf("%v:%v", fundResp.Txid, fundResp.OutputIndex),
)
assertAssetChan(
t.t, alice, bob, fundingAmount, []*taprpc.Asset{cents},
)

t.Logf("Force closing asset channel immediately after confirmation...")
_, _, err = net.CloseChannel(alice, chanPoint, true)
require.NoError(t.t, err)

// The channel first enters waiting close until the commitment
// transaction confirms.
assertWaitingCloseChannelAssetData(t.t, alice, chanPoint)
mineBlocks(t, net, 1, 1)

// After confirmation, Alice should enter pending force close. Unlike the
// cooperative close path, the local force close commitment transaction
// itself is not immediately tracked as an asset transfer for Alice.
assertPendingForceCloseChannelAssetData(t.t, alice, chanPoint)

// With no remote asset balance, Alice eventually sweeps the local output
// after the CSV delay and regains the full on-chain balance.
mineBlocks(t, net, 4, 0)

aliceSweepTxid, err := waitForNTxsInMempool(
net.Miner, 1, ccShortTimeout,
)
require.NoError(t.t, err)

t.Logf("Alice sweep txid: %v", aliceSweepTxid)

aliceSweepBlocks := mineBlocks(t, net, 1, 1)
aliceSweepTxHash := aliceSweepBlocks[0].Transactions[1].TxHash()

locateAssetTransfers(t.t, alice, aliceSweepTxHash)

assertBalance(
t.t, alice, ccItestAsset.Amount, itest.WithAssetID(assetID),
itest.WithNumUtxos(2),
)

// Finally, assert the swept asset can be spent onward to a third party.
const assetSendAmount = 1000
charlieAddr, err := asTapd(charlie).NewAddr(
ctx, &taprpc.NewAddrRequest{
Amt: assetSendAmount,
AssetId: assetID,
ProofCourierAddr: fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
alice.RPCAddr(),
),
},
)
require.NoError(t.t, err)

itest.AssertAddrCreated(t.t, asTapd(charlie), cents, charlieAddr)
_, err = asTapd(alice).SendAsset(
ctx, &taprpc.SendAssetRequest{
TapAddrs: []string{charlieAddr.Encoded},
},
)
require.NoError(t.t, err)
mineBlocks(t, net, 1, 1)
itest.AssertNonInteractiveRecvComplete(t.t, asTapd(charlie), 1)

assertBalance(
t.t, alice, ccItestAsset.Amount-assetSendAmount,
itest.WithAssetID(assetID),
)
assertBalance(
t.t, charlie, assetSendAmount, itest.WithAssetID(assetID),
)
}
2 changes: 1 addition & 1 deletion rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,7 @@ func (r *RPCServer) PublishAndLogTransfer(ctx context.Context,
tapfreighter.NewPreAnchoredParcel(
activePackets, passivePackets, anchorTx,
req.SkipAnchorTxBroadcast, parcelLabel,
fn.None[uint32](),
fn.None[uint32](), false,
),
)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions tapchannel/aux_closer.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ func (a *AuxChanCloser) ShutdownBlob(
func shipChannelTxn(txSender tapfreighter.Porter, chanTx *wire.MsgTx,
outputCommitments tappsbt.OutputCommitments,
vPkts []*tappsbt.VPacket, closeFee int64,
anchorTxHeightHint fn.Option[uint32]) error {
anchorTxHeightHint fn.Option[uint32],
skipOutputProofVerify bool) error {

chanTxPsbt, err := tapsend.PrepareAnchoringTemplate(vPkts)
if err != nil {
Expand Down Expand Up @@ -736,7 +737,7 @@ func shipChannelTxn(txSender tapfreighter.Porter, chanTx *wire.MsgTx,
parcelLabel := fmt.Sprintf("channel-tx-%s", chanTx.TxHash().String())
preSignedParcel := tapfreighter.NewPreAnchoredParcel(
vPkts, nil, closeAnchor, false, parcelLabel,
anchorTxHeightHint,
anchorTxHeightHint, skipOutputProofVerify,
)
_, err = txSender.RequestShipment(preSignedParcel)
if err != nil {
Expand Down Expand Up @@ -912,7 +913,8 @@ func (a *AuxChanCloser) FinalizeClose(desc types.AuxCloseDesc,
// as the transaction is being broadcast now.
err := shipChannelTxn(
a.cfg.TxSender, closeTx, closeInfo.outputCommitments,
closeInfo.vPackets, closeInfo.closeFee, fn.None[uint32](),
closeInfo.vPackets, closeInfo.closeFee,
fn.None[uint32](), false,
)
if err != nil {
return err
Expand Down
39 changes: 37 additions & 2 deletions tapchannel/aux_funding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/lightninglabs/taproot-assets/vm"
lfn "github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
Expand Down Expand Up @@ -585,7 +586,39 @@ func newCommitBlobAndLeaves(pendingFunding *pendingAssetFunding,
localAssets = chanAssets
}

commitWeight := input.CommitWeight
if lndOpenChan.ChanType.IsTaproot() {
commitWeight = input.TaprootCommitWeight
} else if lndOpenChan.ChanType.HasAnchors() {
commitWeight = input.AnchorCommitWeight
}

commitFee := pendingFunding.feeRate.FeeForWeight(
lntypes.WeightUnit(commitWeight),
)
totalFee := commitFee
if lndOpenChan.ChanType.HasAnchors() {
totalFee += 2 * lnwallet.AnchorSize
}

capacityMSat := lnwire.NewMSatFromSatoshis(lndOpenChan.Capacity)
pushMSat := lnwire.NewMSatFromSatoshis(pendingFunding.pushAmt)
feeMSat := lnwire.NewMSatFromSatoshis(totalFee)

var localSatBalance, remoteSatBalance lnwire.MilliSatoshi
if pendingFunding.initiator {
localSatBalance = capacityMSat - feeMSat - pushMSat
remoteSatBalance = pushMSat
} else {
localSatBalance = pushMSat
remoteSatBalance = capacityMSat - feeMSat - pushMSat
}

if localSatBalance < 0 || remoteSatBalance < 0 {
return nil, lnwallet.CommitAuxLeaves{}, fmt.Errorf("invalid "+
"initial balances: capacity=%v push=%v fee=%v",
lndOpenChan.Capacity, pendingFunding.pushAmt, totalFee)
}

// We don't have a real prev state at this point, the leaf creator only
// needs the sum of the remote+local assets, so we'll populate that.
Expand All @@ -596,7 +629,9 @@ func newCommitBlobAndLeaves(pendingFunding *pendingAssetFunding,

// Just like above, we don't have a real HTLC view here, so we'll pass
// in a blank view.
var fakeView lnwallet.AuxHtlcView
fakeView := lnwallet.AuxHtlcView{
FeePerKw: pendingFunding.feeRate,
}

// With all the above, we'll generate the first commitment that'll be
// stored
Expand Down Expand Up @@ -1468,7 +1503,7 @@ func (f *FundingController) completeChannelFunding(ctx context.Context,
)
preSignedParcel := tapfreighter.NewPreAnchoredParcel(
activePkts, passivePkts, anchorTx, false, parcelLabel,
fn.None[uint32](),
fn.None[uint32](), false,
)
_, err = f.cfg.TxSender.RequestShipment(preSignedParcel)
if err != nil {
Expand Down
Loading
Loading