7
7
"sync"
8
8
"time"
9
9
10
+ "github.com/btcsuite/btcd/btcec/v2"
10
11
"github.com/davecgh/go-spew/spew"
11
12
"github.com/lightninglabs/taproot-assets/address"
12
13
"github.com/lightninglabs/taproot-assets/asset"
@@ -805,31 +806,42 @@ func (f *FederationEnvoy) tryFetchServers() ([]ServerAddr, error) {
805
806
}
806
807
807
808
// SyncAssetInfo queries the universes in our federation for genesis and asset
808
- // group information about the given asset ID .
809
+ // group information about the given asset.
809
810
func (f * FederationEnvoy ) SyncAssetInfo (ctx context.Context ,
810
- assetID * asset.ID ) error {
811
+ specifier asset.Specifier ) error {
811
812
812
- if assetID == nil {
813
- return fmt . Errorf ( "no asset ID provided" )
813
+ uniID := Identifier {
814
+ ProofType : ProofTypeIssuance ,
814
815
}
815
816
817
+ // One of asset ID or group key must be set, but not both.
818
+ if specifier .HasId () == specifier .HasGroupPubKey () {
819
+ return fmt .Errorf ("must set either asset ID or group key for " +
820
+ "asset sync" )
821
+ }
822
+
823
+ specifier .WhenId (func (id asset.ID ) {
824
+ uniID .AssetID = id
825
+ })
826
+ specifier .WhenGroupPubKey (func (groupKey btcec.PublicKey ) {
827
+ uniID .GroupKey = & groupKey
828
+ })
829
+
816
830
// Fetch the set of universe servers in our federation.
817
831
fedServers , err := f .tryFetchServers ()
818
832
if err != nil {
819
833
return err
820
834
}
821
835
822
836
assetConfig := FedUniSyncConfig {
823
- UniverseID : Identifier {
824
- AssetID : * assetID ,
825
- ProofType : ProofTypeIssuance ,
826
- },
837
+ UniverseID : uniID ,
827
838
AllowSyncInsert : true ,
828
839
AllowSyncExport : false ,
829
840
}
830
841
fullConfig := SyncConfigs {
831
842
UniSyncConfigs : []* FedUniSyncConfig {& assetConfig },
832
843
}
844
+
833
845
// We'll sync with Universe servers in parallel and collect the diffs
834
846
// from any successful syncs. There can only be one diff per server, as
835
847
// we're only syncing one universe root.
@@ -846,8 +858,8 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
846
858
// Sync failures are expected from Universe servers that do not
847
859
// have a relevant universe root.
848
860
if err != nil {
849
- log .Warnf ("Asset lookup failed: asset_id =%v, " +
850
- "remote_server=%v: %v" , assetID .String (),
861
+ log .Warnf ("Asset lookup failed: id =%v, " +
862
+ "remote_server=%v: %v" , uniID .String (),
851
863
addr .HostStr (), err )
852
864
853
865
// We don't want to abort syncing here, as this might
@@ -863,8 +875,8 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
863
875
if len (syncDiff ) != 1 {
864
876
log .Warnf ("Unexpected number of sync diffs " +
865
877
"when looking up asset: num_diffs=%d, " +
866
- "asset_id =%v, remote_server=%v" ,
867
- len (syncDiff ), assetID .String (),
878
+ "id =%v, remote_server=%v" ,
879
+ len (syncDiff ), uniID .String (),
868
880
addr .HostStr ())
869
881
870
882
// We don't want to abort syncing here, as this
@@ -891,12 +903,11 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
891
903
892
904
syncDiffs := fn .Collect (returnedSyncDiffs )
893
905
log .Infof ("Synced new Universe leaves for asset %v, diff_size=%v" ,
894
- assetID .String (), len (syncDiffs ))
906
+ uniID .String (), len (syncDiffs ))
895
907
896
- // TODO(jhb): Log successful syncs?
897
908
if len (syncDiffs ) == 0 {
898
909
return fmt .Errorf ("asset lookup failed for asset: %v" ,
899
- assetID .String ())
910
+ uniID .String ())
900
911
}
901
912
902
913
return nil
0 commit comments