Skip to content

Commit

Permalink
substrate -> 2.0.0: compile & tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 7, 2020
1 parent 47433d0 commit 93a0ccb
Show file tree
Hide file tree
Showing 22 changed files with 863 additions and 1,186 deletions.
1,696 changes: 616 additions & 1,080 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ polymesh-runtime-testnet = { path = "pallets/runtime/testnet" }
ed25519-dalek = "1.0.0"
log = "0.4.8"
futures = "0.3.4"
jsonrpc-core = "14.2.0"
jsonrpc-pubsub = "14.2.0"
jsonrpc-core = "15.0.0"
serde_json = '1.0.48'
structopt = "0.3.15"
chrono = "0.4.11"
Expand Down
3 changes: 1 addition & 2 deletions node-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pallet-staking-rpc = { path = "../pallets/staking/rpc" }
pallet-protocol-fee-rpc = { path = "../pallets/protocol-fee/rpc" }
node-rpc = { path = "../rpc" }

jsonrpc-core = "14.2.0"
jsonrpc-pubsub = "14.2.0"
jsonrpc-core = "15.0.0"

codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
sp-blockchain = { git = "https:/paritytech/substrate", tag = "v2.0.0" }
Expand Down
25 changes: 16 additions & 9 deletions node-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use polymesh_primitives::{
};
use sc_client_api::light::{Fetcher, RemoteBlockchain};
use sc_consensus_babe::Epoch;
use sc_rpc::DenyUnsafe;
use sc_finality_grandpa::FinalityProofProvider;
use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
Expand Down Expand Up @@ -72,19 +73,21 @@ pub struct BabeDeps {
}

