Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FlexiDAG] fix force upgrade test #4075

Merged
merged 21 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bfc6805
[flexiDAG] fixed mpm integration test
welbon May 16, 2024
10cb560
[flexiDAG] fixed mpm integration test
welbon May 16, 2024
7c8121f
[flexiDAG] new binary for framework version
welbon May 16, 2024
d41e8b1
[flexiDAG] debug test
welbon May 16, 2024
ebc6cb2
[flexiDAG] fixed force-deploy testcase
welbon May 16, 2024
ed9bbb0
[flexiDAG] fixed force-deploy testcase binary files
welbon May 16, 2024
14d7cd6
[fix-testcase] fixed the testcase for force upgrade
welbon May 17, 2024
65e8042
[fix-testcase] revert upgrade block number for test env
welbon May 17, 2024
0fc5c54
[fix-testcase] remove some log
welbon May 17, 2024
a6f9371
[fix-testcase] changed some comment
welbon May 17, 2024
4a321cd
[fix-testcase] changed some comment
welbon May 17, 2024
3834faf
[fix-testcase] fixed error from check_commit.sh
welbon May 17, 2024
147a348
[fix-testcase] fixed build and test workflow pull branch from `dag-mi…
welbon May 17, 2024
0e763ee
[fix-testcase] To ensure uniqueness, `StateView.get_block_metadata_v2…
welbon May 17, 2024
cd5af12
[fix-testcase] Reindex framework repository version
welbon May 17, 2024
f2dbd79
[fix-testcase] fixed cargo clippy
welbon May 17, 2024
3ad1fe0
[fix-testcase] fixed cargo fmt
welbon May 17, 2024
9f0c009
[fix-testcase] fixed StarcoinFramework initialize using StdlibVersion…
welbon May 17, 2024
9c13408
update scripts
simonjiao May 17, 2024
2941b0c
Revert "[fix-testcase] To ensure uniqueness, `StateView.get_block_met…
simonjiao May 18, 2024
6b0aa1e
Only execute extra txn when stdlib version is 11
simonjiao May 18, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
branches:
- dag-mining-net-master
- dag-master

