Skip to content

Commit 6b71e94

Browse files
Merge pull request #23 from paritytech/bko-on-dm-upgrade-polkadot-sdk
Upgrade polkadot sdk - NoCurrency + other nits
2 parents 9431522 + 2b010c8 commit 6b71e94

File tree

16 files changed

+210
-14
lines changed

16 files changed

+210
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
# direnv files
1010
.envrc
1111
.direnv
12+
.idea

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository = "https://github.com/zdave-parity/polkadot-bulletin-chain.git"
77
resolver = "2"
88
members = [
99
"node",
10+
"pallets/common",
1011
"pallets/relayer-set",
1112
"pallets/transaction-storage",
1213
"pallets/validator-set",

pallets/common/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "pallets-common"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2021"
6+
license = "Apache-2.0"
7+
description = "Common utilities for pallets and/or runtime"
8+
repository.workspace = true
9+
10+
[package.metadata.docs.rs]
11+
targets = ["x86_64-unknown-linux-gnu"]
12+
13+
[dependencies]
14+
codec = { package = "parity-scale-codec", version = "3.7.5", default-features = false }
15+
log = "0.4.17"
16+
scale-info = { version = "2.11.6", default-features = false, features = ["derive"] }
17+
18+
polkadot-sdk-frame = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "436b4935b52562f79a83b6ecadeac7dcbc1c2367", default-features = false, features = [
19+
"experimental",
20+
"runtime",
21+
] }
22+
23+
[features]
24+
default = ["std"]
25+
runtime-benchmarks = [
26+
"polkadot-sdk-frame/runtime-benchmarks"
27+
]
28+
std = [
29+
"codec/std",
30+
"scale-info/std",
31+
"polkadot-sdk-frame/std"
32+
]
33+
try-runtime = [
34+
"polkadot-sdk-frame/try-runtime"
35+
]

pallets/common/src/lib.rs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#![cfg_attr(not(feature = "std"), no_std)]
17+
18+
use codec::{Decode, Encode};
19+
use polkadot_sdk_frame::prelude::{
20+
fungible::{Dust, Inspect, InspectHold, MutateHold, Unbalanced, UnbalancedHold},
21+
DepositConsequence, DispatchError, DispatchResult, Fortitude, Preservation, Provenance,
22+
WithdrawConsequence, Zero,
23+
};
24+
use scale_info::TypeInfo;
25+
26+
/// Fungible currency implementation that does not support any balance operations.
27+
/// Works only with zero balances.
28+
///
29+
/// Note: This is a workaround to satisfy the `pallet-session::Config::Currency` trait requirements.
30+
pub struct NoCurrency<AccountId, HoldReason>(core::marker::PhantomData<(AccountId, HoldReason)>);
31+
32+
impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> Inspect<AccountId>
33+
for NoCurrency<AccountId, HoldReason>
34+
{
35+
type Balance = u128;
36+
37+
fn total_issuance() -> Self::Balance {
38+
Zero::zero()
39+
}
40+
41+
fn minimum_balance() -> Self::Balance {
42+
Zero::zero()
43+
}
44+
45+
fn total_balance(_who: &AccountId) -> Self::Balance {
46+
Zero::zero()
47+
}
48+
49+
fn balance(_who: &AccountId) -> Self::Balance {
50+
Zero::zero()
51+
}
52+
53+
fn reducible_balance(
54+
_who: &AccountId,
55+
_preservation: Preservation,
56+
_force: Fortitude,
57+
) -> Self::Balance {
58+
Zero::zero()
59+
}
60+
61+
fn can_deposit(
62+
_who: &AccountId,
63+
_amount: Self::Balance,
64+
_provenance: Provenance,
65+
) -> DepositConsequence {
66+
DepositConsequence::Success
67+
}
68+
69+
fn can_withdraw(
70+
_who: &AccountId,
71+
_amount: Self::Balance,
72+
) -> WithdrawConsequence<Self::Balance> {
73+
WithdrawConsequence::Success
74+
}
75+
}
76+
77+
impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> Unbalanced<AccountId>
78+
for NoCurrency<AccountId, HoldReason>
79+
{
80+
fn handle_dust(_dust: Dust<AccountId, Self>) {}
81+
82+
fn write_balance(
83+
_who: &AccountId,
84+
_amount: Self::Balance,
85+
) -> Result<Option<Self::Balance>, DispatchError> {
86+
Ok(None)
87+
}
88+
89+
fn set_total_issuance(_amount: Self::Balance) {}
90+
}
91+
92+
impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> InspectHold<AccountId>
93+
for NoCurrency<AccountId, HoldReason>
94+
{
95+
type Reason = HoldReason;
96+
97+
fn total_balance_on_hold(_who: &AccountId) -> Self::Balance {
98+
Zero::zero()
99+
}
100+
101+
fn balance_on_hold(_reason: &Self::Reason, _who: &AccountId) -> Self::Balance {
102+
Zero::zero()
103+
}
104+
}
105+
106+
impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> UnbalancedHold<AccountId>
107+
for NoCurrency<AccountId, HoldReason>
108+
{
109+
fn set_balance_on_hold(
110+
_reason: &Self::Reason,
111+
_who: &AccountId,
112+
_amount: Self::Balance,
113+
) -> DispatchResult {
114+
Ok(())
115+
}
116+
}
117+
118+
impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> MutateHold<AccountId>
119+
for NoCurrency<AccountId, HoldReason>
120+
{
121+
}

pallets/relayer-set/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub mod pallet {
4646
#[pallet::config]
4747
pub trait Config: frame_system::Config {
4848
/// The overarching event type.
49+
#[allow(deprecated)]
4950
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
5051
/// Weight information for extrinsics in this pallet.
5152
type WeightInfo: WeightInfo;

pallets/transaction-storage/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub mod pallet {
147147
#[pallet::config]
148148
pub trait Config: frame_system::Config {
149149
/// The overarching event type.
150+
#[allow(deprecated)]
150151
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
151152
/// Weight information for extrinsics in this pallet.
152153
type WeightInfo: WeightInfo;

pallets/validator-set/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pallet-session = { git = "https://github.com/paritytech/polkadot-sdk.git", rev =
2121

2222
[dev-dependencies]
2323
serde = { version = "1.0.126", features = ["derive"] }
24+
pallets-common = { version = "0.1.0", default-features = false, path = "../common" }
2425

2526
[features]
2627
default = ['std']

pallets/validator-set/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub mod pallet {
7878
>
7979
{
8080
/// The overarching event type.
81+
#[allow(deprecated)]
8182
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
8283

8384
/// Weight information for extrinsics in this pallet.

pallets/validator-set/src/mock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ construct_runtime!(
3737
System: frame_system,
3838
ValidatorSet: pallet_validator_set,
3939
Session: pallet_session,
40+
Historical: pallet_session::historical,
4041
}
4142
);
4243

@@ -143,9 +144,14 @@ impl pallet_session::Config for Test {
143144
type Keys = MockSessionKeys;
144145
type WeightInfo = ();
145146
type RuntimeEvent = RuntimeEvent;
147+
type Currency = pallets_common::NoCurrency<AccountId, RuntimeHoldReason>;
148+
type KeyDeposit = ();
149+
// TODO: check this
150+
type DisablingStrategy = ();
146151
}
147152

148153
impl pallet_session::historical::Config for Test {
154+
type RuntimeEvent = RuntimeEvent;
149155
type FullIdentification = Self::ValidatorId;
150156
type FullIdentificationOf = Self::ValidatorIdOf;
151157
}

0 commit comments

Comments
 (0)