Skip to content

Commit

Permalink
Merge pull request #13 from octopus-network/v1.2.1
Browse files Browse the repository at this point in the history
Fix bug in function `complete_switching_era`.
  • Loading branch information
riversyang authored Apr 20, 2022
2 parents 0fb820c + 6f231c6 commit 3a5337d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion appchain-anchor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "appchain-anchor"
version = "1.2.0"
version = "1.2.1"
authors = ["Octopus Network"]
edition = "2018"

Expand Down
2 changes: 2 additions & 0 deletions appchain-anchor/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ pub trait SudoActions {
fn set_latest_applied_appchain_message_nonce(&mut self, nonce: u32);
///
fn remove_appchain_messages_before(&mut self, nonce: u32);
///
fn try_complete_switching_era(&mut self) -> MultiTxsOperationProcessingResult;
}

pub trait ValidatorActions {
Expand Down
2 changes: 1 addition & 1 deletion appchain-anchor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use validator_set::ValidatorSetViewer;
register_custom_getrandom!(get_random_in_near);

/// Version of this contract (the same as in Cargo.toml)
const ANCHOR_VERSION: &str = "v1.2.0";
const ANCHOR_VERSION: &str = "v1.2.1";
/// Constants for gas.
const T_GAS: u64 = 1_000_000_000_000;
const GAS_FOR_FT_TRANSFER: u64 = 10 * T_GAS;
Expand Down
6 changes: 4 additions & 2 deletions appchain-anchor/src/permissionless_actions/switching_era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ impl AppchainAnchor {
)),
},
);
validator_set_histories.insert(&era_number, &validator_set);
MultiTxsOperationProcessingResult::Ok
} else {
validator_set.set_processing_status(
ValidatorSetProcessingStatus::ApplyingStakingHistory { applying_index },
);
validator_set_histories.insert(&era_number, &validator_set);
MultiTxsOperationProcessingResult::NeedMoreGas
}
validator_set_histories.insert(&era_number, &validator_set);
MultiTxsOperationProcessingResult::Ok
}
_ => MultiTxsOperationProcessingResult::Error(format!(
"Wrong processing status '{:?}' of validator set '{}'.",
Expand Down
20 changes: 20 additions & 0 deletions appchain-anchor/src/user_actions/sudo_actions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::permissionless_actions::AppchainMessagesProcessingContext;
use crate::*;
use crate::{interfaces::SudoActions, message_decoder::AppchainMessage};

Expand Down Expand Up @@ -288,4 +289,23 @@ impl SudoActions for AppchainAnchor {
appchain_messages.remove_messages_before(&nonce);
self.appchain_messages.set(&appchain_messages);
}
//
fn try_complete_switching_era(&mut self) -> MultiTxsOperationProcessingResult {
self.assert_owner();
let processing_status = self.permissionless_actions_status.get().unwrap();
let mut processing_context = AppchainMessagesProcessingContext::new(processing_status);
let mut validator_set_histories = self.validator_set_histories.get().unwrap();
if let Some(era_number) = processing_context.switching_era_number() {
let result = self.complete_switching_era(
&mut processing_context,
&mut validator_set_histories,
era_number,
);
self.permissionless_actions_status
.set(processing_context.processing_status());
result
} else {
MultiTxsOperationProcessingResult::Ok
}
}
}

0 comments on commit 3a5337d

Please sign in to comment.