jobs:
build-and-test:
Expand Down
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 @@ -451,7 +451,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 = "2966e3f6a04aef43a0e29e0cfc04d2d11290716d" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "76f3436af2494fc332f14dbacb3d7847cec711c0" }
starcoin-genesis = { path = "genesis" }
starcoin-logger = { path = "commons/logger" }
starcoin-metrics = { path = "commons/metrics" }
Expand Down
19 changes: 18 additions & 1 deletion chain/open-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ use starcoin_vm_runtime::force_upgrade_management::{
};
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_config::{genesis_address, ModuleUpgradeStrategy};
use starcoin_vm_types::genesis_config::StdlibVersion;
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::on_chain_config;
use starcoin_vm_types::on_chain_config::Version;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_view::{StateReaderExt, StateView};
use std::{convert::TryInto, sync::Arc};
Expand Down Expand Up @@ -362,6 +364,17 @@ impl OpenedBlock {
/// First, set the account policy in `0x1::PackageTxnManager` to 100,
/// Second, after the contract deployment is successful, revert it back.
fn execute_extra_txn(&mut self) -> Result<()> {
// Only execute extra_txn when stdlib version is 11
if self
.state
.get_on_chain_config::<Version>()?
.map(|v| v.into_stdlib_version())
.map(|v| v != StdlibVersion::Version(11))
.unwrap_or(true)
{
return Ok(());
}

let extra_txn =
if self.block_meta.number() == get_force_upgrade_block_number(&self.chain_id) {
let account = get_force_upgrade_account(&self.chain_id)?;
Expand All @@ -372,7 +385,11 @@ impl OpenedBlock {
self.block_meta.timestamp() / 1000 + DEFAULT_EXPIRATION_TIME,
&self.chain_id,
)?;
info!("extra txn in opened block ({:?})", extra_txn.id());
info!(
"execute_extra_txn | extra txn in opened block ({:?}), block_num: {:?}",
extra_txn.id(),
self.block_meta.number()
);
Transaction::UserTransaction(extra_txn)
} else {
return Ok(());
Expand Down
6 changes: 4 additions & 2 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,9 @@ impl BlockChain {
verify_block!(
VerifyBlockField::State,
state_root == header.state_root(),
"verify legacy block:{:?} state_root fail",
"verify legacy block:{:?} state_root fail, executed_accumulator_root:{:?}, header.txn_accumulator_root(): {:?}",
block_id,
state_root, header.txn_accumulator_root()
);
let block_gas_used = vec_transaction_info
.iter()
Expand Down Expand Up @@ -1283,7 +1284,8 @@ impl BlockChain {
verify_block!(
VerifyBlockField::State,
executed_accumulator_root == header.txn_accumulator_root(),
"verify block: txn accumulator root mismatch"
"verify block: txn accumulator root mismatch! executed_accumulator_root: {:?}, header.txn_accumulator_root(): {:?} ",
executed_accumulator_root, header.txn_accumulator_root()
);

watch(CHAIN_WATCH_NAME, "n23");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ use starcoin_vm_types::{account_config, state_view::StateReaderExt};
use std::str::FromStr;
use test_helper::executor::get_balance;

#[stest::test]
pub fn test_force_upgrade_generate_block() -> anyhow::Result<()> {
let mut genesis_config = BuiltinNetworkID::Test.genesis_config().clone();
genesis_config.stdlib_version = StdlibVersion::Version(11);
let net = ChainNetwork::new(BuiltinNetworkID::Test.into(), genesis_config);

let force_upgrade_height = get_force_upgrade_block_number(&net.chain_id());
assert!(force_upgrade_height >= 2);
let initial_blocks = force_upgrade_height - 2;

let block_chain = test_helper::gen_blockchain_with_blocks_for_test(initial_blocks, &net)?;
assert_eq!(block_chain.current_header().number(), initial_blocks);

Ok(())
}

#[stest::test]
pub fn test_force_upgrade_1() -> anyhow::Result<()> {
let mut genesis_config = BuiltinNetworkID::Test.genesis_config().clone();
Expand Down Expand Up @@ -188,14 +204,6 @@ fn test_force_upgrade_2() -> anyhow::Result<()> {
let force_upgrade_height = get_force_upgrade_block_number(&net.chain_id());
assert!(force_upgrade_height >= 2);

let chain = test_helper::gen_blockchain_with_blocks_for_test(force_upgrade_height, &net)?;

// genesis 1 + 1meta in each blocks + special block 1meta+1extra.txn
assert_eq!(
chain.get_txn_accumulator().num_leaves(),
force_upgrade_height + 2
);

let chain = test_helper::gen_blockchain_with_blocks_for_test(force_upgrade_height + 1, &net)?;
// genesis 1 + 1meta in each blocks + special block 2 + 1 meta in last block
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ pub static G_TEST_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
),
genesis_key_pair: Some((Arc::new(genesis_private_key), genesis_public_key)),
time_service_type: TimeServiceType::MockTimeService,
stdlib_version: StdlibVersion::Version(12),
stdlib_version: StdlibVersion::Latest,
dao_config: DaoConfig {
voting_delay: 60_000, // 1min
voting_period: 60 * 60 * 1000, // 1h
Expand All @@ -775,7 +775,7 @@ pub static G_DEV_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
let mut gas_constant = G_TEST_GAS_CONSTANTS.clone();
gas_constant.min_price_per_gas_unit = 1;

let stdlib_version = StdlibVersion::Version(12);
let stdlib_version = StdlibVersion::Latest;
GenesisConfig {
genesis_block_parameter: GenesisBlockParameterConfig::Static(GenesisBlockParameter {
parent_hash: HashValue::sha3_256_of(b"starcoin_dev"),
Expand Down
19 changes: 18 additions & 1 deletion executor/src/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ use starcoin_vm_runtime::metrics::VMMetrics;
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_config::{genesis_address, ModuleUpgradeStrategy};
use starcoin_vm_types::contract_event::ContractEvent;
use starcoin_vm_types::genesis_config::StdlibVersion;
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::on_chain_config;
use starcoin_vm_types::on_chain_config::Version;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::table::{TableHandle, TableInfo};
use starcoin_vm_types::state_view::StateReaderExt;
Expand Down Expand Up @@ -119,9 +121,20 @@ pub fn block_execute<S: ChainStateReader + ChainStateWriter>(
fn create_force_upgrade_extra_txn<S: ChainStateReader + ChainStateWriter>(
statedb: &S,
) -> anyhow::Result<Option<Transaction>> {
// Only execute extra_txn when stdlib version is 11
if statedb
.get_on_chain_config::<Version>()?
.map(|v| v.into_stdlib_version())
.map(|v| v != StdlibVersion::Version(11))
.unwrap_or(true)
{
return Ok(None);
}

let chain_id = statedb.get_chain_id()?;
let block_timestamp = statedb.get_timestamp()?.seconds();
let block_number = statedb.get_block_metadata()?.number;

Ok(
if block_number == get_force_upgrade_block_number(&chain_id) {
let account = get_force_upgrade_account(&chain_id)?;
Expand All @@ -132,7 +145,11 @@ fn create_force_upgrade_extra_txn<S: ChainStateReader + ChainStateWriter>(
block_timestamp + DEFAULT_EXPIRATION_TIME,
&chain_id,
)?;
info!("extra txn to execute ({:?})", extra_txn.id());
info!(
"create_force_upgrade_extra_txn | block_number: ({:?}) extra txn to execute ({:?})",
block_number,
extra_txn.id()
);
Some(Transaction::UserTransaction(extra_txn))
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion executor/tests/module_upgrade_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn test_stdlib_upgrade() -> Result<()> {
&alice,
&chain_state,
&net,
vote_language_version(&net, 6),
vote_language_version(&net, 4),
on_chain_config_type_tag(MoveLanguageVersion::type_tag()),
execute_script_on_chain_config(&net, MoveLanguageVersion::type_tag(), proposal_id),
proposal_id,
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/038_Block.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/049_FlexiDagConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/065_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/11-12/stdlib/066_Genesis.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/038_Block.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/049_FlexiDagConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/065_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/12/stdlib/066_Genesis.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/038_Block.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/049_FlexiDagConfig.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/065_StdlibUpgradeScripts.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/066_Genesis.mv
Binary file not shown.
4 changes: 2 additions & 2 deletions vm/types/src/state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ pub trait StateReaderExt: StateView {
.ok_or_else(|| format_err!("ChainId resource should exist at genesis address. "))
}

// Get latest BlockMetadata on chain
// Get BlockMetadata on chain (stdlib version <= 11)
fn get_block_metadata(&self) -> Result<BlockMetadata> {
self.get_resource::<BlockMetadata>(genesis_address())?
.ok_or_else(|| format_err!("BlockMetadata resource should exist at genesis address. "))
}

// Get latest BlockMetadataV2 on chain, since stdlib version(13)
// Get latest BlockMetadataV2 on chain, since stdlib version(12)
fn get_block_metadata_v2(&self) -> Result<Option<BlockMetadataV2>> {
self.get_resource::<BlockMetadataV2>(genesis_address())
}
Expand Down
7 changes: 2 additions & 5 deletions vm/vm-runtime/src/starcoin_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,8 @@ impl StarcoinVM {
package_address: AccountAddress,
) -> Result<bool> {
let chain_id = remote_cache.get_chain_id()?;
let block_number = if let Some(v2) = remote_cache.get_block_metadata_v2()? {
v2.number
} else {
remote_cache.get_block_metadata()?.number
};
let block_number = remote_cache.get_block_metadata()?.number;

// from mainnet after 8015088 and barnard after 8311392, we disable enforce upgrade
if package_address == genesis_address()
|| (chain_id.is_main() && block_number < 8015088)
Expand Down
Loading