Skip to content

Commit

Permalink
network: convert to grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 2, 2022
1 parent f5543e8 commit 0351049
Show file tree
Hide file tree
Showing 34 changed files with 1,939 additions and 1,774 deletions.
242 changes: 227 additions & 15 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ members = [
"sui_programmability/adapter/transactional-tests",
"sui_types",
"faucet",
"test_utils"
"test_utils",
"crates/sui-network",
]

[profile.release]
Expand Down
18 changes: 9 additions & 9 deletions network_utils/Cargo.toml → crates/sui-network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[package]
name = "sui-network"
version = "0.1.0"
version = "0.0.0"
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
bytes = "1.1.0"
futures = "0.3.21"
async-trait = "0.1.53"
tokio = { version = "1.17.0", features = ["full"] }
tracing = { version = "0.1.34", features = ["log"] }
tokio-util = { version = "0.7.1", features = ["codec"] }
tracing = "0.1.34"
tonic = "0.7"
prost = "0.10"
bincode = "1.3.3"
serde = "1.0.136"

sui-types = { path = "../sui_types" }


[package.metadata.cargo-udeps.ignore]
normal = ["net2"]
[dev-dependencies]
tonic-build = { version = "0.7", features = [ "prost", "transport" ] }
prost-build = "0.10.1"
11 changes: 11 additions & 0 deletions crates/sui-network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# sui-network

## Changing an RPC service

The general process for changing an RPC service is as follows:
1. Change the corresponding `.proto` file in the `proto` directory
2. Run `cargo test --test bootstrap` to re-run the code generation.
Generated rust files are in the `src/generated` directory.
3. Update any other corresponding logic that would have been affected by
the interface change, e.g. the server implementation of the service or
usages of the generated client.
12 changes: 12 additions & 0 deletions crates/sui-network/proto/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package sui.common;

// A bincode encoded payload. This is intended to be used in the short-term
// while we don't have good protobuf definitions for sui types
message BincodeEncodedPayload {
bytes payload = 1;
}
19 changes: 19 additions & 0 deletions crates/sui-network/proto/validator.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package sui.validator;

import "common.proto";

// The Validator interface
service Validator {
rpc Transaction (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc ConfirmationTransaction (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc ConsensusTransaction (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc AccountInfo (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc ObjectInfo (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc TransactionInfo (common.BincodeEncodedPayload) returns (common.BincodeEncodedPayload) {}
rpc BatchInfo (common.BincodeEncodedPayload) returns (stream common.BincodeEncodedPayload) {}
}
33 changes: 33 additions & 0 deletions crates/sui-network/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[path = "generated/sui.validator.rs"]
#[rustfmt::skip]
mod validator;

#[path = "generated/sui.common.rs"]
#[rustfmt::skip]
mod common;

pub use common::BincodeEncodedPayload;
pub use validator::{
validator_client::ValidatorClient,
validator_server::{Validator, ValidatorServer},
};

impl BincodeEncodedPayload {
pub fn deserialize<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
bincode::deserialize(self.payload.as_ref())
}

pub fn try_from<T: serde::Serialize>(value: &T) -> Result<Self, bincode::Error> {
let payload = bincode::serialize(value)?.into();
Ok(Self { payload })
}
}

impl From<bytes::Bytes> for BincodeEncodedPayload {
fn from(payload: bytes::Bytes) -> Self {
Self { payload }
}
}
9 changes: 9 additions & 0 deletions crates/sui-network/src/generated/sui.common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
/// A bincode encoded payload. This is intended to be used in the short-term
/// while we don't have good protobuf definitions for sui types
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BincodeEncodedPayload {
#[prost(bytes="bytes", tag="1")]
pub payload: ::prost::bytes::Bytes,
}
Loading

0 comments on commit 0351049

Please sign in to comment.