Skip to content

Commit

Permalink
Remove some dangerous sudo functions.
Browse files Browse the repository at this point in the history
And fix testing code.
  • Loading branch information
riversyang committed Sep 8, 2022
1 parent 4d029a9 commit a620912
Show file tree
Hide file tree
Showing 19 changed files with 650 additions and 811 deletions.
1 change: 1 addition & 0 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 @@ -13,6 +13,7 @@ near-primitives = "0.5.0"
near-units = "0.2.0"
hex = "0.4.2"
num-format = "0.4.0"
parity-scale-codec = "2.0.0"
secp256k1-test = { package = "secp256k1", version = "0.20.3", features = ["rand-std", "recovery"] }
beefy-light-client = { git = "https://github.com/octopus-network/beefy-light-client.git", branch = "main" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
Expand Down
20 changes: 10 additions & 10 deletions appchain-anchor/src/appchain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ pub enum PayloadType {
#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
#[serde(crate = "near_sdk::serde")]
pub struct BurnAssetPayload {
token_id: String,
sender: String,
receiver_id: AccountId,
amount: u128,
pub token_id: String,
pub sender: String,
pub receiver_id: AccountId,
pub amount: u128,
}

#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
#[serde(crate = "near_sdk::serde")]
pub struct LockPayload {
sender: String,
receiver_id: AccountId,
amount: u128,
pub sender: String,
pub receiver_id: AccountId,
pub amount: u128,
}

#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
Expand Down Expand Up @@ -81,9 +81,9 @@ pub enum MessagePayload {

#[derive(Encode, Decode, Clone)]
pub struct RawMessage {
nonce: u64,
payload_type: PayloadType,
payload: Vec<u8>,
pub nonce: u64,
pub payload_type: PayloadType,
pub payload: Vec<u8>,
}

impl RawMessage {
Expand Down
50 changes: 0 additions & 50 deletions appchain-anchor/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ pub trait StakingManager {
pub trait SudoActions {
///
fn set_owner_pk(&mut self, public_key: PublicKey);
/// Apply a certain `AppchainMessage`
fn stage_appchain_message(&mut self, appchain_message: AppchainMessage);
///
fn stage_appchain_encoded_messages(&mut self, encoded_messages: Vec<u8>);
///
fn set_metadata_of_wrapped_appchain_token(&mut self, metadata: FungibleTokenMetadata);
///
Expand All @@ -344,38 +340,14 @@ pub trait SudoActions {
value: U128,
);
///
fn reset_validator_set_histories_to(
&mut self,
era_number: U64,
) -> MultiTxsOperationProcessingResult;
///
fn reset_staking_histories_to(&mut self, era_number: U64) -> MultiTxsOperationProcessingResult;
///
fn clear_user_staking_histories(&mut self) -> MultiTxsOperationProcessingResult;
///
fn regenerate_user_staking_histories(&mut self) -> MultiTxsOperationProcessingResult;
///
fn reset_next_validator_set_to(&mut self, era_number: U64)
-> MultiTxsOperationProcessingResult;
///
fn clear_appchain_notification_histories(&mut self) -> MultiTxsOperationProcessingResult;
///
fn reset_beefy_light_client(&mut self, initial_public_keys: Vec<String>);
///
fn clear_reward_distribution_records(&mut self, era_number: U64);
///
fn clear_unbonded_stakes(&mut self);
///
fn clear_unwithdrawn_rewards(&mut self, era_number: U64);
///
fn reset_validator_profiles_to(&mut self, era_number: U64);
///
fn pause_asset_transfer(&mut self);
///
fn resume_asset_transfer(&mut self);
///
fn remove_staking_history_at(&mut self, index: U64);
///
fn pause_rewards_withdrawal(&mut self);
///
fn resume_rewards_withdrawal(&mut self);
Expand All @@ -386,30 +358,8 @@ pub trait SudoActions {
account_id_in_appchain: String,
);
///
fn force_change_account_id_in_appchain_of_staking_history(
&mut self,
index: U64,
account_id_in_appchain: String,
);
///
fn remove_duplicated_message_nonces_in_reward_distribution_records(&mut self, era_number: U64);
///
fn set_latest_applied_appchain_message_nonce(&mut self, nonce: u32);
///
fn clear_appchain_messages(&mut self) -> MultiTxsOperationProcessingResult;
///
fn try_complete_switching_era(&mut self) -> MultiTxsOperationProcessingResult;
///
fn remove_validator_set_history_of(
&mut self,
era_number: U64,
) -> MultiTxsOperationProcessingResult;
///
fn remove_validator_set_histories_before(
&mut self,
era_number: U64,
) -> MultiTxsOperationProcessingResult;
///
fn unlock_auto_unbonded_stake_of(
&mut self,
delegator_id: Option<AccountId>,
Expand Down
2 changes: 1 addition & 1 deletion appchain-anchor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod anchor_viewer;
pub mod appchain_challenge;
mod appchain_messages;
pub mod appchain_messages;
mod assets;
pub mod interfaces;
mod lookup_array;
Expand Down
6 changes: 4 additions & 2 deletions appchain-anchor/src/permissionless_actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ impl PermissionlessActions for AppchainAnchor {
panic!("Failed in verifying appchain messages: {:?}", err);
}
}
let messages = Decode::decode(&mut &encoded_messages[..]).unwrap();
self.internal_stage_appchain_messages(&messages);
match Decode::decode(&mut &encoded_messages[..]) {
Ok(messages) => self.internal_stage_appchain_messages(&messages),
Err(err) => panic!("Failed to decode messages: {}", err),
}
}
//
fn process_appchain_messages(&mut self) -> MultiTxsOperationProcessingResult {
Expand Down
Loading

0 comments on commit a620912

Please sign in to comment.