Skip to content

Commit

Permalink
fix: update from v0.9.27 to v0.9.36
Browse files Browse the repository at this point in the history
v0.9.28 - changes

v0.9.29 - changes

v0.9.30 - changes

v0.9.31 - changes

v0.9.37 changes

Add indices for calls of ethereum-transactions

See:
paritytech/substrate#12891
paritytech/substrate#11381

Fixes ethereum-events tests

Add indices for calls of ethereum-transactions

See:
- paritytech/substrate#12891
- paritytech/substrate#11381

Fixes compilation errors of avn-proxy pallet

- Cleanups WiP
- Adds indices for calls

Fixes compilation errors of nft-manager pallet

- Cleanup
- Adds indices for calls

Fixes tests for nft-manager pallet

Fixup nft-manager imports

Fixes avn-proxy tests

Fixes tests on Ethereum Events pallet

SYS-3197 - token-manager pallet::call changed

SYS-3197 - summary pallet and exact substrate version

fix: tests

Cleanup warnings and adds call indexes

Fixes some of the test in token manager

Reverts the interface changes to use Box<call>.
Fixes mock, re-introduces some of the tests, and temporarily disables some.

Re-enable the rest of token manager tests

Fixup: Remove warning

Fixes token-manager benchmarks compilation errors

Updates and fixes Benchmarks cargo dependencies.

Also fixes avn-proxy compilation errors.
Adds instructions to run pallet benchmarks

fix: updated benchmarks

fix: added prod-like benchmarks for parachain-staking

Fix staking tests

fix: benchmark test for parachain staking

fix: add max proof to weights init

fix: linting
  • Loading branch information
ivan-cholakov committed Mar 23, 2023
1 parent 8bec087 commit bbc1232
Show file tree
Hide file tree
Showing 106 changed files with 3,615 additions and 2,822 deletions.
1,308 changes: 885 additions & 423 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ We welcome contributions but before you devote quite a bit of time to contributi
Read our contribution guide [HERE](./CONTRIBUTING.adoc).

Note: This repository is managed frequently so you do not need to email/contact us to notify us of your submission.

## Building and testing the pallets

To build and test a pallet, navigate to the directory of the pallet in your project by running the following command:
```sh
cd pallets/<pallet_name>/
```
Once you're in the pallet directory, use cargo to build and test the pallet by running the following commands:
```sh
# Build the pallet
cargo build

# Run the unit and integration tests
cargo test

# Test the benchmark tests
cargo test --features runtime-benchmarks
```
23 changes: 12 additions & 11 deletions pallets/avn-finality-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
scale-info = { version = "2.0", default-features = false, features = ["derive"] }

sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-avn-common = { version = "0.12.0", default-features = false, path = "../../primitives/avn-common" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-avn = { version = "0.12.0", default-features = false, path = "../avn" }

# Optional imports
serde = { version = "1.0.137", optional = true }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", optional = true }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", optional = true }

