Skip to content

Commit 50e38df

Browse files
committed
tapfreighter: set type for burn/tombstone keys correctly
In order for burn/tombstone keys to be stored with the correct type, we need to detect them before storing the transfer outputs to the database. We can't set the script key type before, because we're carrying around the script key in a virtual packet, where that information isn't available.
1 parent 408c4a8 commit 50e38df

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tapfreighter/chain_porter.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,12 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
12961296
"%w", err)
12971297
}
12981298

1299+
// Burn and tombstone keys are the only keys that we don't
1300+
// explicitly store in the DB before this point. But we'll want
1301+
// them to have the correct type when creating the transfer, so
1302+
// we'll set that now.
1303+
detectUnSpendableKeys(currentPkg.VirtualPackets)
1304+
12991305
// We now need to find out if this is a transfer to ourselves
13001306
// (e.g. a change output) or an outbound transfer. A key being
13011307
// local means the lnd node connected to this daemon knows how
@@ -1567,6 +1573,42 @@ func (p *ChainPorter) publishSubscriberEvent(event fn.Event) {
15671573
}
15681574
}
15691575

1576+
// detectUnSpendableKeys checks if any of the outputs in the virtual packets are
1577+
// burn or tombstone keys and sets the appropriate type on the output script
1578+
// key.
1579+
func detectUnSpendableKeys(activeTransfers []*tappsbt.VPacket) {
1580+
setScriptKeyType := func(vOut *tappsbt.VOutput,
1581+
scriptKeyType asset.ScriptKeyType) {
1582+
1583+
if vOut.Asset.ScriptKey.TweakedScriptKey != nil {
1584+
vOut.Asset.ScriptKey.Type = scriptKeyType
1585+
}
1586+
if vOut.ScriptKey.TweakedScriptKey != nil {
1587+
vOut.ScriptKey.Type = scriptKeyType
1588+
}
1589+
}
1590+
1591+
for _, vPkt := range activeTransfers {
1592+
for _, vOut := range vPkt.Outputs {
1593+
if vOut.Asset == nil {
1594+
continue
1595+
}
1596+
1597+
witness := vOut.Asset.PrevWitnesses
1598+
if len(witness) > 0 && asset.IsBurnKey(
1599+
vOut.ScriptKey.PubKey, witness[0],
1600+
) {
1601+
setScriptKeyType(vOut, asset.ScriptKeyBurn)
1602+
}
1603+
1604+
unSpendable, _ := vOut.ScriptKey.IsUnSpendable()
1605+
if unSpendable {
1606+
setScriptKeyType(vOut, asset.ScriptKeyTombstone)
1607+
}
1608+
}
1609+
}
1610+
}
1611+
15701612
// A compile-time assertion to make sure ChainPorter satisfies the
15711613
// fn.EventPublisher interface.
15721614
var _ fn.EventPublisher[fn.Event, bool] = (*ChainPorter)(nil)

0 commit comments

Comments
 (0)