Skip to content

Commit

Permalink
Merge 944b8e0 into faf9bb4
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg authored Dec 9, 2022
2 parents faf9bb4 + 944b8e0 commit ac5635a
Show file tree
Hide file tree
Showing 177 changed files with 4,327 additions and 1,250 deletions.
224 changes: 142 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ members = [
"vm/transaction-builder-generator",
"vm/move-coverage",
"vm/resource-viewer",
"vm/starcoin-gas",
"vm/dev",
"vm/gas-algebra-ext",
"vm/move-explain",
"vm/move-package-manager",
"vm/vm-status-translator",
Expand Down Expand Up @@ -178,7 +180,9 @@ default-members = [
"vm/transaction-builder-generator",
"vm/move-coverage",
"vm/resource-viewer",
"vm/starcoin-gas",
"vm/dev",
"vm/gas-algebra-ext",
"vm/move-explain",
"vm/move-package-manager",
"vm/vm-status-translator",
Expand Down
2 changes: 1 addition & 1 deletion abi/decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "1.12.5"
[dependencies]
anyhow = "1.0.41"
hex = "0.4.3"
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-vm-types = { path = "../../vm/types" }
starcoin-abi-types = { path = "../types" }
Expand Down
2 changes: 1 addition & 1 deletion abi/resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ starcoin-vm-types = { path = "../../vm/types" }
starcoin-abi-types = { path = "../types" }
anyhow = "~1"
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
[dev-dependencies]
stdlib = { path = "../../vm/stdlib" }
serde_json = "1"
Expand Down
7 changes: 3 additions & 4 deletions abi/resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starcoin_resource_viewer::module_cache::ModuleCache;
use starcoin_resource_viewer::resolver::Resolver;
use starcoin_vm_types::access::ModuleAccess;
use starcoin_vm_types::file_format::{
CompiledModule, CompiledScript, FunctionDefinitionIndex, StructDefinitionIndex, Visibility,
CompiledModule, CompiledScript, FunctionDefinitionIndex, StructDefinitionIndex,
};
use starcoin_vm_types::identifier::{IdentStr, Identifier};
use starcoin_vm_types::language_storage::{ModuleId, StructTag, TypeTag};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<'a> ABIResolver<'a> {
let functions = m
.exposed_functions
.iter()
.filter(|(_, func)| func.visibility == Visibility::Script) // only script functions
// .filter(|(_, func)| func.visibility == Visibility::Script) // only script functions
.map(|(name, func)| self.function_to_abi(&module_id, name.as_ident_str(), func))
.collect::<Result<Vec<_>>>()?;
Ok(ModuleABI::new(m.module_id(), structs, functions))
Expand Down Expand Up @@ -388,8 +388,7 @@ mod tests {
}))
}
StateKey::TableItem(_table_item) => {
// XXX FIXME YSG
unimplemented!()
anyhow::bail!("no need table_item")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/db-exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ logger = { path = "../../commons/logger", package = "starcoin-logger" }
clap = { version = "3", features = ["derive"] }
atomic-counter = "1.0.1"
tokio = { version = "^1", features = ["full"] }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-state-tree = { path = "../../state/state-tree" }
[target."cfg(target_os=\"linux\")".dependencies]
Expand Down
7 changes: 1 addition & 6 deletions cmd/db-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ pub fn apply_block(
network: BuiltinNetworkID,
verifier: Verifier,
) -> anyhow::Result<()> {
::logger::init();
let net = ChainNetwork::new_builtin(network);
let db_storage = DBStorage::new(to_dir.join("starcoindb/db"), RocksdbConfig::default(), None)?;
let storage = Arc::new(Storage::new(StorageInstance::new_cache_and_db_instance(
Expand Down Expand Up @@ -767,12 +768,6 @@ pub fn startup_info_back(

let cur_num = chain.status().head().number();
let back_size = back_size.unwrap_or(BACK_SIZE);
let back_size = if back_size < BACK_SIZE {
BACK_SIZE
} else {
back_size
};

if cur_num <= back_size {
println!(
"startup_info block number {} <= back_size {}",
Expand Down
4 changes: 2 additions & 2 deletions cmd/starcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-service-registry = { path = "../../commons/service-registry" }
starcoin-move-explain = { path = "../../vm/move-explain" }
vm-status-translator = { path = "../../vm/vm-status-translator" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
network-api = { path = "../../network/api", package = "network-api" }
starcoin-network-rpc-api = { path = "../../network-rpc/api" }
starcoin-abi-decoder = { path = "../../abi/decoder" }
starcoin-abi-resolver = { path = "../../abi/resolver" }
starcoin-abi-types = { path = "../../abi/types" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }

[dev-dependencies]
test-helper = { path = "../../test-helper" }
Expand Down
2 changes: 1 addition & 1 deletion commons/proptest-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ version = "1.12.5"

[dependencies]
crossbeam = "0.7.3"
diem-proptest-helpers = { package = "diem-proptest-helpers", git = "https://github.com/starcoinorg/move", rev = "204da96abcb6eb82bc50fcbcd4331f6cc3d17439" }
diem-proptest-helpers = { package = "diem-proptest-helpers", git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
proptest = "1.0.0"
proptest-derive = "0.3.0"
2 changes: 2 additions & 0 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ serde_json = { version = "1.0", features = ["arbitrary_precision"] }
starcoin-time-service = { path = "../commons/time-service" }
thiserror = "1.0"
toml = { version = "0.5.9", default-features = false }
gas-algebra-ext = { path = "../vm/gas-algebra-ext" }
starcoin-gas = { path = "../vm/starcoin-gas" }
14 changes: 5 additions & 9 deletions config/example/proxima/genesis_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,23 @@
"memory_gas": 1
},
{
"instruction_gas": 4,
"memory_gas": 1
},
{
"instruction_gas": 4,
"instruction_gas": 10,
"memory_gas": 1
},
{
"instruction_gas": 4,
"instruction_gas": 8,
"memory_gas": 1
},
{
"instruction_gas": 4,
"instruction_gas": 40,
"memory_gas": 1
},
{
"instruction_gas": 4,
"instruction_gas": 20,
"memory_gas": 1
},
{
"instruction_gas": 4,
"instruction_gas": 73,
"memory_gas": 1
},
{
Expand Down
178 changes: 175 additions & 3 deletions config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::{bail, ensure, format_err, Result};
use gas_algebra_ext::{CostTable, FromOnChainGasSchedule};
use network_p2p_types::MultiaddrWithPeerId;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use once_cell::sync::Lazy;
Expand All @@ -14,18 +15,19 @@ use starcoin_crypto::{
multi_ed25519::{genesis_multi_key_pair, MultiEd25519PublicKey},
HashValue, ValidCryptoMaterialStringExt,
};
use starcoin_gas::StarcoinGasParameters;
use starcoin_time_service::{TimeService, TimeServiceType};
use starcoin_uint::U256;
use starcoin_vm_types::account_config::genesis_address;
use starcoin_vm_types::event::EventHandle;
use starcoin_vm_types::gas_schedule::{
latest_cost_table, CostTable, G_GAS_CONSTANTS_V1, G_GAS_CONSTANTS_V2, G_LATEST_GAS_SCHEDULE,
latest_cost_table, G_GAS_CONSTANTS_V1, G_GAS_CONSTANTS_V2, G_LATEST_GAS_SCHEDULE,
G_TEST_GAS_CONSTANTS,
};
use starcoin_vm_types::genesis_config::{ChainId, ConsensusStrategy, StdlibVersion};
use starcoin_vm_types::on_chain_config::{
instruction_table_v1, native_table_v1, native_table_v2, ConsensusConfig, DaoConfig,
TransactionPublishOption, VMConfig, Version,
GasSchedule, TransactionPublishOption, VMConfig, Version,
};
use starcoin_vm_types::on_chain_resource::Epoch;
use starcoin_vm_types::token::stc::STCUnit;
Expand Down Expand Up @@ -586,7 +588,7 @@ pub enum GenesisBlockParameterConfig {
}

/// GenesisConfig is a config for initialize a chain genesis.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GenesisConfig {
/// Parameter for init genesis block
pub genesis_block_parameter: GenesisBlockParameterConfig,
Expand Down Expand Up @@ -1049,3 +1051,173 @@ pub static G_MAIN_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
transaction_timeout: ONE_DAY,
}
});

pub static G_LATEST_GAS_PARAMS: Lazy<StarcoinGasParameters> = Lazy::new(|| {
let vm_config = VMConfig {
gas_schedule: G_LATEST_GAS_SCHEDULE.clone(),
};
let gas_schedule = GasSchedule::from(&vm_config);
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map()).unwrap()
});

#[cfg(test)]
mod tests {
use gas_algebra_ext::{CostTable, FromOnChainGasSchedule};
use starcoin_gas::StarcoinGasParameters;
use starcoin_vm_types::gas_schedule::{
latest_cost_table, G_GAS_CONSTANTS_V1, G_GAS_CONSTANTS_V2, G_LATEST_GAS_SCHEDULE,
G_TEST_GAS_CONSTANTS,
};
use starcoin_vm_types::on_chain_config::{
instruction_gas_schedule_v1, instruction_gas_schedule_v2, instruction_table_v1,
native_gas_schedule_v1, native_gas_schedule_v2, native_gas_schedule_v4, native_table_v1,
native_table_v2, txn_gas_schedule_test, txn_gas_schedule_v1, txn_gas_schedule_v2,
txn_gas_schedule_v3, GasSchedule, VMConfig,
};

fn config_entries(
instrs: Vec<(String, u64)>,
natives: Vec<(String, u64)>,
constants: Vec<(String, u64)>,
) -> Vec<(String, u64)> {
let mut entries = instrs;
let mut natives = natives;
let mut constants = constants;
entries.append(&mut natives);
// instruction_schedule don't have this two
entries.push(("nursery.debug.print.base_cost".to_string(), 1));
entries.push(("nursery.debug.print_stack_trace.base_cost".to_string(), 1));

entries.push((
"move_stdlib.hash.sha2_256.legacy_min_input_len".to_string(),
1,
));
entries.push((
"move_stdlib.hash.sha3_256.legacy_min_input_len".to_string(),
1,
));
entries.push(("move_stdlib.bcs.to_bytes.failure".to_string(), 182));
entries.push((
"move_stdlib.bcs.to_bytes.legacy_min_output_size".to_string(),
1,
));
entries.append(&mut constants);
entries
}

#[test]
fn test_dev_config() {
let vm_config = VMConfig {
gas_schedule: latest_cost_table(G_TEST_GAS_CONSTANTS.clone()),
};

let entries = config_entries(
instruction_gas_schedule_v2(),
native_gas_schedule_v4(),
txn_gas_schedule_test(),
);

let gas_schedule = GasSchedule::from(&vm_config);
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
1.into()
);
}

#[test]
fn test_halley_config() {
let vm_config = VMConfig {
gas_schedule: G_LATEST_GAS_SCHEDULE.clone(),
};

let entries = config_entries(
instruction_gas_schedule_v2(),
native_gas_schedule_v4(),
txn_gas_schedule_v3(),
);

let gas_schedule = GasSchedule::from(&vm_config);
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
1.into()
);
}

#[test]
fn test_proxima_config() {
let vm_config = VMConfig {
gas_schedule: G_LATEST_GAS_SCHEDULE.clone(),
};

let entries = config_entries(
instruction_gas_schedule_v2(),
native_gas_schedule_v4(),
txn_gas_schedule_v3(),
);
let gas_schedule = GasSchedule::from(&vm_config);
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
1.into()
);
}

#[test]
fn test_barnard_config() {
let vm_config = VMConfig {
gas_schedule: CostTable {
instruction_table: instruction_table_v1(),
native_table: native_table_v1(),
gas_constants: G_GAS_CONSTANTS_V1.clone(),
},
};

let entries = config_entries(
instruction_gas_schedule_v1(),
native_gas_schedule_v1(),
txn_gas_schedule_v1(),
);
let gas_schedule = GasSchedule::from(&vm_config);
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
1.into()
);
}

#[test]
fn test_main_config() {
let vm_config = VMConfig {
gas_schedule: CostTable {
instruction_table: instruction_table_v1(),
native_table: native_table_v2(),
gas_constants: G_GAS_CONSTANTS_V2.clone(),
},
};

let entries = config_entries(
instruction_gas_schedule_v1(),
native_gas_schedule_v2(),
txn_gas_schedule_v2(),
);

let gas_schedule = GasSchedule::from(&vm_config);
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
1.into()
);
}
}
3 changes: 0 additions & 3 deletions config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use super::*;
use crate::helper::to_toml;
use starcoin_vm_types::gas_schedule::GasAlgebra;

#[test]
fn test_generate_and_load() -> Result<()> {
Expand Down Expand Up @@ -165,7 +164,6 @@ fn test_genesis_config_security() {
.gas_schedule
.gas_constants
.min_price_per_gas_unit
.get()
> 0
);
// maximum_number_of_gas_units must be less than base_block_gas_limit
Expand All @@ -175,7 +173,6 @@ fn test_genesis_config_security() {
.gas_schedule
.gas_constants
.maximum_number_of_gas_units
.get()
< genesis_config.consensus_config.base_block_gas_limit
);
}
Expand Down
Loading

0 comments on commit ac5635a

Please sign in to comment.