Skip to content

Commit

Permalink
Merge pull request #63 from paritytech/lexnv/test-bind-addr
Browse files Browse the repository at this point in the history
tests: Add sysctl ipv6 and extra CI steps
  • Loading branch information
lexnv authored Mar 20, 2024
2 parents 225788a + 994fb98 commit 25674bf
Show file tree
Hide file tree
Showing 28 changed files with 222 additions and 158 deletions.
114 changes: 67 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,98 +12,118 @@ concurrency:
# ${{ vars.CI_UNIFIED_IMAGE }} is defined in the repository variables

jobs:
check:
name: "check"
fmt:
name: Cargo fmt
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Checkout sources
uses: actions/checkout@v4

# uncomment if needed
# - name: fmt
# run: |
# cargo fmt --all --check

- name: Rust Cache
uses: Swatinem/rust-cache@v2.5.0
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true

- name: check
run: cargo check
- name: Cargo fmt
run: cargo +nightly fmt --all -- --check

test:
name: "test"
machete:
name: Check unused dependencies
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
# options: --privileged
steps:
- uses: actions/checkout@v3
- name: Checkout sources
uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true

- name: Install cargo-machete
run: cargo install cargo-machete

# - name: Install Rust stable toolchain
# uses: actions-rs/[email protected]
# with:
# profile: minimal
# toolchain: 1.75.0
# override: true
- name: Check unused dependencies
run: cargo machete

check:
name: Cargo check
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@v2.5.0
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true

- name: test
run: |
# sudo apt-get update && sudo apt-get install -y iproute2 protobuf-compiler
echo "Installing iproute2..."
apt-get update && apt-get install -y iproute2 iputils-ping
# ip a
# echo "Enabling loopback interface explicitly..."
# ip link set lo up
echo "Result"
ip a
ping -c 1 127.0.0.1
echo "Starting a simple HTTP server..."
python3 -m http.server --bind 127.0.0.1 8080 &
sleep 1
curl 127.0.0.1:8080
echo "Running tests..."
cargo test
- name: Cargo check
run: cargo check

doc:
name: "doc"
name: Check documentation
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Checkout sources
uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@v2.5.0
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true
- name: doc
run: cargo doc
- name: Check documentation
run: RUSTDOCFLAGS="-D warnings -D rustdoc::broken_intra_doc_links" cargo doc --workspace --no-deps --document-private-items

clippy:
name: "clippy"
name: Cargo clippy
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Checkout sources
uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@v2.5.0
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true

- name: clippy
# TODO: Allow clippy to fail and do not cancel other tasks.
# Clippy is fixed by: https://github.com/paritytech/litep2p/pull/57.
- name: Run clippy
continue-on-error: true
run: cargo clippy

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
container:
image: ${{ vars.CI_IMAGE }}
options: --sysctl net.ipv6.conf.all.disable_ipv6=0
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true

- name: Run tests
run: cargo test
11 changes: 10 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bytes = "1.4.0"
cid = "0.10.1"
ed25519-dalek = "1.0.1"
futures = "0.3.27"
futures-rustls = "0.22.2"
futures-timer = "3.0.2"
hex-literal = "0.4.1"
indexmap = { version = "2.0.0", features = ["std"] }
Expand Down Expand Up @@ -79,6 +78,7 @@ libp2p = { version = "0.51.3", features = [
"quic",
]}
quickcheck = "1.0.3"
rand_xorshift = "0.3.0"
sc-network = "0.28.0"
sc-utils = "8.0.0"
serde_json = "1.0.108"
Expand Down
13 changes: 12 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Basic
edition = "2021"
max_width = 100

# Imports
imports_granularity = "Crate"
reorder_imports = true

# Consistency
newline_style = "Unix"

# Misc
chain_width = 80
spaces_around_ranges = false
match_arm_blocks = false
trailing_comma = "Vertical"
edition = "2021"

# Format comments
comment_width = 100
wrap_comments = true
24 changes: 10 additions & 14 deletions src/multistream_select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@
//! echoing the same protocol) or reject (by responding with a message stating
//! "not available"). If a suggested protocol is not available, the dialer may
//! suggest another protocol. This process continues until a protocol is agreed upon,
//! yielding a [`Negotiated`](self::Negotiated) stream, or the dialer has run out of
//! yielding a [`Negotiated`] stream, or the dialer has run out of
//! alternatives.
//!
//! See [`dialer_select_proto`](self::dialer_select_proto) and
//! [`listener_select_proto`](self::listener_select_proto).
//! See [`dialer_select_proto`] and [`listener_select_proto`].
//!
//! ## [`Negotiated`](self::Negotiated)
//! ## [`Negotiated`]
//!
//! A `Negotiated` represents an I/O stream that has settled on a protocol
//! to use. By default, with [`Version::V1`], protocol negotiation is always
Expand All @@ -58,16 +57,15 @@
//! a variant [`Version::V1Lazy`] that permits 0-RTT negotiation if the
//! dialer only supports a single protocol. In that case, when a dialer
//! settles on a protocol to use, the [`DialerSelectFuture`] yields a
//! [`Negotiated`](self::Negotiated) I/O stream before the negotiation
//! [`Negotiated`] I/O stream before the negotiation
//! data has been flushed. It is then expecting confirmation for that protocol
//! as the first messages read from the stream. This behaviour allows the dialer
//! to immediately send data relating to the negotiated protocol together with the
//! remaining negotiation message(s). Note, however, that a dialer that performs
//! multiple 0-RTT negotiations in sequence for different protocols layered on
//! top of each other may trigger undesirable behaviour for a listener not
//! supporting one of the intermediate protocols. See
//! [`dialer_select_proto`](self::dialer_select_proto) and the documentation
//! of [`Version::V1Lazy`] for further details.
//! [`dialer_select_proto`] and the documentation of [`Version::V1Lazy`] for further details.
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

