Skip to content

Commit

Permalink
Upgrade dag framework (#4004)
Browse files Browse the repository at this point in the history
* upgrade stdlib to version 13

* add on-chain-config for flexidagconfig

* add more parameters for new stdlib

* update halley's genesis file

* fix stdlib_upgrade tests

* add blockmetadatav2
  • Loading branch information
simonjiao authored Jan 30, 2024
1 parent 6dc984d commit dd2be0f
Show file tree
Hide file tree
Showing 249 changed files with 152 additions and 18 deletions.
4 changes: 2 additions & 2 deletions 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 = "345a3900a0064dc57a9560235bc72c12f03448b1" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "975539d8bcad6210b443a5f26685bd2e0d14263f" }
starcoin-genesis = { path = "genesis" }
starcoin-logger = { path = "commons/logger" }
starcoin-metrics = { path = "commons/metrics" }
Expand Down
38 changes: 35 additions & 3 deletions executor/tests/module_upgrade_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use starcoin_vm_types::account_config::{association_address, core_code_address,
use starcoin_vm_types::account_config::{genesis_address, stc_type_tag};
use starcoin_vm_types::genesis_config::{ChainId, StdlibVersion};
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::on_chain_config::{MoveLanguageVersion, TransactionPublishOption, Version};
use starcoin_vm_types::on_chain_config::{
FlexiDagConfig, MoveLanguageVersion, TransactionPublishOption, Version,
};
use starcoin_vm_types::on_chain_resource::LinearWithdrawCapability;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::token::stc::G_STC_TOKEN_CODE;
Expand All @@ -28,7 +30,8 @@ use std::fs::File;
use std::io::Read;
use stdlib::{load_upgrade_package, StdlibCompat, G_STDLIB_VERSIONS};
use test_helper::dao::{
dao_vote_test, execute_script_on_chain_config, on_chain_config_type_tag, vote_language_version,
dao_vote_test, execute_script_on_chain_config, on_chain_config_type_tag, vote_flexi_dag_config,
vote_language_version,
};
use test_helper::executor::*;
use test_helper::starcoin_dao;
Expand Down Expand Up @@ -113,7 +116,7 @@ fn test_init_script() -> Result<()> {
}

#[stest::test]
fn test_upgrade_stdlib_with_incremental_package() -> Result<()> {
fn test_stdlib_upgrade_with_incremental_package() -> Result<()> {
let alice = Account::new();
let mut genesis_config = BuiltinNetworkID::Test.genesis_config().clone();
genesis_config.stdlib_version = StdlibVersion::Version(1);
Expand Down Expand Up @@ -196,6 +199,7 @@ fn test_stdlib_upgrade() -> Result<()> {
let alice = Account::new();

for new_version in stdlib_versions.into_iter().skip(1) {
debug!("=== upgrading {current_version} to {new_version}");
// if upgrade from 7 to later, we need to update language version to 3.
if let StdlibVersion::Version(7) = current_version {
dao_vote_test(
Expand Down Expand Up @@ -235,6 +239,18 @@ fn test_stdlib_upgrade() -> Result<()> {
)?;
proposal_id += 1;
}
if let StdlibVersion::Version(13) = current_version {
dao_vote_test(
&alice,
&chain_state,
&net,
vote_flexi_dag_config(&net, 1234567890u64),
on_chain_config_type_tag(FlexiDagConfig::type_tag()),
execute_script_on_chain_config(&net, FlexiDagConfig::type_tag(), proposal_id),
proposal_id,
)?;
proposal_id += 1;
}
verify_version_state(current_version, &chain_state)?;
let dao_action_type_tag = new_version.upgrade_module_type_tag();
let package = match load_upgrade_package(current_version, new_version)? {
Expand All @@ -244,6 +260,7 @@ fn test_stdlib_upgrade() -> Result<()> {
"{:?} is same as {:?}, continue",
current_version, new_version
);
ext_execute_after_upgrade(new_version, &net, &chain_state)?;
continue;
}
};
Expand Down Expand Up @@ -458,6 +475,12 @@ fn ext_execute_after_upgrade(
"expect 0x1::GenesisNFT::GenesisNFTInfo in global storage, but go none."
);
}
StdlibVersion::Version(12) => {
let version_resource = chain_state.get_on_chain_config::<MoveLanguageVersion>()?;
assert!(version_resource.is_some());
let version = version_resource.unwrap();
assert_eq!(version.major, 6, "expect language version is 6");
}

// this is old daospace-v12 starcoin-framework,
// https://github.com/starcoinorg/starcoin-framework/releases/tag/daospace-v12
Expand Down Expand Up @@ -695,6 +718,15 @@ where
"expect LinearWithdrawCapability exist at association_address"
);
}
StdlibVersion::Version(13) => {
let config = chain_state.get_on_chain_config::<FlexiDagConfig>()?;
assert!(config.is_some());
assert_eq!(
config.unwrap().effective_height,
1234567890,
"expect dag effective height is 1234567890"
);
}
_ => {
//do nothing.
}
Expand Down
Binary file modified genesis/generated/halley/genesis
Binary file not shown.
2 changes: 1 addition & 1 deletion genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Genesis {
pub fn init_storage_for_test(
net: &ChainNetwork,
) -> Result<(Arc<Storage>, ChainInfo, Genesis, BlockDAG)> {
debug!("init storage by genesis for test.");
debug!("init storage by genesis for test. {net:?}");
let storage = Arc::new(Storage::new(StorageInstance::new_cache_instance())?);
let genesis = Genesis::load_or_build(net)?;
let dag = BlockDAG::create_for_testing()?;
Expand Down
15 changes: 15 additions & 0 deletions test-helper/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@ pub fn vote_language_version(_net: &ChainNetwork, lang_version: u64) -> ScriptFu
)
}

pub fn vote_flexi_dag_config(_net: &ChainNetwork, effective_height: u64) -> ScriptFunction {
ScriptFunction::new(
ModuleId::new(
core_code_address(),
Identifier::new("OnChainConfigScripts").unwrap(),
),
Identifier::new("propose_update_flexi_dag_effective_height").unwrap(),
vec![],
vec![
bcs_ext::to_bytes(&effective_height).unwrap(),
bcs_ext::to_bytes(&0u64).unwrap(),
],
)
}

/// execute on chain config scripts
pub fn execute_script_on_chain_config(
_net: &ChainNetwork,
Expand Down
3 changes: 2 additions & 1 deletion vm/starcoin-transactional-test-harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,11 @@ impl<'a> StarcoinTestAdapter<'a> {
number: Option<u64>,
uncles: Option<u64>,
) -> Result<(Option<String>, Option<Value>)> {
// use BlockMetadataV2 instead of BlockMetaData since stdlib version(13)
let last_blockmeta = self
.context
.storage
.get_resource::<on_chain_resource::BlockMetadata>(genesis_address())?;
.get_resource::<on_chain_resource::BlockMetadataV2>(genesis_address())?;

let height = number
.or_else(|| last_blockmeta.as_ref().map(|b| b.number + 1))
Expand Down
Binary file added vm/stdlib/compiled/13/12-13/stdlib.blob
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/001_Debug.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/003_FromBCS.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/005_SIP_2.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/006_SIP_3.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/008_Vector.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/009_Errors.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/010_ACL.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/011_Signer.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/012_Math.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/013_Option.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/014_BCS.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/015_Event.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/016_Token.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/018_Timestamp.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/019_Config.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/020_ChainId.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/022_Version.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/025_Dao.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/033_STC.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/035_Hash.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/037_Account.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/039_Arith.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/040_Ring.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/041_Block.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/044_Collection.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/046_Compare.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/049_DummyToken.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/051_EVMAddress.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/052_TypeInfo.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/054_Oracle.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/056_EasyGas.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/059_Epoch.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/12-13/stdlib/060_EventUtil.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/000_BitOperators.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/001_Debug.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/002_EmptyScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/003_FromBCS.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/004_MintScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/005_SIP_2.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/006_SIP_3.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/007_SignedInteger64.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/008_Vector.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/009_Errors.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/010_ACL.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/011_Signer.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/012_Math.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/013_Option.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/014_BCS.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/015_Event.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/016_Token.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/017_CoreAddresses.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/018_Timestamp.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/019_Config.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/020_ChainId.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/021_VMConfig.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/022_Version.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/024_Treasury.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/025_Dao.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/029_RewardConfig.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/030_OnChainConfigDao.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/033_STC.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/034_TransactionFee.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/035_Hash.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/036_Authenticator.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/037_Account.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/038_AccountScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/039_Arith.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/040_Ring.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/041_Block.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/043_BlockReward.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/044_Collection.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/045_Collection2.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/046_Compare.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/048_DaoVoteScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/049_DummyToken.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/051_EVMAddress.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/052_TypeInfo.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/054_Oracle.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/055_PriceOracle.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/056_EasyGas.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/057_TransferScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/058_EasyGasScript.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/059_Epoch.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/060_EventUtil.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/061_FixedPoint32.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/062_FlexiDagConfig.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/063_GasSchedule.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/064_STCUSDOracle.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/065_Offer.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/066_NFT.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/067_LanguageVersion.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/068_MerkleProof.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/070_IdentifierNFT.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/071_GenesisNFT.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/073_Genesis.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/076_MintDaoProposal.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/078_NFTGallery.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/083_Secp256k1.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/084_Signature.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/086_SimpleMap.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/087_StructuredHash.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/089_String.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/090_Table.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/093_TreasuryScripts.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/094_U256.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/13/stdlib/095_YieldFarming.mv
Binary file not shown.
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/041_Block.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/064_STCUSDOracle.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/065_Offer.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/066_NFT.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/068_MerkleProof.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/073_Genesis.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/083_Secp256k1.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/084_Signature.mv
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/086_SimpleMap.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/089_String.mv
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/090_Table.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added vm/stdlib/compiled/latest/stdlib/094_U256.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion vm/stdlib/tests/package_init_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn test_package_init_function() -> Result<()> {
"./compiled/10/9-10/stdlib.blob",
"./compiled/11/10-11/stdlib.blob",
"./compiled/12/11-12/stdlib.blob",
"./compiled/13/12-13/stdlib.blob",
];

let init_strs = [
Expand All @@ -30,8 +31,9 @@ fn test_package_init_function() -> Result<()> {
"",
"",
"0x00000000000000000000000000000001::StdlibUpgradeScripts::upgrade_from_v11_to_v12",
"0x00000000000000000000000000000001::StdlibUpgradeScripts::upgrade_from_v12_to_v13",
];
for (i, version) in (2..=12).collect::<Vec<usize>>().into_iter().enumerate() {
for (i, version) in (2..=13).collect::<Vec<usize>>().into_iter().enumerate() {
let package_file = format!("{}/{}-{}/stdlib.blob", version, version - 1, version);
let package = COMPILED_MOVE_CODE_DIR
.get_file(package_file)
Expand Down
2 changes: 2 additions & 0 deletions vm/types/src/account_config/constants/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub static G_TRANSACTION_MANAGER_MODULE: Lazy<ModuleId> = Lazy::new(|| {
pub static G_PROLOGUE_NAME: Lazy<Identifier> = Lazy::new(|| Identifier::new("prologue").unwrap());
pub static G_BLOCK_PROLOGUE_NAME: Lazy<Identifier> =
Lazy::new(|| Identifier::new("block_prologue").unwrap());
pub static G_BLOCK_PROLOGUE_V2_NAME: Lazy<Identifier> =
Lazy::new(|| Identifier::new("block_prologue_v2").unwrap());
pub static G_EPILOGUE_NAME: Lazy<Identifier> = Lazy::new(|| Identifier::new("epilogue").unwrap());
pub static G_EPILOGUE_V2_NAME: Lazy<Identifier> =
Lazy::new(|| Identifier::new("epilogue_v2").unwrap());
31 changes: 31 additions & 0 deletions vm/types/src/on_chain_config/flexi_dag_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) The Starcoin Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::on_chain_config::OnChainConfig;
use move_core_types::identifier::Identifier;
use move_core_types::language_storage::{StructTag, TypeTag, CORE_CODE_ADDRESS};
use serde::{Deserialize, Serialize};

const MV_FLEXI_DAG_CONFIG_MODULE_NAME: &str = "FlexiDagConfig";
const MV_FLEXI_DAG_CONFIG_STRUCT_NAME: &str = "FlexiDagConfig";

#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct FlexiDagConfig {
pub effective_height: u64,
}

impl OnChainConfig for FlexiDagConfig {
const MODULE_IDENTIFIER: &'static str = MV_FLEXI_DAG_CONFIG_MODULE_NAME;
const CONF_IDENTIFIER: &'static str = MV_FLEXI_DAG_CONFIG_STRUCT_NAME;
}

impl FlexiDagConfig {
pub fn type_tag() -> TypeTag {
TypeTag::Struct(Box::new(StructTag {
address: CORE_CODE_ADDRESS,
module: Identifier::new(MV_FLEXI_DAG_CONFIG_MODULE_NAME).unwrap(),
name: Identifier::new(MV_FLEXI_DAG_CONFIG_STRUCT_NAME).unwrap(),
type_params: vec![],
}))
}
}
2 changes: 2 additions & 0 deletions vm/types/src/on_chain_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{collections::HashMap, sync::Arc};

mod consensus_config;
mod dao_config;
mod flexi_dag_config;
mod gas_schedule;
mod genesis_gas_schedule;
mod move_lang_version;
Expand All @@ -27,6 +28,7 @@ mod vm_config;
pub use self::{
consensus_config::{consensus_config_type_tag, ConsensusConfig, G_CONSENSUS_CONFIG_IDENTIFIER},
dao_config::DaoConfig,
flexi_dag_config::*,
gas_schedule::{
instruction_gas_schedule_v1, instruction_gas_schedule_v2, native_gas_schedule_v1,
native_gas_schedule_v2, native_gas_schedule_v3, native_gas_schedule_v4,
Expand Down
20 changes: 20 additions & 0 deletions vm/types/src/on_chain_resource/block_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ impl MoveResource for BlockMetadata {
const MODULE_NAME: &'static str = "Block";
const STRUCT_NAME: &'static str = "BlockMetadata";
}

/// On chain resource BlockMetadata mapping for FlexiDag block
#[derive(Debug, Serialize, Deserialize)]
pub struct BlockMetadataV2 {
// number of the current block
pub number: u64,
// Hash of the parent block.
pub parent_hash: HashValue,
// Author of the current block.
pub author: AccountAddress,
pub uncles: u64,
pub parents_hash: Vec<HashValue>,
// Handle where events with the time of new blocks are emitted
pub new_block_events: EventHandle,
}

impl MoveResource for BlockMetadataV2 {
const MODULE_NAME: &'static str = "Block";
const STRUCT_NAME: &'static str = "BlockMetadataV2";
}
2 changes: 1 addition & 1 deletion vm/types/src/on_chain_resource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod global_time;
pub mod nft;
mod treasury;

pub use block_metadata::BlockMetadata;
pub use block_metadata::{BlockMetadata, BlockMetadataV2};
pub use epoch::{Epoch, EpochData, EpochInfo};
pub use global_time::GlobalTimeOnChain;
pub use treasury::{LinearWithdrawCapability, Treasury};
7 changes: 6 additions & 1 deletion vm/types/src/state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
on_chain_config::{GlobalTimeOnChain, OnChainConfig},
on_chain_resource::{
dao::{Proposal, ProposalAction},
BlockMetadata, Epoch, EpochData, EpochInfo, Treasury,
BlockMetadata, BlockMetadataV2, Epoch, EpochData, EpochInfo, Treasury,
},
sips::SIP,
};
Expand Down Expand Up @@ -167,6 +167,11 @@ pub trait StateReaderExt: StateView {
.ok_or_else(|| format_err!("BlockMetadata resource should exist at genesis address. "))
}

// Get latest BlockMetadataV2 on chain, since stdlib version(13)
fn get_block_metadata_v2(&self) -> Result<Option<BlockMetadataV2>> {
self.get_resource::<BlockMetadataV2>(genesis_address())
}

fn get_code(&self, module_id: ModuleId) -> Result<Option<Vec<u8>>> {
self.get_state_value(&StateKey::AccessPath(AccessPath::from(&module_id)))
}
Expand Down
Loading

0 comments on commit dd2be0f

Please sign in to comment.