Merge pull request #9856 from ellemouton/writeOpaqueAddr
lnwire: add lnwire.OpaqueAddr case in WriteElement for channel back-ups
This commit is contained in:
5 files changed
+105
-66
No files matched your search
@@ -156,6 +156,8 @@ func TestFetchStaticChanBackups(t *testing.T) {
|
|||||||
chanSource.chans[randomChan2.FundingOutpoint] = randomChan2
|
chanSource.chans[randomChan2.FundingOutpoint] = randomChan2
|
||||||
chanSource.addAddrsForNode(randomChan1.IdentityPub, []net.Addr{addr1})
|
chanSource.addAddrsForNode(randomChan1.IdentityPub, []net.Addr{addr1})
|
||||||
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr2})
|
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr2})
|
||||||
|
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr3})
|
||||||
|
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr4})
|
||||||
|
|
||||||
// With the channel source populated, we'll now attempt to create a set
|
// With the channel source populated, we'll now attempt to create a set
|
||||||
// of backups for all the channels. This should succeed, as all items
|
// of backups for all the channels. This should succeed, as all items
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ func TestMultiPackUnpack(t *testing.T) {
|
|||||||
t.Fatalf("unable to gen channel: %v", err)
|
t.Fatalf("unable to gen channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
single := NewSingle(channel, []net.Addr{addr1, addr2})
|
single := NewSingle(
|
||||||
|
channel, []net.Addr{addr1, addr2, addr3, addr4},
|
||||||
|
)
|
||||||
|
|
||||||
originalSingles = append(originalSingles, single)
|
originalSingles = append(originalSingles, single)
|
||||||
multi.StaticBackups = append(multi.StaticBackups, single)
|
multi.StaticBackups = append(multi.StaticBackups, single)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnencrypt"
|
"github.com/lightningnetwork/lnd/lnencrypt"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
|
"github.com/lightningnetwork/lnd/tor"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,6 +37,15 @@ var (
|
|||||||
|
|
||||||
addr1, _ = net.ResolveTCPAddr("tcp", "10.0.0.2:9000")
|
addr1, _ = net.ResolveTCPAddr("tcp", "10.0.0.2:9000")
|
||||||
addr2, _ = net.ResolveTCPAddr("tcp", "10.0.0.3:9000")
|
addr2, _ = net.ResolveTCPAddr("tcp", "10.0.0.3:9000")
|
||||||
|
addr3 = &tor.OnionAddr{
|
||||||
|
OnionService: "3g2upl4pq6kufc4m.onion",
|
||||||
|
Port: 9735,
|
||||||
|
}
|
||||||
|
addr4 = &lnwire.OpaqueAddrs{
|
||||||
|
// The first byte must be an address type we are not yet aware
|
||||||
|
// of for it to be a valid OpaqueAddrs.
|
||||||
|
Payload: []byte{math.MaxUint8, 1, 2, 3, 4},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertSingleEqual(t *testing.T, a, b Single) {
|
func assertSingleEqual(t *testing.T, a, b Single) {
|
||||||
@@ -309,7 +319,9 @@ func TestSinglePackUnpack(t *testing.T) {
|
|||||||
channel, err := genRandomOpenChannelShell()
|
channel, err := genRandomOpenChannelShell()
|
||||||
require.NoError(t, err, "unable to gen open channel")
|
require.NoError(t, err, "unable to gen open channel")
|
||||||
|
|
||||||
singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2})
|
singleChanBackup := NewSingle(
|
||||||
|
channel, []net.Addr{addr1, addr2, addr3, addr4},
|
||||||
|
)
|
||||||
|
|
||||||
keyRing := &lnencrypt.MockKeyRing{}
|
keyRing := &lnencrypt.MockKeyRing{}
|
||||||
|
|
||||||
@@ -634,7 +646,9 @@ func TestSingleUnconfirmedChannel(t *testing.T) {
|
|||||||
channel.ShortChannelID.BlockHeight = 0
|
channel.ShortChannelID.BlockHeight = 0
|
||||||
channel.FundingBroadcastHeight = fundingBroadcastHeight
|
channel.FundingBroadcastHeight = fundingBroadcastHeight
|
||||||
|
|
||||||
singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2})
|
singleChanBackup := NewSingle(
|
||||||
|
channel, []net.Addr{addr1, addr2, addr3, addr4},
|
||||||
|
)
|
||||||
keyRing := &lnencrypt.MockKeyRing{}
|
keyRing := &lnencrypt.MockKeyRing{}
|
||||||
|
|
||||||
// Pack it and then unpack it again to make sure everything is written
|
// Pack it and then unpack it again to make sure everything is written
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
# Release Notes
|
||||||
|
- [Bug Fixes](#bug-fixes)
|
||||||
|
- [New Features](#new-features)
|
||||||
|
- [Functional Enhancements](#functional-enhancements)
|
||||||
|
- [RPC Additions](#rpc-additions)
|
||||||
|
- [lncli Additions](#lncli-additions)
|
||||||
|
- [Improvements](#improvements)
|
||||||
|
- [Functional Updates](#functional-updates)
|
||||||
|
- [RPC Updates](#rpc-updates)
|
||||||
|
- [lncli Updates](#lncli-updates)
|
||||||
|
- [Breaking Changes](#breaking-changes)
|
||||||
|
- [Performance Improvements](#performance-improvements)
|
||||||
|
- [Deprecations](#deprecations)
|
||||||
|
- [Technical and Architectural Updates](#technical-and-architectural-updates)
|
||||||
|
- [BOLT Spec Updates](#bolt-spec-updates)
|
||||||
|
- [Testing](#testing)
|
||||||
|
- [Database](#database)
|
||||||
|
- [Code Health](#code-health)
|
||||||
|
- [Tooling and Documentation](#tooling-and-documentation)
|
||||||
|
|
||||||
|
# Bug Fixes
|
||||||
|
|
||||||
|
* [Fix a serialisation bug](https://github.com/lightningnetwork/lnd/pull/9856)
|
||||||
|
that would occur when an attempt was made to write a backup file for a channel
|
||||||
|
peer that has advertised an address that we do not yet know how to parse.
|
||||||
|
|
||||||
|
# New Features
|
||||||
|
|
||||||
|
## Functional Enhancements
|
||||||
|
|
||||||
|
## RPC Additions
|
||||||
|
|
||||||
|
## lncli Additions
|
||||||
|
|
||||||
|
# Improvements
|
||||||
|
## Functional Updates
|
||||||
|
|
||||||
|
## RPC Updates
|
||||||
|
|
||||||
|
## lncli Updates
|
||||||
|
|
||||||
|
## Code Health
|
||||||
|
|
||||||
|
## Breaking Changes
|
||||||
|
## Performance Improvements
|
||||||
|
|
||||||
|
## Deprecations
|
||||||
|
|
||||||
|
### ⚠️ **Warning:** The following RPCs will be removed in release version **0.21**:
|
||||||
|
|
||||||
|
| Deprecated RPC Method | REST Equivalent | HTTP Method | Path | Replaced By |
|
||||||
|
|----------------------|----------------|-------------|------------------------------|------------------|
|
||||||
|
| [`lnrpc.SendToRoute`](https://lightning.engineering/api-docs/api/lnd/lightning/send-to-route/index.html) <br> [`routerrpc.SendToRoute`](https://lightning.engineering/api-docs/api/lnd/router/send-to-route/) | ❌ (No direct REST equivalent) | — | — | [`routerrpc.SendToRouteV2`](https://lightning.engineering/api-docs/api/lnd/router/send-to-route-v2/) |
|
||||||
|
| [`lnrpc.SendPayment`](https://lightning.engineering/api-docs/api/lnd/lightning/send-payment/) <br> [`routerrpc.SendPayment`](https://lightning.engineering/api-docs/api/lnd/router/send-payment/) | ✅ | `POST` | `/v1/channels/transaction-stream` | [`routerrpc.SendPaymentV2`](https://lightning.engineering/api-docs/api/lnd/router/send-payment-v2/index.html) |
|
||||||
|
| [`lnrpc.SendToRouteSync`](https://lightning.engineering/api-docs/api/lnd/lightning/send-to-route-sync/index.html) | ✅ | `POST` | `/v1/channels/transactions/route` | [`routerrpc.SendToRouteV2`](https://lightning.engineering/api-docs/api/lnd/router/send-to-route-v2/) |
|
||||||
|
| [`lnrpc.SendPaymentSync`](https://lightning.engineering/api-docs/api/lnd/lightning/send-payment-sync/index.html) | ✅ | `POST` | `/v1/channels/transactions` | [`routerrpc.SendPaymentV2`](https://lightning.engineering/api-docs/api/lnd/router/send-payment-v2/index.html) |
|
||||||
|
| [`router.TrackPayment`](https://lightning.engineering/api-docs/api/lnd/router/track-payment/index.html) | ❌ (No direct REST equivalent) | — | — | [`routerrpc.TrackPaymentV2`](https://lightning.engineering/api-docs/api/lnd/router/track-payment-v2/) |
|
||||||
|
|
||||||
|
🚨 **Users are strongly encouraged** to transition to the new **V2 methods** before release **0.21** to ensure compatibility:
|
||||||
|
|
||||||
|
| New RPC Method | REST Equivalent | HTTP Method | Path |
|
||||||
|
|---------------|----------------|-------------|------------------------|
|
||||||
|
| [`routerrpc.SendToRouteV2`](https://lightning.engineering/api-docs/api/lnd/router/send-to-route-v2/) | ✅ | `POST` | `/v2/router/route/send` |
|
||||||
|
| [`routerrpc.SendPaymentV2`](https://lightning.engineering/api-docs/api/lnd/router/send-payment-v2/index.html) | ✅ | `POST` | `/v2/router/send` |
|
||||||
|
| [`routerrpc.TrackPaymentV2`](https://lightning.engineering/api-docs/api/lnd/router/track-payment-v2/) | ✅ | `GET` | `/v2/router/track/{payment_hash}` |
|
||||||
|
|
||||||
|
# Technical and Architectural Updates
|
||||||
|
## BOLT Spec Updates
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
## Database
|
||||||
|
|
||||||
|
## Code Health
|
||||||
|
|
||||||
|
## Tooling and Documentation
|
||||||
|
|
||||||
|
# Contributors (Alphabetical Order)
|
||||||
|
|
||||||
|
* Elle Mouton
|
||||||
+4
-63
@@ -339,76 +339,17 @@ func WriteElement(w *bytes.Buffer, element interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *net.TCPAddr:
|
case *net.TCPAddr:
|
||||||
if e == nil {
|
if err := WriteTCPAddr(w, e); err != nil {
|
||||||
return fmt.Errorf("cannot write nil TCPAddr")
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.IP.To4() != nil {
|
|
||||||
var descriptor [1]byte
|
|
||||||
descriptor[0] = uint8(tcp4Addr)
|
|
||||||
if _, err := w.Write(descriptor[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var ip [4]byte
|
|
||||||
copy(ip[:], e.IP.To4())
|
|
||||||
if _, err := w.Write(ip[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var descriptor [1]byte
|
|
||||||
descriptor[0] = uint8(tcp6Addr)
|
|
||||||
if _, err := w.Write(descriptor[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var ip [16]byte
|
|
||||||
copy(ip[:], e.IP.To16())
|
|
||||||
if _, err := w.Write(ip[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var port [2]byte
|
|
||||||
binary.BigEndian.PutUint16(port[:], uint16(e.Port))
|
|
||||||
if _, err := w.Write(port[:]); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
case *tor.OnionAddr:
|
case *tor.OnionAddr:
|
||||||
if e == nil {
|
if err := WriteOnionAddr(w, e); err != nil {
|
||||||
return errors.New("cannot write nil onion address")
|
|
||||||
}
|
|
||||||
|
|
||||||
var suffixIndex int
|
|
||||||
switch len(e.OnionService) {
|
|
||||||
case tor.V2Len:
|
|
||||||
descriptor := []byte{byte(v2OnionAddr)}
|
|
||||||
if _, err := w.Write(descriptor); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
suffixIndex = tor.V2Len - tor.OnionSuffixLen
|
|
||||||
case tor.V3Len:
|
|
||||||
descriptor := []byte{byte(v3OnionAddr)}
|
|
||||||
if _, err := w.Write(descriptor); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
suffixIndex = tor.V3Len - tor.OnionSuffixLen
|
|
||||||
default:
|
|
||||||
return errors.New("unknown onion service length")
|
|
||||||
}
|
|
||||||
|
|
||||||
host, err := tor.Base32Encoding.DecodeString(
|
|
||||||
e.OnionService[:suffixIndex],
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := w.Write(host); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var port [2]byte
|
case *OpaqueAddrs:
|
||||||
binary.BigEndian.PutUint16(port[:], uint16(e.Port))
|
if err := WriteOpaqueAddrs(w, e); err != nil {
|
||||||
if _, err := w.Write(port[:]); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user