Skip to content

Commit e54e03b

Browse files
authored
Merge pull request #1541 from lightninglabs/1534-refactor-pre-ignore-tree-rpc
Refactor in Preparation for Ignore Tree RPC Endpoints
2 parents d63289b + 92beb40 commit e54e03b

File tree

13 files changed

+186
-164
lines changed

13 files changed

+186
-164
lines changed

asset/asset.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -548,19 +548,15 @@ func (t Type) String() string {
548548

549549
// PrevID serves as a reference to an asset's previous input.
550550
type PrevID struct {
551-
// OutPoint refers to the asset's previous output position within a
552-
// transaction.
551+
// OutPoint is the Bitcoin-level identifier (TXID + vout) of the UTXO
552+
// anchoring the asset state.
553553
OutPoint wire.OutPoint
554554

555-
// ID is the asset ID of the previous asset tree.
555+
// ID is the TAP-level asset identifier.
556556
ID ID
557557

558-
// TODO(roasbeef): need another ref type for assets w/ a key group?
559-
560-
// ScriptKey is the previously tweaked Taproot output key committing to
561-
// the possible spending conditions of the asset. PrevID is being used
562-
// as map keys, so we want to only use data types with fixed and
563-
// comparable content, which a btcec.PublicKey might not be.
558+
// ScriptKey is the TAP-level Taproot output key that committed to the
559+
// asset's spending conditions. Serialized to ensure comparability.
564560
ScriptKey SerializedKey
565561
}
566562

itest/assets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func testAssetBalances(t *harnessTest) {
742742
},
743743
},
744744
expectError: true,
745-
expectedErrMsg: "invalid Txid",
745+
expectedErrMsg: "invalid outpoint txid",
746746
},
747747
{
748748
name: "Fail if AssetId is too short",

proof/archive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ type AnnotatedProof struct {
136136
// Exporter is used to fetch proofs by their unique identifier.
137137
type Exporter interface {
138138
// FetchProof fetches a proof for an asset uniquely identified by the
139-
// passed ProofIdentifier.
139+
// given locator.
140140
//
141141
// If a proof cannot be found, then ErrProofNotFound should be
142142
// returned. If multiple proofs exist for the given fields of the

proof/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (m *MockProofArchive) FetchIssuanceProof(_ context.Context,
356356
}
357357

358358
// Mimic the pattern matching done with proof file paths in
359-
// FileArchiver.FetchIssuanceProof().
359+
// FileArchiver.FetchProof().
360360
matchingHashes := make([][32]byte, 0)
361361
locMatcher := func(locBytes [132]byte, locHash [32]byte) error {
362362
if bytes.Equal(locBytes[:32], id[:]) &&

rpcserver.go

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,17 +1102,13 @@ func (r *rpcServer) ListAssets(ctx context.Context,
11021102
}
11031103

11041104
if req.AnchorOutpoint != nil {
1105-
txid, err := chainhash.NewHash(req.AnchorOutpoint.Txid)
1105+
op, err := rpcutils.UnmarshalOutPoint(req.AnchorOutpoint)
11061106
if err != nil {
1107-
return nil, fmt.Errorf("error parsing outpoint: %w",
1107+
return nil, fmt.Errorf("unmarshalling outpoint: %w",
11081108
err)
11091109
}
1110-
outPoint := &wire.OutPoint{
1111-
Hash: *txid,
1112-
Index: req.AnchorOutpoint.OutputIndex,
1113-
}
11141110

1115-
filters.AnchorPoint = outPoint
1111+
filters.AnchorPoint = &op
11161112
}
11171113

11181114
scriptKeyType, includeSpent, err := rpcutils.ParseScriptKeyTypeQuery(
@@ -2059,15 +2055,13 @@ func (r *rpcServer) ExportProof(ctx context.Context,
20592055
// error will be returned and the outpoint needs to be specified to
20602056
// disambiguate.
20612057
if req.Outpoint != nil {
2062-
txid, err := chainhash.NewHash(req.Outpoint.Txid)
2058+
op, err := rpcutils.UnmarshalOutPoint(req.Outpoint)
20632059
if err != nil {
2064-
return nil, fmt.Errorf("error parsing outpoint: %w",
2060+
return nil, fmt.Errorf("unmarshalling outpoint: %w",
20652061
err)
20662062
}
2067-
outPoint = &wire.OutPoint{
2068-
Hash: *txid,
2069-
Index: req.Outpoint.OutputIndex,
2070-
}
2063+
2064+
outPoint = &op
20712065
}
20722066

20732067
proofBlob, err := r.cfg.ProofArchive.FetchProof(ctx, proof.Locator{
@@ -2260,14 +2254,19 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
22602254
)
22612255
for i, input := range raw.Inputs {
22622256
if input.Outpoint == nil {
2257+
// Return an error message which specifically
2258+
// refers to the index which has a corresponding
2259+
// nil outpoint.
22632260
return nil, fmt.Errorf("input at index %d has "+
22642261
"a nil Outpoint", i)
22652262
}
22662263

2267-
hash, err := chainhash.NewHash(input.Outpoint.Txid)
2264+
outPoint, err := rpcutils.UnmarshalOutPoint(
2265+
input.Outpoint,
2266+
)
22682267
if err != nil {
2269-
return nil, fmt.Errorf("input at index %d has "+
2270-
"invalid Txid: %w", i, err)
2268+
return nil, fmt.Errorf("unmarshalling "+
2269+
"outpoint: %w", err)
22712270
}
22722271

22732272
scriptKey, err := parseUserKey(input.ScriptKey)
@@ -2283,12 +2282,8 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
22832282
}
22842283

22852284
// Decode the input into an asset.PrevID.
2286-
outpoint := wire.OutPoint{
2287-
Hash: *hash,
2288-
Index: input.Outpoint.OutputIndex,
2289-
}
22902285
prevID := asset.PrevID{
2291-
OutPoint: outpoint,
2286+
OutPoint: outPoint,
22922287
ID: asset.ID(input.Id),
22932288
ScriptKey: asset.ToSerialized(
22942289
scriptKey,
@@ -2975,15 +2970,13 @@ func (r *rpcServer) PublishAndLogTransfer(ctx context.Context,
29752970
FinalTx: finalTx,
29762971
}
29772972
for idx, lndOutpoint := range req.LndLockedUtxos {
2978-
hash, err := chainhash.NewHash(lndOutpoint.Txid)
2973+
op, err := rpcutils.UnmarshalOutPoint(lndOutpoint)
29792974
if err != nil {
2980-
return nil, fmt.Errorf("error parsing txid: %w", err)
2975+
return nil, fmt.Errorf("unmarshalling outpoint: %w",
2976+
err)
29812977
}
29822978

2983-
anchorTx.FundedPsbt.LockedUTXOs[idx] = wire.OutPoint{
2984-
Hash: *hash,
2985-
Index: lndOutpoint.OutputIndex,
2986-
}
2979+
anchorTx.FundedPsbt.LockedUTXOs[idx] = op
29872980
}
29882981

29892982
// We now have everything to ship the pre-anchored parcel using the
@@ -5417,7 +5410,7 @@ func (r *rpcServer) AssetLeaves(ctx context.Context,
54175410
return nil, err
54185411
}
54195412

5420-
assetLeaves, err := r.cfg.UniverseArchive.MintingLeaves(ctx, universeID)
5413+
assetLeaves, err := r.cfg.UniverseArchive.FetchLeaves(ctx, universeID)
54215414
if err != nil {
54225415
return nil, err
54235416
}
@@ -6310,15 +6303,13 @@ func (r *rpcServer) ProveAssetOwnership(ctx context.Context,
63106303
// error will be returned and the outpoint needs to be specified to
63116304
// disambiguate.
63126305
if req.Outpoint != nil {
6313-
txid, err := chainhash.NewHash(req.Outpoint.Txid)
6306+
op, err := rpcutils.UnmarshalOutPoint(req.Outpoint)
63146307
if err != nil {
6315-
return nil, fmt.Errorf("error parsing outpoint: %w",
6308+
return nil, fmt.Errorf("unmarshalling outpoint: %w",
63166309
err)
63176310
}
6318-
outPoint = &wire.OutPoint{
6319-
Hash: *txid,
6320-
Index: req.Outpoint.OutputIndex,
6321-
}
6311+
6312+
outPoint = &op
63226313
}
63236314

63246315
proofBlob, err := r.cfg.ProofArchive.FetchProof(ctx, proof.Locator{
@@ -6605,18 +6596,9 @@ func (r *rpcServer) RemoveUTXOLease(ctx context.Context,
66056596
req *wrpc.RemoveUTXOLeaseRequest) (*wrpc.RemoveUTXOLeaseResponse,
66066597
error) {
66076598

6608-
if req.Outpoint == nil {
6609-
return nil, fmt.Errorf("outpoint must be specified")
6610-
}
6611-
6612-
hash, err := chainhash.NewHash(req.Outpoint.Txid)
6599+
outPoint, err := rpcutils.UnmarshalOutPoint(req.Outpoint)
66136600
if err != nil {
6614-
return nil, fmt.Errorf("error parsing txid: %w", err)
6615-
}
6616-
6617-
outPoint := wire.OutPoint{
6618-
Hash: *hash,
6619-
Index: req.Outpoint.OutputIndex,
6601+
return nil, fmt.Errorf("unmarshaling outpoint: %w", err)
66206602
}
66216603

66226604
err = r.cfg.CoinSelect.ReleaseCoins(ctx, outPoint)
@@ -8898,15 +8880,13 @@ func (r *rpcServer) RegisterTransfer(ctx context.Context,
88988880
}
88998881
locator.ScriptKey = *scriptPubKey
89008882

8901-
hash, err := chainhash.NewHash(req.Outpoint.Txid)
8883+
op, err := rpcutils.UnmarshalOutPoint(req.Outpoint)
89028884
if err != nil {
8903-
return nil, err
8904-
}
8905-
locator.OutPoint = &wire.OutPoint{
8906-
Hash: *hash,
8907-
Index: req.Outpoint.OutputIndex,
8885+
return nil, fmt.Errorf("unmarshalling outpoint: %w", err)
89088886
}
89098887

8888+
locator.OutPoint = &op
8889+
89108890
// Before we query for the proof, we want to make sure the script key is
89118891
// already known to us. In an interactive transfer, we'd expect a script
89128892
// key to be derived on the recipient node, so it should already be

rpcutils/marshal.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/btcec/v2"
1111
"github.com/btcsuite/btcd/btcec/v2/schnorr"
1212
"github.com/btcsuite/btcd/btcutil/hdkeychain"
13+
"github.com/btcsuite/btcd/chaincfg/chainhash"
1314
"github.com/btcsuite/btcd/txscript"
1415
"github.com/btcsuite/btcd/wire"
1516
"github.com/lightninglabs/taproot-assets/asset"
@@ -257,6 +258,25 @@ func UnmarshalGenesisInfo(rpcGen *taprpc.GenesisInfo) (*asset.Genesis, error) {
257258
}, nil
258259
}
259260

261+
// UnmarshalOutPoint parses an outpoint from the RPC variant.
262+
func UnmarshalOutPoint(rpcOutpoint *taprpc.OutPoint) (wire.OutPoint, error) {
263+
var zero wire.OutPoint
264+
265+
if rpcOutpoint == nil {
266+
return zero, fmt.Errorf("unexpected nil RPC outpoint")
267+
}
268+
269+
txid, err := chainhash.NewHash(rpcOutpoint.Txid)
270+
if err != nil {
271+
return zero, fmt.Errorf("invalid outpoint txid: %w", err)
272+
}
273+
274+
return wire.OutPoint{
275+
Hash: *txid,
276+
Index: rpcOutpoint.OutputIndex,
277+
}, nil
278+
}
279+
260280
// UnmarshalTapscriptFullTree parses a Tapscript tree from the RPC variant.
261281
func UnmarshalTapscriptFullTree(tree *taprpc.TapscriptFullTree) (
262282
*asset.TapscriptTreeNodes, error) {

tapcfg/server.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
154154
groupVerifier := tapgarden.GenGroupVerifier(
155155
context.Background(), assetMintingStore,
156156
)
157-
uniCfg := universe.ArchiveConfig{
158-
NewBaseTree: func(id universe.Identifier) universe.BaseBackend {
157+
uniArchiveCfg := universe.ArchiveConfig{
158+
// nolint: lll
159+
NewBaseTree: func(id universe.Identifier) universe.StorageBackend {
159160
return tapdb.NewBaseUniverseTree(
160161
uniDB, id,
161162
)
@@ -284,12 +285,12 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
284285
ErrChan: mainErrChan,
285286
})
286287

287-
baseUni := universe.NewArchive(uniCfg)
288+
uniArchive := universe.NewArchive(uniArchiveCfg)
288289

289290
universeSyncer := universe.NewSimpleSyncer(universe.SimpleSyncCfg{
290-
LocalDiffEngine: baseUni,
291+
LocalDiffEngine: uniArchive,
291292
NewRemoteDiffEngine: tap.NewRpcUniverseDiff,
292-
LocalRegistrar: baseUni,
293+
LocalRegistrar: uniArchive,
293294
SyncBatchSize: defaultUniverseSyncBatchSize,
294295
})
295296

@@ -304,7 +305,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
304305
universe.FederationConfig{
305306
FederationDB: federationDB,
306307
UniverseSyncer: universeSyncer,
307-
LocalRegistrar: baseUni,
308+
LocalRegistrar: uniArchive,
308309
SyncInterval: cfg.Universe.SyncInterval,
309310
NewRemoteRegistrar: tap.NewRpcUniverseRegistrar,
310311
StaticFederationMembers: federationMembers,
@@ -574,7 +575,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
574575
AssetWallet: assetWallet,
575576
CoinSelect: coinSelect,
576577
ChainPorter: chainPorter,
577-
UniverseArchive: baseUni,
578+
UniverseArchive: uniArchive,
578579
UniverseSyncer: universeSyncer,
579580
UniverseFederation: universeFederation,
580581
UniFedSyncAllAssets: cfg.Universe.SyncAllAssets,

tapdb/ignore_tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewIgnoreUniverseTree(db BatchedUniverseTree) *IgnoreUniverseTree {
2424
return &IgnoreUniverseTree{db: db}
2525
}
2626

27-
// AddTuple adds a new ignore tuples to the ignore tree.
27+
// AddTuples adds a new ignore tuples to the ignore tree.
2828
func (it *IgnoreUniverseTree) AddTuples(ctx context.Context,
2929
spec asset.Specifier, tuples ...universe.SignedIgnoreTuple,
3030
) lfn.Result[universe.AuthIgnoreTuples] {

0 commit comments

Comments
 (0)