/// Dependencies for GRANDPA
pub struct GrandpaDeps {
pub struct GrandpaDeps<B> {
/// Voting round info.
pub shared_voter_state: sc_finality_grandpa::SharedVoterState,
/// Authority set info.
pub shared_authority_set: sc_finality_grandpa::SharedAuthoritySet<Hash, BlockNumber>,
/// Receives notifications about justification events from Grandpa.
pub justification_stream: sc_finality_grandpa::GrandpaJustificationStream<Block>,
/// Subscription manager to keep track of pubsub subscribers.
pub subscriptions: jsonrpc_pubsub::manager::SubscriptionManager,
/// Executor to drive the subscription manager in the Grandpa RPC handler.
pub subscription_executor: SubscriptionTaskExecutor,
/// Finality proof provider.
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
}

/// Full client dependencies
pub struct FullDeps<C, P, SC> {
pub struct FullDeps<C, P, SC, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -96,11 +99,11 @@ pub struct FullDeps<C, P, SC> {
/// BABE specific dependencies.
pub babe: BabeDeps,
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps,
pub grandpa: GrandpaDeps<B>,
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, UE, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension
pub fn create_full<C, P, UE, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
Expand Down Expand Up @@ -129,6 +132,8 @@ where
P: TransactionPool + Sync + Send + 'static,
UE: codec::Codec + Send + Sync + 'static,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use frame_rpc_system::{FullSystem, SystemApi};
use node_rpc::compliance_manager::{ComplianceManager, ComplianceManagerApi};
Expand Down Expand Up @@ -163,7 +168,8 @@ where
shared_voter_state,
shared_authority_set,
justification_stream,
subscriptions,
subscription_executor,
finality_provider,
} = grandpa;

io.extend_with(SystemApi::to_delegate(FullSystem::new(
Expand All @@ -189,7 +195,8 @@ where
shared_authority_set,
shared_voter_state,
justification_stream,
subscriptions,
subscription_executor,
finality_provider,
)));
io.extend_with(StakingApi::to_delegate(Staking::new(client.clone())));
io.extend_with(PipsApi::to_delegate(Pips::new(client.clone())));
Expand Down
10 changes: 10 additions & 0 deletions pallets/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
pub mod benchmarking;

use codec::{Decode, Encode};
use frame_support::traits::Get;
use frame_support::{
decl_error, decl_module, decl_storage, ensure,
traits::{
Expand Down Expand Up @@ -537,6 +538,13 @@ impl<T: Trait> Module<T> {

/// Update the account entry for `who`, given the locks.
fn update_locks(who: &T::AccountId, locks: &[BalanceLock<T::Balance>]) {
if locks.len() as u32 > T::MaxLocks::get() {
frame_support::debug::warn!(
"Warning: A user has more currency locks than expected. \
A runtime configuration adjustment may be needed."
);
}

Self::mutate_account(who, |b| {
b.misc_frozen = Zero::zero();
b.fee_frozen = Zero::zero();
Expand Down Expand Up @@ -1114,6 +1122,8 @@ where
{
type Moment = T::BlockNumber;

type MaxLocks = T::MaxLocks;

// Polymesh-note: The implementations below differ from substrate in terms
// of performance (ours uses in-place modification), but are functionally equivalent.

Expand Down
12 changes: 8 additions & 4 deletions pallets/common/src/traits/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ decl_event!(
<T as system::Trait>::AccountId,
<T as CommonTrait>::Balance
{
/// An account was created with some free balance. [did, account, free_balance]
/// An account was created with some free balance. \[did, account, free_balance]
Endowed(Option<IdentityId>, AccountId, Balance),
/// Transfer succeeded (from_did, from, to_did, to, value, memo).
Transfer(Option<IdentityId>, AccountId, Option<IdentityId>, AccountId, Balance, Option<Memo>),
Expand All @@ -125,13 +125,13 @@ decl_event!(
/// The account and the amount of unlocked balance of that account that was burned.
/// (caller Id, caller account, amount)
AccountBalanceBurned(IdentityId, AccountId, Balance),
/// Some balance was reserved (moved from free to reserved). [who, value]
/// Some balance was reserved (moved from free to reserved). \[who, value]
Reserved(AccountId, Balance),
/// Some balance was unreserved (moved from reserved to free). [who, value]
/// Some balance was unreserved (moved from reserved to free). \[who, value]
Unreserved(AccountId, Balance),
/// Some balance was moved from the reserve of the first account to the second account.
/// Final argument indicates the destination balance type.
/// [from, to, balance, destination_status]
/// \[from, to, balance, destination_status]
ReserveRepatriated(AccountId, AccountId, Balance, Status),
}
);
Expand Down Expand Up @@ -200,6 +200,10 @@ pub trait Trait: CommonTrait {

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

/// The maximum number of locks that should exist on an account.
/// Not strictly enforced, but used for weight estimation.
type MaxLocks: Get<u32>;
}

pub trait BalancesTrait<A, B, NI> {
Expand Down
2 changes: 1 addition & 1 deletion pallets/confidential/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sp-runtime-interface = { git = "https:/paritytech/substrate", defaul
# Crypto
rand_core = { version = "0.5", default-features = false }
rand = { version = "0.7.3", default-features = false, optional = true }
cryptography = { git = "https:/PolymathNetwork/cryptography.git", branch = "develop", default-features = false }
cryptography = { git = "https:/PolymathNetwork/cryptography.git", branch = "substrate-2", default-features = false }
curve25519-dalek = { version = "2", default-features = false, features = ["nightly"] }
bulletproofs = { git = "https:/PolymathNetwork/bulletproofs.git", branch = "main", default-features = false, features = ["zeroize"] }

Expand Down
16 changes: 8 additions & 8 deletions pallets/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ edition = "2018"
# Substrate specific
serde = { version = "1.0.104", default-features = false }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
frame-system = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
frame-support = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
pallet-contracts = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
sp-core = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
sp-io = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
sp-runtime = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
sp-std = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0-rc6" }
frame-system = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
frame-support = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
pallet-contracts = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-core = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-io = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-runtime = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-std = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }

# Polymesh specific
pallet-identity = { path = "../identity", default-features = false }
Expand All @@ -40,4 +40,4 @@ std = [
"polymesh-primitives/std",
"pallet-protocol-fee/std",
"polymesh-common-utilities/std",
]
]
6 changes: 3 additions & 3 deletions pallets/group/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pallet-group-rpc-runtime-api = { version = "2.0.0", path = "./runtime-api" }
serde = { version = "1.0.104", features = ["derive"] }

# Json RPC
jsonrpc-core = "14.0.5"
jsonrpc-core-client = "14.0.5"
jsonrpc-derive = "14.0.5"
jsonrpc-core = "15.0.0"
jsonrpc-core-client = "15.0.0"
jsonrpc-derive = "15.0.0"

# Substrate
codec = { package = "parity-scale-codec", version = "1.2.0" }
Expand Down
1 change: 1 addition & 0 deletions pallets/permissions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde = { version = "1.0.104", default-features = false }

# Substrate
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = ["derive"] }
frame-system = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
frame-support = { git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-runtime = { package = "sp-runtime", git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
sp-std = { package = "sp-std", git = "https:/paritytech/substrate", default-features = false, tag = "v2.0.0" }
Expand Down
8 changes: 4 additions & 4 deletions pallets/protocol-fee/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition = "2018"
polymesh-common-utilities = { path = "../../common", default-features = false }
pallet-protocol-fee-rpc-runtime-api = { path = "./runtime-api" }

# General
# General
serde = { version = "1.0.104", features = ["derive"] }
jsonrpc-core = "14.0.5"
jsonrpc-core-client = "14.0.5"
jsonrpc-derive = "14.0.5"
jsonrpc-core = "15.0.0"
jsonrpc-core-client = "15.0.0"
jsonrpc-derive = "15.0.0"

# Substrate
codec = { package = "parity-scale-codec", version = "1.2.0" }
Expand Down
7 changes: 5 additions & 2 deletions pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl frame_system::Trait for Runtime {
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type ModuleToIndex = ModuleToIndex;
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
Expand All @@ -196,6 +196,7 @@ parameter_types! {
}

impl pallet_babe::Trait for Runtime {
type WeightInfo = ();
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
Expand Down Expand Up @@ -230,6 +231,7 @@ impl pallet_indices::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: Balance = 0u128;
pub const MaxLocks: u32 = 50;
}

/// Splits fees 80/20 between treasury and block author.
Expand Down Expand Up @@ -278,6 +280,7 @@ impl CommonTrait for Runtime {
}

impl balances::Trait for Runtime {
type MaxLocks = MaxLocks;
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
Expand Down Expand Up @@ -583,7 +586,6 @@ impl pallet_offences::Trait for Runtime {
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -603,6 +605,7 @@ impl pallet_im_online::Trait for Runtime {
}

impl pallet_grandpa::Trait for Runtime {
type WeightInfo = ();
type Event = Event;
type Call = Call;

Expand Down
7 changes: 5 additions & 2 deletions pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl frame_system::Trait for Runtime {
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type ModuleToIndex = ModuleToIndex;
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
Expand All @@ -195,6 +195,7 @@ parameter_types! {
}

impl pallet_babe::Trait for Runtime {
type WeightInfo = ();
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
Expand Down Expand Up @@ -229,6 +230,7 @@ impl pallet_indices::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: Balance = 0u128;
pub const MaxLocks: u32 = 50;
}

/// Splits fees 80/20 between treasury and block author.
Expand Down Expand Up @@ -277,6 +279,7 @@ impl pallet_transaction_payment::Trait for Runtime {
}

impl balances::Trait for Runtime {
type MaxLocks = MaxLocks;
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
Expand Down Expand Up @@ -582,7 +585,6 @@ impl pallet_offences::Trait for Runtime {
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
type WeightInfo = ();
}

parameter_types! {
Expand All @@ -602,6 +604,7 @@ impl pallet_im_online::Trait for Runtime {
}

impl pallet_grandpa::Trait for Runtime {
type WeightInfo = ();
type Event = Event;
type Call = Call;

Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ polymesh-contracts = { path = "../../contracts", default-features = false }
pallet-group-rpc-runtime-api = { path = "../../group/rpc/runtime-api", default-features = false }

# Crypto
cryptography = { git = "https:/PolymathNetwork/cryptography.git", branch = "develop", default-features = false }
cryptography = { git = "https:/PolymathNetwork/cryptography.git", branch = "substrate-2", default-features = false }

# Runtime
polymesh-runtime-develop = { path = "../develop" }
Expand Down
5 changes: 4 additions & 1 deletion pallets/runtime/tests/src/staking/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ parameter_types! {
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const MaxLocks: u32 = 50;
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
Expand All @@ -259,7 +260,7 @@ impl frame_system::Trait for Test {
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type ModuleToIndex = ();
type PalletInfo = ();
type AccountData = AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
Expand All @@ -280,6 +281,7 @@ impl balances::Trait for Test {
type Identity = identity::Module<Test>;
type CddChecker = Test;
type WeightInfo = ();
type MaxLocks = MaxLocks;
}

parameter_types! {
Expand Down Expand Up @@ -514,6 +516,7 @@ impl From<pallet_babe::Call<Test>> for Call {
}

impl pallet_babe::Trait for Test {
type WeightInfo = ();
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
Expand Down
Loading

0 comments on commit 93a0ccb

Please sign in to comment.