routing: prevent fetching blocks for graph edges with AssumeChannelValid
This serves as a stop-gap for light clients as blocks need to be downloaded from the P2P network, and even with caches, would be too costly for them to verify. Doing this has two side effects however: we'll no longer know of the channel capacity and outpoint, which are essential for some of lnd's responsibilities.
This commit is contained in:
parent
fd1aa478a9
commit
f2637d63ba
@ -1013,7 +1013,6 @@ func (r *ChannelRouter) assertNodeAnnFreshness(node Vertex,
|
|||||||
// state of the draft due to either being out of date, invalid, or redundant,
|
// state of the draft due to either being out of date, invalid, or redundant,
|
||||||
// then error is returned.
|
// then error is returned.
|
||||||
func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *channeldb.LightningNode:
|
case *channeldb.LightningNode:
|
||||||
// Before we add the node to the database, we'll check to see
|
// Before we add the node to the database, we'll check to see
|
||||||
@ -1060,11 +1059,26 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
|||||||
"chan_id=%v", msg.ChannelID)
|
"chan_id=%v", msg.ChannelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If AssumeChannelValid is present, then we are unable to
|
||||||
|
// perform any of the expensive checks below, so we'll
|
||||||
|
// short-circuit our path straight to adding the edge to our
|
||||||
|
// graph.
|
||||||
|
if r.cfg.AssumeChannelValid {
|
||||||
|
if err := r.cfg.Graph.AddChannelEdge(msg); err != nil {
|
||||||
|
return fmt.Errorf("unable to add edge: %v", err)
|
||||||
|
}
|
||||||
|
log.Infof("New channel discovered! Link "+
|
||||||
|
"connects %x and %x with ChannelID(%v)",
|
||||||
|
msg.NodeKey1Bytes, msg.NodeKey2Bytes,
|
||||||
|
msg.ChannelID)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Before we can add the channel to the channel graph, we need
|
// Before we can add the channel to the channel graph, we need
|
||||||
// to obtain the full funding outpoint that's encoded within
|
// to obtain the full funding outpoint that's encoded within
|
||||||
// the channel ID.
|
// the channel ID.
|
||||||
channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
fundingPoint, fundingTxOut, err := r.fetchChanPoint(&channelID)
|
fundingPoint, _, err := r.fetchChanPoint(&channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.rejectMtx.Lock()
|
r.rejectMtx.Lock()
|
||||||
r.rejectCache[msg.ChannelID] = struct{}{}
|
r.rejectCache[msg.ChannelID] = struct{}{}
|
||||||
@ -1088,29 +1102,21 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var chanUtxo *wire.TxOut
|
// Now that we have the funding outpoint of the channel, ensure
|
||||||
if r.cfg.AssumeChannelValid {
|
// that it hasn't yet been spent. If so, then this channel has
|
||||||
// If AssumeChannelValid is present, we'll just use the
|
// been closed so we'll ignore it.
|
||||||
// txout returned from fetchChanPoint.
|
chanUtxo, err := r.cfg.Chain.GetUtxo(
|
||||||
chanUtxo = fundingTxOut
|
fundingPoint, fundingPkScript, channelID.BlockHeight,
|
||||||
} else {
|
|
||||||
// Now that we have the funding outpoint of the channel,
|
|
||||||
// ensure that it hasn't yet been spent. If so, then
|
|
||||||
// this channel has been closed so we'll ignore it.
|
|
||||||
chanUtxo, err = r.cfg.Chain.GetUtxo(
|
|
||||||
fundingPoint, fundingPkScript,
|
|
||||||
channelID.BlockHeight,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.rejectMtx.Lock()
|
r.rejectMtx.Lock()
|
||||||
r.rejectCache[msg.ChannelID] = struct{}{}
|
r.rejectCache[msg.ChannelID] = struct{}{}
|
||||||
r.rejectMtx.Unlock()
|
r.rejectMtx.Unlock()
|
||||||
|
|
||||||
return errors.Errorf("unable to fetch utxo "+
|
return fmt.Errorf("unable to fetch utxo "+
|
||||||
"for chan_id=%v, chan_point=%v: %v",
|
"for chan_id=%v, chan_point=%v: %v",
|
||||||
msg.ChannelID, fundingPoint, err)
|
msg.ChannelID, fundingPoint, err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// By checking the equality of witness pkscripts we checks that
|
// By checking the equality of witness pkscripts we checks that
|
||||||
// funding witness script is multisignature lock which contains
|
// funding witness script is multisignature lock which contains
|
||||||
@ -1137,10 +1143,9 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
|||||||
fundingPoint, msg.ChannelID, msg.Capacity)
|
fundingPoint, msg.ChannelID, msg.Capacity)
|
||||||
|
|
||||||
// As a new edge has been added to the channel graph, we'll
|
// As a new edge has been added to the channel graph, we'll
|
||||||
// update the current UTXO filter, if AssumeChannelValid is not
|
// update the current UTXO filter within our active
|
||||||
// present, within our active FilteredChainView so we are
|
// FilteredChainView so we are notified if/when this channel is
|
||||||
// notified if/when this channel is closed.
|
// closed.
|
||||||
if !r.cfg.AssumeChannelValid {
|
|
||||||
filterUpdate := []channeldb.EdgePoint{
|
filterUpdate := []channeldb.EdgePoint{
|
||||||
{
|
{
|
||||||
FundingPkScript: fundingPkScript,
|
FundingPkScript: fundingPkScript,
|
||||||
@ -1154,7 +1159,6 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
|||||||
return errors.Errorf("unable to update chain "+
|
return errors.Errorf("unable to update chain "+
|
||||||
"view: %v", err)
|
"view: %v", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *channeldb.ChannelEdgePolicy:
|
||||||
// If we recently rejected this channel edge, then we won't
|
// If we recently rejected this channel edge, then we won't
|
||||||
|
Loading…
Reference in New Issue
Block a user