Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
3 changes: 2 additions & 1 deletion .github/workflows/polkadot-companion-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
contexts: 'continuous-integration/gitlab-check-polkadot-companion-build'
timeout: 1800
notPresentTimeout: 3600 # It can take quite a while before the job starts...
notPresentTimeout: 3600 # It can take quite a while before the job starts on Gitlab when the CI queue is large
failureStates: failure
interruptedStates: error # Error = job was probably cancelled. We don't want to label the PR in that case
pollInterval: 30
- name: Label success
uses: andymckay/labeler@master
if: steps.check-companion-status.outputs.result == 'success'
Expand Down
15 changes: 14 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ members = [
"frame/metadata",
"frame/multisig",
"frame/nicks",
"frame/node-authorization",
"frame/offences",
"frame/proxy",
"frame/randomness-collective-flip",
Expand Down
1 change: 0 additions & 1 deletion bin/node/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ substrate-test-client = { version = "2.0.0-rc6", path = "../../../test-utils/cli
pallet-timestamp = { version = "2.0.0-rc6", path = "../../../frame/timestamp" }
pallet-transaction-payment = { version = "2.0.0-rc6", path = "../../../frame/transaction-payment" }
pallet-treasury = { version = "2.0.0-rc6", path = "../../../frame/treasury" }
wat = "1.0"
sp-api = { version = "2.0.0-rc6", path = "../../../primitives/api" }
sp-finality-tracker = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/finality-tracker" }
sp-timestamp = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/timestamp" }
Expand Down
20 changes: 14 additions & 6 deletions client/authority-discovery/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ impl Service {
}
}

/// Get the addresses for the given [`AuthorityId`] from the local address cache.
/// Get the addresses for the given [`AuthorityId`] from the local address
/// cache.
///
/// Returns `None` if no entry was present or connection to the [`crate::Worker`] failed.
/// Returns `None` if no entry was present or connection to the
/// [`crate::Worker`] failed.
///
/// [`Multiaddr`]s returned always include a [`libp2p::core::multiaddr:Protocol::P2p`]
/// component.
/// [`Multiaddr`]s returned always include a [`PeerId`] via a
/// [`libp2p::core::multiaddr:Protocol::P2p`] component. [`Multiaddr`]s
/// might differ in their [`PeerId`], e.g. when each [`Multiaddr`]
/// represents a different sentry node. This might change once support for
/// sentry nodes is removed (see
/// https://github.com/paritytech/substrate/issues/6845).
pub async fn get_addresses_by_authority_id(&mut self, authority: AuthorityId) -> Option<Vec<Multiaddr>> {
let (tx, rx) = oneshot::channel();

Expand All @@ -54,9 +60,11 @@ impl Service {
rx.await.ok().flatten()
}

/// Get the [`AuthorityId`] for the given [`PeerId`] from the local address cache.
/// Get the [`AuthorityId`] for the given [`PeerId`] from the local address
/// cache.
///
/// Returns `None` if no entry was present or connection to the [`crate::Worker`] failed.
/// Returns `None` if no entry was present or connection to the
/// [`crate::Worker`] failed.
pub async fn get_authority_id_by_peer_id(&mut self, peer_id: PeerId) -> Option<AuthorityId> {
let (tx, rx) = oneshot::channel();

Expand Down
6 changes: 3 additions & 3 deletions client/network/src/request_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Collection of request-response protocols.
//!
//! The [`RequestResponses`] struct defined in this module provides support for zero or more
//! The [`RequestResponse`] struct defined in this module provides support for zero or more
//! so-called "request-response" protocols.
//!
//! A request-response protocol works in the following way:
Expand All @@ -29,7 +29,7 @@
//! - Requests have a certain time limit before they time out. This time includes the time it
//! takes to send/receive the request and response.
//!
//! - If provided, a ["requests processing"](RequestResponseConfig::inbound_queue) channel
//! - If provided, a ["requests processing"](ProtocolConfig::inbound_queue) channel
//! is used to handle incoming requests.
//!

Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct IncomingRequest {
pub peer: PeerId,

/// Request sent by the remote. Will always be smaller than
/// [`RequestResponseConfig::max_request_size`].
/// [`ProtocolConfig::max_request_size`].
pub payload: Vec<u8>,

/// Channel to send back the response to.
Expand Down
18 changes: 17 additions & 1 deletion client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! There are two main structs in this module: [`NetworkWorker`] and [`NetworkService`].
//! The [`NetworkWorker`] *is* the network and implements the `Future` trait. It must be polled in
//! order fo the network to advance.
//! order for the network to advance.
//! The [`NetworkService`] is merely a shared version of the [`NetworkWorker`]. You can obtain an
//! `Arc<NetworkService>` by calling [`NetworkWorker::service`].
//!
Expand Down Expand Up @@ -605,6 +605,22 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
&self.local_peer_id
}

/// Set authorized peers.
///
/// Need a better solution to manage authorized peers, but now just use reserved peers for
/// prototyping.
pub fn set_authorized_peers(&self, peers: HashSet<PeerId>) {
self.peerset.set_reserved_peers(peers)
}

/// Set authorized_only flag.
///
/// Need a better solution to decide authorized_only, but now just use reserved_only flag for
/// prototyping.
pub fn set_authorized_only(&self, reserved_only: bool) {
self.peerset.set_reserved_only(reserved_only)
}

/// Appends a notification to the buffer of pending outgoing notifications with the given peer.
/// Has no effect if the notifications channel with this protocol name is not open.
///
Expand Down
50 changes: 35 additions & 15 deletions client/offchain/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ use std::{
sync::Arc,
convert::TryFrom,
thread::sleep,
collections::HashSet,
};

use sp_core::offchain::OffchainStorage;
use crate::NetworkProvider;
use futures::Future;
use log::error;
use sc_network::{PeerId, Multiaddr, NetworkStateInfo};
use sc_network::{PeerId, Multiaddr};
use codec::{Encode, Decode};
use sp_core::OpaquePeerId;
use sp_core::offchain::{
Externalities as OffchainExt, HttpRequestId, Timestamp, HttpRequestStatus, HttpError,
OpaqueNetworkState, OpaquePeerId, OpaqueMultiaddr, StorageKind,
OffchainStorage, OpaqueNetworkState, OpaqueMultiaddr, StorageKind,
};
pub use sp_offchain::STORAGE_PREFIX;
pub use http::SharedClient;
Expand All @@ -49,8 +51,8 @@ mod timestamp;
pub(crate) struct Api<Storage> {
/// Offchain Workers database.
db: Storage,
/// A NetworkState provider.
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
/// A provider for substrate networking.
network_provider: Arc<dyn NetworkProvider + Send + Sync>,
/// Is this node a potential validator?
is_validator: bool,
/// Everything HTTP-related is handled by a different struct.
Expand All @@ -73,10 +75,10 @@ impl<Storage: OffchainStorage> OffchainExt for Api<Storage> {
}

fn network_state(&self) -> Result<OpaqueNetworkState, ()> {
let external_addresses = self.network_state.external_addresses();
let external_addresses = self.network_provider.external_addresses();

let state = NetworkState::new(
self.network_state.local_peer_id(),
self.network_provider.local_peer_id(),
external_addresses,
);
Ok(OpaqueNetworkState::from(state))
Expand Down Expand Up @@ -180,6 +182,15 @@ impl<Storage: OffchainStorage> OffchainExt for Api<Storage> {
) -> Result<usize, HttpError> {
self.http.response_read_body(request_id, buffer, deadline)
}

fn set_authorized_nodes(&mut self, nodes: Vec<OpaquePeerId>, authorized_only: bool) {
let peer_ids: HashSet<PeerId> = nodes.into_iter()
.filter_map(|node| PeerId::from_bytes(node.0).ok())
.collect();

self.network_provider.set_authorized_peers(peer_ids);
self.network_provider.set_authorized_only(authorized_only);
}
}

/// Information about the local node's network state.
Expand Down Expand Up @@ -256,18 +267,18 @@ pub(crate) struct AsyncApi {
}

impl AsyncApi {
/// Creates new Offchain extensions API implementation an the asynchronous processing part.
/// Creates new Offchain extensions API implementation an the asynchronous processing part.
pub fn new<S: OffchainStorage>(
db: S,
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
network_provider: Arc<dyn NetworkProvider + Send + Sync>,
is_validator: bool,
shared_client: SharedClient,
) -> (Api<S>, Self) {
let (http_api, http_worker) = http::http(shared_client);

let api = Api {
db,
network_state,
network_provider,
is_validator,
http: http_api,
};
Expand All @@ -292,11 +303,21 @@ mod tests {
use super::*;
use std::{convert::{TryFrom, TryInto}, time::SystemTime};
use sc_client_db::offchain::LocalStorage;
use sc_network::PeerId;
use sc_network::{NetworkStateInfo, PeerId};

struct MockNetworkStateInfo();
struct TestNetwork();

impl NetworkProvider for TestNetwork {
fn set_authorized_peers(&self, _peers: HashSet<PeerId>) {
unimplemented!()
}

impl NetworkStateInfo for MockNetworkStateInfo {
fn set_authorized_only(&self, _reserved_only: bool) {
unimplemented!()
}
}

impl NetworkStateInfo for TestNetwork {
fn external_addresses(&self) -> Vec<Multiaddr> {
Vec::new()
}
Expand All @@ -309,10 +330,9 @@ mod tests {
fn offchain_api() -> (Api<LocalStorage>, AsyncApi) {
let _ = env_logger::try_init();
let db = LocalStorage::new_test();
let mock = Arc::new(MockNetworkStateInfo());
let mock = Arc::new(TestNetwork());
let shared_client = SharedClient::new();


AsyncApi::new(
db,
mock,
Expand Down
Loading