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 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2007c1f
Alliance pallet: add force_set_members instead of init_members function
muharem Aug 9, 2022
a405dfc
benchmark with witness data
muharem Aug 12, 2022
b654d68
remove invalid limit for clear
muharem Aug 12, 2022
855bb3d
Apply suggestions from code review
muharem Aug 12, 2022
7ad0f97
Revert "remove invalid limit for clear"
muharem Aug 12, 2022
8b071c4
compile constructor only for test
muharem Aug 12, 2022
fb4c22c
Update comments for force_set_members
muharem Aug 12, 2022
a40904e
Apply suggestions from code review
muharem Aug 16, 2022
8a254b4
Merge branch 'master' of https://github.com/paritytech/substrate into…
Aug 16, 2022
d202ae2
".git/.scripts/bench-bot.sh" pallet dev pallet_alliance
Aug 16, 2022
744178f
benchmark - founders count range
muharem Aug 16, 2022
dbc4fdd
Revert "benchmark - founders count range"
muharem Aug 16, 2022
2ea38af
witness members count instead votable members count
muharem Aug 19, 2022
e7b525a
update the doc
muharem Aug 24, 2022
92575a1
use decode_len for witness data checks
muharem Aug 26, 2022
628b1c3
Merge remote-tracking branch 'origin/master' into pallet-alliance-for…
Aug 26, 2022
523f256
change witness data member count to voting member count; update clear…
muharem Aug 26, 2022
cb3e63d
".git/.scripts/bench-bot.sh" pallet dev pallet_alliance
Aug 26, 2022
cd6bea8
merge master
muharem Aug 29, 2022
78d28a2
fixes after merge master
muharem Aug 29, 2022
f9312c5
revert to cb3e63
muharem Aug 29, 2022
ccc35ed
Merge remote-tracking branch 'origin/master' into pallet-alliance-for…
muharem Aug 29, 2022
f7828c2
disband alliance and return deposits
muharem Aug 31, 2022
9531b8a
revert debug changes
muharem Aug 31, 2022
5136902
Merge remote-tracking branch 'origin/master' into pallet-alliance-for…
muharem Aug 31, 2022
973483d
weights
muharem Aug 31, 2022
5cfb043
update docs
muharem Aug 31, 2022
145d14e
update test comments
muharem Aug 31, 2022
183ee71
Apply Joe suggestions from code review
muharem Sep 1, 2022
91b5891
rename event from AllianceDisband to AllianceDisbanded
muharem Sep 1, 2022
e730aa2
Merge branch 'master' of https://github.com/paritytech/substrate into…
Sep 1, 2022
7ba3056
".git/.scripts/bench-bot.sh" pallet dev pallet_alliance
Sep 1, 2022
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
Prev Previous commit
Next Next commit
merge master
  • Loading branch information
muharem committed Aug 29, 2022
commit cd6bea8e2129caa5a86d63d0325d4e4e60155b77
1 change: 1 addition & 0 deletions Cargo.lock

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

17 changes: 14 additions & 3 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,8 +1518,10 @@ impl pallet_state_trie_migration::Config for Runtime {
type WeightInfo = ();
}

const ALLIANCE_MOTION_DURATION_IN_BLOCKS: BlockNumber = 5 * DAYS;

parameter_types! {
pub const AllianceMotionDuration: BlockNumber = 5 * DAYS;
pub const AllianceMotionDuration: BlockNumber = ALLIANCE_MOTION_DURATION_IN_BLOCKS;
pub const AllianceMaxProposals: u32 = 100;
pub const AllianceMaxMembers: u32 = 100;
}
Expand All @@ -1541,6 +1543,7 @@ parameter_types! {
pub const MaxFellows: u32 = AllianceMaxMembers::get() - MaxFounders::get();
pub const MaxAllies: u32 = 100;
pub const AllyDeposit: Balance = 10 * DOLLARS;
pub const RetirementPeriod: BlockNumber = ALLIANCE_MOTION_DURATION_IN_BLOCKS + (1 * DAYS);
}

