-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/storage: Fix worker root tracking, implement retries, internal grpc
- Loading branch information
Showing
2 changed files
with
163 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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,50 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/oasislabs/ekiden/go/common/crypto/signature" | ||
"github.com/oasislabs/ekiden/go/common/grpc" | ||
pb "github.com/oasislabs/ekiden/go/grpc/storage" | ||
"github.com/oasislabs/ekiden/go/worker/storage/committee" | ||
) | ||
|
||
var ( | ||
_ pb.StorageWorkerServer = (*grpcServer)(nil) | ||
|
||
// ErrRuntimeNotFound is the error returned when the called references an unknown runtime. | ||
ErrRuntimeNotFound = errors.New("worker/storage: runtime not found") | ||
) | ||
|
||
type grpcServer struct { | ||
w *Worker | ||
} | ||
|
||
func (s *grpcServer) GetLastSyncedRound(ctx context.Context, req *pb.GetLastSyncedRoundRequest) (*pb.GetLastSyncedRoundResponse, error) { | ||
var id signature.PublicKey | ||
if err := id.UnmarshalBinary(req.GetRuntimeId()); err != nil { | ||
return nil, err | ||
} | ||
|
||
var node *committee.Node | ||
node, ok := s.w.runtimes[id.ToMapKey()] | ||
if !ok { | ||
return nil, ErrRuntimeNotFound | ||
} | ||
|
||
round, ioRoot, stateRoot := node.GetLastSynced() | ||
|
||
resp := &pb.GetLastSyncedRoundResponse{ | ||
Round: round, | ||
IoRoot: ioRoot.MarshalCBOR(), | ||
StateRoot: stateRoot.MarshalCBOR(), | ||
} | ||
return resp, nil | ||
} | ||
|
||
func newGRPCServer(grpc *grpc.Server, w *Worker) { | ||
s := &grpcServer{w} | ||
pb.RegisterStorageWorkerServer(grpc.Server(), s) | ||
} |