Skip to content

G7 #140

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

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open

G7 #140

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7adfc71
multi: rename ChannelAuthProof
ellemouton Aug 21, 2024
0225c6c
multi: rename ChannelEdgePolicy
ellemouton Aug 21, 2024
d2858d3
multi: rename ChannelEdgeInfo
ellemouton Aug 21, 2024
e3fb10c
channeldb: add ChanneEdgeInfo and ChannelAuthProof interfaces
ellemouton Oct 27, 2023
0e8fc7d
channeldb: add ChannelEdgePolicy interface
ellemouton Aug 21, 2024
6165c9b
channeldb: add ChannelAuthProof2
ellemouton Oct 27, 2023
5a7591b
channeldb: add ChannelEdgeInfo2
ellemouton Oct 27, 2023
5b8b7be
channeldb: add ChannelEdgePolicy2
ellemouton Oct 27, 2023
d4bdbe8
channeldb+refactor: move ser/deser funcs to separate files
ellemouton Aug 21, 2024
51bdfbc
channeldb: add encoding for ChannelEdgeInfo2
ellemouton Aug 21, 2024
43715bb
channeldb: add encoding for ChannelEdgePolicy2
ellemouton Aug 21, 2024
425c10d
docs: update release notes
ellemouton Aug 21, 2024
4dbb069
routing+channeldb: update CachedEdgePolicy
ellemouton Oct 27, 2023
b21f165
channeldb: update GraphCache to use interfaces where possible
ellemouton Oct 27, 2023
53c8b77
lnrpc: update in preparation for G175
ellemouton Aug 21, 2024
3d3c8e6
rpcserver: marshal new DB types for lnrpc
ellemouton Aug 21, 2024
bd8c65c
multi: use models.ChannelEdgeInfo throughout
ellemouton Aug 21, 2024
03f0a0e
channeldb: update reject cache
ellemouton Nov 6, 2023
5a9b44b
channeldb: write to new update index for ChannelEdgePolicy2
ellemouton Nov 16, 2023
dd4c935
multi: updates to HasChannelPolicy
ellemouton Aug 23, 2024
e99a00f
docs: update release notes
ellemouton Aug 23, 2024
d383a44
multi: use models.ChannelAuthProof interface where possible
ellemouton Dec 6, 2023
12a7c02
netann: update Ann creation funcs to take interfaces
ellemouton Dec 6, 2023
e070ee3
multi: use lnwire.ChannelAnnouncement interface where possible
ellemouton Nov 6, 2023
90873ce
multi: use ChannelEdgePolicy interface where possible
ellemouton Nov 6, 2023
0506d85
channeldb: prep waiting proof store for taproot proofs
ellemouton Nov 6, 2023
9a6a95c
discovery: let handlAnnSig take lnwire.AnnounceSigs interface
ellemouton Nov 7, 2023
d00d03b
multi: use lnwire.AnnouncementSigs interface throughout
ellemouton Nov 7, 2023
e8c0abe
docs: update release notes
ellemouton Aug 23, 2024
83a7c54
netann: give ChanStatusManager access to BestBlockView
ellemouton Nov 7, 2023
1d1d222
multi: use MessageSignerRing where needed
ellemouton Nov 16, 2023
ec855fe
netann: update ChanUpdate modifiers to use interface
ellemouton Nov 7, 2023
7a19392
netann: let SignChannelUpdate take ChannelUpdate interface
ellemouton Nov 7, 2023
a2b58cb
multi: update SignAliasUpdate to take ChannelUpdate interface
ellemouton Nov 7, 2023
5ce647a
routing: update to use lnwire.ChannelUpdate interface
ellemouton Nov 7, 2023
5aee5fb
multi: let some netann funcs use lnwire.ChannelUpdate
ellemouton Nov 7, 2023
92b6d11
multi: use ChannelUpdate interface for failure messages
ellemouton Nov 7, 2023
b3602d6
htlcswitch: let failAliasUpdate return lnwire.ChannelUpdate
ellemouton Nov 7, 2023
c42cdd4
htlcswitch: use ChannelUpdate interface in FetchLastChannelUpdate
ellemouton Nov 7, 2023
39f0eee
netann: use ChannelUpdate interface in ExtractChannelUpdate
ellemouton Nov 7, 2023
d5ecbeb
multi: use ChannelUpdate interface in various places
ellemouton Nov 7, 2023
58bad38
discovery+routing: update to use ChanUpdate interface
ellemouton Nov 7, 2023
a0f99e9
discovery: use ChannelUpdate interface in handleChanUpdate
ellemouton Nov 7, 2023
df145e7
docs: add release notes
ellemouton Aug 23, 2024
f5fb2a4
discovery: Filter ChanUpdate2 messages
ellemouton Nov 7, 2023
18423e8
channeldb: Update ChanUpdatesInHorizon
ellemouton Nov 7, 2023
40fff04
discovery: update UpdatesInHorizon
ellemouton Nov 7, 2023
b1d21fc
discovery: start sending block heights in range query
ellemouton Nov 7, 2023
97e807e
docs: update release notes
ellemouton Aug 23, 2024
49519e5
channeldb: Nonce persistance
ellemouton Oct 9, 2023
c4a77a1
funding: add channel_ready nonce exchange
ellemouton Oct 10, 2023
770a643
funding: prep with signers needed for g175 messages
ellemouton Nov 16, 2023
cd8eec5
funding: start creating channel_announcement_2
ellemouton Nov 7, 2023
0f0483d
feature+lnwire: add taproot gossip feature bit
ellemouton Oct 10, 2023
6e5d114
funding: allow public taproot channels
ellemouton Oct 10, 2023
d7d85e5
server+rpcserver: allow public tap chans
ellemouton Oct 10, 2023
8eaa970
itest: allow public taproot chan tests
ellemouton Oct 10, 2023
f60b58e
docs: update release notes
ellemouton Aug 23, 2024
72831aa
comments
ellemouton Oct 10, 2024
29285c8
errything
ellemouton Oct 11, 2024
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.ForEachNodeChannelTx(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 @@ -106,17 +106,15 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
}

node, err := d.db.FetchLightningNodeTx(
tx, ep.ToNode,
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 @@ -238,15 +236,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 @@ -262,7 +260,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 @@ -28,6 +28,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/migration31"
"github.com/lightningnetwork/lnd/channeldb/migration32"
"github.com/lightningnetwork/lnd/channeldb/migration33"
"github.com/lightningnetwork/lnd/channeldb/migration34"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/invoices"
Expand Down Expand Up @@ -296,6 +297,10 @@ var (
number: 33,
migration: migration33.MigrateMCStoreNameSpacedResults,
},
{
number: 34,
migration: migration34.MigrateWaitingProofStore,
},
}

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