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

Update deposit precompile interfaces #1558

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
21 changes: 9 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ version = "6.6.4"
# crates.io
array-bytes = { version = "6.2" }
codec = { package = "parity-scale-codec", version = "3.6", default-features = false }
ethabi = { version = "18.0", default-features = false }
ethereum = { version = "0.15", default-features = false, features = ["with-codec"] }
libsecp256k1 = { version = "0.7", default-features = false }
log = { version = "0.4" }
Expand Down
2 changes: 1 addition & 1 deletion node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ where
network_provider: network.clone(),
is_validator: config.role.is_authority(),
enable_http_requests: false,
custom_extensions: move |_| vec![],
custom_extensions: move |_| Vec::new(),
})
.run(client.clone(), task_manager.spawn_handle())
.boxed(),
Expand Down
32 changes: 0 additions & 32 deletions pallet/account-migration/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,6 @@ mod benchmarks {
extra: Default::default(),
},
);
<Deposits<T>>::insert(
from,
vec![
Deposit {
id: Default::default(),
value: 1,
start_time: Default::default(),
expired_time: Default::default(),
in_use: Default::default(),
};
<T as darwinia_deposit::Config>::MaxDeposits::get() as usize
],
);
<Ledgers<T>>::insert(
from,
OldLedger {
staked_ring: 1,
staked_deposits: BoundedVec::truncate_from(vec![
Default::default();
<T as darwinia_deposit::Config>::MaxDeposits::get()
as usize
]),
unstaking_ring: BoundedVec::truncate_from(vec![
(
Default::default(),
Default::default()
);
16
]),
..Default::default()
},
);
}

#[benchmark]
Expand Down
80 changes: 47 additions & 33 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ mod weights;
pub use weights::WeightInfo;

// darwinia
use darwinia_deposit::Deposit;
use darwinia_staking::{migration::v2::OldLedger, Ledger};
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, Nonce};
use darwinia_deposit::{Deposit, DepositId};
use darwinia_staking::Ledger;
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, BlockNumber, Nonce};
// polkadot-sdk
use frame_support::{
migration,
Expand Down Expand Up @@ -108,7 +108,10 @@ pub mod pallet {
> + pallet_assets::Config<Balance = Balance, AssetId = AssetId>
+ pallet_balances::Config<Balance = Balance>
+ darwinia_deposit::Config
+ darwinia_staking::Config
+ darwinia_staking::Config<
Deposit = darwinia_deposit::Pallet<Self>,
MaxDeposits = ConstU32<512>,
>
{
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -161,7 +164,7 @@ pub mod pallet {
/// [`darwinia_staking::migration::v2::OldLedger`] data.
#[pallet::storage]
#[pallet::getter(fn ledger_of)]
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, OldLedger<T>>;
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, OldLedger>;

/// Multisig migration caches.
#[pallet::storage]
Expand Down Expand Up @@ -417,34 +420,34 @@ pub mod pallet {
asset_details,
);
}
}
if let Some(l) = <Ledgers<T>>::take(from) {
if l.staked_ring > 0 {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_staking::account_id(),
l.staked_ring,
AllowDeath,
)?;
}
if let Some(l) = <Ledgers<T>>::take(from) {
if l.staked_ring > 0 {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_staking::account_id(),
l.staked_ring,
AllowDeath,
)?;
}

if let Some(ds) = <Deposits<T>>::take(from) {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_deposit::account_id(),
ds.iter().map(|d| d.value).sum(),
AllowDeath,
)?;
<darwinia_deposit::Deposits<T>>::insert(
if let Some(ds) = <Deposits<T>>::take(from) {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_deposit::account_id(),
ds.iter().map(|d| d.value).sum(),
AllowDeath,
)?;
<darwinia_deposit::Deposits<T>>::insert(
to,
BoundedVec::try_from(ds).map_err(|_| <Error<T>>::ExceedMaxDeposits)?,
);
}

<darwinia_staking::Ledgers<T>>::insert(
to,
BoundedVec::try_from(ds).map_err(|_| <Error<T>>::ExceedMaxDeposits)?,
Ledger { ring: l.staked_ring, deposits: l.staked_deposits },
);
}

<darwinia_staking::Ledgers<T>>::insert(
to,
Ledger { ring: l.staked_ring, deposits: l.staked_deposits },
);
}

