Skip to content

Commit 135a4bd

Browse files
authored
Merge pull request #1854 from lightninglabs/wip/issue1850-improve-v2-addr-management
rpcserver: NewAddr universal courier connectivity check, offline skip, and local asset precheck
2 parents be1742c + e9e312a commit 135a4bd

File tree

7 files changed

+649
-595
lines changed

7 files changed

+649
-595
lines changed

docs/release-notes/release-notes-0.7.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@
271271

272272
## RPC Updates
273273

274+
- [PR](https://github.com/lightninglabs/taproot-assets/pull/1854) The `NewAddr`
275+
RPC now performs a proof courier connectivity check for all tap address types
276+
using a universe RPC URL scheme. A new flag allows skipping this check for
277+
offline address generation. Additionally, an early sanity check ensures the
278+
asset is recognized locally before attempting any courier connection check.
279+
274280
## tapcli Updates
275281

276282
- The default script key type in the `tapcli assets list`,

itest/addrs_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"net/url"
78
"time"
89

910
"github.com/btcsuite/btcd/btcec/v2/schnorr"
@@ -491,7 +492,12 @@ func testAddressAssetSyncer(t *harnessTest) {
491492

492493
thirdAsset := secondRpcAssets[2]
493494
thirdGroup := thirdAsset.AssetGroup
494-
v2Courier := address.RandProofCourierAddrForVersion(t.t, address.V2)
495+
496+
v2Courier, err := url.Parse(
497+
"authmailbox+universerpc://" + t.universeServer.ListenAddr,
498+
)
499+
require.NoError(t.t, err)
500+
495501
_, err = bob.NewAddr(ctxt, &taprpc.NewAddrRequest{
496502
AddressVersion: taprpc.AddrVersion_ADDR_VERSION_V2,
497503
GroupKey: thirdGroup.TweakedGroupKey,

itest/send_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,10 @@ func testSpendChangeOutputWhenProofTransferFail(t *harnessTest) {
11801180
// (due to the proof courier being shut down). We will generate a new
11811181
// address for this new transaction.
11821182
recvAddr, err = recvTapd.NewAddr(ctxb, &taprpc.NewAddrRequest{
1183-
AssetId: genInfo.AssetId,
1184-
Amt: 42,
1185-
ProofCourierAddr: proofCourierAddr,
1183+
AssetId: genInfo.AssetId,
1184+
Amt: 42,
1185+
ProofCourierAddr: proofCourierAddr,
1186+
SkipProofCourierConnCheck: true,
11861187
})
11871188
require.NoError(t.t, err)
11881189
AssertAddrCreated(t.t, recvTapd, rpcAssets[0], recvAddr)

rpcserver.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,12 @@ func (r *rpcServer) NewAddr(ctx context.Context,
16621662
err)
16631663
}
16641664

1665+
// Sanity check early to ensure that the asset is known.
1666+
_, err = r.cfg.AddrBook.QueryAssetInfo(ctx, specifier)
1667+
if err != nil {
1668+
return nil, fmt.Errorf("unable to find asset or group: %w", err)
1669+
}
1670+
16651671
err = r.checkBalanceOverflow(ctx, assetID, groupKey, req.Amt)
16661672
if err != nil {
16671673
return nil, err
@@ -1698,40 +1704,49 @@ func (r *rpcServer) NewAddr(ctx context.Context,
16981704
"courier=%v, addr_version=%v, asset_version=%v", &specifier,
16991705
req.Amt, courierAddr, addrVersion, assetVersion)
17001706

1701-
// Addresses with version 2 must use the new authmailbox proof courier
1707+
// Addresses with version 2 must use the new auth mailbox proof courier
17021708
// type.
1703-
protocol := courierAddr.Scheme
17041709
switch {
17051710
case addrVersion == address.V2 &&
1706-
protocol == proof.UniverseRpcCourierType:
1711+
courierAddr.Scheme == proof.UniverseRpcCourierType:
17071712

17081713
// We assume that any proof courier running an RPC universe
17091714
// server will upgrade soon to support the new auth mailbox
17101715
// courier type, so we bump the protocol/scheme to the combined
17111716
// one.
17121717
courierAddr.Scheme = proof.AuthMailboxUniRpcCourierType
17131718

1714-
// Let's make sure the proof courier actually supports the
1715-
// auth mailbox courier type.
1716-
err := proof.CheckUniverseRpcCourierConnection(
1717-
ctx, proofCourierCheckTimeout, courierAddr,
1718-
)
1719-
if err != nil {
1720-
return nil, err
1721-
}
1722-
17231719
case addrVersion == address.V2 &&
1724-
protocol == proof.AuthMailboxUniRpcCourierType:
1720+
courierAddr.Scheme == proof.AuthMailboxUniRpcCourierType:
17251721

17261722
// Great, nothing to do here, this is the courier type we want.
17271723

1728-
case addrVersion == address.V2 && protocol == proof.HashmailCourierType:
1724+
case addrVersion == address.V2 &&
1725+
courierAddr.Scheme == proof.HashmailCourierType:
1726+
17291727
return nil, fmt.Errorf("%w: address version %d must use the "+
17301728
"'%s' proof courier type",
17311729
address.ErrInvalidProofCourierAddr, addrVersion,
17321730
proof.AuthMailboxUniRpcCourierType)
17331731
}
17341732

1733+
// If the courier is an (auth mailbox) universe RPC type we will check
1734+
// that we can connect to it.
1735+
connCheckScheme := courierAddr.Scheme == proof.UniverseRpcCourierType ||
1736+
courierAddr.Scheme == proof.AuthMailboxUniRpcCourierType
1737+
if !req.SkipProofCourierConnCheck && connCheckScheme {
1738+
rpcsLog.DebugS(ctx, "Checking connection to universe server "+
1739+
"RPC", "courier_addr", courierAddr.String())
1740+
1741+
err := proof.CheckUniverseRpcCourierConnection(
1742+
ctx, proofCourierCheckTimeout, courierAddr,
1743+
)
1744+
if err != nil {
1745+
return nil, fmt.Errorf("connection check failed for "+
1746+
"universe server RPC proof courier: %w", err)
1747+
}
1748+
}
1749+
17351750
var addr *address.AddrWithKeyInfo
17361751
switch {
17371752
// No key was specified, we'll let the address book derive them.

0 commit comments

Comments
 (0)