Skip to content

Commit d33377e

Browse files
committed
rpcserver: NewAddr endpoint: check connections for all uni URLs
Move the connection check to a general location so it runs for all tap address types, as long as the proof courier URL scheme is a universe RPC URL scheme. Add a flag to skip the connection check when generating tap addresses offline.
1 parent 108b400 commit d33377e

File tree

6 files changed

+637
-595
lines changed

6 files changed

+637
-595
lines changed

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: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,40 +1704,49 @@ func (r *rpcServer) NewAddr(ctx context.Context,
17041704
"courier=%v, addr_version=%v, asset_version=%v", &specifier,
17051705
req.Amt, courierAddr, addrVersion, assetVersion)
17061706

1707-
// Addresses with version 2 must use the new authmailbox proof courier
1707+
// Addresses with version 2 must use the new auth mailbox proof courier
17081708
// type.
1709-
protocol := courierAddr.Scheme
17101709
switch {
17111710
case addrVersion == address.V2 &&
1712-
protocol == proof.UniverseRpcCourierType:
1711+
courierAddr.Scheme == proof.UniverseRpcCourierType:
17131712

17141713
// We assume that any proof courier running an RPC universe
17151714
// server will upgrade soon to support the new auth mailbox
17161715
// courier type, so we bump the protocol/scheme to the combined
17171716
// one.
17181717
courierAddr.Scheme = proof.AuthMailboxUniRpcCourierType
17191718

1720-
// Let's make sure the proof courier actually supports the
1721-
// auth mailbox courier type.
1722-
err := proof.CheckUniverseRpcCourierConnection(
1723-
ctx, proofCourierCheckTimeout, courierAddr,
1724-
)
1725-
if err != nil {
1726-
return nil, err
1727-
}
1728-
17291719
case addrVersion == address.V2 &&
1730-
protocol == proof.AuthMailboxUniRpcCourierType:
1720+
courierAddr.Scheme == proof.AuthMailboxUniRpcCourierType:
17311721

17321722
// Great, nothing to do here, this is the courier type we want.
17331723

1734-
case addrVersion == address.V2 && protocol == proof.HashmailCourierType:
1724+
case addrVersion == address.V2 &&
1725+
courierAddr.Scheme == proof.HashmailCourierType:
1726+
17351727
return nil, fmt.Errorf("%w: address version %d must use the "+
17361728
"'%s' proof courier type",
17371729
address.ErrInvalidProofCourierAddr, addrVersion,
17381730
proof.AuthMailboxUniRpcCourierType)
17391731
}
17401732

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+
17411750
var addr *address.AddrWithKeyInfo
17421751
switch {
17431752
// No key was specified, we'll let the address book derive them.

0 commit comments

Comments
 (0)