Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update substrate to 0444ab7b4af
  • Loading branch information
kvinwang committed Dec 29, 2021
commit f6db27a0042e711eb0d9f858970b03a144e3597b
1,774 changes: 1,154 additions & 620 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions crates/phaxt/src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;

use subxt::extrinsic::*;
use subxt::Config;
use subxt::sp_runtime::generic::Era;
use subxt::sp_runtime::traits::SignedExtension;
use subxt::sp_runtime::transaction_validity::TransactionValidityError;
use subxt::Config;

#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)]
pub struct EraInfo<Hash> {
Expand Down Expand Up @@ -43,7 +43,7 @@ impl<T: Config + Clone + Debug + Eq + Send + Sync + TypeInfo + 'static> SignedEx
CheckNonce<T>,
CheckWeight<T>,
// NOTE: skipped the ZST CheckMqSequence<T> here.
ChargeTransactionPayment,
ChargeAssetTxPayment,
);
type Parameters = ExtraConfig<T::Hash>;

Expand Down Expand Up @@ -81,7 +81,10 @@ impl<T: Config + Clone + Debug + Eq + Send + Sync + TypeInfo + 'static> SignedEx
CheckNonce(self.nonce),
CheckWeight(PhantomData),
// NOTE: skipped the ZST CheckMqSequence<T> here.
ChargeTransactionPayment(self.additional_params.tip.into()),
ChargeAssetTxPayment {
tip: self.additional_params.tip.into(),
asset_id: None,
},
)
}
}
Expand All @@ -98,4 +101,14 @@ impl<T: Config + Clone + Debug + Eq + Send + Sync + TypeInfo + 'static> SignedEx
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
self.extra().additional_signed()
}

fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &subxt::sp_runtime::traits::DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}
7 changes: 5 additions & 2 deletions crates/pink/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pallet_contracts_primitives::StorageDeposit;
use scale::{Decode, Encode};
use sp_core::Hasher as _;
use sp_runtime::DispatchError;
Expand All @@ -8,7 +9,7 @@ use crate::{
types::{AccountId, BlockNumber, Hashing, ENOUGH, GAS_LIMIT},
};

use pallet_contracts_primitives::ContractExecResult;
type ContractExecResult = pallet_contracts_primitives::ContractExecResult<crate::types::Balance>;

pub type Storage = storage::Storage<storage::InMemoryBackend>;

Expand Down Expand Up @@ -75,6 +76,7 @@ impl Contract {
origin.clone(),
ENOUGH,
GAS_LIMIT,
None,
pallet_contracts_primitives::Code::Upload(code.into()),
input_data,
salt.clone(),
Expand Down Expand Up @@ -132,6 +134,7 @@ impl Contract {
gas_required: 0,
debug_message: b"Default account is not allowed to call contracts".to_vec(),
result: Err(DispatchError::BadOrigin),
storage_deposit: StorageDeposit::Charge(0),
},
ExecSideEffects::default(),
);
Expand All @@ -152,7 +155,7 @@ impl Contract {
storage.execute_with(rollback, move || {
System::set_block_number(block_number);
Timestamp::set_timestamp(now);
Contracts::bare_call(origin, addr, 0, GAS_LIMIT, input_data, true)
Contracts::bare_call(origin, addr, 0, GAS_LIMIT, None, input_data, true)
})
}

Expand Down
14 changes: 10 additions & 4 deletions crates/pink/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ mod extension;
mod mock_types;

