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

[WIP] multi: use ChannelAnnouncement2 to advertise Taproot Channels #8079

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
019e307
lnwire: make MuSig2Nonce TLV type re-usable
ellemouton Sep 29, 2023
b6240b7
lnwire: add RawFeatureVectorRecordProducer
ellemouton Sep 29, 2023
d2975da
lnwire: add Encode and Pack methods for tlv.Records
ellemouton Sep 29, 2023
dc63290
lnwire: use the RawFeatureVector record methods for ChannelType
ellemouton Sep 29, 2023
3297a93
lnwire: make ShortChannelID type re-usable
ellemouton Sep 29, 2023
9b5ee28
lnwire: add btc and node announcement nonces to channel_ready
ellemouton Sep 29, 2023
1c93bbb
lnwire: add AnnouncementSignatures2 message
ellemouton Sep 29, 2023
2d246ba
lnwire: add ChannelAnnouncement2 message
ellemouton Sep 29, 2023
ecbf18f
lnwire: introduce the BooleanRecordProducer
ellemouton Sep 29, 2023
1041ad4
lnwire: add ChannelUpdate2
ellemouton Sep 29, 2023
9c03cfa
lnwire: add NodeAnnouncement2
ellemouton Sep 29, 2023
461f21f
channeldb: prepare for new channel edge encoding
ellemouton Oct 10, 2023
ee92935
channeldb: add new edge encoding for taproot channels
ellemouton Oct 10, 2023
e1917d1
lnwire: add DigestToSign to ChannelAnnouncement2
ellemouton Oct 9, 2023
f0d2d8a
routing: add ValidateChannelAnn2
ellemouton Oct 10, 2023
5b01382
netann: add CreateChanAnnouncement2
ellemouton Oct 10, 2023
c5469cd
discovery: add ChanAnn interface for handleChanAnnouncement
ellemouton Oct 10, 2023
d836ce2
discovery: add taproot impl of the ChanAnn interface
ellemouton Oct 10, 2023
aa5dfb5
multi: account for the ChannelAnnoucement2 msg everywhere
ellemouton Oct 10, 2023
9a2f667
multi: add SignMuSig2 to the MessageSigner interface
ellemouton Oct 9, 2023
4c286ad
channeldb: Nonce persistance
ellemouton Oct 9, 2023
72f9409
channeldb: prep waiting proof store for taproot proofs
ellemouton Oct 9, 2023
7b3d094
funding: add channel_ready nonce exchange
ellemouton Oct 10, 2023
37e6430
discovery: handleAnnSig2
ellemouton Oct 10, 2023
5d1e6c8
multi: allow AnnouncementSignatures2
ellemouton Oct 10, 2023
fff4188
funding+routing: start creating channel_announcement_2
ellemouton Oct 10, 2023
1f32b11
feature+lnwire: add taproot gossip feature bit
ellemouton Oct 10, 2023
da59956
funding: allow public taproot channels
ellemouton Oct 10, 2023
0350196
server+rpcserver: allow public tap chans
ellemouton Oct 10, 2023
21c241d
temp
ellemouton Oct 10, 2023
11fa696
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
132 changes: 132 additions & 0 deletions channeldb/announcement_nonces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package channeldb

import (
"fmt"

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

var announcementNoncesBucket = []byte("announcement-nonces")

func (c *ChannelStateDB) SaveAnnouncementNonces(chanID lnwire.ChannelID, node,
btc [musig2.PubNonceSize]byte) error {

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

scratch := make([]byte, musig2.PubNonceSize*2)
copy(scratch[:musig2.PubNonceSize], node[:])
copy(scratch[musig2.PubNonceSize:], 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() {})
}

type AnnouncementNonces struct {
Btc [musig2.PubNonceSize]byte
Node [musig2.PubNonceSize]byte
}

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(btc[:], v[:musig2.PubNonceSize])
copy(node[:], 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
}

func (c *ChannelStateDB) GetAnnouncementNonces(chanID lnwire.ChannelID) (
*[musig2.PubNonceSize]byte, *[musig2.PubNonceSize]byte, error) {

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

var node, btc [musig2.PubNonceSize]byte
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(node[:], noncesBytes[:musig2.PubNonceSize])
copy(btc[:], noncesBytes[musig2.PubNonceSize:])

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

return &node, &btc, nil
}

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() {})
}
Loading