Skip to content

Commit 2f36953

Browse files
committed
rpc: add PushProof for uploading single proofs
In this commit, we add an RPC to query a proof from the local Universe and upload it to a remote Universe (which may not be in our current federation).
1 parent 128bb13 commit 2f36953

File tree

9 files changed

+1202
-282
lines changed

9 files changed

+1202
-282
lines changed

perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ var (
200200
Entity: "universe",
201201
Action: "write",
202202
}},
203+
"/universerpc.Universe/PushProof": {{
204+
Entity: "universe",
205+
Action: "read",
206+
}},
203207
"/universerpc.Universe/SyncUniverse": {{
204208
Entity: "universe",
205209
Action: "write",

rpcserver.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5340,6 +5340,76 @@ func (r *rpcServer) InsertProof(ctx context.Context,
53405340
return r.marshalUniverseProofLeaf(ctx, req.Key, newUniverseState)
53415341
}
53425342

5343+
// PushProof attempts to query the local universe for a proof specified by a
5344+
// UniverseKey. If found, a connection is made to a remote Universe server to
5345+
// attempt to upload the asset leaf.
5346+
func (r *rpcServer) PushProof(ctx context.Context,
5347+
req *unirpc.PushProofRequest) (*unirpc.PushProofResponse, error) {
5348+
5349+
switch {
5350+
case req.Server == nil:
5351+
return nil, fmt.Errorf("remote Universe must be specified")
5352+
5353+
case req.Key == nil:
5354+
return nil, fmt.Errorf("universe key must be specified")
5355+
5356+
case req.Server.Host == "" && req.Server.Id == 0:
5357+
return nil, fmt.Errorf("remote Universe must be specified")
5358+
5359+
case req.Server.Host != "" && req.Server.Id != 0:
5360+
return nil, fmt.Errorf("cannot specify both universe host " +
5361+
"and id")
5362+
}
5363+
5364+
remoteUniAddr := unmarshalUniverseServer(req.Server)
5365+
universeID, leafKey, err := unmarshalUniverseKey(req.Key)
5366+
if err != nil {
5367+
return nil, err
5368+
}
5369+
5370+
// Try to fetch the requested proof from the local universe.
5371+
localProof, err := r.queryProof(ctx, universeID, leafKey)
5372+
if err != nil {
5373+
return nil, err
5374+
}
5375+
if localProof.Leaf == nil {
5376+
return nil, fmt.Errorf("proof not found in local universe")
5377+
}
5378+
5379+
// Make sure that we aren't trying to push the proof to ourself, and
5380+
// then attempt to push the proof.
5381+
err = CheckFederationServer(
5382+
r.cfg.RuntimeID, universe.DefaultTimeout, remoteUniAddr,
5383+
)
5384+
if err != nil {
5385+
return nil, err
5386+
}
5387+
5388+
remoteUni, err := NewRpcUniverseRegistrar(remoteUniAddr)
5389+
if err != nil {
5390+
return nil, err
5391+
}
5392+
5393+
rpcsLog.Debugf("[PushProof]: pushing proof to universe "+
5394+
"(universeID=%v, server=%v", universeID.StringForLog(),
5395+
remoteUniAddr)
5396+
5397+
_, err = remoteUni.UpsertProofLeaf(
5398+
ctx, universeID, leafKey, localProof.Leaf,
5399+
)
5400+
if err != nil {
5401+
return nil, err
5402+
}
5403+
5404+
rpcsLog.Debugf("[PushProof]: proof pushed to universe "+
5405+
"(universeID=%v, server=%v", universeID.StringForLog(),
5406+
remoteUniAddr)
5407+
5408+
return &unirpc.PushProofResponse{
5409+
Key: req.Key,
5410+
}, nil
5411+
}
5412+
53435413
// Info returns a set of information about the current state of the Universe.
53445414
func (r *rpcServer) Info(ctx context.Context,
53455415
_ *unirpc.InfoRequest) (*unirpc.InfoResponse, error) {

0 commit comments

Comments
 (0)