Skip to content

Commit

Permalink
Two tests still failing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ada committed Mar 8, 2023
1 parent 467e5c7 commit 335dbbf
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 339 deletions.
583 changes: 345 additions & 238 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ runtime-benchmarks = [
'frame-benchmarking-cli/runtime-benchmarks',
]
std = ['sp-api/std', 'sp-block-builder/std', 'task-scheduler-runtime-api/std']
try-runtime = ["creditcoin-node-runtime/try-runtime", "try-runtime-cli"]
try-runtime = ["creditcoin-node-runtime/try-runtime", "try-runtime-cli/try-runtime"]
12 changes: 11 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
service,
};
use creditcoin_node_runtime::{Block, ExistentialDeposit};
use frame_benchmarking::frame_support;
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
use sc_service::PartialComponents;
Expand Down Expand Up @@ -112,6 +113,9 @@ pub fn run() -> sc_cli::Result<()> {
},
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use crate::service::ExecutorDispatch;
use frame_support::sp_io::SubstrateHostFunctions;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
Expand All @@ -120,7 +124,13 @@ pub fn run() -> sc_cli::Result<()> {
let task_manager =
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
Ok((cmd.run::<Block, service::ExecutorDispatch>(config), task_manager))
Ok((
cmd.run::<Block, ExtendedHostFunctions<
SubstrateHostFunctions,
<service::ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>>(),
task_manager,
))
})
},
#[cfg(not(feature = "try-runtime"))]
Expand Down
44 changes: 22 additions & 22 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Claims legacy wallet and transfers the balance to the sender's account.
#[pallet::call_index(0)]
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::claim_legacy_wallet())]
pub fn claim_legacy_wallet(
origin: OriginFor<T>,
Expand Down Expand Up @@ -596,7 +596,7 @@ pub mod pallet {
}

/// Registers an external address on `blockchain` and `network` with value `address`
#[pallet::call_index(1)]
#[pallet::call_index(2)]
#[pallet::weight(<T as Config>::WeightInfo::register_address())]
pub fn register_address(
origin: OriginFor<T>,
Expand Down Expand Up @@ -639,7 +639,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(2)]
#[pallet::call_index(3)]
#[pallet::weight(<T as Config>::WeightInfo::add_ask_order())]
pub fn add_ask_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -681,7 +681,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(3)]
#[pallet::call_index(4)]
#[pallet::weight(<T as Config>::WeightInfo::add_bid_order())]
pub fn add_bid_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -723,7 +723,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(4)]
#[pallet::call_index(5)]
#[pallet::weight(<T as Config>::WeightInfo::add_offer())]
pub fn add_offer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -775,7 +775,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(5)]
#[pallet::call_index(6)]
#[pallet::weight(<T as Config>::WeightInfo::add_deal_order())]
pub fn add_deal_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -827,7 +827,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(6)]
#[pallet::call_index(7)]
#[pallet::weight(<T as Config>::WeightInfo::lock_deal_order())]
pub fn lock_deal_order(
origin: OriginFor<T>,
Expand All @@ -854,7 +854,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(7)]
#[pallet::call_index(8)]
#[pallet::weight(<T as Config>::WeightInfo::fund_deal_order())]
pub fn fund_deal_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -907,7 +907,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(8)]
#[pallet::call_index(9)]
#[pallet::weight(<T as Config>::WeightInfo::register_deal_order())]
pub fn register_deal_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1018,7 +1018,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(9)]
#[pallet::call_index(10)]
#[pallet::weight(<T as Config>::WeightInfo::close_deal_order())]
pub fn close_deal_order(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1072,7 +1072,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(10)]
#[pallet::call_index(11)]
#[pallet::weight(<T as Config>::WeightInfo::request_collect_coins())]
pub fn request_collect_coins(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1114,7 +1114,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(11)]
#[pallet::call_index(12)]
#[pallet::weight(<T as Config>::WeightInfo::register_funding_transfer_legacy())]
pub fn register_funding_transfer_legacy(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1143,7 +1143,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(12)]
#[pallet::call_index(13)]
#[pallet::weight(<T as Config>::WeightInfo::register_repayment_transfer_legacy())]
pub fn register_repayment_transfer_legacy(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1173,7 +1173,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(13)]
#[pallet::call_index(14)]
#[pallet::weight(<T as Config>::WeightInfo::register_funding_transfer())]
pub fn register_funding_transfer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1201,7 +1201,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(14)]
#[pallet::call_index(15)]
#[pallet::weight(<T as Config>::WeightInfo::register_repayment_transfer())]
pub fn register_repayment_transfer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1229,7 +1229,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(15)]
#[pallet::call_index(16)]
#[pallet::weight(<T as Config>::WeightInfo::exempt())]
pub fn exempt(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1280,7 +1280,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(16)]
#[pallet::call_index(17)]
#[pallet::weight(match &task_output {
crate::TaskOutput::CollectCoins(..) => <T as Config>::WeightInfo::persist_collect_coins(),
crate::TaskOutput::VerifyTransfer(..) => <T as Config>::WeightInfo::persist_transfer(),
Expand Down Expand Up @@ -1332,7 +1332,7 @@ pub mod pallet {
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

#[pallet::call_index(17)]
#[pallet::call_index(18)]
#[pallet::weight(match &task_id {
crate::TaskId::VerifyTransfer(..) => <T as Config>::WeightInfo::fail_transfer(),
crate::TaskId::CollectCoins(..) => <T as Config>::WeightInfo::fail_collect_coins(),
Expand Down Expand Up @@ -1375,7 +1375,7 @@ pub mod pallet {
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

#[pallet::call_index(18)]
#[pallet::call_index(19)]
#[pallet::weight(<T as Config>::WeightInfo::add_authority())]
pub fn add_authority(
origin: OriginFor<T>,
Expand All @@ -1390,7 +1390,7 @@ pub mod pallet {
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

#[pallet::call_index(19)]
#[pallet::call_index(20)]
#[pallet::weight(<T as Config>::WeightInfo::register_currency())]
pub fn register_currency(origin: OriginFor<T>, currency: Currency) -> DispatchResult {
ensure_root(origin)?;
Expand All @@ -1406,7 +1406,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(20)]
#[pallet::call_index(21)]
#[pallet::weight(<T as Config>::WeightInfo::set_collect_coins_contract())]
pub fn set_collect_coins_contract(
origin: OriginFor<T>,
Expand All @@ -1418,7 +1418,7 @@ pub mod pallet {
}

#[transactional]
#[pallet::call_index(21)]
#[pallet::call_index(22)]
#[pallet::weight(<T as Config>::WeightInfo::remove_authority())]
pub fn remove_authority(
origin: OriginFor<T>,
Expand Down
4 changes: 2 additions & 2 deletions pallets/difficulty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::set_target_block_time())]
pub fn set_target_block_time(
origin: OriginFor<T>,
Expand All @@ -129,7 +129,7 @@ pub mod pallet {

Ok(())
}
#[pallet::call_index(1)]
#[pallet::call_index(2)]
#[pallet::weight(<T as Config>::WeightInfo::set_adjustment_period())]
pub fn set_adjustment_period(origin: OriginFor<T>, period: i64) -> DispatchResult {
ensure_root(origin)?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-session = { workspace = true }
pallet-staking-substrate = { workspace = true }
pallet-staking-substrate = { package = "pallet-staking", default-features = false, branch = "polkadot-v0.9.38", git = "https://github.com/paritytech/substrate.git" }
parity-scale-codec = { workspace = true }
serde.workspace = true
scale-info = { workspace = true }
Expand Down
56 changes: 35 additions & 21 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_election_provider_support::{
BoundedSupportsOf, ElectionDataProvider, ElectionProvider, ElectionProviderBase,
SortedListProvider,
BoundedSupportsOf, ElectionDataProvider, ElectionProvider, ElectionProviderBase, Get,
SortedListProvider, Support,
};
use frame_support::{defensive, traits::Defensive, traits::DefensiveTruncateFrom, RuntimeDebug};
use frame_support::{defensive, traits::Defensive, BoundedVec, RuntimeDebug};
pub use pallet_staking_substrate as pallet;
pub use pallet_staking_substrate::weights;
#[cfg(feature = "std")]
Expand All @@ -19,10 +19,10 @@ pub use pallet_staking_substrate::{
use parity_scale_codec::{Decode, Encode, EncodeLike};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_runtime::traits::{OpaqueKeys, Zero};
use sp_runtime::{AccountId32, BoundedVec};
use sp_runtime::traits::{ConstU32, OpaqueKeys, Zero};
use sp_runtime::AccountId32;
pub use sp_staking::{EraIndex, StakingInterface};
use sp_std::{boxed::Box, fmt::Debug, marker::PhantomData, vec, vec::Vec};
use sp_std::{boxed::Box, fmt::Debug, marker::PhantomData, vec};

pub(crate) const LOG_TARGET: &str = "runtime::staking";

Expand Down Expand Up @@ -230,11 +230,17 @@ where
type AccountId = AccountId;
type BlockNumber = BlockNumber;
type Error = &'static str;
type MaxWinners = (); //TODO
type MaxWinners = ConstU32<10>; //TODO determine number here
type DataProvider = DataProvider;

fn desired_targets_checked() -> frame_election_provider_support::data_provider::Result<u32> {
todo!()
DataProvider::desired_targets().and_then(|desired_targets| {
if desired_targets <= Self::MaxWinners::get() {
Ok(desired_targets)
} else {
Err("desired_targets must not be greater than MaxWinners.")
}
})
}
}

Expand All @@ -249,18 +255,26 @@ where
}

fn elect() -> Result<BoundedSupportsOf<Self>, Self::Error> {
DataProvider::electable_targets(Some(1))
.defensive_proof("Trivial 0 AccountId")
.map_err(|_| "failed to elect")
.map(|accounts| {
// Attempt to fit the resulting accounts into a bounded vec,
// If they don't fit print a warning and return what we can
BoundedVec::defensive_truncate_from(
accounts
.iter()
.map(|acc| (acc.clone(), Default::default()))
.collect::<Vec<_>>(),
)
})
/* Based on substrate example */
// DataProvider::electable_targets(None)
// .defensive_proof("Trivial 0 AccountId") // Wrap in defensive
// .map_err(|_| "failed to elect")
// .map(|t| bounded_vec![(t[0].clone(), Default::default())])

/* Based on previous implementation */
let candidates: Result<BoundedSupportsOf<Self>, Self::Error> =
DataProvider::electable_targets(Some(1)) // Get electable targets
.defensive_proof("Trivial 0 AccountId") // Wrap in defensive
.map(|accounts| {
// Map resulting vector of vectors
BoundedVec::truncate_from(
// Wrap resulting Vec into a BoundedVec via truncation
accounts
.iter() // Turn given vector into an iterator
.map(|acc| (acc.clone(), Support::default())) // Map to a tuple
.collect(), // Collect as a Vec
)
});
candidates
}
}
11 changes: 8 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub use frame_support::{
},
StorageValue,
};

#[cfg(feature = "try-runtime")]
use frame_support::traits::UpgradeCheckSelect;

pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -611,22 +615,23 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {
fn on_runtime_upgrade(checks: UpgradeCheckSelect) -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade().unwrap();
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}

fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect
) -> Weight {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here.
Executive::try_execute_block(block, state_root_check, select).expect("execute-block failed")
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
}
}
}
Expand Down
Loading

0 comments on commit 335dbbf

Please sign in to comment.