Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[n/n] Gossip 1.75 #8185

Draft
wants to merge 74 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7ec9641
multi: rename AnnounceSignatures to AnnounceSignatures1
ellemouton Oct 26, 2023
4836ed3
multi: rename ChannelAnnouncement to ChannelAnnouncment1
ellemouton Oct 26, 2023
7dd7925
multi: rename ChannelUpdate to ChannelUpdate1
ellemouton Oct 26, 2023
46c5edb
multi: rename NodeAnnouncement
ellemouton Oct 26, 2023
73d98b2
lnwire: make MuSig2Nonce TLV type re-usable
ellemouton Sep 29, 2023
1042ee7
lnwire: add RawFeatureVectorRecordProducer
ellemouton Sep 29, 2023
ec7c3df
lnwire: add Encode and Pack methods for tlv.Records
ellemouton Sep 29, 2023
b4e77f1
lnwire: use the RawFeatureVector record methods for ChannelType
ellemouton Sep 29, 2023
5e58776
lnwire: make ShortChannelID type re-usable
ellemouton Sep 29, 2023
33b3873
lnwire: add btc and node announcement nonces to channel_ready
ellemouton Sep 29, 2023
a85e964
lnwire: add FirstBlock and BlockRange to GossipTimestampRange
ellemouton Oct 26, 2023
5e78518
lnwire: add AnnounceSignatures interface
ellemouton Oct 26, 2023
0bf0f33
lnwire: add a ChannelAnnouncement interface
ellemouton Oct 26, 2023
3e45809
lnwire: add a ChannelUpdate interface
ellemouton Oct 26, 2023
ee3ad3a
lnwire: add MsgHash helper
ellemouton Oct 26, 2023
2de5721
lnwire: add AnnounceSignatures2 message
ellemouton Sep 29, 2023
6c8e2b3
lnwire: add ChannelAnnouncement2 message
ellemouton Sep 29, 2023
216f3a7
lnwire: introduce the BooleanRecordProducer
ellemouton Sep 29, 2023
0ba99ba
lnwire: add ChannelUpdate2
ellemouton Sep 29, 2023
6ee21d7
lnwire: add NodeAnnouncement2
ellemouton Sep 29, 2023
c299e9d
multi: rename ChannelAuthProof
ellemouton Nov 9, 2023
865113b
multi: rename ChannelEdgePolicy
ellemouton Nov 9, 2023
c0c99b0
multi: rename ChannelEdgeInfo
ellemouton Nov 9, 2023
209c820
channeldb: add ChanneEdgeInfo and ChannelAuthProof interfaces
ellemouton Oct 27, 2023
e39089e
channeldb: add ChannelEdgePolicy interface
ellemouton Oct 27, 2023
ece54b7
channeldb: add ChannelAuthProof2
ellemouton Oct 27, 2023
31b9420
channeldb: add ChannelEdgeInfo2
ellemouton Oct 27, 2023
73b693e
channeldb: add ChannelEdgePolicy2
ellemouton Oct 27, 2023
d99c55d
channeldb+refactor: move ser/deser funcs to separate files
ellemouton Oct 27, 2023
8ee8cc2
channeldb: add encoding for ChannelEdgeInfo2
ellemouton Nov 14, 2023
b9f65e3
channeldb: add encoding for ChannelEdgePolicy2
ellemouton Nov 16, 2023
542e3be
routing+server: move FetchTx method to server
ellemouton Dec 6, 2023
e78d254
routing: update chan announce and update validation
ellemouton Dec 6, 2023
99d1749
routing+channeldb: update CachedEdgePolicy
ellemouton Oct 27, 2023
502ff18
channeldb: update GraphCache to use interfaces where possible
ellemouton Oct 27, 2023
6a49e86
lnrpc: update in preparation for G175
ellemouton Oct 27, 2023
3f7ba38
rpcserver: marshal new DB types for lnrpc
ellemouton Oct 27, 2023
952d53b
multi: use models.ChannelEdgeInfo throughout
ellemouton Oct 27, 2023
735d784
channeldb: update reject cache
ellemouton Nov 6, 2023
3688a87
channeldb: write to new update index for ChannelEdgePolicy2
ellemouton Nov 16, 2023
9f01c45
multi: updates to HasChannelPolicy
ellemouton Nov 6, 2023
52f0c00
multi: use models.ChannelAuthProof interface where possible
ellemouton Dec 6, 2023
13d8ad2
netann: update Ann creation funcs to take interfaces
ellemouton Dec 6, 2023
ef2ea1d
multi: use lnwire.ChannelAnnouncement interface where possible
ellemouton Nov 6, 2023
0968bb8
multi: use ChannelEdgePolicy interface where possible
ellemouton Nov 6, 2023
7c9de39
channeldb: prep waiting proof store for taproot proofs
ellemouton Nov 6, 2023
4e0691b
discovery: let handlAnnSig take lnwire.AnnounceSigs interface
ellemouton Nov 7, 2023
5ab6876
multi: use lnwire.AnnouncementSigs interface throughout
ellemouton Nov 7, 2023
1645d08
netann: give ChanStatusManager access to BestBlockView
ellemouton Nov 7, 2023
5a89027
multi: use MessageSignerRing where needed
ellemouton Nov 16, 2023
681a858
netann: update ChanUpdate modifiers to use interface
ellemouton Nov 7, 2023
f7dacf3
netann: let SignChannelUpdate take ChannelUpdate interface
ellemouton Nov 7, 2023
d5cef13
multi: update SignAliasUpdate to take ChannelUpdate interface
ellemouton Nov 7, 2023
213a696
routing: update to use lnwire.ChannelUpdate interface
ellemouton Nov 7, 2023
d3c0180
multi: let some netann funcs use lnwire.ChannelUpdate
ellemouton Nov 7, 2023
63d6ff4
multi: use ChannelUpdate interface for failure messages
ellemouton Nov 7, 2023
10df4f1
htlcswitch: let failAliasUpdate return lnwire.ChannelUpdate
ellemouton Nov 7, 2023
032404e
htlcswitch: use ChannelUpdate interface in FetchLastChannelUpdate
ellemouton Nov 7, 2023
3df0edc
netann: use ChannelUpdate interface in ExtractChannelUpdate
ellemouton Nov 7, 2023
23ae902
multi: use ChannelUpdate interface in various places
ellemouton Nov 7, 2023
d02804a
discovery+routing: update to use ChanUpdate interface
ellemouton Nov 7, 2023
c76c05b
discovery: use ChannelUpdate interface in handleChanUpdate
ellemouton Nov 7, 2023
1325380
discovery: Filter ChanUpdate2 messages
ellemouton Nov 7, 2023
5b484b8
channeldb: Update ChanUpdatesInHorizon
ellemouton Nov 7, 2023
5531356
discovery: update UpdatesInHorizon
ellemouton Nov 7, 2023
5d2291b
discovery: start sending block heights in range query
ellemouton Nov 7, 2023
1a9d5e2
channeldb: Nonce persistance
ellemouton Oct 9, 2023
34be158
funding: add channel_ready nonce exchange
ellemouton Oct 10, 2023
483fb0f
funding: prep with signers needed for g175 messages
ellemouton Nov 16, 2023
d56c54b
funding: start creating channel_announcement_2
ellemouton Nov 7, 2023
a0336c8
feature+lnwire: add taproot gossip feature bit
ellemouton Oct 10, 2023
e8ea3d8
funding: allow public taproot channels
ellemouton Oct 10, 2023
13ebe5d
server+rpcserver: allow public tap chans
ellemouton Oct 10, 2023
7c956a6
itest: allow public taproot chan tests
ellemouton Oct 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions autopilot/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (d *dbNode) Addrs() []net.Addr {
// NOTE: Part of the autopilot.Node interface.
func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
return d.db.ForEachNodeChannel(d.tx, d.node.PubKeyBytes,
func(tx kvdb.RTx, ei *models.ChannelEdgeInfo, ep,
_ *models.ChannelEdgePolicy) error {
func(tx kvdb.RTx, ei models.ChannelEdgeInfo, ep,
_ models.ChannelEdgePolicy) error {

// Skip channels for which no outgoing edge policy is
// available.
Expand All @@ -105,16 +105,14 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
return nil
}

node, err := d.db.FetchLightningNode(tx, ep.ToNode)
node, err := d.db.FetchLightningNode(tx, ep.GetToNode())
if err != nil {
return err
}

edge := ChannelEdge{
ChanID: lnwire.NewShortChanIDFromInt(
ep.ChannelID,
),
Capacity: ei.Capacity,
ChanID: ep.SCID(),
Capacity: ei.GetCapacity(),
Peer: &dbNode{
tx: tx,
db: d.db,
Expand Down Expand Up @@ -236,15 +234,15 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
}

chanID := randChanID()
edge := &models.ChannelEdgeInfo{
edge := &models.ChannelEdgeInfo1{
ChannelID: chanID.ToUint64(),
Capacity: capacity,
}
edge.AddNodeKeys(lnNode1, lnNode2, lnNode1, lnNode2)
if err := d.db.AddChannelEdge(edge); err != nil {
return nil, nil, err
}
edgePolicy := &models.ChannelEdgePolicy{
edgePolicy := &models.ChannelEdgePolicy1{
SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
Expand All @@ -260,7 +258,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, nil, err
}
edgePolicy = &models.ChannelEdgePolicy{
edgePolicy = &models.ChannelEdgePolicy1{
SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
Expand Down
161 changes: 161 additions & 0 deletions channeldb/announcement_nonces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package channeldb

import (
"fmt"

"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
)

var (
// announcementNoncesBucket is a top level bucket with the following
// structure: channel_id => node_nonce || bitcoin_nonce
announcementNoncesBucket = []byte("announcement-nonces")
)

type AnnouncementNonceStore interface {
SaveAnnouncementNonces(chanID lnwire.ChannelID,
nonces *AnnouncementNonces) error

GetAllAnnouncementNonces() (map[lnwire.ChannelID]AnnouncementNonces,
error)

DeleteAnnouncementNonces(chanID lnwire.ChannelID) error

GetAnnouncementNonces(chanID lnwire.ChannelID) (*AnnouncementNonces,
error)
}

// AnnouncementNonces holds the nonces used during the creating of a
// ChannelAnnouncement2.
type AnnouncementNonces struct {
Btc [musig2.PubNonceSize]byte
Node [musig2.PubNonceSize]byte
}

// SaveAnnouncementNonces persist the given announcement nonces.
func (c *ChannelStateDB) SaveAnnouncementNonces(chanID lnwire.ChannelID,
nonces *AnnouncementNonces) error {

chanIDCopy := make([]byte, 32)
copy(chanIDCopy, chanID[:])

scratch := make([]byte, musig2.PubNonceSize*2)
copy(scratch[:musig2.PubNonceSize], nonces.Node[:])
copy(scratch[musig2.PubNonceSize:], nonces.Btc[:])

return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
bucket, err := tx.CreateTopLevelBucket(
announcementNoncesBucket,
)
if err != nil {
return err
}

return bucket.Put(chanIDCopy, scratch)
}, func() {})
}

// GetAllAnnouncementNonces returns all the announcement nonce pairs currently
// stored in the DB.
func (c *ChannelStateDB) GetAllAnnouncementNonces() (
map[lnwire.ChannelID]AnnouncementNonces, error) {

m := make(map[lnwire.ChannelID]AnnouncementNonces)
err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
bucket := tx.ReadBucket(announcementNoncesBucket)
if bucket == nil {
return nil
}

return bucket.ForEach(func(k, v []byte) error {
if len(k) != 32 {
return fmt.Errorf("invalid chan ID key")
}
if len(v) != musig2.PubNonceSize*2 {
return fmt.Errorf("wrong number of bytes")
}

var chanID lnwire.ChannelID
copy(chanID[:], k)

var btc, node [musig2.PubNonceSize]byte

copy(node[:], v[:musig2.PubNonceSize])
copy(btc[:], v[musig2.PubNonceSize:])

m[chanID] = AnnouncementNonces{
Btc: btc,
Node: node,
}

return nil
})
}, func() {
m = make(map[lnwire.ChannelID]AnnouncementNonces)
})
if err != nil {
return nil, err
}

return m, nil
}

// GetAnnouncementNonces fetches the announcement nonces for the given channel
// ID.
func (c *ChannelStateDB) GetAnnouncementNonces(chanID lnwire.ChannelID) (
*AnnouncementNonces, error) {

chanIDCopy := make([]byte, 32)
copy(chanIDCopy, chanID[:])

var nonces AnnouncementNonces
err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
bucket := tx.ReadBucket(announcementNoncesBucket)
if bucket == nil {
return ErrChannelNotFound
}

noncesBytes := bucket.Get(chanIDCopy)
if noncesBytes == nil {
return ErrChannelNotFound
}

if len(noncesBytes) != musig2.PubNonceSize*2 {
return fmt.Errorf("wrong number of bytes")
}

copy(nonces.Node[:], noncesBytes[:musig2.PubNonceSize])
copy(nonces.Btc[:], noncesBytes[musig2.PubNonceSize:])

return nil
}, func() {
nonces = AnnouncementNonces{}
})
if err != nil {
return nil, err
}

return &nonces, nil
}

// DeleteAnnouncementNonces deletes the announcement nonce pair stored under
// the given channel ID key if an entry exists.
func (c *ChannelStateDB) DeleteAnnouncementNonces(
chanID lnwire.ChannelID) error {

chanIDCopy := make([]byte, 32)
copy(chanIDCopy, chanID[:])

return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
bucket := tx.ReadWriteBucket(
announcementNoncesBucket,
)
if bucket == nil {
return nil
}

return bucket.Delete(chanIDCopy)
}, func() {})
}
109 changes: 109 additions & 0 deletions channeldb/announcement_nonces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package channeldb