Ok(())
Expand All @@ -459,15 +462,15 @@ pub(crate) type Signature = [u8; 64];
// Copy from <https://github.dev/paritytech/substrate/blob/polkadot-v0.9.30/frame/assets/src/types.rs#L115>.
// Due to its visibility.
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub struct AssetAccount {
balance: Balance,
is_frozen: bool,
reason: ExistenceReason,
extra: (),
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) enum ExistenceReason {
#[codec(index = 0)]
Consumer,
Expand All @@ -479,7 +482,7 @@ pub(crate) enum ExistenceReason {
DepositRefunded,
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) struct AssetDetails {
owner: AccountId20,
issuer: AccountId20,
Expand All @@ -495,13 +498,24 @@ pub(crate) struct AssetDetails {
status: AssetStatus,
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) enum AssetStatus {
Live,
Frozen,
Destroying,
}

#[allow(missing_docs)]
#[derive(Default, PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub struct OldLedger {
pub staked_ring: Balance,
pub staked_kton: Balance,
pub staked_deposits: BoundedVec<DepositId, ConstU32<512>>,
pub unstaking_ring: BoundedVec<(Balance, BlockNumber), ConstU32<512>>,
pub unstaking_kton: BoundedVec<(Balance, BlockNumber), ConstU32<512>>,
pub unstaking_deposits: BoundedVec<(DepositId, BlockNumber), ConstU32<512>>,
}

#[allow(missing_docs)]
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct MultisigParams {
Expand Down
26 changes: 12 additions & 14 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use crate as darwinia_account_migration;
pub use dc_primitives::*;

// polkadot-sdk
Expand Down Expand Up @@ -125,30 +124,34 @@ frame_support::parameter_types! {
}

impl darwinia_deposit::Config for Runtime {
type DepositMigrator = ();
type Kton = Dummy;
type MaxDeposits = ();
type MaxDeposits = frame_support::traits::ConstU32<512>;
type MinLockingAmount = ();
type Ring = Balances;
type RuntimeEvent = RuntimeEvent;
type Treasury = ();
type WeightInfo = ();
}

impl darwinia_staking::Config for Runtime {
type Currency = Balances;
type Deposit = Deposit;
type IssuingManager = ();
type Kton = Dummy;
type KtonStakerNotifier = ();
type MaxDeposits = ();
type KtonStaking = ();
type MaxDeposits = frame_support::traits::ConstU32<512>;
type Ring = Dummy;
type RingStaking = ();
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = ();
type Treasury = ();
type UnixTime = Timestamp;
type WeightInfo = ();
}
#[cfg(not(feature = "runtime-benchmarks"))]
impl darwinia_staking::DepositConfig for Runtime {}

impl darwinia_account_migration::Config for Runtime {
impl crate::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
Expand All @@ -159,23 +162,18 @@ frame_support::construct_runtime! {
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Assets: pallet_assets,
AccountMigration: crate,
Deposit: darwinia_deposit,
Staking: darwinia_staking,
AccountMigration: darwinia_account_migration,
}
}

pub(crate) fn new_test_ext() -> TestExternalities {
let mut storage = <frame_system::GenesisConfig<Runtime>>::default().build_storage().unwrap();

pallet_assets::GenesisConfig::<Runtime> {
assets: vec![(darwinia_account_migration::KTON_ID, [0; 20].into(), true, 1)],
metadata: vec![(
darwinia_account_migration::KTON_ID,
b"KTON".to_vec(),
b"KTON".to_vec(),
18,
)],
assets: vec![(crate::KTON_ID, [0; 20].into(), true, 1)],
metadata: vec![(crate::KTON_ID, b"KTON".to_vec(), b"KTON".to_vec(), 18)],
..Default::default()
}
.assimilate_storage(&mut storage)
Expand Down
Loading