Skip to content

Commit 48f7842

Browse files
committed
graph: add channel point to utxo filter
In case we assume valid channels or have alias channels we make sure we also add the channel point to the block filter so that we are notified if the channel point is spent in a block.
1 parent ce27b34 commit 48f7842

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

graph/builder.go

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,16 @@ func (b *Builder) processUpdate(msg interface{},
12061206
"chan_id=%v", msg.ChannelID)
12071207
}
12081208

1209+
// Look up the funding pk script so that we can register the
1210+
// channel output in the UTXO filter.
1211+
fundingPkScript, err := makeFundingScript(
1212+
msg.BitcoinKey1Bytes[:], msg.BitcoinKey2Bytes[:],
1213+
msg.Features, msg.TapscriptRoot,
1214+
)
1215+
if err != nil {
1216+
return err
1217+
}
1218+
12091219
// If AssumeChannelValid is present, then we are unable to
12101220
// perform any of the expensive checks below, so we'll
12111221
// short-circuit our path straight to adding the edge to our
@@ -1219,10 +1229,44 @@ func (b *Builder) processUpdate(msg interface{},
12191229
if err != nil {
12201230
return fmt.Errorf("unable to add edge: %w", err)
12211231
}
1222-
log.Tracef("New channel discovered! Link "+
1223-
"connects %x and %x with ChannelID(%v)",
1224-
msg.NodeKey1Bytes, msg.NodeKey2Bytes,
1225-
msg.ChannelID)
1232+
1233+
// Use different log levels based on channel type.
1234+
if b.cfg.IsAlias(scid) {
1235+
log.Debugf("New alias channel discovered! "+
1236+
"Link connects %x and %x with "+
1237+
"ChannelID(%v)", msg.NodeKey1Bytes,
1238+
msg.NodeKey2Bytes,
1239+
msg.ChannelID)
1240+
1241+
// For alias channels, we make sure we add the
1242+
// channel to the UTXO filter so that we are
1243+
// notified if/when this channel is closed.
1244+
// This is safe because for zeroconf we trust
1245+
// the funding tx anyway. And for non-zeroconf
1246+
// alias channel we would only reach this point
1247+
// if the funding tx is confirmed.
1248+
//
1249+
//nolint:ll
1250+
filterUpdate := []graphdb.EdgePoint{
1251+
{
1252+
FundingPkScript: fundingPkScript,
1253+
OutPoint: msg.ChannelPoint,
1254+
},
1255+
}
1256+
err = b.cfg.ChainView.UpdateFilter(
1257+
filterUpdate, b.bestHeight.Load(),
1258+
)
1259+
if err != nil {
1260+
return errors.Errorf("unable to "+
1261+
"update chain view: %v", err)
1262+
}
1263+
} else {
1264+
log.Tracef("New channel discovered! Link "+
1265+
"connects %x and %x with ChannelID(%v)",
1266+
msg.NodeKey1Bytes, msg.NodeKey2Bytes,
1267+
msg.ChannelID)
1268+
}
1269+
12261270
b.stats.incNumEdgesDiscovered()
12271271

12281272
break
@@ -1270,17 +1314,6 @@ func (b *Builder) processUpdate(msg interface{},
12701314
"locate funding tx: %v", err)
12711315
}
12721316

1273-
// Recreate witness output to be sure that declared in channel
1274-
// edge bitcoin keys and channel value corresponds to the
1275-
// reality.
1276-
fundingPkScript, err := makeFundingScript(
1277-
msg.BitcoinKey1Bytes[:], msg.BitcoinKey2Bytes[:],
1278-
msg.Features, msg.TapscriptRoot,
1279-
)
1280-
if err != nil {
1281-
return err
1282-
}
1283-
12841317
// Next we'll validate that this channel is actually well
12851318
// formed. If this check fails, then this channel either
12861319
// doesn't exist, or isn't the one that was meant to be created

0 commit comments

Comments
 (0)