Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polkadot update v0.9.42 #322

Merged
merged 18 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,519 changes: 1,536 additions & 983 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions balances-tx-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ pallet-encointer-balances = { path = "../balances", default-features = false }
pallet-encointer-ceremonies = { path = "../ceremonies", default-features = false }

# substrate dependencies
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
pallet-asset-tx-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
pallet-transaction-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }

frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
pallet-asset-tx-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
pallet-transaction-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }

[dev-dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
rstest = "0.12.0"
scale-info = { version = "2.0.1", default-features = false }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
test-utils = { path = "../test-utils" }

[features]
Expand All @@ -43,6 +44,4 @@ std = [
"sp-runtime/std",
]

try-runtime = [
"frame-system/try-runtime",
]
try-runtime = ["frame-system/try-runtime"]
24 changes: 14 additions & 10 deletions balances-tx-payment/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ version = "1.0.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
jsonrpsee = { version = "0.16.2", features = ["client-core", "server", "macros"] }
jsonrpsee = { version = "0.16.2", features = [
"client-core",
"server",
"macros",
] }
log = "0.4.14"
parking_lot = "0.12.0"
thiserror = "1.0.31"
Expand All @@ -17,12 +21,12 @@ encointer-primitives = { path = "../../primitives" }
encointer-rpc = { path = "../../rpc" }

# substrate deps
pallet-transaction-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.37" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-rpc = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-transaction-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.42" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-rpc = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
10 changes: 6 additions & 4 deletions balances-tx-payment/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ edition = "2021"
encointer-primitives = { path = "../../../primitives", default-features = false }

# substrate deps
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

[features]
default = ["std"]
Expand Down
15 changes: 6 additions & 9 deletions balances-tx-payment/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use sp_api::{Decode, Encode, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_core::Bytes;
use sp_rpc::number::NumberOrHex;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, MaybeDisplay},
};
use sp_runtime::traits::{Block as BlockT, MaybeDisplay};
use std::sync::Arc;

#[rpc(client, server)]
Expand Down Expand Up @@ -91,7 +88,7 @@ where
at: Option<Block::Hash>,
) -> RpcResult<FeeDetails<NumberOrHex>> {
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));
let at = at.unwrap_or_else(|| self.client.info().best_hash);

let encoded_len = encoded_xt.len() as u32;

