Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump serde_cbor to 0.10 #1897

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ ekiden-runtime = { path = "../runtime" }
serde = "1.0.71"
serde_bytes = "~0.10"
serde_derive = "1.0"
# TODO: Change to released version when 0.10.0 is released.
serde_cbor = { git = "https://github.com/pyfisch/cbor", rev = "114ecaeac53799d0bf81ca8d1b980c7c419d76fe" }
failure = "0.1.5"
futures = "0.1.25"
tokio-executor = "0.1.6"
Expand Down
1 change: 0 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern crate rustracing;
extern crate rustracing_jaeger;
extern crate serde;
extern crate serde_bytes;
extern crate serde_cbor;
extern crate serde_derive;
#[macro_use]
extern crate failure;
Expand Down
11 changes: 4 additions & 7 deletions client/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use futures::{
use grpcio::Channel;
use io_context::Context;
use serde::{de::DeserializeOwned, Serialize};
use serde_cbor;
use tokio_executor::spawn;

use ekiden_runtime::{
common::cbor,
protocol::Protocol,
rpc::{
session::{Builder, Session},
Expand Down Expand Up @@ -61,7 +61,7 @@ trait Transport: Send + Sync {
payload: data,
};

self.write_message_impl(ctx, serde_cbor::to_vec(&frame).unwrap())
self.write_message_impl(ctx, cbor::to_vec(&frame))
}

fn write_message_impl(&self, ctx: Context, data: Vec<u8>) -> BoxFuture<Vec<u8>>;
Expand Down Expand Up @@ -197,16 +197,13 @@ impl RpcClient {
{
let request = types::Request {
method: method.to_owned(),
args: match serde_cbor::to_value(args) {
Ok(args) => args,
Err(error) => return Box::new(future::err(error.into())),
},
args: cbor::to_value(args),
};

Box::new(
self.execute_call(ctx, request)
.and_then(|response| match response.body {
types::Body::Success(value) => Ok(serde_cbor::from_value(value)?),
types::Body::Success(value) => Ok(cbor::from_value(value)?),
types::Body::Error(error) => Err(RpcClientError::CallFailed(error).into()),
}),
)
Expand Down
36 changes: 13 additions & 23 deletions client/src/transaction/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use grpcio::{Channel, Error::RpcFailure, RpcStatus, RpcStatusCode};
use rustracing::{sampler::AllSampler, tag};
use rustracing_jaeger::{span::Span, Tracer};
use serde::{de::DeserializeOwned, Serialize};
use serde_cbor;

use ekiden_runtime::{
common::{crypto::hash::Hash, runtime::RuntimeId},
common::{cbor, crypto::hash::Hash, runtime::RuntimeId},
transaction::types::{TxnBatch, TxnCall, TxnOutput},
};

Expand Down Expand Up @@ -67,10 +66,7 @@ impl TxnClient {
{
let call = TxnCall {
method: method.to_owned(),
args: match serde_cbor::to_value(args) {
Ok(args) => args,
Err(error) => return Box::new(future::err(error.into())),
},
args: cbor::to_value(args),
};

Box::new(
Expand All @@ -88,10 +84,7 @@ impl TxnClient {

let mut request = api::client::SubmitTxRequest::new();
request.set_runtime_id(self.runtime_id.as_ref().to_vec());
match serde_cbor::to_vec(&call) {
Ok(data) => request.set_data(data),
Err(error) => return Box::new(future::err(error.into())),
}
request.set_data(cbor::to_vec(&call));

match self.client.submit_tx_async_opt(&request, options) {
Ok(resp) => Box::new(
Expand Down Expand Up @@ -165,7 +158,7 @@ impl TxnClient {
.and_then(move |rsp| {
Ok(BlockSnapshot::new(
storage_client.clone(),
serde_cbor::from_slice(&rsp.block)?,
cbor::from_slice(&rsp.block)?,
Hash::from(rsp.block_hash),
))
}),
Expand Down Expand Up @@ -204,7 +197,7 @@ impl TxnClient {
Err(error) => Err(TxnClientError::CallFailed(format!("{}", error)).into()),
Ok(rsp) => Ok(Some(BlockSnapshot::new(
storage_client,
serde_cbor::from_slice(&rsp.block)?,
cbor::from_slice(&rsp.block)?,
Hash::from(rsp.block_hash),
))),
}))
Expand Down Expand Up @@ -236,7 +229,7 @@ impl TxnClient {
})) => Ok(None),
Err(error) => Err(TxnClientError::CallFailed(format!("{}", error)).into()),
Ok(rsp) => {
let rsp: TxnResult = serde_cbor::from_slice(&rsp.result)?;
let rsp: TxnResult = cbor::from_slice(&rsp.result)?;
Ok(Some(TransactionSnapshot::new(
storage_client,
rsp.block,
Expand Down Expand Up @@ -281,7 +274,7 @@ impl TxnClient {
})) => Ok(None),
Err(error) => Err(TxnClientError::CallFailed(format!("{}", error)).into()),
Ok(rsp) => {
let rsp: TxnResult = serde_cbor::from_slice(&rsp.result)?;
let rsp: TxnResult = cbor::from_slice(&rsp.result)?;
Ok(Some(TransactionSnapshot::new(
storage_client,
rsp.block,
Expand Down Expand Up @@ -347,7 +340,7 @@ impl TxnClient {
Err(error) => Err(TxnClientError::CallFailed(format!("{}", error)).into()),
Ok(rsp) => Ok(Some(BlockSnapshot::new(
storage_client,
serde_cbor::from_slice(&rsp.block)?,
cbor::from_slice(&rsp.block)?,
Hash::from(rsp.block_hash),
))),
}))
Expand Down Expand Up @@ -383,7 +376,7 @@ impl TxnClient {
})) => Ok(None),
Err(error) => Err(TxnClientError::CallFailed(format!("{}", error)).into()),
Ok(rsp) => {
let rsp: TxnResult = serde_cbor::from_slice(&rsp.result)?;
let rsp: TxnResult = cbor::from_slice(&rsp.result)?;
Ok(Some(TransactionSnapshot::new(
storage_client,
rsp.block,
Expand All @@ -408,10 +401,7 @@ impl TxnClient {
let (span, options) = self.prepare_options("TxnClient::query_txn");
let mut request = api::client::QueryTxnsRequest::new();
request.set_runtime_id(self.runtime_id.as_ref().to_vec());
match serde_cbor::to_vec(&query) {
Ok(query) => request.set_query(query),
Err(error) => return Box::new(future::err(error.into())),
}
request.set_query(cbor::to_vec(&query));

let result: BoxFuture<Vec<TransactionSnapshot>> = match self
.client
Expand All @@ -422,7 +412,7 @@ impl TxnClient {
Box::new(
resp.map_err(|error| TxnClientError::CallFailed(format!("{}", error)).into())
.and_then(move |rsp| {
let rsp: Vec<TxnResult> = serde_cbor::from_slice(&rsp.results)?;
let rsp: Vec<TxnResult> = cbor::from_slice(&rsp.results)?;
rsp.into_iter()
.map(|tx| {
TransactionSnapshot::new(
Expand Down Expand Up @@ -493,9 +483,9 @@ pub fn parse_call_output<O>(output: Vec<u8>) -> Fallible<O>
where
O: DeserializeOwned,
{
let output: TxnOutput = serde_cbor::from_slice(&output)?;
let output: TxnOutput = cbor::from_slice(&output)?;
match output {
TxnOutput::Success(data) => Ok(serde_cbor::from_value(data)?),
TxnOutput::Success(data) => Ok(cbor::from_value(data)?),
TxnOutput::Error(error) => Err(TxnClientError::TxnFailed(error).into()),
}
}
12 changes: 6 additions & 6 deletions client/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{any::Any, cell::RefCell, rc::Rc};

use ekiden_runtime::{
common::{
cbor,
crypto::hash::Hash,
roothash::{Block, Namespace},
},
Expand All @@ -20,7 +21,6 @@ use ekiden_runtime::{
};
use failure::{Fallible, ResultExt};
use io_context::Context;
use serde_cbor;

use super::{api, client::TxnClientError};

Expand Down Expand Up @@ -49,8 +49,8 @@ impl TransactionSnapshot {
Ok(Self {
block_snapshot: BlockSnapshot::new(storage_client, block, block_hash),
index,
input: serde_cbor::from_slice(&input).context("input is malformed")?,
output: serde_cbor::from_slice(&output).context("output is malformed")?,
input: cbor::from_slice(&input).context("input is malformed")?,
output: cbor::from_slice(&output).context("output is malformed")?,
})
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ impl ReadSync for RemoteReadSync {
max_depth: u8,
) -> Fallible<Subtree> {
let mut request = api::storage::GetSubtreeRequest::new();
request.set_root(serde_cbor::to_vec(&root).unwrap());
request.set_root(cbor::to_vec(&root));
request.set_id({
let mut nid = api::storage::NodeID::new();
nid.set_path(id.path.as_ref().to_vec());
Expand All @@ -184,7 +184,7 @@ impl ReadSync for RemoteReadSync {
start_depth: u8,
) -> Fallible<Subtree> {
let mut request = api::storage::GetPathRequest::new();
request.set_root(serde_cbor::to_vec(&root).unwrap());
request.set_root(cbor::to_vec(&root));
request.set_key(key.as_ref().to_vec());
request.set_start_depth(start_depth.into());

Expand All @@ -200,7 +200,7 @@ impl ReadSync for RemoteReadSync {

fn get_node(&mut self, _ctx: Context, root: Root, id: NodeID) -> Fallible<NodeRef> {
let mut request = api::storage::GetNodeRequest::new();
request.set_root(serde_cbor::to_vec(&root).unwrap());
request.set_root(cbor::to_vec(&root));
request.set_id({
let mut nid = api::storage::NodeID::new();
nid.set_path(id.path.as_ref().to_vec());
Expand Down
2 changes: 1 addition & 1 deletion go/common/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ func (n *Namespace) Equal(cmp *Namespace) bool {
}

// String returns the string representation of a chain namespace identifier.
func (n *Namespace) String() string {
func (n Namespace) String() string {
return hex.EncodeToString(n[:])
}
20 changes: 20 additions & 0 deletions go/common/runtime/runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package runtime

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/oasislabs/ekiden/go/common/crypto/hash"
)

func TestConsistentHash(t *testing.T) {
// NOTE: These hashes MUST be synced with runtime/src/transaction/types.rs.
batch := Batch{[]byte("foo"), []byte("bar"), []byte("aaa")}
var h hash.Hash
h.From(batch)

var expectedHash hash.Hash
_ = expectedHash.UnmarshalHex("c451dd4fd065b815e784aac6b300e479b2167408f0eebbb95a8bd36b9e71e34d")
require.EqualValues(t, h, expectedHash)
}
5 changes: 5 additions & 0 deletions go/storage/mkvs/urkel/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type Root struct {
Hash hash.Hash `codec:"hash"`
}

// String returns the string representation of a storage root.
func (r Root) String() string {
return fmt.Sprintf("<Root ns=%s round=%d hash=%s>", r.Namespace, r.Round, r.Hash)
}

// MarshalCBOR serializes the type into a CBOR byte vector.
func (r *Root) MarshalCBOR() []byte {
return cbor.Marshal(r)
Expand Down
41 changes: 13 additions & 28 deletions go/worker/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,50 +308,35 @@ func (w *worker) onProcessStart(proto *protocol.Protocol, tee *node.CapabilityTE
}

func extractMessageResponsePayload(raw []byte) ([]byte, error) {
// Because of how serde_cbor serializes unit enums, simply de-serializing
// the response into a struct is not possible. Do this the hard way.
//
// This could alternatively be done by changing the rust side, or maybe
// this should be a general protocol helper, but this is probably the
// only place that will need such a thing.
//
// See: runtime/src/rcp/types.rs
// See: runtime/src/rpc/types.rs
type MessageResponseBody struct {
Status string `codec:""`
Value interface{} `codec:""`
Success interface{}
Error *string
}
type MessageResponse struct {
Type string `codec:""`
Inner struct {
Response *struct {
Body MessageResponseBody `codec:"body"`
} `codec:""`
}
}

var msg MessageResponse
if err := cbor.Unmarshal(raw, &msg); err != nil {
return nil, errors.Wrap(err, "malformed message envelope")
}

if mType := msg.Type; mType != "Response" {
return nil, fmt.Errorf("message is not a response: '%s'", mType)
if msg.Response == nil {
return nil, fmt.Errorf("message is not a response: '%s'", hex.EncodeToString(raw))
}

switch msg.Inner.Body.Status {
case "Success":
case "Error":
if msg.Inner.Body.Value == nil {
return nil, fmt.Errorf("unknown rpc response failure (nil)")
}
mErr, ok := msg.Inner.Body.Value.(string)
if !ok {
return nil, fmt.Errorf("unknown rpc response failure (%T)", msg.Inner.Body.Value)
}
return nil, fmt.Errorf("rpc failure: '%s'", mErr)
switch {
case msg.Response.Body.Success != nil:
case msg.Response.Body.Error != nil:
return nil, fmt.Errorf("rpc failure: '%s'", *msg.Response.Body.Error)
default:
return nil, fmt.Errorf("unknown rpc response status: '%s'", msg.Inner.Body.Status)
return nil, fmt.Errorf("unknown rpc response status: '%s'", hex.EncodeToString(raw))
}

return cbor.Marshal(msg.Inner.Body.Value), nil
return cbor.Marshal(msg.Response.Body.Success), nil
}

func (w *worker) onNodeRegistration(n *node.Node) error {
Expand Down
2 changes: 0 additions & 2 deletions keymanager-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ ekiden-keymanager-client = { path = "../keymanager-client" }
failure = "0.1.5"
lazy_static = "1.3.0"
lru = "0.1.15"
# TODO: Change to released version when 0.10.0 is released.
serde_cbor = { git = "https://github.com/pyfisch/cbor", rev = "114ecaeac53799d0bf81ca8d1b980c7c419d76fe" }
io-context = "0.2.0"
rand = "0.6.5"
sgx-isa = { version = "0.2.0", features = ["sgxstd"] }
Expand Down
Loading