Skip to content

Commit

Permalink
update to substrate-v1.0.0 (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj authored Aug 3, 2023
1 parent 0eb527f commit 8360611
Show file tree
Hide file tree
Showing 39 changed files with 2,778 additions and 3,379 deletions.
2,529 changes: 1,178 additions & 1,351 deletions Cargo.lock

Large diffs are not rendered by default.

238 changes: 119 additions & 119 deletions Cargo.toml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dkg-gadget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ scale-info = { workspace = true }
curv = { workspace = true }

codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
prometheus = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
prometheus = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }

sp-api = { workspace = true }
sp-application-crypto = { workspace = true }
Expand All @@ -43,7 +43,6 @@ sc-keystore = { workspace = true }
sc-network = { workspace = true }
sc-network-common = { workspace = true }
sc-network-sync = { workspace = true }
sc-peerset = { workspace = true }

round-based = { workspace = true }
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion dkg-gadget/src/gossip_engine/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl NetworkGossipEngineBuilder {

#[allow(unused)]
mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Reputation change when a peer sends us a message that we didn't know about.
pub const GOOD_MESSAGE: Rep = Rep::new(1 << 7, "Good message");
/// We received an unexpected message packet.
Expand Down
1 change: 1 addition & 0 deletions dkg-gadget/src/storage/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use sp_runtime::traits::{Block, Get, Header, NumberFor};
use std::sync::Arc;

/// processes signed proposals and puts them in storage
#[allow(clippy::extra_unused_type_parameters)]
pub(crate) fn save_signed_proposals_in_storage<
B,
C,
Expand Down
3 changes: 3 additions & 0 deletions dkg-runtime-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ frame-support = { workspace = true }
default = ["std"]
std = [
"codec/std",
"ethabi/std",
"ethereum/std",
"ethereum-types/std",
"scale-info/std",
"webb-proposals/std",
"sp-io/std",
Expand Down
10 changes: 8 additions & 2 deletions dkg-test-orchestrator/src/dummy_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ impl ApiExt<TestBlock> for DummyApi {
{
todo!()
}

fn set_call_context(&mut self, _call_context: CallContext) {
todo!()
}

fn register_extension<E: Extension>(&mut self, _extension: E) {
todo!()
}
}

impl AsTrieBackend<BlakeTwo256, Vec<u8>> for DummyStateBackend {
Expand Down Expand Up @@ -507,7 +515,6 @@ impl sp_api::Core<TestBlock> for DummyApi {
fn __runtime_api_internal_call_api_at(
&self,
_: H256,
_: ExecutionContext,
_: Vec<u8>,
_: &dyn Fn(RuntimeVersion) -> &'static str,
) -> ApiResult<Vec<u8>> {
Expand All @@ -527,7 +534,6 @@ impl
fn __runtime_api_internal_call_api_at(
&self,
_: H256,
_: ExecutionContext,
_: Vec<u8>,
_: &dyn Fn(RuntimeVersion) -> &'static str,
) -> ApiResult<Vec<u8>> {
Expand Down
1 change: 1 addition & 0 deletions pallets/bridge-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ std = [
"sp-std/std",
"webb-proposals/std",
"pallet-identity/std",
"dkg-runtime-primitives/std"
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
14 changes: 4 additions & 10 deletions pallets/bridge-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ pub mod pallet {
/// Maximum number of additional fields that may be stored in a bridge's metadata. Needed to
/// bound the I/O required to access an identity, but can be pretty high.
#[pallet::constant]
type MaxAdditionalFields: Get<u32>;
type MaxAdditionalFields: Get<u32> + MaybeSerializeDeserialize;

/// Maximum number of resources that may be stored in a bridge. This is not to be confused
/// with the actual maximum supported by the bridge. Needed to bound the I/O
/// required to access a metadata object, but can be pretty high.
#[pallet::constant]
type MaxResources: Get<u32>;
type MaxResources: Get<u32> + MaybeSerializeDeserialize;

/// Max length of a proposal
#[pallet::constant]
Expand All @@ -111,20 +111,14 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub phantom: PhantomData<T>,
pub bridges: Vec<BridgeMetadata<T::MaxResources, T::MaxAdditionalFields>>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { phantom: Default::default(), bridges: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
NextBridgeIndex::<T>::put(T::BridgeIndex::one());
for bridge in &self.bridges {
Expand Down
33 changes: 14 additions & 19 deletions pallets/bridge-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@ use super::*;
use crate as pallet_bridge_registry;

use codec::{Decode, Encode};
use frame_support::{parameter_types, traits::GenesisBuild};
use frame_support::parameter_types;
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
AccountId32, MultiSignature,
AccountId32, BuildStorage, MultiSignature,
};
use sp_std::convert::{TryFrom, TryInto};

pub type Signature = MultiSignature;
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
BridgeRegistry: pallet_bridge_registry::{Pallet, Call, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},
System: frame_system,
BridgeRegistry: pallet_bridge_registry,
Balances: pallet_balances,
}
);

Expand All @@ -42,15 +36,14 @@ impl system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = BlockHashCount;
type BlockLength = ();
type BlockNumber = u64;
type Block = frame_system::mocking::MockBlock<Test>;
type BlockWeights = ();
type RuntimeCall = RuntimeCall;
type DbWeight = ();
type RuntimeEvent = RuntimeEvent;
type Hash = H256;
type Hashing = BlakeTwo256;
type Header = Header;
type Index = u64;
type Nonce = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type OnKilledAccount = ();
Expand All @@ -76,18 +69,20 @@ impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type RuntimeHoldReason = RuntimeHoldReason;
type MaxHolds = ();
type MaxFreezes = ();
type WeightInfo = ();
}

parameter_types! {
#[derive(serde::Serialize, serde::Deserialize)]
pub const MaxAdditionalFields: u32 = 5;
#[derive(serde::Serialize, serde::Deserialize)]
pub const MaxResources: u32 = 32;
#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, scale_info::TypeInfo, Ord, PartialOrd)]
pub const MaxProposalLength : u32 = 10_000;
#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, scale_info::TypeInfo, Ord, PartialOrd)]
pub const MaxProposalLength : u32 = 10_000;
}

impl pallet_bridge_registry::Config for Test {
Expand All @@ -102,7 +97,7 @@ impl pallet_bridge_registry::Config for Test {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut storage = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let _ = pallet_balances::GenesisConfig::<Test> {
balances: vec![
(AccountId32::new([1u8; 32]), 10u128.pow(18)),
Expand Down
17 changes: 12 additions & 5 deletions pallets/bridge-registry/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ use sp_std::prelude::*;
PartialEqNoBound,
RuntimeDebugNoBound,
TypeInfo,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[codec(mel_bound())]
#[scale_info(skip_type_params(FieldLimit))]
pub struct BridgeInfo<FieldLimit: Get<u32>> {
Expand Down Expand Up @@ -70,12 +71,11 @@ pub struct BridgeInfo<FieldLimit: Get<u32>> {
)]
pub struct SerdeData(Data);

#[cfg(feature = "std")]
mod serde_ {
use super::*;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
struct DataVisitor;
use std::{fmt::Formatter, str::FromStr};
use sp_std::{fmt::Formatter, str::FromStr};

impl FromStr for SerdeData {
type Err = ();
Expand Down Expand Up @@ -130,9 +130,16 @@ mod serde_ {
/// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a
/// backwards compatible way through a specialized `Decode` impl.
#[derive(
CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
CloneNoBound,
Encode,
Eq,
MaxEncodedLen,
PartialEqNoBound,
RuntimeDebugNoBound,
TypeInfo,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[codec(mel_bound())]
#[scale_info(skip_type_params(MaxResources, MaxAdditionalFields))]
pub struct BridgeMetadata<MaxResources: Get<u32>, MaxAdditionalFields: Get<u32>> {
Expand Down
3 changes: 2 additions & 1 deletion pallets/dkg-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ std = [
"frame-support/std",
"frame-system/std",
"libsecp256k1/std",
"pallet-session/std"
"pallet-session/std",
"webb-proposals/std",
]
8 changes: 4 additions & 4 deletions pallets/dkg-metadata/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ benchmarks! {
for id in 1..MAX_AUTHORITIES{
let dkg_id = T::DKGId::from(ecdsa::Public::from_raw([id as u8; 33]));
let account_id = T::AccountId::from(sr25519::Public::from_raw([id as u8; 32]));
let block_number: T::BlockNumber = id.into();
let block_number: BlockNumberFor<T> = id.into();
AccountToAuthority::<T>::insert(&account_id, dkg_id.clone());
JailedKeygenAuthorities::<T>::insert(dkg_id.clone(), block_number);
JailedSigningAuthorities::<T>::insert(dkg_id.clone(), block_number);
}
let caller = T::AccountId::from(sr25519::Public::from_raw([1u8; 32]));
let offender = T::DKGId::from(ecdsa::Public::from_raw([1u8; 33]));
let key_gen_sentence = T::KeygenJailSentence::get();
let block_number = key_gen_sentence + T::BlockNumber::from(BLOCK_NUMBER);
let block_number = key_gen_sentence + BlockNumberFor<T>::from(BLOCK_NUMBER);
frame_system::Pallet::<T>::set_block_number(block_number.into());
}: _(RawOrigin::Signed(caller))
verify {
Expand All @@ -235,7 +235,7 @@ benchmarks! {
force_unjail_signing {
for id in 1..MAX_AUTHORITIES{
let dkg_id = T::DKGId::from(ecdsa::Public::from_raw([id as u8; 33]));
let block_number: T::BlockNumber = id.into();
let block_number: BlockNumberFor<T> = id.into();
JailedSigningAuthorities::<T>::insert(dkg_id.clone(), block_number);
}
let offender = T::DKGId::from(ecdsa::Public::from_raw([1u8; 33]));
Expand All @@ -247,7 +247,7 @@ benchmarks! {
force_unjail_keygen {
for id in 1..MAX_AUTHORITIES{
let dkg_id = T::DKGId::from(ecdsa::Public::from_raw([id as u8; 33]));
let block_number: T::BlockNumber = id.into();
let block_number: BlockNumberFor<T> = id.into();
JailedKeygenAuthorities::<T>::insert(dkg_id.clone(), block_number);
}
let offender = T::DKGId::from(ecdsa::Public::from_raw([1u8; 33]));
Expand Down
Loading

0 comments on commit 8360611

Please sign in to comment.