Skip to content
Merged
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
1,251 changes: 596 additions & 655 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/pink/pink-extension/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn patch_or_err(input: TokenStream2, config: TokenStream2) -> Result<TokenStream
});

let method_name = item_method.sig.ident.to_string();
let selector = Selector::new(method_name.as_bytes()).into_be_u32();
let selector = Selector::compute(method_name.as_bytes()).into_be_u32();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

let literal_selector = selector.hex_suffixed();

attrs.push(syn::parse_quote! {
Expand Down
1 change: 0 additions & 1 deletion crates/pink/pink-extension/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl Environment for PinkEnvironment {
type Hash = <ink_env::DefaultEnvironment as Environment>::Hash;
type BlockNumber = <ink_env::DefaultEnvironment as Environment>::BlockNumber;
type Timestamp = <ink_env::DefaultEnvironment as Environment>::Timestamp;
type RentFraction = <ink_env::DefaultEnvironment as Environment>::RentFraction;

type ChainExtension = <ink_env::DefaultEnvironment as Environment>::ChainExtension;
}
Expand Down
20 changes: 10 additions & 10 deletions pallets/bridge_transfer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ fn transfer() {
assert_eq!(Balances::free_balance(&bridge_id), ENDOWED_BALANCE - 10);
assert_eq!(Balances::free_balance(RELAYER_A), ENDOWED_BALANCE + 10);

assert_events(vec![Event::Balances(balances::Event::Transfer(
Bridge::account_id(),
RELAYER_A,
10,
))]);
assert_events(vec![Event::Balances(balances::Event::Transfer {
from: Bridge::account_id(),
to: RELAYER_A,
amount: 10,
})]);
})
}

