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

check formatting and lint rules in CI #3

Merged
merged 3 commits into from
Jan 31, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Clippy (default features)
run: cargo clippy --all-targets
- name: Rustfmt
run: cargo fmt -- --check --config unstable_features=true --config imports_granularity=Crate
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,26 @@ kill %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16
cd ../..
```

## Dealing with test failures `test_format` after code changes
## Contributing

### Formatting and linting

Make sure to fix the lint errors reported by
```
cargo clippy --all-targets
```
and run `cargo fmt` like this:
```
cargo fmt -- --config unstable_features=true --config imports_granularity=Crate
```

The long command for `cargo fmt` is needed to normalize imports (see [rust-lang/rustfmt#4991](https://github.com/rust-lang/rustfmt/issues/4991) )

### Dealing with test failures `test_format` after code changes

Getting an error with the test in [`zef-core/tests/format.rs`](zef-core/tests/format.rs) ?
Probably the file [`zef-core/tests/staged/formats.yaml`](zef-core/tests/staged/formats.yaml) (recording message formats) is
outdated. In the most case (but not always sadly), this can be fixed by running
[`zef-core/generate-format.sh`](zef-core/generate-format.sh).

See https://github.com/novifinancial/serde-reflection for more context.

## AWS Rust SDK demo with localstack

```
# localstack start
AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_REGION=us-west-2 LOCALSTACK=true cargo --bin aws-test run
```
6 changes: 6 additions & 0 deletions aws-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AWS Rust SDK demo with localstack

```
# localstack start
AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_REGION=us-west-2 LOCALSTACK=true cargo --bin aws-test run
```
1 change: 0 additions & 1 deletion aws-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ fn s3_client(conf: &aws_types::config::Config) -> aws_sdk_s3::Client {
}
aws_sdk_s3::Client::from_conf(s3_config_builder.build())
}

15 changes: 9 additions & 6 deletions zef-service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#![deny(warnings)]

use zef_service::{config::*, network, transport};
use zef_core::{
authority::*, base_types::*, client::*, committee::Committee, messages::*, serialize::*,
};
use zef_service::{config::*, network, transport};

use bytes::Bytes;
use futures::stream::StreamExt;
Expand Down Expand Up @@ -164,7 +164,8 @@ impl ClientContext {
account.next_sequence_number.try_add_assign_one().unwrap();
let order = RequestOrder::new(request.clone().into(), key_pair);
orders.push(order.clone());
let serialized_order = serialize_message(&SerializedMessage::RequestOrder(Box::new(order)));
let serialized_order =
serialize_message(&SerializedMessage::RequestOrder(Box::new(order)));
serialized_orders.push((account.account_id.clone(), serialized_order.into()));
if serialized_orders.len() >= max_orders {
break;
Expand Down Expand Up @@ -202,8 +203,9 @@ impl ClientContext {
let sig = Signature::new(&certificate.value, secx);
certificate.signatures.push((*pubx, sig));
}
let serialized_certificate =
serialize_message(&SerializedMessage::ConfirmationOrder(Box::new(ConfirmationOrder { certificate })));
let serialized_certificate = serialize_message(&SerializedMessage::ConfirmationOrder(
Box::new(ConfirmationOrder { certificate }),
));
serialized_certificates.push((
order.value.request.account_id,
serialized_certificate.into(),
Expand Down Expand Up @@ -239,8 +241,9 @@ impl ClientContext {
match aggregator.append(vote.authority, vote.signature) {
Ok(Some(certificate)) => {
debug!("Found certificate: {:?}", certificate);
let buf =
serialize_message(&SerializedMessage::ConfirmationOrder(Box::new(ConfirmationOrder { certificate })));
let buf = serialize_message(&SerializedMessage::ConfirmationOrder(Box::new(
ConfirmationOrder { certificate },
)));
certificates.push((account_id.clone(), buf.into()));
done_senders.insert(account_id);
}
Expand Down
12 changes: 6 additions & 6 deletions zef-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
// SPDX-License-Identifier: Apache-2.0

use crate::transport::NetworkProtocol;
use zef_core::{
base_types::*,
client::AccountClientState,
committee::Committee,
messages::{Address, Certificate, Operation, Value},
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
collections::BTreeMap,
fs::{self, File, OpenOptions},
io::{BufRead, BufReader, BufWriter, Write},
path::Path,
};
use zef_core::{
base_types::*,
client::AccountClientState,
committee::Committee,
messages::{Address, Certificate, Operation, Value},
};

pub trait Import: DeserializeOwned {
fn read(path: &Path) -> Result<Self, std::io::Error> {
Expand Down
49 changes: 37 additions & 12 deletions zef-service/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,20 @@ impl MessageHandler for RunningServerState {
.server
.state
.handle_request_order(*message)
.map(|info| Some(serialize_message(&SerializedMessage::AccountInfoResponse(Box::new(info))))),
.map(|info| {
Some(serialize_message(&SerializedMessage::AccountInfoResponse(
Box::new(info),
)))
}),
SerializedMessage::ConfirmationOrder(message) => {
match self.server.state.handle_confirmation_order(*message) {
Ok((info, continuation)) => {
// Cross-shard request
self.handle_continuation(continuation).await;
// Response
Ok(Some(serialize_message(&SerializedMessage::AccountInfoResponse(Box::new(info)))))
Ok(Some(serialize_message(
&SerializedMessage::AccountInfoResponse(Box::new(info)),
)))
}
Err(error) => Err(error),
}
Expand All @@ -207,11 +213,15 @@ impl MessageHandler for RunningServerState {
match self.server.state.handle_consensus_order(*message) {
Ok(ConsensusResponse::Info(info)) => {
// Response
Ok(Some(serialize_message(&SerializedMessage::ConsensusInfoResponse(Box::new(info)))))
Ok(Some(serialize_message(
&SerializedMessage::ConsensusInfoResponse(Box::new(info)),
)))
}
Ok(ConsensusResponse::Vote(vote)) => {
// Response
Ok(Some(serialize_message(&SerializedMessage::Vote(Box::new(vote)))))
Ok(Some(serialize_message(&SerializedMessage::Vote(Box::new(
vote,
)))))
}
Ok(ConsensusResponse::Continuations(continuations)) => {
// Cross-shard requests
Expand All @@ -228,7 +238,11 @@ impl MessageHandler for RunningServerState {
.server
.state
.handle_account_info_query(*message)
.map(|info| Some(serialize_message(&SerializedMessage::AccountInfoResponse(Box::new(info))))),
.map(|info| {
Some(serialize_message(&SerializedMessage::AccountInfoResponse(
Box::new(info),
)))
}),
SerializedMessage::CrossShardRequest(request) => {
match self.server.state.handle_cross_shard_request(*request) {
Ok(()) => (),
Expand Down Expand Up @@ -265,7 +279,9 @@ impl MessageHandler for RunningServerState {
Err(error) => {
warn!("User query failed: {}", error);
self.server.user_errors += 1;
Some(serialize_message(&SerializedMessage::Error(Box::new(error))))
Some(serialize_message(&SerializedMessage::Error(Box::new(
error,
))))
}
}
})
Expand Down Expand Up @@ -375,8 +391,11 @@ impl AuthorityClient for Client {
) -> AsyncResult<AccountInfoResponse, Error> {
Box::pin(async move {
let shard = AuthorityState::get_shard(self.num_shards, &order.value.request.account_id);
self.send_recv_info_bytes(shard, serialize_message(&SerializedMessage::RequestOrder(Box::new(order))))
.await
self.send_recv_info_bytes(
shard,
serialize_message(&SerializedMessage::RequestOrder(Box::new(order))),
)
.await
})
}

Expand All @@ -394,8 +413,11 @@ impl AuthorityClient for Client {
.confirm_account_id()
.ok_or(Error::InvalidConfirmationOrder)?,
);
self.send_recv_info_bytes(shard, serialize_message(&SerializedMessage::ConfirmationOrder(Box::new(order))))
.await
self.send_recv_info_bytes(
shard,
serialize_message(&SerializedMessage::ConfirmationOrder(Box::new(order))),
)
.await
})
}

Expand All @@ -406,8 +428,11 @@ impl AuthorityClient for Client {
) -> AsyncResult<AccountInfoResponse, Error> {
Box::pin(async move {
let shard = AuthorityState::get_shard(self.num_shards, &request.account_id);
self.send_recv_info_bytes(shard, serialize_message(&SerializedMessage::AccountInfoQuery(Box::new(request))))
.await
self.send_recv_info_bytes(
shard,
serialize_message(&SerializedMessage::AccountInfoQuery(Box::new(request))),
)
.await
})
}
}
Expand Down
16 changes: 4 additions & 12 deletions zef-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#![deny(warnings)]

use zef_service::{config::*, network, transport};
use zef_core::{account::AccountState, authority::*, base_types::*};
use futures::future::join_all;
use log::*;
use std::{
Expand All @@ -14,6 +12,8 @@ use std::{
};
use structopt::StructOpt;
use tokio::runtime::Runtime;
use zef_core::{account::AccountState, authority::*, base_types::*};
use zef_service::{config::*, network, transport};

#[allow(clippy::too_many_arguments)]
fn make_shard_server(
Expand All @@ -38,12 +38,7 @@ fn make_shard_server(
let committee = committee_config.into_committee();
let num_shards = server_config.authority.num_shards;

let mut state = AuthorityState::new_shard(
committee,
server_config.key,
shard,
num_shards,
);
let mut state = AuthorityState::new_shard(committee, server_config.key, shard, num_shards);

// Load initial states
for (id, owner, balance) in &initial_accounts_config.accounts {
Expand Down Expand Up @@ -163,10 +158,7 @@ fn make_server_config(options: AuthorityOptions) -> AuthorityServerConfig {
base_port: options.port,
num_shards: options.shards,
};
AuthorityServerConfig {
authority,
key,
}
AuthorityServerConfig { authority, key }
}

#[derive(StructOpt)]
Expand Down