-
Notifications
You must be signed in to change notification settings - Fork 3
waved: export Taproot Asset runtime registration #1037
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
Open
darioAnongba
wants to merge
1
commit into
feat/taproot-assets-carrier-selection
Choose a base branch
from
feat/taproot-assets-runtime-registration
base: feat/taproot-assets-carrier-selection
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,107 +1,11 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
|
|
||
| tapsdk "github.com/lightninglabs/tap-sdk" | ||
| tapgrpc "github.com/lightninglabs/tap-sdk/grpc" | ||
| "github.com/lightninglabs/tap-sdk/macaroon" | ||
| "github.com/lightninglabs/wavelength/tapassets" | ||
| "github.com/lightninglabs/wavelength/waved" | ||
| "google.golang.org/grpc" | ||
| ) | ||
|
|
||
| // configureTaprootAssets installs a lazy daemon registrar. The authenticated | ||
| // tapd connection is opened only after waved has validated and initialized its | ||
| // own runtime, and is closed by the normal daemon shutdown path. | ||
| // configureTaprootAssets delegates production runtime registration to waved so | ||
| // command and embedded consumers install the same tapd lifecycle. | ||
| func configureTaprootAssets(cfg *waved.Config) { | ||
| if cfg == nil || cfg.TaprootAssets == nil || | ||
| !cfg.TaprootAssets.Enabled || | ||
| cfg.TaprootAssetOORPreparer != nil { | ||
| return | ||
| } | ||
|
|
||
| cfg.RPCServiceRegistrars = append( | ||
| cfg.RPCServiceRegistrars, | ||
| func(_ context.Context, _ *grpc.Server, | ||
| rpcServer *waved.RPCServer, daemonCfg *waved.Config) ( | ||
| func(), error) { | ||
|
|
||
| assetCfg := daemonCfg.TaprootAssets | ||
| clientCfg := &tapgrpc.Config{ | ||
| Host: assetCfg.Host, | ||
| Network: tapsdk.Network(daemonCfg.Network), | ||
| RPCTimeout: assetCfg.RPCTimeout, | ||
| } | ||
| if assetCfg.MacaroonPath != "" { | ||
| clientCfg.Macaroon = macaroon.FromPath( | ||
| assetCfg.MacaroonPath, | ||
| ) | ||
| } | ||
| switch { | ||
| case assetCfg.Insecure: | ||
| clientCfg.TLS = tapgrpc.TLSInsecure() | ||
|
|
||
| case assetCfg.TLSCertPath != "": | ||
| clientCfg.TLS = tapgrpc.TLSFromPath( | ||
| assetCfg.TLSCertPath, | ||
| ) | ||
| } | ||
|
|
||
| client, err := tapgrpc.NewClient(clientCfg) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| wallet := tapsdk.NewWallet( | ||
| client, tapsdk.Network(daemonCfg.Network), | ||
| ) | ||
| closeWallet := func() { | ||
| _ = wallet.Close() | ||
| } | ||
|
|
||
| journalDir := assetCfg.PreparationDir | ||
| if journalDir == "" { | ||
| journalDir = filepath.Join( | ||
| daemonCfg.NetworkDir(), | ||
| "taproot-assets-oor", | ||
| ) | ||
| } | ||
| store, err := tapassets.NewFileStore(journalDir) | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| reservationStore, err := rpcServer.OORReservationStore() | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| preparer, err := tapassets.NewPreparer( | ||
| tapassets.PreparerConfig{ | ||
| Wallet: wallet, | ||
| Store: store, | ||
| ReservationStore: reservationStore, | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| daemonCfg.TaprootAssetOORPreparer = preparer | ||
| if err := rpcServer.ConfigureTaprootAssetOnboarding( | ||
| wallet, store, | ||
| ); err != nil { | ||
|
|
||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
|
|
||
| return closeWallet, nil | ||
| }, | ||
| ) | ||
| waved.ConfigureTaprootAssets(cfg) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package waved | ||
|
|
||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
|
|
||
| tapsdk "github.com/lightninglabs/tap-sdk" | ||
| tapgrpc "github.com/lightninglabs/tap-sdk/grpc" | ||
| "github.com/lightninglabs/tap-sdk/macaroon" | ||
| "github.com/lightninglabs/wavelength/tapassets" | ||
| "google.golang.org/grpc" | ||
| ) | ||
|
|
||
| // ConfigureTaprootAssets registers the production tap-sdk and tapd runtime on | ||
| // cfg. The runtime remains opt-in through TaprootAssets.Enabled and is | ||
| // installed at most once per Config. A caller that injects its own Taproot | ||
| // Asset OOR preparer retains ownership of the integration, so this helper is a | ||
| // no-op in that case. | ||
| // | ||
| // Registration is lazy: no authenticated tapd connection or preparation store | ||
| // is opened until waved starts its gRPC services. The daemon shutdown path | ||
| // closes the connection returned by the registrar. Embedded consumers should | ||
| // call this helper before Main instead of recreating the tapd credential, | ||
| // journal, reservation, OOR preparation, and onboarding wiring. | ||
| func ConfigureTaprootAssets(cfg *Config) { | ||
| if cfg == nil || cfg.TaprootAssets == nil || | ||
| !cfg.TaprootAssets.Enabled || | ||
| cfg.TaprootAssetOORPreparer != nil || | ||
| cfg.taprootAssetsRuntimeConfigured { | ||
| return | ||
| } | ||
|
|
||
| cfg.taprootAssetsRuntimeConfigured = true | ||
| cfg.RPCServiceRegistrars = append( | ||
| cfg.RPCServiceRegistrars, registerTaprootAssets, | ||
| ) | ||
| } | ||
|
|
||
| // registerTaprootAssets constructs the production Taproot Assets services | ||
| // after waved has initialized the shared runtime dependencies they require. | ||
| func registerTaprootAssets(_ context.Context, _ *grpc.Server, | ||
| rpcServer *RPCServer, daemonCfg *Config) (func(), error) { | ||
|
|
||
| assetCfg := daemonCfg.TaprootAssets | ||
| clientCfg := &tapgrpc.Config{ | ||
| Host: assetCfg.Host, | ||
| Network: tapsdk.Network(daemonCfg.Network), | ||
| RPCTimeout: assetCfg.RPCTimeout, | ||
| } | ||
| if assetCfg.MacaroonPath != "" { | ||
| clientCfg.Macaroon = macaroon.FromPath( | ||
| assetCfg.MacaroonPath, | ||
| ) | ||
| } | ||
| switch { | ||
| case assetCfg.Insecure: | ||
| clientCfg.TLS = tapgrpc.TLSInsecure() | ||
|
|
||
| case assetCfg.TLSCertPath != "": | ||
| clientCfg.TLS = tapgrpc.TLSFromPath( | ||
| assetCfg.TLSCertPath, | ||
| ) | ||
| } | ||
|
|
||
| client, err := tapgrpc.NewClient(clientCfg) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| wallet := tapsdk.NewWallet( | ||
| client, tapsdk.Network(daemonCfg.Network), | ||
| ) | ||
| closeWallet := func() { | ||
| _ = wallet.Close() | ||
| } | ||
|
|
||
| journalDir := assetCfg.PreparationDir | ||
| if journalDir == "" { | ||
| journalDir = filepath.Join( | ||
| daemonCfg.NetworkDir(), | ||
| "taproot-assets-oor", | ||
| ) | ||
| } | ||
| store, err := tapassets.NewFileStore(journalDir) | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| reservationStore, err := rpcServer.OORReservationStore() | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| preparer, err := tapassets.NewPreparer(tapassets.PreparerConfig{ | ||
| Wallet: wallet, | ||
| Store: store, | ||
| ReservationStore: reservationStore, | ||
| }) | ||
| if err != nil { | ||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
| daemonCfg.TaprootAssetOORPreparer = preparer | ||
| if err := rpcServer.ConfigureTaprootAssetOnboarding( | ||
| wallet, store, | ||
| ); err != nil { | ||
|
|
||
| closeWallet() | ||
|
|
||
| return nil, err | ||
| } | ||
|
|
||
| return closeWallet, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package waved | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestConfigureTaprootAssetsDisabled proves production registration remains | ||
| // explicitly opt-in and nil-safe for embedded consumers. | ||
| func TestConfigureTaprootAssetsDisabled(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ConfigureTaprootAssets(nil) | ||
|
|
||
| cfg := DefaultConfig() | ||
| ConfigureTaprootAssets(cfg) | ||
| require.Empty(t, cfg.RPCServiceRegistrars) | ||
|
|
||
| cfg.TaprootAssets = nil | ||
| ConfigureTaprootAssets(cfg) | ||
| require.Empty(t, cfg.RPCServiceRegistrars) | ||
| } | ||
|
|
||
| // TestConfigureTaprootAssetsRegistersOnce proves repeated setup paths install | ||
| // exactly one lazy production registrar. | ||
| func TestConfigureTaprootAssetsRegistersOnce(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cfg := DefaultConfig() | ||
| cfg.TaprootAssets.Enabled = true | ||
|
|
||
| ConfigureTaprootAssets(cfg) | ||
| require.Len(t, cfg.RPCServiceRegistrars, 1) | ||
| require.True(t, cfg.taprootAssetsRuntimeConfigured) | ||
| require.Nil(t, cfg.TaprootAssetOORPreparer) | ||
| require.Nil(t, cfg.TaprootAssetOnboarder) | ||
|
|
||
| ConfigureTaprootAssets(cfg) | ||
| require.Len(t, cfg.RPCServiceRegistrars, 1) | ||
| } | ||
|
|
||
| // TestConfigureTaprootAssetsPreservesInjectedPreparer proves an embedding | ||
| // application can retain ownership of its explicitly supplied integration. | ||
| func TestConfigureTaprootAssetsPreservesInjectedPreparer(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| preparer := &testTaprootAssetOORPreparer{} | ||
| cfg := DefaultConfig() | ||
| cfg.TaprootAssets.Enabled = true | ||
| cfg.TaprootAssetOORPreparer = preparer | ||
|
|
||
| ConfigureTaprootAssets(cfg) | ||
| require.Empty(t, cfg.RPCServiceRegistrars) | ||
| require.False(t, cfg.taprootAssetsRuntimeConfigured) | ||
| require.Same(t, preparer, cfg.TaprootAssetOORPreparer) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's remove
configureTaprootAssetsfunction altogether and just callwaved.ConfigureTaprootAssets(cfg)