Expand Down Expand Up @@ -499,11 +499,11 @@ fn create_successful_transfer_proposal() {
Event::Bridge(bridge::Event::VoteAgainst(src_id, prop_id, RELAYER_B)),
Event::Bridge(bridge::Event::VoteFor(src_id, prop_id, RELAYER_C)),
Event::Bridge(bridge::Event::ProposalApproved(src_id, prop_id)),
Event::Balances(balances::Event::Transfer(
Bridge::account_id(),
RELAYER_A,
10,
)),
Event::Balances(balances::Event::Transfer {
from: Bridge::account_id(),
to: RELAYER_A,
amount: 10,
}),
Event::Bridge(bridge::Event::ProposalSucceeded(src_id, prop_id)),
]);
})
Expand Down
8 changes: 6 additions & 2 deletions pallets/phala/src/ott.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ pub mod pallet {
assert_eq!(
take_events(),
vec![
TestEvent::Balances(pallet_balances::Event::Transfer(1, 2, 1 * DOLLARS)),
TestEvent::Balances(pallet_balances::Event::Transfer(1, 3, 1 * DOLLARS)),
TestEvent::Balances(pallet_balances::Event::Transfer {
from: 1, to: 2, amount: 1 * DOLLARS
}),
TestEvent::Balances(pallet_balances::Event::Transfer {
from: 1, to: 3, amount: 1 * DOLLARS
}),
TestEvent::PhalaOneshotTransfer(Event::AccountsBlacklisted(vec![2, 3, 1]))
]
);
Expand Down
82 changes: 53 additions & 29 deletions pallets/phala/src/stakepool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,9 +1831,13 @@ pub mod pallet {
assert_eq!(
ev,
vec![
TestEvent::Balances(pallet_balances::Event::Slashed(1, 50000000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 1, amount: 50000000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 1, 50000000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed(2, 200000000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 2, amount: 200000000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 2, 200000000000000))
]
);
Expand Down Expand Up @@ -1912,15 +1916,21 @@ pub mod pallet {
ev,
vec![
// Account1: ~25 PHA remaining
TestEvent::Balances(pallet_balances::Event::Slashed(1, 25000000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 1, amount: 25000000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 1, 25000000000000)),
TestEvent::PhalaStakePool(Event::Withdrawal(0, 1, 25000000000000)),
// Account2: ~100 PHA remaining
TestEvent::Balances(pallet_balances::Event::Slashed(2, 100000000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 2, amount: 100000000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 2, 100000000000000)),
TestEvent::PhalaStakePool(Event::Withdrawal(0, 2, 100000000000000)),
// Account1: ~125 PHA remaining
TestEvent::Balances(pallet_balances::Event::Slashed(3, 125000000000001)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 3, amount: 125000000000001
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 3, 125000000000001)),
TestEvent::PhalaStakePool(Event::Withdrawal(0, 3, 125000000000000))
]
Expand Down Expand Up @@ -1992,8 +2002,8 @@ pub mod pallet {
// Mined 500 PHA
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(500).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(500u32).to_bits(),
treasury: 0,
}]);
// Should result in 100, 400 PHA pending reward for staker1 & 2
Expand All @@ -2010,11 +2020,13 @@ pub mod pallet {
assert_eq!(
take_events().as_slice(),
[
TestEvent::Balances(pallet_balances::Event::<Test>::Transfer(
PhalaMining::account_id(),
1,
100 * DOLLARS
)),
TestEvent::Balances(
pallet_balances::Event::<Test>::Transfer {
from: PhalaMining::account_id(),
to: 1,
amount: 100 * DOLLARS
}
),
TestEvent::PhalaStakePool(Event::RewardsWithdrawn(0, 1, 100 * DOLLARS))
]
);
Expand All @@ -2027,8 +2039,8 @@ pub mod pallet {
// Mined 500 PHA
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(500).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(500u32).to_bits(),
treasury: 0,
}]);
// Should result in 100, 800 PHA pending reward for staker1 & 2
Expand Down Expand Up @@ -2059,8 +2071,8 @@ pub mod pallet {
// Mined 800 PHA
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(800).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(800u32).to_bits(),
treasury: 0,
}]);
assert_ok!(PhalaStakePool::claim_rewards(Origin::signed(1), 0, 1));
Expand Down Expand Up @@ -2117,7 +2129,7 @@ pub mod pallet {
// Inject 100 pico PHA payout to trigger dust removal (99 after convering to fp)
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: 100u128.to_fixed().to_bits(),
treasury: 0,
}]);
Expand All @@ -2141,8 +2153,8 @@ pub mod pallet {
let _ = take_events();
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(500).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(500u32).to_bits(),
treasury: 0,
}]);
let ev = take_events();
Expand All @@ -2162,8 +2174,8 @@ pub mod pallet {
let _ = take_events();
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(500).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(500u32).to_bits(),
treasury: 0,
}]);
let ev = take_events();
Expand Down Expand Up @@ -2191,8 +2203,8 @@ pub mod pallet {
));
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(500).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(500u32).to_bits(),
treasury: 0,
}]);
assert_ok!(Balances::set_balance(
Expand Down Expand Up @@ -2360,11 +2372,15 @@ pub mod pallet {
[
TestEvent::PhalaStakePool(Event::PoolSlashed(0, 100 * DOLLARS)),
// Staker 2 got 75% * 99 PHA back
TestEvent::Balances(pallet_balances::Event::Slashed(2, 99_750000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 2, amount: 99_750000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 2, 99_750000000000)),
TestEvent::PhalaStakePool(Event::Withdrawal(0, 2, 74_250000000000)),
// Staker 1 got 75% * 1 PHA back
TestEvent::Balances(pallet_balances::Event::Slashed(1, 250000000000)),
TestEvent::Balances(pallet_balances::Event::Slashed {
who: 1, amount: 250000000000
}),
TestEvent::PhalaStakePool(Event::SlashSettled(0, 1, 250000000000)),
TestEvent::PhalaStakePool(Event::Withdrawal(0, 1, 750000000000)),
]
Expand Down Expand Up @@ -2557,8 +2573,8 @@ pub mod pallet {
// Mined 100 PHA
PhalaStakePool::on_reward(&vec![SettleInfo {
pubkey: worker_pubkey(1),
v: FixedPoint::from_num(1).to_bits(),
payout: FixedPoint::from_num(100).to_bits(),
v: FixedPoint::from_num(1u32).to_bits(),
payout: FixedPoint::from_num(100u32).to_bits(),
treasury: 0,
}]);
// Both owner and staker2 can claim 50 PHA
Expand All @@ -2569,9 +2585,17 @@ pub mod pallet {
assert_matches!(
ev.as_slice(),
[
TestEvent::Balances(pallet_balances::Event::Transfer(_, 1, 50000000000000)),
TestEvent::Balances(
pallet_balances::Event::Transfer {
from: _, to: 1, amount: 50000000000000
}
),
TestEvent::PhalaStakePool(Event::RewardsWithdrawn(0, 1, 50000000000000)),
TestEvent::Balances(pallet_balances::Event::Transfer(_, 2, 49999999999999)),
TestEvent::Balances(
pallet_balances::Event::Transfer {
from: _, to: 2, amount: 49999999999999
}
),
TestEvent::PhalaStakePool(Event::RewardsWithdrawn(0, 2, 49999999999999))
]
);
Expand Down
2 changes: 1 addition & 1 deletion pallets/utility/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-utility"
version = "4.0.0-dev"
version = "4.0.0-phala-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
22 changes: 15 additions & 7 deletions pallets/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event {
/// Batch of dispatches did not complete fully. Index of first failing dispatch given, as
/// well as the error. \[index, error\]
BatchInterrupted(u32, DispatchError),
/// well as the error.
BatchInterrupted { index: u32, error: DispatchError },
/// Batch of dispatches completed fully with no error.
BatchCompleted,
/// Batch of dispatches complete but has errors. Index of failing dispatches.
BatchCompletedWithErrors(Vec<u32>),
BatchCompletedWithErrors { indexes: Vec<u32> },
/// A single item within a Batch of dispatches has completed with no error.
ItemCompleted,
/// A single item within a Batch of dispatches has completed with error.
ItemFailed(u32, DispatchError),
ItemFailed { index: u32, error: DispatchError },
/// A call was dispatched. \[result\]
DispatchedAs(DispatchResult),
}
Expand Down Expand Up @@ -221,7 +221,10 @@ pub mod pallet {
// Add the weight of this call.
weight = weight.saturating_add(extract_actual_weight(&result, &info));
if let Err(e) = result {
Self::deposit_event(Event::BatchInterrupted(index as u32, e.error));
Self::deposit_event(Event::BatchInterrupted {
index: index as u32,
error: e.error,
});
// Take the weight of this function itself into account.
let base_weight = T::WeightInfo::batch(index.saturating_add(1) as u32);
// Return the actual used weight + base_weight of this call.
Expand Down Expand Up @@ -441,13 +444,18 @@ pub mod pallet {
weight = weight.saturating_add(extract_actual_weight(&result, &info));
if let Err(e) = result {
error_indexes.push(index as u32);
Self::deposit_event(Event::ItemFailed(index as u32, e.error));
Self::deposit_event(Event::ItemFailed {
index: index as u32,
error: e.error,
});
} else {
Self::deposit_event(Event::ItemCompleted);
}
}
if error_indexes.len() > 0 {
Self::deposit_event(Event::BatchCompletedWithErrors(error_indexes));
Self::deposit_event(Event::BatchCompletedWithErrors {
indexes: error_indexes
});
} else {
Self::deposit_event(Event::BatchCompleted);
}
Expand Down
27 changes: 20 additions & 7 deletions pallets/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ fn batch_with_signed_filters() {
vec![Call::Balances(pallet_balances::Call::transfer_keep_alive { dest: 2, value: 1 })]
),);
System::assert_last_event(
utility::Event::BatchInterrupted(0, frame_system::Error::<Test>::CallFiltered.into())
.into(),
utility::Event::BatchInterrupted {
index: 0,
error: frame_system::Error::<Test>::CallFiltered.into(),
}.into(),
);
});
}
Expand Down Expand Up @@ -411,7 +413,10 @@ fn batch_handles_weight_refund() {
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
System::assert_last_event(
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
utility::Event::BatchInterrupted {
index: 1,
error: DispatchError::Other("")
}.into(),
);
// No weight is refunded
assert_eq!(extract_actual_weight(&result, &info), info.weight);
Expand All @@ -426,7 +431,10 @@ fn batch_handles_weight_refund() {
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
System::assert_last_event(
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
utility::Event::BatchInterrupted {
index: 1,
error: DispatchError::Other(""),
}.into(),
);
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);

Expand All @@ -439,7 +447,10 @@ fn batch_handles_weight_refund() {
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
System::assert_last_event(
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
utility::Event::BatchInterrupted {
index: 1,
error: DispatchError::Other(""),
}.into(),
);
assert_eq!(
extract_actual_weight(&result, &info),
Expand Down Expand Up @@ -587,8 +598,10 @@ fn batch_all_does_not_nest() {
// and balances.
assert_ok!(Utility::batch_all(Origin::signed(1), vec![batch_nested]));
System::assert_has_event(
utility::Event::BatchInterrupted(0, frame_system::Error::<Test>::CallFiltered.into())
.into(),
utility::Event::BatchInterrupted {
index: 0,
error: frame_system::Error::<Test>::CallFiltered.into(),
}.into(),
);
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
Expand Down
2 changes: 1 addition & 1 deletion standalone/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ frame-benchmarking-cli = { optional = true, path = "../../substrate/utils/frame/
node-inspect = { optional = true, path = "../../substrate/bin/node/inspect" }
try-runtime-cli = { optional = true, path = "../../substrate/utils/frame/try-runtime/cli" }

[target.'cfg(target_arch="x86_64")'.dependencies]
[target.'cfg(any(target_arch="x86_64", target_arch="aarch64"))'.dependencies]
node-executor = { path = "../executor", features = ["wasmtime"] }
sc-cli = { optional = true, path = "../../substrate/client/cli", features = ["wasmtime"] }
sc-service = { default-features = false, path = "../../substrate/client/service", features = ["wasmtime"] }
Expand Down
Loading