Skip to content

Commit 48b13a6

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 cda1bb3 commit 48b13a6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tapfreighter/chain_porter.go

Lines changed: 53 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,53 @@ 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.TweakedScriptKey = new(
1585+
asset.TweakedScriptKey,
1586+
)
1587+
vOut.Asset.ScriptKey.RawKey.PubKey =
1588+
vOut.Asset.ScriptKey.PubKey
1589+
}
1590+
if vOut.ScriptKey.TweakedScriptKey == nil {
1591+
vOut.ScriptKey.TweakedScriptKey = new(
1592+
asset.TweakedScriptKey,
1593+
)
1594+
vOut.ScriptKey.RawKey.PubKey = vOut.ScriptKey.PubKey
1595+
}
1596+
1597+
vOut.Asset.ScriptKey.Type = scriptKeyType
1598+
vOut.ScriptKey.Type = scriptKeyType
1599+
}
1600+
1601+
for _, vPkt := range activeTransfers {
1602+
for _, vOut := range vPkt.Outputs {
1603+
if vOut.Asset == nil {
1604+
continue
1605+
}
1606+
1607+
witness := vOut.Asset.PrevWitnesses
1608+
if len(witness) > 0 && asset.IsBurnKey(
1609+
vOut.ScriptKey.PubKey, witness[0],
1610+
) {
1611+
1612+
setScriptKeyType(vOut, asset.ScriptKeyBurn)
1613+
}
1614+
1615+
unSpendable, _ := vOut.ScriptKey.IsUnSpendable()
1616+
if unSpendable {
1617+
setScriptKeyType(vOut, asset.ScriptKeyTombstone)
1618+
}
1619+
}
1620+
}
1621+
}
1622+
15701623
// A compile-time assertion to make sure ChainPorter satisfies the
15711624
// fn.EventPublisher interface.
15721625
var _ fn.EventPublisher[fn.Event, bool] = (*ChainPorter)(nil)

0 commit comments

Comments
 (0)