Skip to content

Commit 9f24e16

Browse files
committed
tapchannel: fix allocation handling
One allocation entry means one on-chain output. So we should not create multiple allocations for the same balance (e.g. if there are multiple asset pieces with different asset IDs in the local or remote balance). Instead we just create one allocation for the sum, then let the coin distribution algorithm decide what output goes where.
1 parent d36a78e commit 9f24e16

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

tapchannel/aux_closer.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -552,18 +552,10 @@ func (a *AuxChanCloser) ShutdownBlob(
552552
return none, err
553553
}
554554

555-
// We now add the a
556-
// TODO(guggero): This only works if there's only a single asset
557-
// in the channel. We need to extend this to support multiple
558-
// assets.
559-
_, err = a.cfg.AddrBook.NewAddressWithKeys(
560-
ctx, address.V1, channelAsset.AssetID.Val,
561-
channelAsset.Amount.Val, newKey, newInternalKey, nil,
562-
*a.cfg.DefaultCourierAddr,
563-
)
555+
err = a.cfg.AddrBook.InsertScriptKey(ctx, newKey, true)
564556
if err != nil {
565-
return none, fmt.Errorf("error adding new address: %w",
566-
err)
557+
return none, fmt.Errorf("error declaring script key: "+
558+
"%w", err)
567559
}
568560

569561
scriptKeys[channelAsset.AssetID.Val] = *newKey.PubKey

tapchannel/aux_sweeper.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -1876,8 +1876,9 @@ func (a *AuxSweeper) resolveContract(
18761876
return lfn.Err[tlv.Blob](err)
18771877
}
18781878

1879+
type packetList = []*tappsbt.VPacket
18791880
var (
1880-
secondLevelPkts []*tappsbt.VPacket
1881+
secondLevelPkts packetList
18811882
secondLevelSigDesc lfn.Option[cmsg.TapscriptSigDesc]
18821883
)
18831884

@@ -1886,25 +1887,30 @@ func (a *AuxSweeper) resolveContract(
18861887
if needsSecondLevel {
18871888
log.Infof("Creating+signing 2nd level vPkts")
18881889

1889-
// We'll make a place holder for the second level output based
1890-
// on the assetID+value tuple.
1891-
secondLevelInputs := []*cmsg.AssetOutput{cmsg.NewAssetOutput(
1892-
assetOutputs[0].AssetID.Val,
1893-
assetOutputs[0].Amount.Val, assetOutputs[0].Proof.Val,
1894-
)}
1890+
// We'll make a placeholder for the second level output based
1891+
// on the assetID+value tuples.
1892+
secondLevelInputs := fn.Map(
1893+
assetOutputs,
1894+
func(a *cmsg.AssetOutput) *cmsg.AssetOutput {
1895+
return cmsg.NewAssetOutput(
1896+
a.AssetID.Val, a.Amount.Val,
1897+
a.Proof.Val,
1898+
)
1899+
},
1900+
)
18951901

18961902
// Unlike the first level packets, we can't yet sign the second
18971903
// level packets yet, as we don't know what the sweeping
18981904
// transaction will look like. So we'll just create them.
18991905
secondLevelPkts, err = lfn.MapOption(
19001906
//nolint:lll
1901-
func(desc tapscriptSweepDesc) lfn.Result[[]*tappsbt.VPacket] {
1907+
func(desc tapscriptSweepDesc) lfn.Result[packetList] {
19021908
return a.createSweepVpackets(
19031909
secondLevelInputs, lfn.Ok(desc), req,
19041910
)
19051911
},
19061912
)(tapSweepDesc.secondLevel).UnwrapOr(
1907-
lfn.Ok[[]*tappsbt.VPacket](nil),
1913+
lfn.Ok[packetList](nil),
19081914
).Unpack()
19091915
if err != nil {
19101916
return lfn.Errf[tlv.Blob]("unable to make "+

0 commit comments

Comments
 (0)