use crate::types::{AccountId, Balance, BlockNumber, Hash, Hashing, Index};
use frame_support::weights::Weight;
use frame_support::{parameter_types, weights::constants::WEIGHT_PER_SECOND};
use pallet_contracts::{Config, Frame, Schedule};
use frame_support::{
parameter_types,
traits::ConstU128,
weights::{constants::WEIGHT_PER_SECOND, Weight},
};
use pallet_contracts::{Config, Frame, Schedule, DefaultAddressGenerator};
use sp_runtime::{
generic::Header,
traits::{Convert, IdentityLookup},
Expand Down Expand Up @@ -61,6 +64,7 @@ impl frame_system::Config for PinkRuntime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_randomness_collective_flip::Config for PinkRuntime {}
Expand Down Expand Up @@ -112,7 +116,9 @@ impl Config for PinkRuntime {
type DeletionQueueDepth = DeletionQueueDepth;
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = DefaultSchedule;
type ContractDeposit = ();
type DepositPerByte = ConstU128<0>;
type DepositPerItem = ConstU128<0>;
type AddressGenerator = DefaultAddressGenerator;
}

#[cfg(test)]
Expand Down
60 changes: 43 additions & 17 deletions crates/pink/src/runtime/mock_types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

use super::Balance;
use frame_support::traits;
use frame_support::{traits::{self, BalanceStatus}, dispatch::DispatchResult};

use call_trace::{trace_with, CallContext, Trace};
use sp_runtime::AccountId32;
use sp_runtime::DispatchError;


const ENOUGH: Balance = Balance::MAX / 2;
Expand Down Expand Up @@ -71,19 +71,19 @@ impl traits::Imbalance<Balance> for NoImbalance {

pub struct NoCurrency;

impl traits::Currency<AccountId32> for NoCurrency {
impl<AccountId> traits::Currency<AccountId> for NoCurrency {
type Balance = Balance;

type PositiveImbalance = NoImbalance;
type NegativeImbalance = NoImbalance;

#[trace_with(Null)]
fn total_balance(_who: &AccountId32) -> Self::Balance {
fn total_balance(_who: &AccountId) -> Self::Balance {
ENOUGH
}

#[trace_with(Null)]
fn can_slash(_who: &AccountId32, _value: Self::Balance) -> bool {
fn can_slash(_who: &AccountId, _value: Self::Balance) -> bool {
false
}

Expand All @@ -108,13 +108,13 @@ impl traits::Currency<AccountId32> for NoCurrency {
}

#[trace_with(Null)]
fn free_balance(_who: &AccountId32) -> Self::Balance {
fn free_balance(_who: &AccountId) -> Self::Balance {
ENOUGH
}

#[trace_with(Null)]
fn ensure_can_withdraw(
_who: &AccountId32,
_who: &AccountId,
_amount: Self::Balance,
_reasons: frame_support::traits::WithdrawReasons,
_new_balance: Self::Balance,
Expand All @@ -124,8 +124,8 @@ impl traits::Currency<AccountId32> for NoCurrency {

#[trace_with(Null)]
fn transfer(
_source: &AccountId32,
_dest: &AccountId32,
_source: &AccountId,
_dest: &AccountId,
_value: Self::Balance,
_existence_requirement: frame_support::traits::ExistenceRequirement,
) -> frame_support::dispatch::DispatchResult {
Expand All @@ -134,28 +134,28 @@ impl traits::Currency<AccountId32> for NoCurrency {

#[trace_with(Null)]
fn slash(
_who: &AccountId32,
_who: &AccountId,
_value: Self::Balance,
) -> (Self::NegativeImbalance, Self::Balance) {
(traits::Imbalance::zero(), 0)
}

#[trace_with(Null)]
fn deposit_into_existing(
_who: &AccountId32,
_who: &AccountId,
_value: Self::Balance,
) -> Result<Self::PositiveImbalance, sp_runtime::DispatchError> {
Ok(traits::Imbalance::zero())
}

#[trace_with(Null)]
fn deposit_creating(_who: &AccountId32, _value: Self::Balance) -> Self::PositiveImbalance {
fn deposit_creating(_who: &AccountId, _value: Self::Balance) -> Self::PositiveImbalance {
traits::Imbalance::zero()
}

#[trace_with(Null)]
fn withdraw(
_who: &AccountId32,
_who: &AccountId,
_value: Self::Balance,
_reasons: frame_support::traits::WithdrawReasons,
_liveness: frame_support::traits::ExistenceRequirement,
Expand All @@ -165,18 +165,44 @@ impl traits::Currency<AccountId32> for NoCurrency {

#[trace_with(Null)]
fn make_free_balance_be(
_who: &AccountId32,
_who: &AccountId,
_balance: Self::Balance,
) -> frame_support::traits::SignedImbalance<Self::Balance, Self::PositiveImbalance> {
frame_support::traits::SignedImbalance::zero()
}
}

impl<AccountId> traits::ReservableCurrency<AccountId> for NoCurrency {
fn can_reserve(_: &AccountId, _: Self::Balance) -> bool {
true
}
fn slash_reserved(_: &AccountId, _: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) {
(Default::default(), 0)
}
fn reserved_balance(_: &AccountId) -> Self::Balance {
0
}
fn reserve(_: &AccountId, _: Self::Balance) -> DispatchResult {
Ok(())
}
fn unreserve(_: &AccountId, _: Self::Balance) -> Self::Balance {
0
}
fn repatriate_reserved(
_: &AccountId,
_: &AccountId,
_: Self::Balance,
_: BalanceStatus,
) -> Result<Self::Balance, DispatchError> {
Ok(0)
}
}


pub struct NoAccountStore;

impl traits::StoredMap<AccountId32, pallet_balances::AccountData<Balance>> for NoAccountStore {
fn get(_: &AccountId32) -> pallet_balances::AccountData<Balance> {
impl<AccountId> traits::StoredMap<AccountId, pallet_balances::AccountData<Balance>> for NoAccountStore {
fn get(_: &AccountId) -> pallet_balances::AccountData<Balance> {
pallet_balances::AccountData {
free: ENOUGH,
reserved: ENOUGH,
Expand All @@ -186,7 +212,7 @@ impl traits::StoredMap<AccountId32, pallet_balances::AccountData<Balance>> for N
}

fn try_mutate_exists<R, E: From<sp_runtime::DispatchError>>(
_k: &AccountId32,
_k: &AccountId,
f: impl FnOnce(&mut Option<pallet_balances::AccountData<Balance>>) -> Result<R, E>,
) -> Result<R, E> {
f(&mut None)
Expand Down
3 changes: 2 additions & 1 deletion crates/pink/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ where
)
});

self.backend.full_storage_root(delta, child_delta)
self.backend
.full_storage_root(delta, child_delta)
}

pub fn commit_transaction(&mut self, root: Hash, transaction: Backend::Transaction) {
Expand Down
2 changes: 1 addition & 1 deletion pallets/phala/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ pub mod pallet {
type Config = T;
}

#[derive(Encode, Decode, TypeInfo, Default, Debug, Clone)]
#[derive(Encode, Decode, TypeInfo, Debug, Clone)]
pub struct WorkerInfo<AccountId> {
// identity
pubkey: WorkerPublicKey,
Expand Down
11 changes: 5 additions & 6 deletions pallets/phala/src/stakepool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,17 +1114,17 @@ pub mod pallet {

fn pool_sub_account<T>(pid: u64, pubkey: &WorkerPublicKey) -> T
where
T: Encode + Decode + Default,
T: Encode + Decode,
{
let hash = crate::hashing::blake2_256(&(pid, pubkey).encode());
// stake pool miner
(b"spm/", hash)
.using_encoded(|b| T::decode(&mut TrailingZeroInput::new(b)))
.unwrap_or_default()
.expect("Decoding zero-padded account id should always succeed; qed")
}

#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, Default, RuntimeDebug)]
pub struct PoolInfo<AccountId: Default, Balance> {
pub struct PoolInfo<AccountId, Balance> {
/// Pool ID
pub pid: u64,
/// The owner of the pool
Expand Down Expand Up @@ -1153,7 +1153,6 @@ pub mod pallet {

impl<AccountId, Balance> PoolInfo<AccountId, Balance>
where
AccountId: Default,
Balance: sp_runtime::traits::AtLeast32BitUnsigned + Copy + FixedPointConvert + Display,
{
/// Adds some stake to a user.
Expand Down Expand Up @@ -1398,7 +1397,7 @@ pub mod pallet {
}

#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug)]
pub struct UserStakeInfo<AccountId: Default, Balance> {
pub struct UserStakeInfo<AccountId, Balance> {
/// User account
pub user: AccountId,
/// The actual locked stake
Expand All @@ -1415,7 +1414,7 @@ pub mod pallet {
}

#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug)]
pub struct WithdrawInfo<AccountId: Default, Balance> {
pub struct WithdrawInfo<AccountId, Balance> {
/// The withdrawal requester
pub user: AccountId,
/// The shares to withdraw. Cannot be dust.
Expand Down
2 changes: 1 addition & 1 deletion pallets/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,6 @@ impl<T: Config> Pallet<T> {
/// Derive a derivative account ID from the owner account and the sub-account index.
pub fn derivative_account_id(who: T::AccountId, index: u16) -> T::AccountId {
let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256);
T::AccountId::decode(&mut &entropy[..]).unwrap_or_default()
T::AccountId::decode(&mut &entropy[..]).expect("Should always be able to decode the derived account ID.")
}
}
1 change: 1 addition & 0 deletions pallets/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<2>;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
Expand Down
4 changes: 3 additions & 1 deletion standalone/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub fn testnet_genesis(
},
technical_membership: Default::default(),
sudo: SudoConfig {
key: root_key,
key: Some(root_key),
},
babe: BabeConfig {
authorities: vec![],
Expand All @@ -387,6 +387,8 @@ pub fn testnet_genesis(
vesting: Default::default(),
phala_registry,
phala_mining: Default::default(),
scheduler: Default::default(),
transaction_payment: Default::default(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion standalone/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub fn new_partial(
config.wasm_method,
config.default_heap_pages,
config.max_runtime_instances,
config.runtime_cache_size,
);

let (client, backend, keystore_container, task_manager) =
Expand Down Expand Up @@ -195,7 +196,7 @@ pub fn new_partial(
let justification_import = grandpa_block_import.clone();

let (block_import, babe_link) = sc_consensus_babe::block_import(
sc_consensus_babe::Config::get_or_compute(&*client)?,
sc_consensus_babe::Config::get(&*client)?,
grandpa_block_import,
client.clone(),
)?;
Expand Down
2 changes: 1 addition & 1 deletion standalone/pherry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rand = "0.8.4"
structopt = { version = "0.3" }
jsonrpsee-types = "0.4.1"
jsonrpsee-types = "0.5.1"

async-trait = "0.1.49"
system = { path = "../../substrate/frame/system", package = "frame-system" }
Expand Down
Loading