impl pallet_alliance::Config for Runtime {
Expand Down Expand Up @@ -1577,6 +1580,7 @@ impl pallet_alliance::Config for Runtime {
type MaxMembersCount = AllianceMaxMembers;
type AllyDeposit = AllyDeposit;
type WeightInfo = pallet_alliance::weights::SubstrateWeight<Runtime>;
type RetirementPeriod = RetirementPeriod;
}

construct_runtime!(
Expand Down Expand Up @@ -1682,9 +1686,16 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
pallet_nomination_pools::migration::v2::MigrateToV2<Runtime>,
Migrations,
>;

// All migrations executed on runtime upgrade as a nested tuple of types implementing
// `OnRuntimeUpgrade`.
type Migrations = (
pallet_nomination_pools::migration::v2::MigrateToV2<Runtime>,
pallet_alliance::migration::Migration<Runtime>,
);

/// MMR helper types.
mod mmr {
use super::Runtime;
Expand Down Expand Up @@ -1843,7 +1854,7 @@ impl_runtime_apis! {

impl pallet_nomination_pools_runtime_api::NominationPoolsApi<Block, AccountId, Balance> for Runtime {
fn pending_rewards(member_account: AccountId) -> Balance {
NominationPools::pending_rewards(member_account)
NominationPools::pending_rewards(member_account).unwrap_or_default()
}
}

Expand Down
12 changes: 11 additions & 1 deletion client/executor/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ codec = { package = "parity-scale-codec", version = "3.0.0" }
libc = "0.2.121"
log = "0.4.17"
parity-wasm = "0.42.0"

# When bumping wasmtime do not forget to also bump rustix
# to exactly the same version as used by wasmtime!
wasmtime = { version = "0.38.0", default-features = false, features = [
"cache",
"cranelift",
Expand All @@ -33,9 +36,16 @@ sp-sandbox = { version = "0.10.0-dev", path = "../../../primitives/sandbox" }
sp-wasm-interface = { version = "6.0.0", features = ["wasmtime"], path = "../../../primitives/wasm-interface" }

[target.'cfg(target_os = "linux")'.dependencies]
rustix = { version = "0.35.6", default-features = false, features = ["std", "mm", "fs", "param"] }
rustix = { version = "0.35.6", default-features = false, features = ["std", "mm", "fs", "param", "use-libc"] }
once_cell = "1.12.0"

# Here we include the rustix crate used by wasmtime just to enable its 'use-libc' flag.
#
# By default rustix directly calls the appropriate syscalls completely bypassing libc;
# this doesn't have any actual benefits for us besides making it harder to debug memory
# problems (since then `mmap` etc. cannot be easily hooked into).
rustix_wasmtime = { package = "rustix", version = "0.33.7", default-features = false, features = ["std", "use-libc"] }

[dev-dependencies]
wat = "1.0"
sc-runtime-test = { version = "2.0.0", path = "../runtime-test" }
Expand Down
3 changes: 2 additions & 1 deletion client/finality-grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use futures::prelude::*;
use parity_scale_codec::Encode;
use sc_network::{config::Role, Multiaddr, PeerId, ReputationChange};
use sc_network_common::{
config::MultiaddrWithPeerId,
protocol::event::{Event as NetworkEvent, ObservedRole},
service::{
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
Expand Down Expand Up @@ -87,7 +88,7 @@ impl NetworkPeers for TestNetwork {
unimplemented!();
}

fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, _peer: MultiaddrWithPeerId) -> Result<(), String> {
unimplemented!();
}

Expand Down
3 changes: 2 additions & 1 deletion client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ mod tests {
};
use quickcheck::{Arbitrary, Gen, QuickCheck};
use sc_network_common::{
config::MultiaddrWithPeerId,
protocol::event::ObservedRole,
service::{
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
Expand Down Expand Up @@ -371,7 +372,7 @@ mod tests {
unimplemented!();
}

fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, _peer: MultiaddrWithPeerId) -> Result<(), String> {
unimplemented!();
}

Expand Down
3 changes: 2 additions & 1 deletion client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ mod tests {
use crate::multiaddr::Multiaddr;
use futures::prelude::*;
use sc_network_common::{
config::MultiaddrWithPeerId,
protocol::event::Event,
service::{
NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
Expand Down Expand Up @@ -610,7 +611,7 @@ mod tests {
unimplemented!();
}

fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, _peer: MultiaddrWithPeerId) -> Result<(), String> {
unimplemented!();
}

Expand Down
10 changes: 5 additions & 5 deletions client/network/common/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// If you read this, you are very thorough, congratulations.

use crate::{
config::MultiaddrWithPeerId,
protocol::event::Event,
request_responses::{IfDisconnected, RequestFailure},
sync::{warp::WarpSyncProgress, StateDownloadProgress, SyncState},
Expand Down Expand Up @@ -179,12 +180,11 @@ pub trait NetworkPeers {
/// purposes.
fn deny_unreserved_peers(&self);

/// Adds a `PeerId` and its address as reserved. The string should encode the address
/// and peer ID of the remote node.
/// Adds a `PeerId` and its `Multiaddr` as reserved.
///
/// Returns an `Err` if the given string is not a valid multiaddress
/// or contains an invalid peer ID (which includes the local peer ID).
fn add_reserved_peer(&self, peer: String) -> Result<(), String>;
fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>;

/// Removes a `PeerId` from the list of reserved peers.
fn remove_reserved_peer(&self, peer_id: PeerId);
Expand Down Expand Up @@ -285,7 +285,7 @@ where
T::deny_unreserved_peers(self)
}

fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String> {
T::add_reserved_peer(self, peer)
}

Expand Down Expand Up @@ -387,7 +387,7 @@ pub trait NotificationSenderReady {

/// A `NotificationSender` allows for sending notifications to a peer with a chosen protocol.
#[async_trait::async_trait]
pub trait NotificationSender {
pub trait NotificationSender: Send + Sync + 'static {
/// Returns a future that resolves when the `NotificationSender` is ready to send a
/// notification.
async fn ready(&self)
Expand Down
16 changes: 7 additions & 9 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use parking_lot::Mutex;
use sc_client_api::{BlockBackend, ProofProvider};
use sc_consensus::{BlockImportError, BlockImportStatus, ImportQueue, Link};
use sc_network_common::{
config::parse_str_addr,
config::MultiaddrWithPeerId,
protocol::event::{DhtEvent, Event},
request_responses::{IfDisconnected, RequestFailure},
service::{
Expand Down Expand Up @@ -702,9 +702,8 @@ where
self.service.remove_reserved_peer(peer);
}

/// Adds a `PeerId` and its address as reserved. The string should encode the address
/// and peer ID of the remote node.
pub fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
/// Adds a `PeerId` and its `Multiaddr` as reserved.
pub fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String> {
self.service.add_reserved_peer(peer)
}

Expand Down Expand Up @@ -912,17 +911,16 @@ where
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::SetReservedOnly(true));
}

fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
let (peer_id, addr) = parse_str_addr(&peer).map_err(|e| format!("{:?}", e))?;
fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String> {
// Make sure the local peer ID is never added to the PSM.
if peer_id == self.local_peer_id {
if peer.peer_id == self.local_peer_id {
return Err("Local peer ID cannot be added as a reserved peer.".to_string())
}

let _ = self
.to_worker
.unbounded_send(ServiceToWorkerMsg::AddKnownAddress(peer_id, addr));
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::AddReserved(peer_id));
.unbounded_send(ServiceToWorkerMsg::AddKnownAddress(peer.peer_id, peer.multiaddr));
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::AddReserved(peer.peer_id));
Ok(())
}

Expand Down
7 changes: 5 additions & 2 deletions client/offchain/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ mod tests {
use super::*;
use libp2p::PeerId;
use sc_client_db::offchain::LocalStorage;
use sc_network_common::service::{NetworkPeers, NetworkStateInfo};
use sc_network_common::{
config::MultiaddrWithPeerId,
service::{NetworkPeers, NetworkStateInfo},
};
use sc_peerset::ReputationChange;
use sp_core::offchain::{DbExternalities, Externalities};
use std::{borrow::Cow, time::SystemTime};
Expand Down Expand Up @@ -362,7 +365,7 @@ mod tests {
unimplemented!();
}

fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, _peer: MultiaddrWithPeerId) -> Result<(), String> {
unimplemented!();
}

Expand Down
3 changes: 2 additions & 1 deletion client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ mod tests {
use libp2p::{Multiaddr, PeerId};
use sc_block_builder::BlockBuilderProvider as _;
use sc_client_api::Backend as _;
use sc_network_common::config::MultiaddrWithPeerId;
use sc_peerset::ReputationChange;
use sc_transaction_pool::{BasicPool, FullChainApi};
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
Expand Down Expand Up @@ -300,7 +301,7 @@ mod tests {
unimplemented!();
}

fn add_reserved_peer(&self, _peer: String) -> Result<(), String> {
fn add_reserved_peer(&self, _peer: MultiaddrWithPeerId) -> Result<(), String> {
unimplemented!();
}

Expand Down
13 changes: 10 additions & 3 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use jsonrpsee::{core::Error as JsonRpseeError, RpcModule};
use log::{debug, error, warn};
use sc_client_api::{blockchain::HeaderBackend, BlockBackend, BlockchainEvents, ProofProvider};
use sc_network::PeerId;
use sc_network_common::service::NetworkBlock;
use sc_network_common::{config::MultiaddrWithPeerId, service::NetworkBlock};
use sc_rpc_server::WsConfig;
use sc_utils::mpsc::TracingUnboundedReceiver;
use sp_blockchain::HeaderMetadata;
Expand Down Expand Up @@ -230,8 +230,15 @@ async fn build_network_future<
}
}
sc_rpc::system::Request::NetworkAddReservedPeer(peer_addr, sender) => {
let x = network.add_reserved_peer(peer_addr)
.map_err(sc_rpc::system::error::Error::MalformattedPeerArg);
let result = match MultiaddrWithPeerId::try_from(peer_addr) {
Ok(peer) => {
network.add_reserved_peer(peer)
},
Err(err) => {
Err(err.to_string())
},
};
let x = result.map_err(sc_rpc::system::error::Error::MalformattedPeerArg);
let _ = sender.send(x);
}
sc_rpc::system::Request::NetworkRemoveReservedPeer(peer_id, sender) => {
Expand Down
27 changes: 15 additions & 12 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ use parking_lot::Mutex;
use sc_client_api::{Backend, CallExecutor};
use sc_network::{
config::{NetworkConfiguration, TransportConfig},
multiaddr, Multiaddr,
multiaddr,
};
use sc_network_common::{
config::MultiaddrWithPeerId,
service::{NetworkBlock, NetworkPeers, NetworkStateInfo},
};
use sc_network_common::service::{NetworkBlock, NetworkPeers, NetworkStateInfo};
use sc_service::{
client::Client,
config::{BasePath, DatabaseSource, KeystoreConfig},
Expand All @@ -49,8 +52,8 @@ const MAX_WAIT_TIME: Duration = Duration::from_secs(60 * 3);

struct TestNet<G, E, F, U> {
runtime: Runtime,
authority_nodes: Vec<(usize, F, U, Multiaddr)>,
full_nodes: Vec<(usize, F, U, Multiaddr)>,
authority_nodes: Vec<(usize, F, U, MultiaddrWithPeerId)>,
full_nodes: Vec<(usize, F, U, MultiaddrWithPeerId)>,
chain_spec: GenericChainSpec<G, E>,
base_port: u16,
nodes: usize,
Expand Down Expand Up @@ -320,7 +323,7 @@ where

handle.spawn(service.clone().map_err(|_| ()));
let addr =
addr.with(multiaddr::Protocol::P2p((service.network().local_peer_id()).into()));
MultiaddrWithPeerId { multiaddr: addr, peer_id: service.network().local_peer_id() };
self.authority_nodes.push((self.nodes, service, user_data, addr));
self.nodes += 1;
}
Expand All @@ -340,7 +343,7 @@ where

handle.spawn(service.clone().map_err(|_| ()));
let addr =
addr.with(multiaddr::Protocol::P2p((service.network().local_peer_id()).into()));
MultiaddrWithPeerId { multiaddr: addr, peer_id: service.network().local_peer_id() };
self.full_nodes.push((self.nodes, service, user_data, addr));
self.nodes += 1;
}
Expand Down Expand Up @@ -382,7 +385,7 @@ where
for (_, service, _, _) in network.full_nodes.iter().skip(1) {
service
.network()
.add_reserved_peer(first_address.to_string())
.add_reserved_peer(first_address.clone())
.expect("Error adding reserved peer");
}

Expand Down Expand Up @@ -414,7 +417,7 @@ where
if let Some((_, service, _, node_id)) = network.full_nodes.get(i) {
service
.network()
.add_reserved_peer(address.to_string())
.add_reserved_peer(address)
.expect("Error adding reserved peer");
address = node_id.clone();
}
Expand Down Expand Up @@ -479,7 +482,7 @@ pub fn sync<G, E, Fb, F, B, ExF, U>(
for (_, service, _, _) in network.full_nodes.iter().skip(1) {
service
.network()
.add_reserved_peer(first_address.to_string())
.add_reserved_peer(first_address.clone())
.expect("Error adding reserved peer");
}

Expand Down Expand Up @@ -532,13 +535,13 @@ pub fn consensus<G, E, Fb, F>(
for (_, service, _, _) in network.full_nodes.iter() {
service
.network()
.add_reserved_peer(first_address.to_string())
.add_reserved_peer(first_address.clone())
.expect("Error adding reserved peer");
}
for (_, service, _, _) in network.authority_nodes.iter().skip(1) {
service
.network()
.add_reserved_peer(first_address.to_string())
.add_reserved_peer(first_address.clone())
.expect("Error adding reserved peer");
}
network.run_until_all_full(|_index, service| {
Expand All @@ -556,7 +559,7 @@ pub fn consensus<G, E, Fb, F>(
for (_, service, _, _) in network.full_nodes.iter() {
service
.network()
.add_reserved_peer(first_address.to_string())
.add_reserved_peer(first_address.clone())
.expect("Error adding reserved peer");
}

Expand Down
1 change: 1 addition & 0 deletions frame/alliance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ to update the Alliance's rule and make announcements.

#### For Members (All)

- `give_retirement_notice` - Give a retirement notice and start a retirement period required to pass in order to retire.
- `retire` - Retire from the Alliance and release the caller's deposit.

#### For Members (Founders/Fellows)
Expand Down
Loading