[dev-dependencies]
hex-literal = { version = "0.3.4", default-features = false }
parking_lot = { version = "0.12.0" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

[features]
migrate = []
default = ["std"]
std = [
"frame-benchmarking?/std",
"serde",
"codec/std",
"sp-std/std",
Expand All @@ -48,7 +49,7 @@ std = [
"pallet-avn/std"
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
2 changes: 1 addition & 1 deletion pallets/avn-finality-tracker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::*;

use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
Expand Down
16 changes: 8 additions & 8 deletions pallets/avn-finality-tracker/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: AvnFinalityTracker LastFinalisedBlockSubmission (r:0 w:1)
/// The range of component `v` is `[3, 10]`.
fn submit_latest_finalised_block_number(v: u32, ) -> Weight {
(19_069_000 as Weight)
(Weight::from_ref_time(19_069_000))
// Standard Error: 18_000
.saturating_add((118_000 as Weight).saturating_mul(v as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(Weight::from_ref_time(118_000)).saturating_mul(v as u64)
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}

Expand All @@ -80,10 +80,10 @@ impl WeightInfo for () {
// Storage: AvnFinalityTracker LastFinalisedBlockSubmission (r:0 w:1)
/// The range of component `v` is `[3, 10]`.
fn submit_latest_finalised_block_number(v: u32, ) -> Weight {
(19_069_000 as Weight)
(Weight::from_ref_time(19_069_000))
// Standard Error: 18_000
.saturating_add((118_000 as Weight).saturating_mul(v as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
.saturating_add(Weight::from_ref_time(118_000)).saturating_mul(v as u64)
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(2))
}
}
45 changes: 24 additions & 21 deletions pallets/avn-finality-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const MAX_VALIDATOR_ACCOUNT_IDS: u32 = 10;
pub type AVN<T> = avn::Pallet<T>;

#[cfg(test)]
#[path = "mock.rs"]
mod mock;

mod benchmarking;
Expand All @@ -65,9 +66,9 @@ pub mod pallet {
SendTransactionTypes<Call<Self>> + frame_system::Config + avn::Config
{
/// Overarching event type
type Event: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::Event>
+ Into<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>
+ Into<<Self as frame_system::Config>::RuntimeEvent>;
/// The number of block we can keep the calculated finalised block, before recalculating it
/// again.
type CacheAge: Get<Self::BlockNumber>;
Expand Down Expand Up @@ -131,6 +132,7 @@ pub mod pallet {
#[pallet::weight(
<T as pallet::Config>::WeightInfo::submit_latest_finalised_block_number(MAX_VALIDATOR_ACCOUNT_IDS)
)]
#[pallet::call_index(0)]
pub fn submit_latest_finalised_block_number(
origin: OriginFor<T>,
new_finalised_block_number: T::BlockNumber,
Expand Down Expand Up @@ -219,9 +221,21 @@ pub mod pallet {
}
}

#[derive(Encode, Decode, Default, Clone, Copy, PartialEq, Debug, Eq, TypeInfo, MaxEncodedLen)]
pub struct SubmissionData<BlockNumber: Member + AtLeast32Bit> {
pub finalised_block: BlockNumber,
pub submitted_at_block: BlockNumber,
}

impl<BlockNumber: Member + AtLeast32Bit> SubmissionData<BlockNumber> {
pub fn new(finalised_block: BlockNumber, submitted_at_block: BlockNumber) -> Self {
return SubmissionData::<BlockNumber> { finalised_block, submitted_at_block }
}
}

impl<T: Config> Pallet<T> {
/// This function will only update the finalised block if there are 2/3rd or more submissions
/// from distinct validators
/// This function will only update the finalised block if there are 2/3rd or more
/// submissions from distinct validators
pub fn update_latest_finalised_block_if_required() {
let quorum = AVN::<T>::calculate_two_third_quorum();
let current_block_number = <frame_system::Pallet<T>>::block_number();
Expand All @@ -246,7 +260,8 @@ impl<T: Config> Pallet<T> {
});
}

// check if there is something wrong with submissions in general and notify via an event
// check if there is something wrong with submissions in general and notify via an
// event
if current_block_number - last_finalised_block_submission > T::ReportLatency::get() {
Self::deposit_event(Event::<T>::FinalisedBlockUpdateStalled {
block: last_finalised_block_submission,
Expand Down Expand Up @@ -329,9 +344,9 @@ impl<T: Config> Pallet<T> {
return
}

// send a transaction on chain with the latest finalised block data. We shouldn't have any
// sig re-use issue here because new block number must be > current finalised block
// number
// send a transaction on chain with the latest finalised block data. We shouldn't have
// any sig re-use issue here because new block number must be > current
// finalised block number
let signature = this_validator
.key
.sign(&(UPDATE_FINALISED_BLOCK_NUMBER_CONTEXT, calculated_finalised_block).encode())
Expand Down Expand Up @@ -453,15 +468,3 @@ impl<T: Config> FinalisedBlockChecker<T::BlockNumber> for Pallet<T> {
return Self::latest_finalised_block_number() >= block_number
}
}

#[derive(Encode, Decode, Default, Clone, Copy, PartialEq, Debug, Eq, TypeInfo, MaxEncodedLen)]
pub struct SubmissionData<BlockNumber: Member + AtLeast32Bit> {
pub finalised_block: BlockNumber,
pub submitted_at_block: BlockNumber,
}

impl<BlockNumber: Member + AtLeast32Bit> SubmissionData<BlockNumber> {
fn new(finalised_block: BlockNumber, submitted_at_block: BlockNumber) -> Self {
return SubmissionData::<BlockNumber> { finalised_block, submitted_at_block }
}
}
16 changes: 8 additions & 8 deletions pallets/avn-finality-tracker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
};

pub type Extrinsic = TestXt<Call, ()>;
pub type Extrinsic = TestXt<RuntimeCall, ()>;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;
type Block = frame_system::mocking::MockBlock<TestRuntime>;
Expand All @@ -34,8 +34,8 @@ parameter_types! {
pub const ReportLatency: u64 = 1000;
}

impl Config for TestRuntime {
type Event = Event;
impl avn_finality_tracker::Config for TestRuntime {
type RuntimeEvent = RuntimeEvent;
type CacheAge = CacheAge;
type SubmissionInterval = SubmissionInterval;
type ReportLatency = ReportLatency;
Expand All @@ -51,16 +51,16 @@ impl system::Config for TestRuntime {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
Expand All @@ -83,9 +83,9 @@ impl avn::Config for TestRuntime {

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for TestRuntime
where
Call: From<LocalCall>,
RuntimeCall: From<LocalCall>,
{
type OverarchingCall = Call;
type OverarchingCall = RuntimeCall;
type Extrinsic = Extrinsic;
}

Expand Down
21 changes: 11 additions & 10 deletions pallets/avn-offence-handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ homepage = "http://www.aventus.io/"
repository = "https://github.com/Aventus-Network-Services/avn-parachain/"

[dependencies]
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-avn-common = { version = "0.12.0", default-features = false, path = "../../primitives/avn-common" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-avn = { version = "0.12.0", default-features = false, path = "../avn" }
pallet-session = { default-features = false, features = ["historical"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
pallet-session = { default-features = false, features = ["historical"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

# Optional imports for benchmarking
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", optional = true }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", optional = true }

[dev-dependencies]
serde = { version = "1.0.101"}
parking_lot = { version = "0.12.0" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

[features]
default = ["std"]
std = [
"frame-benchmarking?/std",
"codec/std",
"frame-support/std",
"frame-system/std",
Expand All @@ -42,7 +43,7 @@ std = [
"pallet-avn/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
4 changes: 2 additions & 2 deletions pallets/avn-offence-handler/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl_benchmark_test_suite!(
crate::mock::TestRuntime,
);

fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len().saturating_sub(1 as usize)];
assert_eq!(event, &system_event);
Expand Down
8 changes: 4 additions & 4 deletions pallets/avn-offence-handler/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: AvnOffenceHandler SlashingEnabled (r:0 w:1)
fn configure_slashing() -> Weight {
(15_281_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
(Weight::from_ref_time(15_281_000))
.saturating_add(T::DbWeight::get().writes(1))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: AvnOffenceHandler SlashingEnabled (r:0 w:1)
fn configure_slashing() -> Weight {
(15_281_000 as Weight)
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
(Weight::from_ref_time(15_281_000))
.saturating_add(RocksDbWeight::get().writes(1))
}
}
9 changes: 5 additions & 4 deletions pallets/avn-offence-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config + session::historical::Config {
/// The overarching event type.
type Event: From<Event<Self>>
+ Into<<Self as frame_system::Config>::Event>
+ IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self>>
+ Into<<Self as frame_system::Config>::RuntimeEvent>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// A trait responsible for punishing malicious validators
type Enforcer: Enforcer<<Self as session::Config>::ValidatorId>;
Expand Down Expand Up @@ -82,6 +82,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(<T as pallet::Config>::WeightInfo::configure_slashing())]
#[pallet::call_index(0)]
pub fn configure_slashing(origin: OriginFor<T>, enabled: bool) -> DispatchResult {
let _sender = ensure_root(origin)?;
<SlashingEnabled<T>>::put(enabled);
Expand All @@ -108,7 +109,7 @@ impl<T: Config> OnOffenceHandler<T::AccountId, IdentificationTuple<T>, Weight> f
_session: SessionIndex,
_disable_strategy: DisableStrategy,
) -> Weight {
let mut consumed_weight: Weight = 0;
let mut consumed_weight: Weight = Weight::from_ref_time(0);
let mut add_db_reads_writes = |reads, writes| {
consumed_weight += T::DbWeight::get().reads_writes(reads, writes);
};
Expand Down
Loading

0 comments on commit bbc1232

Please sign in to comment.