diff --git a/.changelog/3055.breaking.md b/.changelog/3055.breaking.md new file mode 100644 index 00000000000..4d30ea13f8a --- /dev/null +++ b/.changelog/3055.breaking.md @@ -0,0 +1 @@ +runtime: Cleanup some runtime host protocol messages diff --git a/go/common/version/version.go b/go/common/version/version.go index 6545c597931..48e24367f27 100644 --- a/go/common/version/version.go +++ b/go/common/version/version.go @@ -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. diff --git a/go/runtime/host/protocol/types.go b/go/runtime/host/protocol/types.go index 10e479d33a7..3850afe6c07 100644 --- a/go/runtime/host/protocol/types.go +++ b/go/runtime/host/protocol/types.go @@ -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"` @@ -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. @@ -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"` diff --git a/go/runtime/host/protocol/types_test.go b/go/runtime/host/protocol/types_test.go index 93af52b2062..aa4236315eb 100644 --- a/go/runtime/host/protocol/types_test.go +++ b/go/runtime/host/protocol/types_test.go @@ -22,8 +22,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. diff --git a/go/worker/keymanager/init.go b/go/worker/keymanager/init.go index 021870dea75..d2714613391 100644 --- a/go/worker/keymanager/init.go +++ b/go/worker/keymanager/init.go @@ -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") diff --git a/go/worker/keymanager/worker.go b/go/worker/keymanager/worker.go index 09fadf4e93e..1ad9e6218e9 100644 --- a/go/worker/keymanager/worker.go +++ b/go/worker/keymanager/worker.go @@ -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" @@ -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. @@ -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, }, } @@ -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), }, } diff --git a/runtime/src/common/version.rs b/runtime/src/common/version.rs index f587a62eb03..fc93cd0da17 100644 --- a/runtime/src/common/version.rs +++ b/runtime/src/common/version.rs @@ -66,6 +66,6 @@ impl From for Version { // the worker host. pub const PROTOCOL_VERSION: Version = Version { major: 0, - minor: 14, + minor: 15, patch: 0, }; diff --git a/runtime/src/dispatcher.rs b/runtime/src/dispatcher.rs index 1391034b218..41a0658f596 100644 --- a/runtime/src/dispatcher.rs +++ b/runtime/src/dispatcher.rs @@ -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, @@ -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, @@ -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, @@ -471,9 +449,8 @@ impl Dispatcher { ctx: Context, id: u64, request: Vec, - 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![]; @@ -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(), @@ -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); @@ -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); @@ -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(); @@ -619,21 +576,14 @@ impl Dispatcher { ctx: Context, id: u64, request: Vec, - 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(), diff --git a/runtime/src/storage/mkvs/sync/noop.rs b/runtime/src/storage/mkvs/sync/noop.rs index 2a8f8531d9e..7f0a67e8989 100644 --- a/runtime/src/storage/mkvs/sync/noop.rs +++ b/runtime/src/storage/mkvs/sync/noop.rs @@ -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 { diff --git a/runtime/src/storage/mkvs/sync/test.rs b/runtime/src/storage/mkvs/sync/test.rs index 09bca7c09da..f45b068b824 100644 --- a/runtime/src/storage/mkvs/sync/test.rs +++ b/runtime/src/storage/mkvs/sync/test.rs @@ -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. diff --git a/runtime/src/storage/mkvs/tree/iterator.rs b/runtime/src/storage/mkvs/tree/iterator.rs index ad2c5869ffe..0d4b7b29ed6 100644 --- a/runtime/src/storage/mkvs/tree/iterator.rs +++ b/runtime/src/storage/mkvs/tree/iterator.rs @@ -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()); @@ -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()), @@ -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, Vec)> = vec![ ( @@ -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, Vec)> = keys.into_iter().zip(values.into_iter()).collect(); diff --git a/runtime/src/storage/mkvs/tree/tree_bench.rs b/runtime/src/storage/mkvs/tree/tree_bench.rs index 951f2a4c14a..68bbab77072 100644 --- a/runtime/src/storage/mkvs/tree/tree_bench.rs +++ b/runtime/src/storage/mkvs/tree/tree_bench.rs @@ -19,7 +19,7 @@ fn gen_pairs() -> (Vec>, Vec>) { } fn gen_tree() -> (Tree, Vec>) { - 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() { @@ -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(|| { @@ -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()) @@ -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); diff --git a/runtime/src/storage/mkvs/tree/tree_test.rs b/runtime/src/storage/mkvs/tree/tree_test.rs index d9e4e442505..0ccc4526c34 100644 --- a/runtime/src/storage/mkvs/tree/tree_test.rs +++ b/runtime/src/storage/mkvs/tree/tree_test.rs @@ -51,7 +51,7 @@ fn generate_long_key_value_pairs() -> (Vec>, Vec>) { #[test] fn test_basic() { - let mut tree = Tree::make().new(Box::new(NoopReadSyncer {})); + let mut tree = Tree::make().new(Box::new(NoopReadSyncer)); let key_zero = b"foo"; let value_zero = b"bar"; @@ -293,7 +293,7 @@ fn test_basic() { #[test] fn test_long_keys() { - let mut tree = Tree::make().new(Box::new(NoopReadSyncer {})); + let mut tree = Tree::make().new(Box::new(NoopReadSyncer)); // First insert keys 0..n and remove them in order n..0. let mut roots: Vec = Vec::new(); @@ -354,7 +354,7 @@ fn test_long_keys() { #[test] fn test_empty_keys() { - let mut tree = Tree::make().new(Box::new(NoopReadSyncer {})); + let mut tree = Tree::make().new(Box::new(NoopReadSyncer)); fn test_empty_key(tree: &mut Tree) { let empty_key = b""; @@ -480,7 +480,7 @@ fn test_empty_keys() { #[test] fn test_insert_commit_batch() { - let mut tree = Tree::make().new(Box::new(NoopReadSyncer {})); + let mut tree = Tree::make().new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -507,7 +507,7 @@ fn test_insert_commit_batch() { fn test_insert_commit_each() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -536,7 +536,7 @@ fn test_insert_commit_each() { fn test_remove() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); // First insert keys 0..n and remove them in order n..0. let mut roots: Vec = Vec::new(); @@ -659,7 +659,7 @@ fn test_syncer_basic() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -714,7 +714,7 @@ fn test_syncer_remove() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let mut roots: Vec = Vec::new(); let mut write_log = WriteLog::new(); @@ -777,7 +777,7 @@ fn test_syncer_insert() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -829,7 +829,7 @@ fn test_syncer_writelog_remove() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -862,7 +862,7 @@ fn test_syncer_prefetch_prefixes() { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -915,7 +915,7 @@ fn test_syncer_prefetch_prefixes() { fn test_value_eviction() { let mut tree = Tree::make() .with_capacity(0, 512) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs(); for i in 0..keys.len() { @@ -945,7 +945,7 @@ fn test_value_eviction() { fn test_node_eviction() { let mut tree = Tree::make() .with_capacity(128, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let (keys, values) = generate_key_value_pairs_ex("foo".to_string(), 150); for i in 0..keys.len() { @@ -996,7 +996,7 @@ fn test_special_case_from_json(fixture: &'static str) { let mut tree = Tree::make() .with_capacity(0, 0) - .new(Box::new(NoopReadSyncer {})); + .new(Box::new(NoopReadSyncer)); let mut remote_tree: Option = None; let mut root = Hash::empty_hash(); diff --git a/runtime/src/transaction/tree.rs b/runtime/src/transaction/tree.rs index a13e12adde5..c6207c4326c 100644 --- a/runtime/src/transaction/tree.rs +++ b/runtime/src/transaction/tree.rs @@ -238,7 +238,7 @@ mod test { #[test] fn test_transaction() { let mut tree = Tree::new( - Box::new(NoopReadSyncer {}), + Box::new(NoopReadSyncer), Root { hash: Hash::empty_hash(), ..Default::default() diff --git a/runtime/src/types.rs b/runtime/src/types.rs index a2f73a4afdd..115fdceac21 100644 --- a/runtime/src/types.rs +++ b/runtime/src/types.rs @@ -92,18 +92,14 @@ pub enum Body { RuntimeRPCCallRequest { #[serde(with = "serde_bytes")] request: Vec, - state_root: Hash, }, RuntimeRPCCallResponse { #[serde(with = "serde_bytes")] response: Vec, - write_log: WriteLog, - new_state_root: Hash, }, RuntimeLocalRPCCallRequest { #[serde(with = "serde_bytes")] request: Vec, - state_root: Hash, }, RuntimeLocalRPCCallResponse { #[serde(with = "serde_bytes")]