Skip to content

Commit 7da2bf5

Browse files
committed
multi: add MultiverseRoot RPC method
1 parent 69072b5 commit 7da2bf5

File tree

9 files changed

+1259
-812
lines changed

9 files changed

+1259
-812
lines changed

perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ var (
136136
Entity: "mint",
137137
Action: "read",
138138
}},
139+
"/universerpc.Universe/MultiverseRoot": {{
140+
Entity: "universe",
141+
Action: "read",
142+
}},
139143
"/universerpc.Universe/AssetRoots": {{
140144
Entity: "universe",
141145
Action: "read",

rpcserver.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,56 @@ func marshalUniverseRoot(node universe.Root) (*unirpc.UniverseRoot, error) {
29602960
}, nil
29612961
}
29622962

2963+
// MultiverseRoot returns the root of the multiverse tree. This is useful to
2964+
// determine the equality of two multiverse trees, since the root can directly
2965+
// be compared to another multiverse root to find out if a sync is required.
2966+
func (r *rpcServer) MultiverseRoot(ctx context.Context,
2967+
req *unirpc.MultiverseRootRequest) (*unirpc.MultiverseRootResponse,
2968+
error) {
2969+
2970+
proofType, err := UnmarshalUniProofType(req.ProofType)
2971+
if err != nil {
2972+
return nil, fmt.Errorf("invalid proof type: %w", err)
2973+
}
2974+
2975+
if proofType == universe.ProofTypeUnspecified {
2976+
return nil, fmt.Errorf("proof type must be specified")
2977+
}
2978+
2979+
filterByIDs := make([]universe.Identifier, len(req.SpecificIds))
2980+
for idx, rpcID := range req.SpecificIds {
2981+
filterByIDs[idx], err = UnmarshalUniID(rpcID)
2982+
if err != nil {
2983+
return nil, fmt.Errorf("unable to parse universe id: "+
2984+
"%w", err)
2985+
}
2986+
2987+
// Allow the RPC user to not specify the proof type for each ID
2988+
// individually since the outer one is mandatory.
2989+
if filterByIDs[idx].ProofType == universe.ProofTypeUnspecified {
2990+
filterByIDs[idx].ProofType = proofType
2991+
}
2992+
2993+
if filterByIDs[idx].ProofType != proofType {
2994+
return nil, fmt.Errorf("proof type mismatch in ID "+
2995+
"%d: %v != %v", idx, filterByIDs[idx].ProofType,
2996+
proofType)
2997+
}
2998+
}
2999+
3000+
rootNode, err := r.cfg.UniverseArchive.MultiverseRoot(
3001+
ctx, proofType, filterByIDs,
3002+
)
3003+
if err != nil {
3004+
return nil, fmt.Errorf("unable to fetch multiverse root: %w",
3005+
err)
3006+
}
3007+
3008+
return &unirpc.MultiverseRootResponse{
3009+
MultiverseRoot: marshalMssmtNode(rootNode),
3010+
}, nil
3011+
}
3012+
29633013
// AssetRoots queries for the known Universe roots associated with each known
29643014
// asset. These roots represent the supply/audit state for each known asset.
29653015
func (r *rpcServer) AssetRoots(ctx context.Context,

0 commit comments

Comments
 (0)