Skip to content

Commit 335dbbf

Browse files
author
Ada
committed
Two tests still failing
1 parent 467e5c7 commit 335dbbf

11 files changed

Lines changed: 476 additions & 339 deletions

File tree

Cargo.lock

Lines changed: 345 additions & 238 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ runtime-benchmarks = [
8080
'frame-benchmarking-cli/runtime-benchmarks',
8181
]
8282
std = ['sp-api/std', 'sp-block-builder/std', 'task-scheduler-runtime-api/std']
83-
try-runtime = ["creditcoin-node-runtime/try-runtime", "try-runtime-cli"]
83+
try-runtime = ["creditcoin-node-runtime/try-runtime", "try-runtime-cli/try-runtime"]

node/src/command.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
service,
66
};
77
use creditcoin_node_runtime::{Block, ExistentialDeposit};
8+
use frame_benchmarking::frame_support;
89
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
910
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
1011
use sc_service::PartialComponents;
@@ -112,6 +113,9 @@ pub fn run() -> sc_cli::Result<()> {
112113
},
113114
#[cfg(feature = "try-runtime")]
114115
Some(Subcommand::TryRuntime(cmd)) => {
116+
use crate::service::ExecutorDispatch;
117+
use frame_support::sp_io::SubstrateHostFunctions;
118+
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
115119
let runner = cli.create_runner(cmd)?;
116120
runner.async_run(|config| {
117121
// we don't need any of the components of new_partial, just a runtime, or a task
@@ -120,7 +124,13 @@ pub fn run() -> sc_cli::Result<()> {
120124
let task_manager =
121125
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
122126
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
123-
Ok((cmd.run::<Block, service::ExecutorDispatch>(config), task_manager))
127+
Ok((
128+
cmd.run::<Block, ExtendedHostFunctions<
129+
SubstrateHostFunctions,
130+
<service::ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
131+
>>(),
132+
task_manager,
133+
))
124134
})
125135
},
126136
#[cfg(not(feature = "try-runtime"))]

pallets/creditcoin/src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub mod pallet {
565565
#[pallet::call]
566566
impl<T: Config> Pallet<T> {
567567
/// Claims legacy wallet and transfers the balance to the sender's account.
568-
#[pallet::call_index(0)]
568+
#[pallet::call_index(1)]
569569
#[pallet::weight(<T as Config>::WeightInfo::claim_legacy_wallet())]
570570
pub fn claim_legacy_wallet(
571571
origin: OriginFor<T>,
@@ -596,7 +596,7 @@ pub mod pallet {
596596
}
597597

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

642-
#[pallet::call_index(2)]
642+
#[pallet::call_index(3)]
643643
#[pallet::weight(<T as Config>::WeightInfo::add_ask_order())]
644644
pub fn add_ask_order(
645645
origin: OriginFor<T>,
@@ -681,7 +681,7 @@ pub mod pallet {
681681
Ok(())
682682
}
683683

684-
#[pallet::call_index(3)]
684+
#[pallet::call_index(4)]
685685
#[pallet::weight(<T as Config>::WeightInfo::add_bid_order())]
686686
pub fn add_bid_order(
687687
origin: OriginFor<T>,
@@ -723,7 +723,7 @@ pub mod pallet {
723723
Ok(())
724724
}
725725

726-
#[pallet::call_index(4)]
726+
#[pallet::call_index(5)]
727727
#[pallet::weight(<T as Config>::WeightInfo::add_offer())]
728728
pub fn add_offer(
729729
origin: OriginFor<T>,
@@ -775,7 +775,7 @@ pub mod pallet {
775775
Ok(())
776776
}
777777

778-
#[pallet::call_index(5)]
778+
#[pallet::call_index(6)]
779779
#[pallet::weight(<T as Config>::WeightInfo::add_deal_order())]
780780
pub fn add_deal_order(
781781
origin: OriginFor<T>,
@@ -827,7 +827,7 @@ pub mod pallet {
827827
Ok(())
828828
}
829829

830-
#[pallet::call_index(6)]
830+
#[pallet::call_index(7)]
831831
#[pallet::weight(<T as Config>::WeightInfo::lock_deal_order())]
832832
pub fn lock_deal_order(
833833
origin: OriginFor<T>,
@@ -854,7 +854,7 @@ pub mod pallet {
854854
Ok(())
855855
}
856856

857-
#[pallet::call_index(7)]
857+
#[pallet::call_index(8)]
858858
#[pallet::weight(<T as Config>::WeightInfo::fund_deal_order())]
859859
pub fn fund_deal_order(
860860
origin: OriginFor<T>,
@@ -907,7 +907,7 @@ pub mod pallet {
907907
Ok(())
908908
}
909909

910-
#[pallet::call_index(8)]
910+
#[pallet::call_index(9)]
911911
#[pallet::weight(<T as Config>::WeightInfo::register_deal_order())]
912912
pub fn register_deal_order(
913913
origin: OriginFor<T>,
@@ -1018,7 +1018,7 @@ pub mod pallet {
10181018
Ok(())
10191019
}
10201020

1021-
#[pallet::call_index(9)]
1021+
#[pallet::call_index(10)]
10221022
#[pallet::weight(<T as Config>::WeightInfo::close_deal_order())]
10231023
pub fn close_deal_order(
10241024
origin: OriginFor<T>,
@@ -1072,7 +1072,7 @@ pub mod pallet {
10721072
}
10731073

10741074
#[transactional]
1075-
#[pallet::call_index(10)]
1075+
#[pallet::call_index(11)]
10761076
#[pallet::weight(<T as Config>::WeightInfo::request_collect_coins())]
10771077
pub fn request_collect_coins(
10781078
origin: OriginFor<T>,
@@ -1114,7 +1114,7 @@ pub mod pallet {
11141114
}
11151115

11161116
#[transactional]
1117-
#[pallet::call_index(11)]
1117+
#[pallet::call_index(12)]
11181118
#[pallet::weight(<T as Config>::WeightInfo::register_funding_transfer_legacy())]
11191119
pub fn register_funding_transfer_legacy(
11201120
origin: OriginFor<T>,
@@ -1143,7 +1143,7 @@ pub mod pallet {
11431143
}
11441144

11451145
#[transactional]
1146-
#[pallet::call_index(12)]
1146+
#[pallet::call_index(13)]
11471147
#[pallet::weight(<T as Config>::WeightInfo::register_repayment_transfer_legacy())]
11481148
pub fn register_repayment_transfer_legacy(
11491149
origin: OriginFor<T>,
@@ -1173,7 +1173,7 @@ pub mod pallet {
11731173
}
11741174

11751175
#[transactional]
1176-
#[pallet::call_index(13)]
1176+
#[pallet::call_index(14)]
11771177
#[pallet::weight(<T as Config>::WeightInfo::register_funding_transfer())]
11781178
pub fn register_funding_transfer(
11791179
origin: OriginFor<T>,
@@ -1201,7 +1201,7 @@ pub mod pallet {
12011201
}
12021202

12031203
#[transactional]
1204-
#[pallet::call_index(14)]
1204+
#[pallet::call_index(15)]
12051205
#[pallet::weight(<T as Config>::WeightInfo::register_repayment_transfer())]
12061206
pub fn register_repayment_transfer(
12071207
origin: OriginFor<T>,
@@ -1229,7 +1229,7 @@ pub mod pallet {
12291229
Ok(())
12301230
}
12311231

1232-
#[pallet::call_index(15)]
1232+
#[pallet::call_index(16)]
12331233
#[pallet::weight(<T as Config>::WeightInfo::exempt())]
12341234
pub fn exempt(
12351235
origin: OriginFor<T>,
@@ -1280,7 +1280,7 @@ pub mod pallet {
12801280
}
12811281

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

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

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

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

14081408
#[transactional]
1409-
#[pallet::call_index(20)]
1409+
#[pallet::call_index(21)]
14101410
#[pallet::weight(<T as Config>::WeightInfo::set_collect_coins_contract())]
14111411
pub fn set_collect_coins_contract(
14121412
origin: OriginFor<T>,
@@ -1418,7 +1418,7 @@ pub mod pallet {
14181418
}
14191419

14201420
#[transactional]
1421-
#[pallet::call_index(21)]
1421+
#[pallet::call_index(22)]
14221422
#[pallet::weight(<T as Config>::WeightInfo::remove_authority())]
14231423
pub fn remove_authority(
14241424
origin: OriginFor<T>,

pallets/difficulty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub mod pallet {
115115

116116
#[pallet::call]
117117
impl<T: Config> Pallet<T> {
118-
#[pallet::call_index(0)]
118+
#[pallet::call_index(1)]
119119
#[pallet::weight(<T as Config>::WeightInfo::set_target_block_time())]
120120
pub fn set_target_block_time(
121121
origin: OriginFor<T>,
@@ -129,7 +129,7 @@ pub mod pallet {
129129

130130
Ok(())
131131
}
132-
#[pallet::call_index(1)]
132+
#[pallet::call_index(2)]
133133
#[pallet::weight(<T as Config>::WeightInfo::set_adjustment_period())]
134134
pub fn set_adjustment_period(origin: OriginFor<T>, period: i64) -> DispatchResult {
135135
ensure_root(origin)?;

pallets/staking/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ frame-support = { workspace = true }
1919
frame-system = { workspace = true }
2020
log = { workspace = true }
2121
pallet-session = { workspace = true }
22-
pallet-staking-substrate = { workspace = true }
22+
pallet-staking-substrate = { package = "pallet-staking", default-features = false, branch = "polkadot-v0.9.38", git = "https://github.com/paritytech/substrate.git" }
2323
parity-scale-codec = { workspace = true }
2424
serde.workspace = true
2525
scale-info = { workspace = true }

pallets/staking/src/lib.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

33
use frame_election_provider_support::{
4-
BoundedSupportsOf, ElectionDataProvider, ElectionProvider, ElectionProviderBase,
5-
SortedListProvider,
4+
BoundedSupportsOf, ElectionDataProvider, ElectionProvider, ElectionProviderBase, Get,
5+
SortedListProvider, Support,
66
};
7-
use frame_support::{defensive, traits::Defensive, traits::DefensiveTruncateFrom, RuntimeDebug};
7+
use frame_support::{defensive, traits::Defensive, BoundedVec, RuntimeDebug};
88
pub use pallet_staking_substrate as pallet;
99
pub use pallet_staking_substrate::weights;
1010
#[cfg(feature = "std")]
@@ -19,10 +19,10 @@ pub use pallet_staking_substrate::{
1919
use parity_scale_codec::{Decode, Encode, EncodeLike};
2020
use scale_info::TypeInfo;
2121
use serde::{Deserialize, Serialize};
22-
use sp_runtime::traits::{OpaqueKeys, Zero};
23-
use sp_runtime::{AccountId32, BoundedVec};
22+
use sp_runtime::traits::{ConstU32, OpaqueKeys, Zero};
23+
use sp_runtime::AccountId32;
2424
pub use sp_staking::{EraIndex, StakingInterface};
25-
use sp_std::{boxed::Box, fmt::Debug, marker::PhantomData, vec, vec::Vec};
25+
use sp_std::{boxed::Box, fmt::Debug, marker::PhantomData, vec};
2626

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

@@ -230,11 +230,17 @@ where
230230
type AccountId = AccountId;
231231
type BlockNumber = BlockNumber;
232232
type Error = &'static str;
233-
type MaxWinners = (); //TODO
233+
type MaxWinners = ConstU32<10>; //TODO determine number here
234234
type DataProvider = DataProvider;
235235

236236
fn desired_targets_checked() -> frame_election_provider_support::data_provider::Result<u32> {
237-
todo!()
237+
DataProvider::desired_targets().and_then(|desired_targets| {
238+
if desired_targets <= Self::MaxWinners::get() {
239+
Ok(desired_targets)
240+
} else {
241+
Err("desired_targets must not be greater than MaxWinners.")
242+
}
243+
})
238244
}
239245
}
240246

@@ -249,18 +255,26 @@ where
249255
}
250256

251257
fn elect() -> Result<BoundedSupportsOf<Self>, Self::Error> {
252-
DataProvider::electable_targets(Some(1))
253-
.defensive_proof("Trivial 0 AccountId")
254-
.map_err(|_| "failed to elect")
255-
.map(|accounts| {
256-
// Attempt to fit the resulting accounts into a bounded vec,
257-
// If they don't fit print a warning and return what we can
258-
BoundedVec::defensive_truncate_from(
259-
accounts
260-
.iter()
261-
.map(|acc| (acc.clone(), Default::default()))
262-
.collect::<Vec<_>>(),
263-
)
264-
})
258+
/* Based on substrate example */
259+
// DataProvider::electable_targets(None)
260+
// .defensive_proof("Trivial 0 AccountId") // Wrap in defensive
261+
// .map_err(|_| "failed to elect")
262+
// .map(|t| bounded_vec![(t[0].clone(), Default::default())])
263+
264+
/* Based on previous implementation */
265+
let candidates: Result<BoundedSupportsOf<Self>, Self::Error> =
266+
DataProvider::electable_targets(Some(1)) // Get electable targets
267+
.defensive_proof("Trivial 0 AccountId") // Wrap in defensive
268+
.map(|accounts| {
269+
// Map resulting vector of vectors
270+
BoundedVec::truncate_from(
271+
// Wrap resulting Vec into a BoundedVec via truncation
272+
accounts
273+
.iter() // Turn given vector into an iterator
274+
.map(|acc| (acc.clone(), Support::default())) // Map to a tuple
275+
.collect(), // Collect as a Vec
276+
)
277+
});
278+
candidates
265279
}
266280
}

runtime/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub use frame_support::{
3939
},
4040
StorageValue,
4141
};
42+
43+
#[cfg(feature = "try-runtime")]
44+
use frame_support::traits::UpgradeCheckSelect;
45+
4246
pub use frame_system::Call as SystemCall;
4347
pub use pallet_balances::Call as BalancesCall;
4448
pub use pallet_timestamp::Call as TimestampCall;
@@ -611,22 +615,23 @@ impl_runtime_apis! {
611615

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

622626
fn execute_block(
623627
block: Block,
624628
state_root_check: bool,
629+
signature_check: bool,
625630
select: frame_try_runtime::TryStateSelect
626631
) -> Weight {
627632
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
628633
// have a backtrace here.
629-
Executive::try_execute_block(block, state_root_check, select).expect("execute-block failed")
634+
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
630635
}
631636
}
632637
}

0 commit comments

Comments
 (0)