Skip to content

Commit

Permalink
Merge pull request #26 from octopus-network/v2.3.1
Browse files Browse the repository at this point in the history
Upgrade to v2.3.1
  • Loading branch information
riversyang authored Nov 4, 2022
2 parents 7180969 + eb826c7 commit 7ee325d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "appchain-anchor-wrapper"
version = "2.3.0"
version = "2.3.1"
authors = ["Octopus Network"]
edition = "2021"

Expand All @@ -24,7 +24,7 @@ mock-appchain-registry = { path = "./mock-appchain-registry" }
mock-oct-token = { path = "./mock-oct-token" }
wrapped-appchain-token = { git = "https://github.com/octopus-network/wrapped-appchain-token.git", branch = "v2.0.0" }
wrapped-appchain-nft = { git = "https://github.com/octopus-network/wrapped-appchain-nft.git", branch = "main" }
octopus-council = { git = "https://github.com/octopus-network/octopus-dao", branch = "v0.2.0" }
octopus-council = { git = "https://github.com/octopus-network/octopus-dao", branch = "main" }
tokio = { version = "1.14", features = ["full"] }
workspaces = "0.4"

Expand Down
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 = "2.3.0"
version = "2.3.1"
authors = ["Octopus Network"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions appchain-anchor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 = "v2.3.0";
const ANCHOR_VERSION: &str = "v2.3.1";
/// Constants for gas.
const T_GAS_FOR_FT_TRANSFER: u64 = 10;
const T_GAS_FOR_BURN_FUNGIBLE_TOKEN: u64 = 10;
Expand All @@ -62,7 +62,7 @@ const T_GAS_FOR_NFT_TRANSFER: u64 = 10;
const T_GAS_FOR_MINT_NFT: u64 = 10;
const T_GAS_FOR_RESOLVER_FUNCTION: u64 = 10;
const T_GAS_FOR_SYNC_STATE_TO_REGISTRY: u64 = 10;
const T_GAS_CAP_FOR_MULTI_TXS_PROCESSING: u64 = 150;
const T_GAS_CAP_FOR_MULTI_TXS_PROCESSING: u64 = 130;
const T_GAS_CAP_FOR_PROCESSING_APPCHAIN_MESSAGES: u64 = 240;
const T_GAS_FOR_NFT_CONTRACT_INITIALIZATION: u64 = 50;
const T_GAS_FOR_REGISTER_VALIDATOR: u64 = 100;
Expand Down
22 changes: 22 additions & 0 deletions appchain-anchor/src/user_actions/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ impl AppchainAnchor {
serde_json::to_string(&self.appchain_state).unwrap()
),
};
assert!(
!delegator_id.eq(&validator_id),
"You can not delegate to yourself."
);
let mut next_validator_set = self.next_validator_set.get().unwrap();
self.assert_validator_id(&validator_id, &next_validator_set);
assert!(
Expand Down Expand Up @@ -688,9 +692,27 @@ impl StakingManager for AppchainAnchor {
};
let mut next_validator_set = self.next_validator_set.get().unwrap();
let delegator_id = env::predecessor_account_id();
assert!(
!delegator_id.eq(&new_validator_id),
"You can not delegate to yourself."
);
self.assert_delegator_id(&delegator_id, &old_validator_id, &next_validator_set);
self.assert_validator_id(&new_validator_id, &next_validator_set);
//
let delegator = next_validator_set
.get_delegator(&delegator_id, &old_validator_id)
.unwrap();
let new_validator = next_validator_set.get_validator(&new_validator_id).unwrap();
assert!(
new_validator.can_be_delegated_to,
"Validator '{}' cannot be delegated to.",
&new_validator_id
);
self.assert_validator_stake_is_valid(
new_validator.deposit_amount,
Some(new_validator.total_stake + delegator.deposit_amount),
);
//
let staking_history = self.record_staking_fact(StakingFact::DelegatedValidatorChanged {
delegator_id,
old_validator_id,
Expand Down
30 changes: 22 additions & 8 deletions appchain-anchor/src/validator_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,26 @@ impl ValidatorSet {
new_validator_id,
} => {
//
let delegator = self
let old_delegator = self
.delegators
.remove(&(delegator_id.clone(), old_validator_id.clone()))
.unwrap();
let new_delegator = Delegator {
delegator_id: delegator_id.clone(),
validator_id: new_validator_id.clone(),
registered_block_height: env::block_height(),
registered_timestamp: env::block_timestamp(),
deposit_amount: match self
.delegators
.get(&(delegator_id.clone(), new_validator_id.clone()))
{
Some(delegator) => old_delegator.deposit_amount + delegator.deposit_amount,
None => old_delegator.deposit_amount,
},
};
self.delegators.insert(
&(delegator_id.clone(), new_validator_id.clone()),
&Delegator {
delegator_id: delegator_id.clone(),
validator_id: new_validator_id.clone(),
registered_block_height: env::block_height(),
registered_timestamp: env::block_timestamp(),
deposit_amount: delegator.deposit_amount,
},
&new_delegator,
);
//
let mut delegator_id_set = self
Expand Down Expand Up @@ -431,6 +438,13 @@ impl ValidatorSet {
validator_id_set.insert(new_validator_id);
self.delegator_id_to_validator_id_set
.insert(delegator_id, &validator_id_set);
//
let mut old_validator = self.validators.get(&old_validator_id).unwrap();
old_validator.total_stake -= old_delegator.deposit_amount;
self.validators.insert(&old_validator_id, &old_validator);
let mut new_validator = self.validators.get(&new_validator_id).unwrap();
new_validator.total_stake += old_delegator.deposit_amount;
self.validators.insert(&new_validator_id, &new_validator);
}
}
}
Expand Down

0 comments on commit 7ee325d

Please sign in to comment.