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

CI & code base upgrades #2

Merged
merged 3 commits into from
Nov 21, 2021
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
73 changes: 58 additions & 15 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,70 @@ on:
branches: [ main, extensions ]
pull_request:
branches: [ main, extensions ]
types: [opened, synchronize, reopened, ready_for_review]

env:
CARGO_TERM_COLOR: always


jobs:
build:
test:
name: Test Rust ${{matrix.toolchain}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
matrix:
toolchain: [stable, nightly]
os: [ubuntu]
steps:
- uses: actions/checkout@v2
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{matrix.toolchain}}
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install minimal nightly with clippy
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true
- uses: Swatinem/rust-cache@v1
- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all -- -D clippy::all -D warnings

rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup
run: |
rustup toolchain install 1.54.0-x86_64-unknown-linux-gnu
rustup component add rustfmt --toolchain 1.54.0-x86_64-unknown-linux-gnu
rustup component add clippy --toolchain 1.54.0-x86_64-unknown-linux-gnu
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Rustfmt
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-targets
- uses: actions/checkout@v2
- name: Install minimal nightly with rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
override: true
- uses: Swatinem/rust-cache@v1
- name: rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
6 changes: 6 additions & 0 deletions fastpay/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

#![warn(
future_incompatible,
nonstandard_style,
rust_2018_idioms,
rust_2021_compatibility
)]
#![deny(warnings)]

