From 339ff357d107f84c64a3a1de3854c26f6ebb39a2 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 23 Sep 2019 13:05:02 +0200 Subject: [PATCH] channeldb: invalidate channel signature cache on update --- channeldb/graph.go | 10 +++++++++- discovery/gossiper.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/channeldb/graph.go b/channeldb/graph.go index 571ab31f..8cd23973 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -2735,7 +2735,8 @@ func (c *ChannelAuthProof) IsEmpty() bool { type ChannelEdgePolicy struct { // SigBytes is the raw bytes of the signature of the channel edge // policy. We'll only parse these if the caller needs to access the - // signature for validation purposes. + // signature for validation purposes. Do not set SigBytes directly, but + // use SetSigBytes instead to make sure that the cache is invalidated. SigBytes []byte // sig is a cached fully parsed signature. @@ -2814,6 +2815,13 @@ func (c *ChannelEdgePolicy) Signature() (*btcec.Signature, error) { return sig, nil } +// SetSigBytes updates the signature and invalidates the cached parsed +// signature. +func (c *ChannelEdgePolicy) SetSigBytes(sig []byte) { + c.SigBytes = sig + c.sig = nil +} + // IsDisabled determines whether the edge has the disabled bit set. func (c *ChannelEdgePolicy) IsDisabled() bool { return c.ChannelFlags&lnwire.ChanUpdateDisabled == diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 812ca0a3..b5bbfe8d 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -2552,7 +2552,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, // Next, we'll set the new signature in place, and update the reference // in the backing slice. - edge.SigBytes = sig.Serialize() + edge.SetSigBytes(sig.Serialize()) chanUpdate.Signature, err = lnwire.NewSigFromSignature(sig) if err != nil { return nil, nil, err