Skip to content

Commit

Permalink
update barnard rollback height (#4360)
Browse files Browse the repository at this point in the history
* update barnard rollback height

* update barnard rollback height test

* update barnard rollback height test

* update force deploy extra transaction stdlib.blob

* revert commit

* fix check

* [force-deploy] change framework version to a9eaa8f97aa40d3ab19bfbe90fb720ac63268a613

* update starcoin_framework repo

* [force-deploy] fixed cargo fmt

* update starcoin_framework v12 stdlib.blob

* fix fmt

* [force-deploy] Added some modifications to the test flow in test_force_upgrade_1

* fix test_force_upgrade_1

* remove unused imports

---------

Co-authored-by: welbon <[email protected]>
Co-authored-by: simonjiao <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2024
1 parent ad2c6a0 commit d058b86
Show file tree
Hide file tree
Showing 21 changed files with 135 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev
starcoin-decrypt = { path = "commons/decrypt" }
starcoin-dev = { path = "vm/dev" }
starcoin-executor = { path = "executor" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "3e879a168036dceaa60c57c8e2b9228283476f81" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "9eaa8f97aa40d3ab19bfbe90fb720ac63268a613" }
starcoin-genesis = { path = "genesis" }
starcoin-logger = { path = "commons/logger" }
starcoin-metrics = { path = "commons/metrics" }
Expand Down
89 changes: 78 additions & 11 deletions chain/tests/test_force_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use std::str::FromStr;
use std::sync::Arc;

use anyhow::format_err;

use starcoin_accumulator::Accumulator;
use starcoin_chain_api::{ChainReader, ChainWriter};
use starcoin_config::NodeConfig;
use starcoin_consensus::Consensus;
use starcoin_statedb::ChainStateDB;
use starcoin_transaction_builder::{build_transfer_from_association, DEFAULT_EXPIRATION_TIME};
use starcoin_transaction_builder::{
build_burn_illegal_stc_txn_with_association, build_transfer_from_association,
DEFAULT_EXPIRATION_TIME,
};
use starcoin_types::account_address::AccountAddress;
use starcoin_vm_runtime::force_upgrade_management::get_force_upgrade_block_number;
use starcoin_vm_types::on_chain_config::Version;
use starcoin_vm_types::{account_config, state_view::StateReaderExt};
use std::str::FromStr;
use std::sync::Arc;
use test_helper::executor::get_balance;

#[stest::test]
Expand Down Expand Up @@ -130,23 +135,79 @@ pub fn test_force_upgrade_1() -> anyhow::Result<()> {
let txns_num = txns_num + 2;
assert_eq!(miner.get_txn_accumulator().num_leaves(), txns_num);

let black1_balance = get_balance(black1, miner.chain_state());
println!("Black 1 balance is: {:?}", black1_balance);
assert_eq!(
get_balance(black1, miner.chain_state()),
0,
"Upgrade Failed, Balance of black list account not 0"
black1_balance,
initial_balance + 1,
"Force-Upgrading Failed, Balance of black-1 account changed!"
);

let black2_balance = get_balance(black2, miner.chain_state());
println!("Black 2 balance is: {:?}", black2_balance);
assert_eq!(
get_balance(black2, miner.chain_state()),
0,
"Upgrade Failed, Balance of black list account not 0"
black2_balance,
initial_balance + 2,
"Force-upgrading Failed, Balance of black-2 account changed!"
);

assert_eq!(get_balance(rand3, miner.chain_state()), initial_balance + 3);

block2
};

// Apply block number 3, this will call StdlibUpgrade::burn_illegal_token_from_frozen_address
{
let burn_black_txn_1 = build_burn_illegal_stc_txn_with_association(
&black1,
association_sequence_num + 4,
initial_balance + 1,
config.net(),
);
let burn_black_txn_2 = build_burn_illegal_stc_txn_with_association(
&black2,
association_sequence_num + 5,
initial_balance + 2,
config.net(),
);

let (block_template, _excluded) = miner
.create_block_template(
account_config::association_address(),
None,
vec![burn_black_txn_1, burn_black_txn_2],
vec![],
Some(block_gas_limit),
)
.unwrap();

let block3 = miner
.consensus()
.create_block(block_template, miner.time_service().as_ref())?;

miner.apply(block3.clone())?;

// 1 meta + 3 txns = 4 txns
//let txns_num = txns_num + 3;
//let leaves_num = miner.get_txn_accumulator().num_leaves();
//assert_eq!(leaves_num, txns_num);

let black1_balance = get_balance(black1, miner.chain_state());
println!("Black 1 balance is: {:?}", black1_balance);
assert_eq!(
black1_balance, 0,
"Burning Failed, Balance of black-1 account is not 0"
);

let black2_balance = get_balance(black2, miner.chain_state());
println!("Black 2 balance is: {:?}", black2_balance);
assert_eq!(
black2_balance, 0,
"Burning Failed, Balance of black-2 account is not 0"
);
block3
};

// apply block number 2 to another chain
{
// !!!non-zero balance
Expand All @@ -160,8 +221,14 @@ pub fn test_force_upgrade_1() -> anyhow::Result<()> {
let txns_num = txns_num + 2;
assert_eq!(chain_to_apply.get_txn_accumulator().num_leaves(), txns_num);

assert_eq!(get_balance(black1, chain_to_apply.chain_state()), 0);
assert_eq!(get_balance(black2, chain_to_apply.chain_state()), 0);
assert_eq!(
get_balance(black1, chain_to_apply.chain_state()),
initial_balance + 1
);
assert_eq!(
get_balance(black2, chain_to_apply.chain_state()),
initial_balance + 2
);
assert_eq!(
get_balance(rand3, chain_to_apply.chain_state()),
initial_balance + 3
Expand Down
4 changes: 2 additions & 2 deletions network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::ops::RangeInclusive;
use std::sync::Arc;

const BARNARD_HARD_FORK_PEER_VERSION_STRING_PREFIX: &str = "barnard_rollback_block_fix";
const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 13, 11];
const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 13, 12];

pub struct NetworkActorService {
/// Worker and inner have ChainInfo instances separately. There might be some way to solve the problem.
Expand Down Expand Up @@ -930,7 +930,7 @@ mod test {
assert!(!greater_barnard_fork_version(&v3));
let v4 = String::from("starcoin/1.12.9 (build:v1.12.9) (kele01)");
assert!(!greater_barnard_fork_version(&v4));
let v5 = String::from("starcoin/1.13.12 (build:v1.13.12-alpha) (kele01)");
let v5 = String::from("starcoin/1.13.13 (build:v1.13.13-alpha) (kele01)");
assert!(greater_barnard_fork_version(&v5));
}
}
4 changes: 2 additions & 2 deletions storage/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::cmp::Ordering;

pub struct DBUpgrade;

pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16057000;
pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16080000;
pub static BARNARD_HARD_FORK_HASH: Lazy<HashValue> = Lazy::new(|| {
HashValue::from_hex_literal(
"0x1dd5987fa3b8bffad60f7a7756e73acd7b6808fed5a174200bf49e9f5de2d073",
"0x2dd593a9ac3e44d4a70423d39ffbd94930dba00b4682fcde9ebb2be8950bae7c",
)
.expect("")
});
Expand Down
Binary file modified vm/stdlib/compiled/12/11-12/stdlib.blob
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/036_Account.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/051_FrozenConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/064_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/065_Genesis.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/036_Account.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/051_FrozenConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/064_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/065_Genesis.mv
Binary file not shown.
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/036_Account.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/051_FrozenConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/064_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/065_Genesis.mv
Binary file not shown.
52 changes: 49 additions & 3 deletions vm/transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

use std::convert::TryInto;

use anyhow::Result;
use starcoin_config::{genesis_config::G_TOTAL_STC_AMOUNT, ChainNetwork};
use starcoin_crypto::hash::PlainCryptoHash;
use starcoin_crypto::HashValue;

use starcoin_config::{genesis_config::G_TOTAL_STC_AMOUNT, ChainNetwork};
use starcoin_types::account::Account;
use starcoin_vm_types::access::ModuleAccess;
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::account_config;
use starcoin_vm_types::account_config::{core_code_address, genesis_address};
use starcoin_vm_types::account_config::{association_address, core_code_address, genesis_address};
use starcoin_vm_types::file_format::CompiledModule;
use starcoin_vm_types::genesis_config::ChainId;
use starcoin_vm_types::identifier::Identifier;
Expand All @@ -25,7 +28,6 @@ use starcoin_vm_types::transaction::{
TransactionPayload,
};
use starcoin_vm_types::value::MoveValue;
use std::convert::TryInto;
use stdlib::{module_to_package, stdlib_package};
pub use stdlib::{stdlib_compiled_modules, stdlib_modules, StdLibOptions, StdlibVersion};

Expand Down Expand Up @@ -910,3 +912,47 @@ pub fn build_signed_empty_txn(
let signature = prikey.sign(&txn);
SignedUserTransaction::new(txn, signature)
}

// Build a signed user transaction for burning illegal tokens from a frozen address.
// This function creates a signed user transaction that attempts to burn illegal tokens
// from a frozen address. The transaction is signed by the `signer` and is intended for the `recipient`.
//
// # Arguments
// - `signer`: A reference to the `Account` that will sign the transaction.
// - `recipient`: A reference to the `AccountAddress` of the recipient.
// - `seq_num`: The sequence number of the transaction.
// - `amount`: The amount of tokens to be burned, represented as a `u128`.
// - `net`: A reference to the `ChainNetwork` which provides the chain ID for the transaction.
//
// # Returns
// - A `SignedUserTransaction` that is signed by the `signer` with the specified transaction details.
pub fn build_burn_illegal_stc_txn_with_association(
recipient: &AccountAddress,
seq_num: u64,
amount: u128,
net: &ChainNetwork,
) -> SignedUserTransaction {
let raw_txn = RawUserTransaction::new_with_default_gas_token(
association_address(),
seq_num,
TransactionPayload::ScriptFunction(ScriptFunction::new(
ModuleId::new(
core_code_address(),
Identifier::new("StdlibUpgradeScripts").unwrap(),
),
Identifier::new("burn_illegal_token_from_frozen_address").unwrap(),
vec![],
vec![
bcs_ext::to_bytes(&recipient).unwrap(),
bcs_ext::to_bytes(&amount).unwrap(),
],
)),
10000000,
1,
1000 + 60 * 60,
net.chain_id(),
);
net.genesis_config()
.sign_with_association(raw_txn)
.expect("Sign with association failed")
}
3 changes: 2 additions & 1 deletion vm/vm-runtime/src/force_upgrade_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub fn get_force_upgrade_block_number(chain_id: &ChainId) -> u64 {
} else if chain_id.is_halley() || chain_id.is_proxima() {
300
} else if chain_id.is_barnard() {
16085000
// add 8000 + BARNARD_HARD_FORK_HEIGHT
16088000
} else {
FORCE_UPGRADE_BLOCK_NUMBER
}
Expand Down

0 comments on commit d058b86

Please sign in to comment.