Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ members = [
"vm/stdlib",
"vm/compiler",
"vm/move-prover",
"vm/mvhashmap",
"vm/parallel-executor",
"commons/mvhashmap",
"commons/parallel-executor",
"vm/transaction-builder",
"vm/transaction-builder-generator",
"vm/move-coverage",
Expand All @@ -89,7 +89,7 @@ members = [
"vm/move-package-manager",
"vm/vm-status-translator",
"vm/starcoin-transactional-test-harness",
"vm/parallel-executor",
"commons/parallel-executor",
"vm/transaction-benchmarks",
"vm/e2e-tests",
"vm/proptest-helpers",
Expand Down Expand Up @@ -205,8 +205,8 @@ default-members = [
"vm/stdlib",
"vm/compiler",
"vm/move-prover",
"vm/mvhashmap",
"vm/parallel-executor",
"commons/mvhashmap",
"commons/parallel-executor",
"vm/transaction-builder",
"vm/transaction-builder-generator",
"vm/move-coverage",
Expand Down Expand Up @@ -574,9 +574,9 @@ stdlib = { path = "vm/stdlib" }
stest = { path = "commons/stest" }
stest-macro = { path = "commons/stest/stest-macro" }
stream-task = { path = "commons/stream-task" }
starcoin-mvhashmap = { path = "vm/mvhashmap" }
starcoin-mvhashmap = { path = "commons/mvhashmap" }
starcoin-infallible = { path = "commons/infallible" }
starcoin-parallel-executor = { path = "vm/parallel-executor" }
starcoin-parallel-executor = { path = "commons/parallel-executor" }
starcoin-transaction-benchmarks = { path = "vm/transaction-benchmarks" }
starcoin-language-e2e-tests = { path = "vm/e2e-tests" }
starcoin-proptest-helpers = { path = "vm/proptest-helpers" }
Expand Down
2 changes: 1 addition & 1 deletion chain/tests/test_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ fn test_block_chain_txn_info_fork_mapping() -> Result<()> {
);

// Verify they belong to different blocks
let block_ids = vec![block_b2.id(), block_b3.id()];
let block_ids = [block_b2.id(), block_b3.id()];
assert!(
block_ids.contains(&txn_info1.block_id()),
"txn_info1 should be in b2 or b3"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 10 additions & 80 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub use errors::GenesisError;
use starcoin_vm_types::state_store::table::{TableHandle, TableInfo};
use starcoin_vm_types::state_view::StateView;

use starcoin_types::block::{legacy, BlockBody};
use starcoin_vm2_storage::{
storage::StorageInstance as StorageInstance2, Storage as Storage2, Store as Store2,
};
Expand All @@ -58,56 +57,6 @@ pub struct Genesis {
block: Block,
}

#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename = "Genesis")]
pub struct LegacyGenesis {
block: legacy::Block,
}

impl From<LegacyGenesis> for Genesis {
fn from(legacy_genesis: LegacyGenesis) -> Self {
let txns = legacy_genesis
.block
.body
.transactions
.into_iter()
.map(|tx| tx.into())
.collect();
Genesis {
block: Block {
header: legacy_genesis.block.header.into(),

body: BlockBody::new(
txns,
legacy_genesis
.block
.body
.uncles
.map(|uncles| uncles.into_iter().map(|uncle| uncle.into()).collect()),
),
},
}
}
}

impl From<Genesis> for LegacyGenesis {
fn from(genesis: Genesis) -> Self {
LegacyGenesis {
block: legacy::Block {
header: genesis.block.header.into(),
body: legacy::BlockBody {
transactions: genesis.block.body.transactions,
uncles: genesis
.block
.body
.uncles
.map(|uncles| uncles.into_iter().map(|uncle| uncle.into()).collect()),
},
},
}
}
}

impl Display for Genesis {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Genesis {{")?;
Expand All @@ -128,10 +77,6 @@ impl Display for Genesis {
}
}

pub fn net_with_legacy_genesis(net: &BuiltinNetworkID) -> bool {
!(net.is_test_or_dev() || net.is_proxima())
}

impl Genesis {
pub const GENESIS_FILE_NAME: &'static str = "genesis";

Expand Down Expand Up @@ -328,7 +273,7 @@ impl Genesis {
&self.block
}

pub fn load_from_dir<P>(data_dir: P, legacy: bool) -> Result<Option<Self>>
pub fn load_from_dir<P>(data_dir: P) -> Result<Option<Self>>
where
P: AsRef<Path>,
{
Expand All @@ -339,12 +284,7 @@ impl Genesis {
let mut genesis_file = File::open(genesis_file_path)?;
let mut content = vec![];
genesis_file.read_to_end(&mut content)?;
let genesis = if legacy {
let legacy_genesis = bcs_ext::from_bytes::<LegacyGenesis>(&content)?;
legacy_genesis.into()
} else {
bcs_ext::from_bytes(&content)?
};
let genesis = bcs_ext::from_bytes(&content)?;
Ok(Some(genesis))
}

Expand Down Expand Up @@ -415,7 +355,7 @@ impl Genesis {
.ok_or_else(|| format_err!("ChainInfo should exist after genesis block executed."))
}

pub fn save<P>(&self, data_dir: P, legacy: bool) -> Result<()>
pub fn save<P>(&self, data_dir: P) -> Result<()>
where
P: AsRef<Path>,
{
Expand All @@ -425,21 +365,14 @@ impl Genesis {
}
let genesis_file = data_dir.join(Self::GENESIS_FILE_NAME);
let mut file = File::create(genesis_file)?;
let contents = if legacy {
let legacy_genesis = LegacyGenesis::from(self.clone());
bcs_ext::to_bytes(&legacy_genesis)?
} else {
bcs_ext::to_bytes(self)?
};
let contents = bcs_ext::to_bytes(self)?;
file.write_all(&contents)?;

Ok(())
}

fn load_and_check_genesis(net: &ChainNetwork, data_dir: &Path, init: bool) -> Result<Genesis> {
// todo: how and when upgrade legacy genesis?
let legacy_genesis = false;
let genesis = match Genesis::load_from_dir(data_dir, legacy_genesis) {
let genesis = match Genesis::load_from_dir(data_dir) {
Ok(Some(genesis)) => {
let expect_genesis = Genesis::load_or_build(net)?;
if genesis.block().header().id() != expect_genesis.block().header().id() {
Expand All @@ -455,7 +388,7 @@ impl Genesis {
Ok(None) => {
if init {
let genesis = Genesis::load_or_build(net)?;
genesis.save(data_dir, legacy_genesis)?;
genesis.save(data_dir)?;
info!(
"Genesis::load_and_check_genesis | Build and save new genesis: {}",
genesis
Expand Down Expand Up @@ -606,7 +539,7 @@ mod tests {
}
let net = ChainNetwork::new_builtin(id);
let temp_dir = starcoin_config::temp_dir();
do_test_genesis(&net, temp_dir.path(), false)?;
do_test_genesis(&net, temp_dir.path())?;
}
Ok(())
}
Expand All @@ -620,10 +553,10 @@ mod tests {
BuiltinNetworkID::Test.genesis_config2().clone(),
)?;
let temp_dir = starcoin_config::temp_dir();
do_test_genesis(&net, temp_dir.path(), false)
do_test_genesis(&net, temp_dir.path())
}

pub fn do_test_genesis(net: &ChainNetwork, data_dir: &Path, legacy: bool) -> Result<()> {
pub fn do_test_genesis(net: &ChainNetwork, data_dir: &Path) -> Result<()> {
let storage1 = Arc::new(Storage::new(StorageInstance::new_cache_instance())?);
let storage2 = Arc::new(Storage2::new(StorageInstance2::new_cache_instance())?);
let dag1 = BlockDAG::create_for_testing()?;
Expand Down Expand Up @@ -743,10 +676,7 @@ mod tests {
.expect("Genesis block info must exist.");

let txn_accumulator_info = block_info.get_txn_accumulator_info();
assert_eq!(
txn_accumulator_info.num_leaves,
1 + if legacy { 0 } else { 1 }
);
assert_eq!(txn_accumulator_info.num_leaves, 2);
//assert_eq!(txn_accumulator_info.frozen_subtree_roots.len(), 1);

let txn_accumulator = MerkleAccumulator::new_with_info(
Expand Down
4 changes: 1 addition & 3 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ fn main() {
std::env::set_current_dir(base_path).expect("failed to change directory");

let path = Path::new(G_GENESIS_GENERATED_DIR).join(net.to_string());
new_genesis
.save(path.as_path(), false)
.expect("save genesis fail");
new_genesis.save(path.as_path()).expect("save genesis fail");
} else {
info!(
"Chain net {} previous generated genesis same as new genesis, do nothing. id: {:?}",
Expand Down
14 changes: 12 additions & 2 deletions rpc/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,14 +932,24 @@ impl BlockView {
let (header, body) = block.into_inner();
let BlockBody {
transactions,
transactions2: _,
transactions2,
uncles,
} = body;
let txns_view = if thin {
BlockTransactionsView::Hashes(transactions.into_iter().map(|t| t.id()).collect())
} else {
transactions.try_into()?
transactions
.into_iter()
.map(MultiSignedUserTransaction::VM1)
.chain(
transactions2
.into_iter()
.map(MultiSignedUserTransaction::VM2),
)
.collect::<Vec<_>>()
.try_into()?
};

Ok(BlockView {
header: header.into(),
uncles: uncles
Expand Down
Loading