pub mod config;
Expand Down
6 changes: 3 additions & 3 deletions fastpay/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl AuthorityClient for Client {
fn handle_transfer_order(
&mut self,
order: TransferOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
Box::pin(async move {
let shard = AuthorityState::get_shard(self.num_shards, &order.transfer.sender);
self.send_recv_bytes(shard, serialize_transfer_order(&order))
Expand All @@ -303,7 +303,7 @@ impl AuthorityClient for Client {
fn handle_confirmation_order(
&mut self,
order: ConfirmationOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
Box::pin(async move {
let shard = AuthorityState::get_shard(
self.num_shards,
Expand All @@ -318,7 +318,7 @@ impl AuthorityClient for Client {
fn handle_account_info_request(
&mut self,
request: AccountInfoRequest,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
Box::pin(async move {
let shard = AuthorityState::get_shard(self.num_shards, &request.sender);
self.send_recv_bytes(shard, serialize_info_request(&request))
Expand Down
6 changes: 3 additions & 3 deletions fastpay/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait DataStream: Send {
&'a mut self,
buffer: &'a [u8],
) -> future::BoxFuture<'a, Result<(), std::io::Error>>;
fn read_data(&mut self) -> future::BoxFuture<Result<Vec<u8>, std::io::Error>>;
fn read_data(&mut self) -> future::BoxFuture<'_, Result<Vec<u8>, std::io::Error>>;
}

/// A pool of (outgoing) data streams.
Expand Down Expand Up @@ -151,7 +151,7 @@ impl DataStream for UdpDataStream {
})
}

fn read_data(&mut self) -> future::BoxFuture<Result<Vec<u8>, std::io::Error>> {
fn read_data(&mut self) -> future::BoxFuture<'_, Result<Vec<u8>, std::io::Error>> {
Box::pin(async move {
let size = self.socket.recv(&mut self.buffer).await?;
Ok(self.buffer[..size].into())
Expand Down Expand Up @@ -275,7 +275,7 @@ impl DataStream for TcpDataStream {
Box::pin(Self::tcp_write_data(&mut self.stream, buffer))
}

fn read_data(&mut self) -> future::BoxFuture<Result<Vec<u8>, std::io::Error>> {
fn read_data(&mut self) -> future::BoxFuture<'_, Result<Vec<u8>, std::io::Error>> {
Box::pin(Self::tcp_read_data(&mut self.stream, self.max_data_size))
}
}
Expand Down
28 changes: 14 additions & 14 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ pub trait AuthorityClient {
fn handle_transfer_order(
&mut self,
order: TransferOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError>;
) -> AsyncResult<'_, AccountInfoResponse, FastPayError>;

/// Confirm a transfer to a FastPay or Primary account.
fn handle_confirmation_order(
&mut self,
order: ConfirmationOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError>;
) -> AsyncResult<'_, AccountInfoResponse, FastPayError>;

/// Handle information requests for this account.
fn handle_account_info_request(
&mut self,
request: AccountInfoRequest,
) -> AsyncResult<AccountInfoResponse, FastPayError>;
) -> AsyncResult<'_, AccountInfoResponse, FastPayError>;
}

pub struct ClientState<AuthorityClient> {
Expand Down Expand Up @@ -71,21 +71,21 @@ pub trait Client {
amount: Amount,
recipient: FastPayAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error>;
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error>;

/// Send money to a Primary account.
fn transfer_to_primary(
&mut self,
amount: Amount,
recipient: PrimaryAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error>;
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error>;

/// Receive money from FastPay.
fn receive_from_fastpay(
&mut self,
certificate: CertifiedTransferOrder,
) -> AsyncResult<(), failure::Error>;
) -> AsyncResult<'_, (), failure::Error>;

/// Send money to a FastPay account.
/// Do not check balance. (This may block the client)
Expand All @@ -95,12 +95,12 @@ pub trait Client {
amount: Amount,
recipient: FastPayAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error>;
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error>;

/// Find how much money we can spend.
/// TODO: Currently, this value only reflects received transfers that were
/// locally processed by `receive_from_fastpay`.
fn get_spendable_amount(&mut self) -> AsyncResult<Amount, failure::Error>;
fn get_spendable_amount(&mut self) -> AsyncResult<'_, Amount, failure::Error>;
}

impl<A> ClientState<A> {
Expand Down Expand Up @@ -184,7 +184,7 @@ where
fn query(
&mut self,
sequence_number: SequenceNumber,
) -> AsyncResult<CertifiedTransferOrder, FastPayError> {
) -> AsyncResult<'_, CertifiedTransferOrder, FastPayError> {
Box::pin(async move {
let request = AccountInfoRequest {
sender: self.sender,
Expand Down Expand Up @@ -600,7 +600,7 @@ where
amount: Amount,
recipient: FastPayAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error> {
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error> {
Box::pin(self.transfer(amount, Address::FastPay(recipient), user_data))
}

Expand All @@ -609,11 +609,11 @@ where
amount: Amount,
recipient: PrimaryAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error> {
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error> {
Box::pin(self.transfer(amount, Address::Primary(recipient), user_data))
}

fn get_spendable_amount(&mut self) -> AsyncResult<Amount, failure::Error> {
fn get_spendable_amount(&mut self) -> AsyncResult<'_, Amount, failure::Error> {
Box::pin(async move {
if let Some(order) = self.pending_transfer.clone() {
// Finish executing the previous transfer.
Expand All @@ -637,7 +637,7 @@ where
fn receive_from_fastpay(
&mut self,
certificate: CertifiedTransferOrder,
) -> AsyncResult<(), failure::Error> {
) -> AsyncResult<'_, (), failure::Error> {
Box::pin(async move {
certificate.check(&self.committee)?;
let transfer = &certificate.value.transfer;
Expand Down Expand Up @@ -670,7 +670,7 @@ where
amount: Amount,
recipient: FastPayAddress,
user_data: UserData,
) -> AsyncResult<CertifiedTransferOrder, failure::Error> {
) -> AsyncResult<'_, CertifiedTransferOrder, failure::Error> {
Box::pin(async move {
let transfer = Transfer {
sender: self.address,
Expand Down
2 changes: 1 addition & 1 deletion fastpay_core/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait Requester {
type Value: std::fmt::Debug + Send + Clone + 'static;

/// Request the value corresponding to the given key.
fn query(&mut self, key: Self::Key) -> future::BoxFuture<Self::Value>;
fn query(&mut self, key: Self::Key) -> future::BoxFuture<'_, Self::Value>;
}

/// Channel for using code to send requests and stop the downloader task.
Expand Down
2 changes: 1 addition & 1 deletion fastpay_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
#[macro_export]
macro_rules! fp_bail {
($e:expr) => {
return Err($e);
return Err($e)
};
}

Expand Down
7 changes: 6 additions & 1 deletion fastpay_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// SPDX-License-Identifier: Apache-2.0

#![warn(
future_incompatible,
nonstandard_style,
rust_2018_idioms,
rust_2021_compatibility
)]
#![deny(warnings)]

#[macro_use]
Expand Down
6 changes: 3 additions & 3 deletions fastpay_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ impl AuthorityClient for LocalAuthorityClient {
fn handle_transfer_order(
&mut self,
order: TransferOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
let state = self.0.clone();
Box::pin(async move { state.lock().await.handle_transfer_order(order) })
}

fn handle_confirmation_order(
&mut self,
order: ConfirmationOrder,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
let state = self.0.clone();
Box::pin(async move {
state
Expand All @@ -43,7 +43,7 @@ impl AuthorityClient for LocalAuthorityClient {
fn handle_account_info_request(
&mut self,
request: AccountInfoRequest,
) -> AsyncResult<AccountInfoResponse, FastPayError> {
) -> AsyncResult<'_, AccountInfoResponse, FastPayError> {
let state = self.0.clone();
Box::pin(async move { state.lock().await.handle_account_info_request(request) })
}
Expand Down
2 changes: 1 addition & 1 deletion fastpay_core/src/unit_tests/downloader_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Requester for LocalRequester {
type Key = &'static str;
type Value = u32;

fn query(&mut self, _key: Self::Key) -> future::BoxFuture<Self::Value> {
fn query(&mut self, _key: Self::Key) -> future::BoxFuture<'_, Self::Value> {
Box::pin(future::ready(self.0.fetch_add(1, Ordering::Relaxed)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.54.0
1.56.0