import (
"math/rand"
"testing"

"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)

// TestAnnouncementNonces tests the various announcement nonce pair CRUD
// operations.
func TestAnnouncementNonces(t *testing.T) {
cdb, err := MakeTestDB(t)
require.NoError(t, err)

db := cdb.ChannelStateDB()

// Show that the set of nonces is currently empty.
nonceSet, err := db.GetAllAnnouncementNonces()
require.NoError(t, err)
require.Empty(t, nonceSet)

// Generate a random channel ID.
chanID1 := randChannelID(t)

// Assert that there is no entry for this channel yet.
_, err = db.GetAnnouncementNonces(chanID1)
require.ErrorIs(t, err, ErrChannelNotFound)

// Insert an entry.
nonces1 := AnnouncementNonces{
Btc: randNonce(t),
Node: randNonce(t),
}

err = db.SaveAnnouncementNonces(chanID1, &nonces1)
require.NoError(t, err)

// Assert that the entry is now returned.
n, err := db.GetAnnouncementNonces(chanID1)
require.NoError(t, err)
require.Equal(t, &nonces1, n)

nonceSet, err = db.GetAllAnnouncementNonces()
require.NoError(t, err)
require.EqualValues(t, map[lnwire.ChannelID]AnnouncementNonces{
chanID1: nonces1,
}, nonceSet)

// Add another entry.
chanID2 := randChannelID(t)
nonces2 := AnnouncementNonces{
Btc: randNonce(t),
Node: randNonce(t),
}

err = db.SaveAnnouncementNonces(chanID2, &nonces2)
require.NoError(t, err)

n, err = db.GetAnnouncementNonces(chanID2)
require.NoError(t, err)
require.Equal(t, &nonces2, n)

nonceSet, err = db.GetAllAnnouncementNonces()
require.NoError(t, err)
require.EqualValues(t, map[lnwire.ChannelID]AnnouncementNonces{
chanID1: nonces1,
chanID2: nonces2,
}, nonceSet)

// Now, assert that deletion works.
err = db.DeleteAnnouncementNonces(chanID1)
require.NoError(t, err)

_, err = db.GetAnnouncementNonces(chanID1)
require.ErrorIs(t, err, ErrChannelNotFound)

nonceSet, err = db.GetAllAnnouncementNonces()
require.NoError(t, err)
require.EqualValues(t, map[lnwire.ChannelID]AnnouncementNonces{
chanID2: nonces2,
}, nonceSet)

err = db.DeleteAnnouncementNonces(chanID2)
require.NoError(t, err)

nonceSet, err = db.GetAllAnnouncementNonces()
require.NoError(t, err)
require.Empty(t, nonceSet)
}

func randChannelID(t *testing.T) lnwire.ChannelID {
var chanID lnwire.ChannelID

_, err := rand.Read(chanID[:])
require.NoError(t, err)

return chanID
}

func randNonce(t *testing.T) [66]byte {
var b [66]byte

_, err := rand.Read(b[:])
require.NoError(t, err)

return b
}
2 changes: 1 addition & 1 deletion channeldb/channel_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func assertHasChanEntries(t *testing.T, c *channelCache, start, end uint64) {
// channelForInt generates a unique ChannelEdge given an integer.
func channelForInt(i uint64) ChannelEdge {
return ChannelEdge{
Info: &models.ChannelEdgeInfo{
Info: &models.ChannelEdgeInfo1{
ChannelID: i,
},
}
Expand Down
5 changes: 5 additions & 0 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/migration29"
"github.com/lightningnetwork/lnd/channeldb/migration30"
"github.com/lightningnetwork/lnd/channeldb/migration31"
"github.com/lightningnetwork/lnd/channeldb/migration32"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/invoices"
Expand Down Expand Up @@ -286,6 +287,10 @@ var (
number: 31,
migration: migration31.DeleteLastPublishedTxTLB,
},
{
number: 32,
migration: migration32.MigrateWaitingProofStore,
},
}

// optionalVersions stores all optional migrations that are applied
Expand Down
Loading