Expand All @@ -102,7 +99,7 @@ where
Some(format!("{e:?}")),
))
})?;
let fee_details = api.query_fee_details(&at, uxt, encoded_len).map_err(|e| {
let fee_details = api.query_fee_details(at, uxt, encoded_len).map_err(|e| {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
"Unable to query fee details.",
Expand All @@ -123,7 +120,7 @@ where
Ok(FeeDetails {
inclusion_fee: if let Some(inclusion_fee) = fee_details.inclusion_fee {
let base_fee = api
.balance_to_asset_balance(&at, inclusion_fee.base_fee, asset_id)
.balance_to_asset_balance(at, inclusion_fee.base_fee, asset_id)
.map_err(|e| {
runtime_api_error_into_rpc_error(e, "Unable to query fee details")
})?
Expand All @@ -132,7 +129,7 @@ where
})?;

let len_fee = api
.balance_to_asset_balance(&at, inclusion_fee.len_fee, asset_id)
.balance_to_asset_balance(at, inclusion_fee.len_fee, asset_id)
.map_err(|e| {
runtime_api_error_into_rpc_error(e, "Unable to query fee details")
})?
Expand All @@ -141,7 +138,7 @@ where
})?;

let adjusted_weight_fee = api
.balance_to_asset_balance(&at, inclusion_fee.adjusted_weight_fee, asset_id)
.balance_to_asset_balance(at, inclusion_fee.adjusted_weight_fee, asset_id)
.map_err(|e| {
runtime_api_error_into_rpc_error(e, "Unable to query fee details")
})?
Expand Down
4 changes: 2 additions & 2 deletions balances-tx-payment/src/balance_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::{AssetBalanceOf, AssetIdOf, BalanceOf};
use core::marker::PhantomData;
use encointer_primitives::{balances::EncointerBalanceConverter, communities::CommunityIdentifier};
use frame_support::traits::tokens::BalanceConversion;
use frame_support::traits::tokens::ConversionToAssetBalance;
use pallet_encointer_balances::Pallet as BalancesPallet;
use pallet_encointer_ceremonies::{Config as CeremoniesConfig, Pallet as CeremoniesPallet};
use sp_runtime::traits::Convert;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn apply_fee_conversion_factor(

pub struct BalanceToCommunityBalance<T>(PhantomData<T>);

impl<T> BalanceConversion<BalanceOf<T>, AssetIdOf<T>, AssetBalanceOf<T>>
impl<T> ConversionToAssetBalance<BalanceOf<T>, AssetIdOf<T>, AssetBalanceOf<T>>
for BalanceToCommunityBalance<T>
where
T: CeremoniesConfig + pallet_asset_tx_payment::Config,
Expand Down
4 changes: 3 additions & 1 deletion balances-tx-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ impl<T> HandleCredit<<T as frame_system::Config>::AccountId, pallet_encointer_ba
for BurnCredit
where
T: frame_system::Config + pallet_encointer_balances::Config,
pallet_encointer_balances::Pallet<T>:
frame_support::traits::fungibles::Balanced<<T as frame_system::Config>::AccountId>,
{
fn handle_credit(
_credit: fungibles::CreditOf<AccountIdOf<T>, pallet_encointer_balances::Pallet<T>>,
_credit: fungibles::Credit<AccountIdOf<T>, pallet_encointer_balances::Pallet<T>>,
) {
// just doing nothing with the credit, will use the default implementation
// of fungibles an decrease total issuance.
Expand Down
29 changes: 15 additions & 14 deletions balances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
[package]
name = "pallet-encointer-balances"
version = "1.2.0"
authors = ["encointer.org <[email protected]> and Parity Technologies <[email protected]>"]
authors = [
"encointer.org <[email protected]> and Parity Technologies <[email protected]>",
]
edition = "2021"

[dependencies]
approx = { version = "0.5.1", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.0.1", default-features = false }

# local deps
encointer-primitives = { path = "../primitives", default-features = false }

# substrate deps
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-asset-tx-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-asset-tx-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

[dev-dependencies]
approx = "0.5.1"
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
test-utils = { path = "../test-utils" }

[features]
Expand All @@ -47,6 +50,4 @@ std = [

runtime-benchmarks = ["frame-benchmarking", "approx"]

try-runtime = [
"frame-system/try-runtime",
]
try-runtime = ["frame-system/try-runtime"]
57 changes: 24 additions & 33 deletions balances/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,13 @@
// along with Encointer. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use encointer_primitives::{balances::EncointerBalanceConverter, common::UnboundedPalletString};
use frame_support::{
inherent::Vec,
traits::tokens::{DepositConsequence, WithdrawConsequence},
};
use crate::fungibles::{DecreaseIssuance, IncreaseIssuance};
use encointer_primitives::balances::EncointerBalanceConverter;
use sp_runtime::traits::{Convert, Zero};

// Implementation of this trait is just to satisfy the trait bounds of the
// `pallet-asset-tx-payment`. It is not used in our case.
impl<T: Config> fungibles::InspectMetadata<T::AccountId> for Pallet<T> {
fn name(_asset: &Self::AssetId) -> Vec<u8> {
UnboundedPalletString::from("Encointer").into()
}

fn symbol(_asset: &Self::AssetId) -> Vec<u8> {
UnboundedPalletString::from("ETR").into()
}

fn decimals(_asset: &Self::AssetId) -> u8 {
// Our BalanceType is I64F64 which is base2 fixpoint and therefore doesn't use decimals (which would be base10 fixpoint)
// but in order to comply with this trait we need to define decimals nevertheless.
// the smallest possible number is 2^-64 = 5.42101086242752217003726400434970855712890625 × 10^-20
// and an upper bound is 2^63 + 1 = 9.223372036854775809 × 10^18
// so we chose 18 decimals and lose some precision but can prevent overflows that way.
// due to demurrage, that lost precision is meaningless anyway
18u8
}
}
pub use frame_support::traits::tokens::{
DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence,
};

pub(crate) fn fungible(balance: BalanceType) -> u128 {
EncointerBalanceConverter::convert(balance)
Expand Down Expand Up @@ -72,10 +51,15 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
fungible(Pallet::<T>::balance(asset, who))
}

fn total_balance(asset: Self::AssetId, who: &T::AccountId) -> Self::Balance {
fungible(Pallet::<T>::balance(asset, who))
}

fn reducible_balance(
asset: Self::AssetId,
who: &T::AccountId,
_keep_alive: bool,
_preservation: Preservation,
_force: Fortitude,
) -> Self::Balance {
fungible(Pallet::<T>::balance(asset, who))
}
Expand All @@ -84,7 +68,7 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
asset: Self::AssetId,
who: &T::AccountId,
amount: Self::Balance,
_mint: bool,
_provenance: Provenance,
) -> DepositConsequence {
if !<TotalIssuance<T>>::contains_key(asset) {
return DepositConsequence::UnknownAsset
Expand Down Expand Up @@ -129,25 +113,25 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
let balance = fungible(Pallet::<T>::balance(asset, who));

if balance.checked_sub(amount).is_none() {
return NoFunds
return WithdrawConsequence::BalanceLow
}
Success
WithdrawConsequence::Success
}
}

impl<T: Config> fungibles::Unbalanced<T::AccountId> for Pallet<T> {
fn set_balance(
fn write_balance(
asset: Self::AssetId,
who: &T::AccountId,
amount: Self::Balance,
) -> DispatchResult {
) -> Result<Option<Self::Balance>, DispatchError> {
let current_block = frame_system::Pallet::<T>::block_number();
<Balance<T>>::insert(
asset,
who,
BalanceEntry { principal: balance_type(amount), last_update: current_block },
);
Ok(())
Ok(Some(amount))
}

fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance) {
Expand All @@ -157,4 +141,11 @@ impl<T: Config> fungibles::Unbalanced<T::AccountId> for Pallet<T> {
BalanceEntry { principal: balance_type(amount), last_update: current_block },
);
}

fn handle_dust(_dust: fungibles::Dust<T::AccountId, Self>) {}
}

impl<T: Config> fungibles::Balanced<T::AccountId> for Pallet<T> {
type OnDropDebt = IncreaseIssuance<T::AccountId, Self>;
type OnDropCredit = DecreaseIssuance<T::AccountId, Self>;
}
1 change: 0 additions & 1 deletion balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
Expand Down
2 changes: 1 addition & 1 deletion balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ frame_support::construct_runtime!(
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EncointerScheduler: encointer_scheduler::{Pallet, Call, Storage, Config<T>, Event},
EncointerBalances: dut::{Pallet, Call, Storage, Event<T>},
EncointerBalances: dut::{Pallet, Call, Storage, Event<T>, Config},
}
);

Expand Down
Loading