Expand All @@ -77,14 +75,12 @@ mod listener_select;
mod negotiated;
mod protocol;

pub use crate::multistream_select::dialer_select::{
dialer_select_proto, DialerSelectFuture, DialerState, HandshakeResult,
pub use crate::multistream_select::{
dialer_select::{dialer_select_proto, DialerSelectFuture, DialerState, HandshakeResult},
listener_select::{listener_negotiate, listener_select_proto, ListenerSelectFuture},
negotiated::{Negotiated, NegotiatedComplete, NegotiationError},
protocol::{HeaderLine, Message, Protocol, ProtocolError},
};
pub use crate::multistream_select::listener_select::{
listener_negotiate, listener_select_proto, ListenerSelectFuture,
};
pub use crate::multistream_select::negotiated::{Negotiated, NegotiatedComplete, NegotiationError};
pub use crate::multistream_select::protocol::{HeaderLine, Message, Protocol, ProtocolError};

/// Supported multistream-select versions.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
6 changes: 4 additions & 2 deletions src/multistream_select/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
//! `Stream` and `Sink` implementations of `MessageIO` and
//! `MessageReader`.
use crate::multistream_select::length_delimited::{LengthDelimited, LengthDelimitedReader};
use crate::multistream_select::Version;
use crate::multistream_select::{
length_delimited::{LengthDelimited, LengthDelimitedReader},
Version,
};

use bytes::{BufMut, Bytes, BytesMut};
use futures::{io::IoSlice, prelude::*, ready};
Expand Down
10 changes: 4 additions & 6 deletions src/protocol/libp2p/kademlia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ use tokio::sync::mpsc::{Receiver, Sender};

use std::collections::{hash_map::Entry, HashMap};

pub use {
config::{Config, ConfigBuilder},
handle::{KademliaEvent, KademliaHandle, Quorum, RoutingTableUpdateMode},
query::QueryId,
record::{Key as RecordKey, Record},
};
pub use config::{Config, ConfigBuilder};
pub use handle::{KademliaEvent, KademliaHandle, Quorum, RoutingTableUpdateMode};
pub use query::QueryId;
pub use record::{Key as RecordKey, Record};

/// Logging target for the file.
const LOG_TARGET: &str = "litep2p::ipfs::kademlia";
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/libp2p/kademlia/routing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ impl RoutingTable {
/// An iterator over the bucket indices, in the order determined by the `Distance` of a target from
/// the `local_key`, such that the entries in the buckets are incrementally further away from the
/// target, starting with the bucket covering the target.
/// The original implementation is taken from `rust-libp2p`, see [1] for the explanation of the
/// algorithm used.
/// The original implementation is taken from `rust-libp2p`, see [issue#1117][1] for the explanation
/// of the algorithm used.
///
/// [1]: https://github.com/libp2p/rust-libp2p/pull/1117#issuecomment-494694635
struct ClosestBucketsIter {
/// The distance to the `local_key`.
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/libp2p/kademlia/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl<T: Clone> Key<T> {
/// Constructs a new `Key` by running the given value through a random
/// oracle.
///
/// The preimage of type `T` is preserved. See [`Key::preimage`] and
/// [`Key::into_preimage`].
/// The preimage of type `T` is preserved.
/// See [`Key::into_preimage`] for more details.
pub fn new(_preimage: T) -> Key<T>
where
T: Borrow<[u8]>,
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/notification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl NotificationProtocol {
/// substream is a result of a valid state transition.
///
/// For the third case, if the nodes have opened substreams at the same time, the outbound state
/// must be [`OutbounState::OutboundInitiated`] to ascertain that the an outbound substream was
/// must be [`OutboundState::OutboundInitiated`] to ascertain that the an outbound substream was
/// actually opened. Any other state would be a state mismatch and would mean that the
/// connection is opening substreams without the permission of the protocol handler.
async fn on_outbound_substream(
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/notification/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub enum NotificationEvent {
},
}

/// Notification commands sent by the [`NotificationService`] to the protocol.
/// Notification commands sent to the protocol.
pub(crate) enum NotificationCommand {
/// Open substreams to one or more peers.
OpenSubstream {
Expand Down
3 changes: 1 addition & 2 deletions src/protocol/request_response/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

use crate::{
crypto::ed25519::Keypair,
mock::substream::DummySubstream,
mock::substream::MockSubstream,
mock::substream::{DummySubstream, MockSubstream},
protocol::{
request_response::{
ConfigBuilder, DialOptions, RequestResponseError, RequestResponseEvent,
Expand Down
2 changes: 1 addition & 1 deletion src/transport/manager/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl AddressStore {
self.by_score.push(record);
}

/// Pop address with the highest score from [`AddressScore`].
/// Pop address with the highest score from [`AddressStore`].
pub fn pop(&mut self) -> Option<AddressRecord> {
self.by_score.pop().map(|record| {
self.by_address.remove(&record.address);
Expand Down
Loading

0 comments on commit 25674bf

Please sign in to comment.