Rework default values used by the RelayChainCli (#189)

This reworks the default values used by the RelayChainCli for stuff like
the listen port etc.

This also renames all the contracts related stuff to `cumulus-*` to
support `.cargo/config` overrides.
This commit is contained in:
Bastian Köcher
2020-08-10 09:53:07 +02:00
committed by GitHub
parent 2efe482c40
commit 3ed6030110
13 changed files with 265 additions and 325 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ sc-informant = { git = "https://github.com/paritytech/substrate", branch = "roco
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
# RPC related dependencies
pallet-contracts-rpc = { path = "./pallets/contracts/rpc" }
cumulus-pallet-contracts-rpc = { path = "./pallets/contracts/rpc" }
jsonrpc-core = "14.2.0"
# Cumulus dependencies
@@ -34,9 +34,9 @@ pallet-sudo = { git = "https://github.com/paritytech/substrate", default-feature
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
# In-Tree Fork of seal that does not use child trie nor storage transactions
pallet-contracts = { path = "../pallets/contracts", default-features = false }
pallet-contracts-primitives = { path = "../pallets/contracts/common", default-features = false }
pallet-contracts-rpc-runtime-api = { path = "../pallets/contracts/rpc/runtime-api", default-features = false }
cumulus-pallet-contracts = { path = "../pallets/contracts", default-features = false }
cumulus-pallet-contracts-primitives = { path = "../pallets/contracts/common", default-features = false }
cumulus-pallet-contracts-rpc-runtime-api = { path = "../pallets/contracts/rpc/runtime-api", default-features = false }
# Cumulus dependencies
cumulus-runtime = { path = "../../runtime", default-features = false }
@@ -71,9 +71,9 @@ std = [
"frame-executive/std",
"frame-system/std",
"pallet-balances/std",
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-contracts-rpc-runtime-api/std",
"cumulus-pallet-contracts/std",
"cumulus-pallet-contracts-primitives/std",
"cumulus-pallet-contracts-rpc-runtime-api/std",
"pallet-randomness-collective-flip/std",
"pallet-timestamp/std",
"pallet-sudo/std",
@@ -22,7 +22,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use cumulus_pallet_contracts_rpc_runtime_api::ContractExecResult;
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_runtime::{
@@ -269,23 +269,23 @@ parameter_types! {
pub const SurchargeReward: Balance = 0;
}
impl pallet_contracts::Trait for Runtime {
impl cumulus_pallet_contracts::Trait for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Currency = Balances;
type Call = Call;
type Event = Event;
type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;
type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;
type DetermineContractAddress = cumulus_pallet_contracts::SimpleAddressDeterminer<Runtime>;
type TrieIdGenerator = cumulus_pallet_contracts::TrieIdFromParentCounter<Runtime>;
type RentPayment = ();
type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;
type SignedClaimHandicap = cumulus_pallet_contracts::DefaultSignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;
type StorageSizeOffset = cumulus_pallet_contracts::DefaultStorageSizeOffset;
type RentByteFee = RentByteFee;
type RentDepositOffset = RentDepositOffset;
type SurchargeReward = SurchargeReward;
type MaxDepth = pallet_contracts::DefaultMaxDepth;
type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
type MaxDepth = cumulus_pallet_contracts::DefaultMaxDepth;
type MaxValueSize = cumulus_pallet_contracts::DefaultMaxValueSize;
type WeightPrice = pallet_transaction_payment::Module<Self>;
}
@@ -298,7 +298,7 @@ construct_runtime! {
System: frame_system::{Module, Call, Storage, Config, Event<T>},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},
Contracts: cumulus_pallet_contracts::{Module, Call, Config, Storage, Event<T>},
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
@@ -413,7 +413,7 @@ impl_runtime_apis! {
}
}
impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>
impl cumulus_pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>
for Runtime
{
fn call(
@@ -438,13 +438,13 @@ impl_runtime_apis! {
fn get_storage(
address: AccountId,
key: [u8; 32],
) -> pallet_contracts_primitives::GetStorageResult {
) -> cumulus_pallet_contracts_primitives::GetStorageResult {
Contracts::get_storage(address, key)
}
fn rent_projection(
address: AccountId,
) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
) -> cumulus_pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
Contracts::rent_projection(address)
}
}
@@ -1,5 +1,5 @@
[package]
name = "pallet-contracts"
name = "cumulus-pallet-contracts"
version = "2.0.0-rc3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -24,7 +24,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f
sp-sandbox = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
pallet-contracts-primitives = { path = "./common", default-features = false }
cumulus-pallet-contracts-primitives = { path = "./common", default-features = false }
[dev-dependencies]
wabt = "0.10"
@@ -49,5 +49,5 @@ std = [
"parity-wasm/std",
"pwasm-utils/std",
"wasmi-validation/std",
"pallet-contracts-primitives/std",
"cumulus-pallet-contracts-primitives/std",
]
@@ -1,5 +1,5 @@
[package]
name = "pallet-contracts-primitives"
name = "cumulus-pallet-contracts-primitives"
version = "2.0.0-rc3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -1,5 +1,5 @@
[package]
name = "pallet-contracts-rpc"
name = "cumulus-pallet-contracts-rpc"
version = "0.8.0-rc3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -22,8 +22,8 @@ sp-rpc = { git = "https://github.com/paritytech/substrate", default-features = f
serde = { version = "1.0.101", features = ["derive"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
pallet-contracts-primitives = { path = "../common" }
pallet-contracts-rpc-runtime-api = { path = "./runtime-api" }
cumulus-pallet-contracts-primitives = { path = "../common" }
cumulus-pallet-contracts-rpc-runtime-api = { path = "./runtime-api" }
[dev-dependencies]
serde_json = "1.0.41"
@@ -1,5 +1,5 @@
[package]
name = "pallet-contracts-rpc-runtime-api"
name = "cumulus-pallet-contracts-rpc-runtime-api"
version = "0.8.0-rc3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -16,7 +16,7 @@ sp-api = { git = "https://github.com/paritytech/substrate", default-features = f
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
pallet-contracts-primitives = { path = "../../common", default-features = false }
cumulus-pallet-contracts-primitives = { path = "../../common", default-features = false }
[features]
default = ["std"]
@@ -25,5 +25,5 @@ std = [
"codec/std",
"sp-std/std",
"sp-runtime/std",
"pallet-contracts-primitives/std",
"cumulus-pallet-contracts-primitives/std",
]
@@ -24,7 +24,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Codec, Decode, Encode};
use pallet_contracts_primitives::{GetStorageResult, RentProjectionResult};
use cumulus_pallet_contracts_primitives::{GetStorageResult, RentProjectionResult};
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;
@@ -22,7 +22,7 @@ use std::sync::Arc;
use codec::Codec;
use jsonrpc_core::{Error, ErrorCode, Result};
use jsonrpc_derive::rpc;
use pallet_contracts_primitives::RentProjection;
use cumulus_pallet_contracts_primitives::RentProjection;
use serde::{Deserialize, Serialize};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
@@ -35,7 +35,7 @@ use sp_runtime::{
use std::convert::TryInto;
pub use self::gen_client::Client as ContractsClient;
pub use pallet_contracts_rpc_runtime_api::{
pub use cumulus_pallet_contracts_rpc_runtime_api::{
self as runtime_api, ContractExecResult, ContractsApi as ContractsRuntimeApi,
};
@@ -54,10 +54,10 @@ const CONTRACT_IS_A_TOMBSTONE: i64 = 3;
const GAS_PER_SECOND: u64 = 1_000_000_000_000;
/// A private newtype for converting `ContractAccessError` into an RPC error.
struct ContractAccessError(pallet_contracts_primitives::ContractAccessError);
struct ContractAccessError(cumulus_pallet_contracts_primitives::ContractAccessError);
impl From<ContractAccessError> for Error {
fn from(e: ContractAccessError) -> Error {
use pallet_contracts_primitives::ContractAccessError::*;
use cumulus_pallet_contracts_primitives::ContractAccessError::*;
match e.0 {
DoesntExist => Error {
code: ErrorCode::ServerError(CONTRACT_DOESNT_EXIST),
@@ -118,7 +118,7 @@ use frame_support::{
use frame_support::traits::{OnUnbalanced, Currency, Get, Time, Randomness};
use frame_support::weights::GetDispatchInfo;
use frame_system::{ensure_signed, RawOrigin, ensure_root};
use pallet_contracts_primitives::{RentProjection, ContractAccessError};
use cumulus_pallet_contracts_primitives::{RentProjection, ContractAccessError};
use frame_support::weights::Weight;
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
@@ -23,7 +23,7 @@ use crate::{
use frame_support::storage::unhashed as storage;
use frame_support::traits::{Currency, ExistenceRequirement, Get, OnUnbalanced, WithdrawReason};
use frame_support::StorageMap;
use pallet_contracts_primitives::{ContractAccessError, RentProjection, RentProjectionResult};
use cumulus_pallet_contracts_primitives::{ContractAccessError, RentProjection, RentProjectionResult};
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul, SaturatedConversion, Saturating, Zero};
/// The amount to charge.
+27 -87
View File
@@ -24,8 +24,8 @@ use log::info;
use parachain_runtime::Block;
use polkadot_parachain::primitives::AccountIdConversion;
use sc_cli::{
ChainSpec, CliConfiguration, Error, ImportParams, KeystoreParams, NetworkParams, Result,
RuntimeVersion, SharedParams, SubstrateCli,
ChainSpec, CliConfiguration, ImportParams, KeystoreParams, NetworkParams, Result,
RuntimeVersion, SharedParams, SubstrateCli, DefaultConfigurationValues,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
@@ -269,7 +269,25 @@ pub fn run() -> Result<()> {
}
}
impl CliConfiguration for RelayChainCli {
impl DefaultConfigurationValues for RelayChainCli {
fn p2p_listen_port() -> u16 {
30334
}
fn rpc_ws_listen_port() -> u16 {
9945
}
fn rpc_http_listen_port() -> u16 {
9934
}
fn prometheus_listen_port() -> u16 {
9616
}
}
impl CliConfiguration<Self> for RelayChainCli {
fn shared_params(&self) -> &SharedParams {
self.base.base.shared_params()
}
@@ -293,59 +311,20 @@ impl CliConfiguration for RelayChainCli {
.or_else(|| self.base_path.clone().map(Into::into)))
}
fn rpc_http(&self) -> Result<Option<SocketAddr>> {
let rpc_external = self.base.base.rpc_external;
let unsafe_rpc_external = self.base.base.unsafe_rpc_external;
let validator = self.base.base.validator;
let rpc_port = self.base.base.rpc_port;
// copied directly from substrate
let rpc_interface: &str = interface_str(rpc_external, unsafe_rpc_external, validator)?;
Ok(Some(parse_address(
&format!("{}:{}", rpc_interface, 9934),
rpc_port,
)?))
fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {
self.base.base.rpc_http(default_listen_port)
}
fn rpc_ipc(&self) -> Result<Option<String>> {
self.base.base.rpc_ipc()
}
fn rpc_ws(&self) -> Result<Option<SocketAddr>> {
let ws_external = self.base.base.ws_external;
let unsafe_ws_external = self.base.base.unsafe_ws_external;
let validator = self.base.base.validator;
let ws_port = self.base.base.ws_port;
// copied directly from substrate
let ws_interface: &str = interface_str(ws_external, unsafe_ws_external, validator)?;
Ok(Some(parse_address(
&format!("{}:{}", ws_interface, 9945),
ws_port,
)?))
fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {
self.base.base.rpc_ws(default_listen_port)
}
fn prometheus_config(&self) -> Result<Option<PrometheusConfig>> {
let no_prometheus = self.base.base.no_prometheus;
let prometheus_external = self.base.base.prometheus_external;
let prometheus_port = self.base.base.prometheus_port;
if no_prometheus {
Ok(None)
} else {
let prometheus_interface: &str = if prometheus_external {
"0.0.0.0"
} else {
"127.0.0.1"
};
Ok(Some(PrometheusConfig::new_with_default_registry(
parse_address(
&format!("{}:{}", prometheus_interface, 9616),
prometheus_port,
)?,
)))
}
fn prometheus_config(&self, default_listen_port: u16) -> Result<Option<PrometheusConfig>> {
self.base.base.prometheus_config(default_listen_port)
}
fn init<C: SubstrateCli>(&self) -> Result<()> {
@@ -410,42 +389,3 @@ impl CliConfiguration for RelayChainCli {
self.base.base.announce_block()
}
}
// copied directly from substrate
fn parse_address(address: &str, port: Option<u16>) -> std::result::Result<SocketAddr, String> {
let mut address: SocketAddr = address
.parse()
.map_err(|_| format!("Invalid address: {}", address))?;
if let Some(port) = port {
address.set_port(port);
}
Ok(address)
}
// copied directly from substrate
fn interface_str(
is_external: bool,
is_unsafe_external: bool,
is_validator: bool,
) -> Result<&'static str> {
if is_external && is_validator {
return Err(Error::Input(
"--rpc-external and --ws-external options shouldn't be \
used if the node is running as a validator. Use `--unsafe-rpc-external` if you understand \
the risks. See the options description for more information."
.to_owned(),
));
}
if is_external || is_unsafe_external {
log::warn!(
"It isn't safe to expose RPC publicly without a proxy server that filters \
available set of RPC methods."
);
Ok("0.0.0.0")
} else {
Ok("127.0.0.1")
}
}