Skip to content

Commit

Permalink
Merge pull request #3055 from oasisprotocol/kostko/feature/rhp-cleanup
Browse files Browse the repository at this point in the history
runtime: Cleanup some runtime host protocol messages
  • Loading branch information
kostko authored Jun 26, 2020
2 parents 925b7f2 + 1e0d475 commit 8cb0b36
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 121 deletions.
1 change: 1 addition & 0 deletions .changelog/3055.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: Cleanup some runtime host protocol messages
2 changes: 1 addition & 1 deletion go/common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
// the runtime.
//
// NOTE: This version must be synced with runtime/src/common/version.rs.
RuntimeProtocol = Version{Major: 0, Minor: 14, Patch: 0}
RuntimeProtocol = Version{Major: 0, Minor: 15, Patch: 0}

// CommitteeProtocol versions the P2P protocol used by the
// committee members.
Expand Down
20 changes: 6 additions & 14 deletions go/runtime/host/protocol/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ type Message struct {
SpanContext []byte `json:"span_context"`
}

// RuntimeKeyManagerPolicyUpdateRequest is a runtime key manager policy request
// message body.
type RuntimeKeyManagerPolicyUpdateRequest struct {
SignedPolicyRaw []byte `json:"signed_policy_raw"`
}

// Body is a protocol message body.
type Body struct {
Empty *Empty `json:",omitempty"`
Expand Down Expand Up @@ -156,26 +150,18 @@ type RuntimeCapabilityTEERakAvrRequest struct {
type RuntimeRPCCallRequest struct {
// Request.
Request []byte `json:"request"`
// State root hash.
StateRoot hash.Hash `json:"state_root"`
}

// RuntimeRPCCallResponse is a worker RPC call response message body.
type RuntimeRPCCallResponse struct {
// Response.
Response []byte `json:"response"`
// Batch of storage write operations.
WriteLog storage.WriteLog `json:"write_log"`
// New state root hash.
NewStateRoot hash.Hash `json:"new_state_root"`
}

// RuntimeLocalRPCCallRequest is a worker local RPC call request message body.
type RuntimeLocalRPCCallRequest struct {
// Request.
Request []byte `json:"request"`
// State root hash.
StateRoot hash.Hash `json:"state_root"`
}

// RuntimeLocalRPCCallResponse is a worker local RPC call response message body.
Expand Down Expand Up @@ -232,6 +218,12 @@ type RuntimeExecuteTxBatchResponse struct {
Batch ComputedBatch `json:"batch"`
}

// RuntimeKeyManagerPolicyUpdateRequest is a runtime key manager policy request
// message body.
type RuntimeKeyManagerPolicyUpdateRequest struct {
SignedPolicyRaw []byte `json:"signed_policy_raw"`
}

// HostRPCCallRequest is a host RPC call request message body.
type HostRPCCallRequest struct {
Endpoint string `json:"endpoint"`
Expand Down
5 changes: 1 addition & 4 deletions go/runtime/host/protocol/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
)

func TestBody_Type(t *testing.T) {
Expand All @@ -22,8 +20,7 @@ func TestBody_Type(t *testing.T) {
b = Body{
RuntimeCapabilityTEERakInitRequest: &RuntimeCapabilityTEERakInitRequest{TargetInfo: []byte{'a', 'b', 'c', 'd'}},
RuntimeRPCCallRequest: &RuntimeRPCCallRequest{
Request: []byte{'a', 'b', 'c', 'd'},
StateRoot: hash.Hash{},
Request: []byte{'a', 'b', 'c', 'd'},
},
}
// First non-nil member should be considered.
Expand Down
2 changes: 0 additions & 2 deletions go/worker/keymanager/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func New(
}

func init() {
emptyRoot.Empty()

Flags.Bool(CfgEnabled, false, "Enable key manager worker")

Flags.String(CfgRuntimeID, "", "Key manager Runtime ID")
Expand Down
9 changes: 2 additions & 7 deletions go/worker/keymanager/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/accessctl"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/grpc/policy"
"github.com/oasisprotocol/oasis-core/go/common/logging"
Expand Down Expand Up @@ -41,8 +40,6 @@ var (
_ service.BackgroundService = (*Worker)(nil)

errMalformedResponse = fmt.Errorf("worker/keymanager: malformed response from worker")

emptyRoot hash.Hash
)

// The key manager worker.
Expand Down Expand Up @@ -155,8 +152,7 @@ func (w *Worker) callLocal(ctx context.Context, data []byte) ([]byte, error) {

req := &protocol.Body{
RuntimeRPCCallRequest: &protocol.RuntimeRPCCallRequest{
Request: data,
StateRoot: emptyRoot,
Request: data,
},
}

Expand Down Expand Up @@ -219,8 +215,7 @@ func (w *Worker) updateStatus(status *api.Status, startedEvent *host.StartedEven
}
req := &protocol.Body{
RuntimeLocalRPCCallRequest: &protocol.RuntimeLocalRPCCallRequest{
Request: cbor.Marshal(&call),
StateRoot: emptyRoot,
Request: cbor.Marshal(&call),
},
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/common/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ impl From<u64> for Version {
// the worker host.
pub const PROTOCOL_VERSION: Version = Version {
major: 0,
minor: 14,
minor: 15,
patch: 0,
};
76 changes: 13 additions & 63 deletions runtime/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,7 @@ impl Dispatcher {
}

match rx.recv() {
Ok((
ctx,
id,
Body::RuntimeRPCCallRequest {
request,
state_root,
},
)) => {
Ok((ctx, id, Body::RuntimeRPCCallRequest { request })) => {
// RPC call.
self.dispatch_rpc(
&mut rpc_demux,
Expand All @@ -222,26 +215,11 @@ impl Dispatcher {
ctx,
id,
request,
state_root,
);
}
Ok((
ctx,
id,
Body::RuntimeLocalRPCCallRequest {
request,
state_root,
},
)) => {
Ok((ctx, id, Body::RuntimeLocalRPCCallRequest { request })) => {
// Local RPC call.
self.dispatch_local_rpc(
&mut rpc_dispatcher,
&protocol,
ctx,
id,
request,
state_root,
);
self.dispatch_local_rpc(&mut rpc_dispatcher, &protocol, ctx, id, request);
}
Ok((
ctx,
Expand Down Expand Up @@ -385,7 +363,7 @@ impl Dispatcher {
// to fetch them again by generating the previous I/O tree (generated by the
// transaction scheduler) from the inputs.
let mut txn_tree = TxnTree::new(
Box::new(NoopReadSyncer {}),
Box::new(NoopReadSyncer),
Root {
namespace: block.header.namespace,
version: block.header.round + 1,
Expand Down Expand Up @@ -471,9 +449,8 @@ impl Dispatcher {
ctx: Context,
id: u64,
request: Vec<u8>,
state_root: Hash,
) {
debug!(self.logger, "Received RPC call request"; "state_root" => ?state_root);
debug!(self.logger, "Received RPC call request");

// Process frame.
let mut buffer = vec![];
Expand Down Expand Up @@ -525,13 +502,7 @@ impl Dispatcher {

// Request, dispatch.
let ctx = ctx.freeze();
let read_syncer = HostReadSyncer::new(protocol.clone());
let mut mkvs = Tree::make()
.with_root(Root {
hash: state_root,
..Default::default()
})
.new(Box::new(read_syncer));
let mut mkvs = Tree::make().new(Box::new(NoopReadSyncer));
let untrusted_local = Arc::new(ProtocolUntrustedLocalStorage::new(
Context::create_child(&ctx),
protocol.clone(),
Expand All @@ -543,21 +514,15 @@ impl Dispatcher {
});
let response = RpcMessage::Response(response);

let (write_log, new_state_root) = mkvs
.commit(Context::create_child(&ctx), Default::default(), 0)
.expect("mkvs commit must succeed");
// Note: MKVS commit is omitted, this MUST be global side-effect free.

debug!(self.logger, "RPC call dispatch complete"; "new_state_root" => ?new_state_root);
debug!(self.logger, "RPC call dispatch complete");

let mut buffer = vec![];
match rpc_demux.write_message(session_id, response, &mut buffer) {
Ok(_) => {
// Transmit response.
protocol_response = Body::RuntimeRPCCallResponse {
response: buffer,
write_log: write_log,
new_state_root,
};
protocol_response = Body::RuntimeRPCCallResponse { response: buffer };
}
Err(error) => {
error!(self.logger, "Error while writing response"; "err" => %error);
Expand All @@ -575,11 +540,7 @@ impl Dispatcher {
match rpc_demux.close(session_id, &mut buffer) {
Ok(_) => {
// Transmit response.
protocol_response = Body::RuntimeRPCCallResponse {
response: buffer,
write_log: vec![],
new_state_root: state_root,
};
protocol_response = Body::RuntimeRPCCallResponse { response: buffer };
}
Err(error) => {
error!(self.logger, "Error while closing session"; "err" => %error);
Expand All @@ -602,11 +563,7 @@ impl Dispatcher {
}
} else {
// Send back any handshake frames.
protocol_response = Body::RuntimeRPCCallResponse {
response: buffer,
write_log: vec![],
new_state_root: state_root,
};
protocol_response = Body::RuntimeRPCCallResponse { response: buffer };
}

protocol.send_response(id, protocol_response).unwrap();
Expand All @@ -619,21 +576,14 @@ impl Dispatcher {
ctx: Context,
id: u64,
request: Vec<u8>,
state_root: Hash,
) {
debug!(self.logger, "Received local RPC call request"; "state_root" => ?state_root);
debug!(self.logger, "Received local RPC call request");

let req: RpcRequest = cbor::from_slice(&request).unwrap();

// Request, dispatch.
let ctx = ctx.freeze();
let read_syncer = HostReadSyncer::new(protocol.clone());
let mut mkvs = Tree::make()
.with_root(Root {
hash: state_root,
..Default::default()
})
.new(Box::new(read_syncer));
let mut mkvs = Tree::make().new(Box::new(NoopReadSyncer));
let untrusted_local = Arc::new(ProtocolUntrustedLocalStorage::new(
Context::create_child(&ctx),
protocol.clone(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/storage/mkvs/sync/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use io_context::Context;
use crate::storage::mkvs::sync::*;

/// A no-op read syncer which doesn't support any of the required operations.
pub struct NoopReadSyncer {}
pub struct NoopReadSyncer;

impl ReadSync for NoopReadSyncer {
fn as_any(&self) -> &dyn Any {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/storage/mkvs/sync/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::storage::mkvs::{
fn test_nil_pointers() {
let server = ProtocolServer::new();

let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

// Arbitrary sequence of operations. The point is to produce a tree with
// an internal node where at least one of the children is a null pointer.
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/storage/mkvs/tree/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod test {
fn test_iterator() {
let server = ProtocolServer::new();

let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

// Test with an empty tree.
let mut it = tree.iter(Context::background());
Expand Down Expand Up @@ -477,7 +477,7 @@ mod test {

#[test]
fn test_iterator_case1() {
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

let items = vec![
(b"key 5".to_vec(), b"fivey".to_vec()),
Expand All @@ -495,7 +495,7 @@ mod test {

#[test]
fn test_iterator_case2() {
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

let items: Vec<(Vec<u8>, Vec<u8>)> = vec![
(
Expand Down Expand Up @@ -536,7 +536,7 @@ mod test {

let mut tree = Tree::make()
.with_capacity(0, 0)
.new(Box::new(NoopReadSyncer {}));
.new(Box::new(NoopReadSyncer));

let (keys, values) = generate_key_value_pairs_ex("T".to_owned(), 100);
let items: Vec<(Vec<u8>, Vec<u8>)> = keys.into_iter().zip(values.into_iter()).collect();
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/storage/mkvs/tree/tree_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn gen_pairs() -> (Vec<Vec<u8>>, Vec<Vec<u8>>) {
}

fn gen_tree() -> (Tree, Vec<Vec<u8>>) {
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

let (keys, vals) = gen_pairs();
for i in 0..keys.len() {
Expand Down Expand Up @@ -53,7 +53,7 @@ fn bench_existing_scan(b: &mut Bencher) {
#[bench]
fn bench_single_inserts(b: &mut Bencher) {
let (keys, vals) = gen_pairs();
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

let mut i = 0;
b.iter(|| {
Expand All @@ -72,7 +72,7 @@ fn bench_insert(b: &mut Bencher) {
let (keys, vals) = gen_pairs();

b.iter(|| {
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));

for i in 0..keys.len() {
tree.insert(Context::background(), keys[i].as_ref(), vals[i].as_ref())
Expand All @@ -85,7 +85,7 @@ fn bench_insert(b: &mut Bencher) {

fn bench_insert_batch(b: &mut Bencher, num_values: usize, commit: bool) {
b.iter(|| {
let mut tree = Tree::make().new(Box::new(NoopReadSyncer {}));
let mut tree = Tree::make().new(Box::new(NoopReadSyncer));
for i in 0..num_values {
let key = format!("key {}", i);
let value = format!("value {}", i);
Expand Down
Loading

0 comments on commit 8cb0b36

Please sign in to comment.