Skip to content

Commit

Permalink
debug: epoch test.
Browse files Browse the repository at this point in the history
  • Loading branch information
l-monninger committed Jan 29, 2025
1 parent eecfa2d commit 7030b2f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ venv
*.jot.*
*.jot
*.env
.debug
.debug
.out
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
.unwrap();

let temp_dir = tempdir().map_err(|e| ReleaseBundleError::Build(e.into()))?;
let gas_script_path = temp_dir.path().join("gas_upgrade");
let gas_script_path = temp_dir.path().join("proposal");
let mut gas_script_path = gas_script_path.as_path().to_path_buf();
gas_script_path.set_extension("move");
fs::write(gas_script_path.as_path(), update_gas_script)
Expand All @@ -87,7 +87,7 @@ where
);

let bytecode = compiler
.compile_in_temp_dir_to_bytecode("gas_upgrade", &gas_script_path)
.compile_in_temp_dir_to_bytecode("proposal", &gas_script_path)
.map_err(|e| ReleaseBundleError::Build(e.into()))?;

Ok(bytecode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Compiler {
script_path: &Path,
) -> Result<BuiltPackage, anyhow::Error> {
// Make a temporary directory for compilation
let package_dir = PathBuf::from(".debug/move-scripts/").join(script_name);
let package_dir = PathBuf::from(".debug/move-scripts").join(script_name);

// Make the temporary directory
fs::create_dir_all(&package_dir).context(format!(
Expand Down
26 changes: 19 additions & 7 deletions protocol-units/execution/maptos/framework/releases/util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,32 @@ pub trait Release {
.await?;

// wait for the transactions to be executed
let mut i = 0;
let mut errors = vec![];
for transaction in &submitted_transactions {
client.wait_for_signed_transaction_bcs(transaction).await.map_err(|e| {
match client.wait_for_signed_transaction_bcs(transaction).await.map_err(|e| {
ReleaseBundleError::Proposing(
format!(
"waiting for transaction {:?} failed with: {:?}",
"waiting for transaction {:?} {:?} failed with: {:?}",
i,
transaction.committed_hash(),
e
)
.into(),
)
})?;
}) {
Ok(_) => {}
Err(e) => {
errors.push(e);
}
}
i += 1;
}

if !errors.is_empty() {
return Err(ReleaseBundleError::Proposing(
format!("transaction errors: {:?}", errors).into(),
));
}

Ok(submitted_transactions)
Expand Down Expand Up @@ -437,10 +452,7 @@ fn build_release_package_transaction_payload(
) -> Result<TransactionPayload, ReleaseBundleError> {
println!("release_package_code: {:?}", release_package.code().len());

// use .debug/move-scripts/{package.package_metadata.name()} to write out the script
let script_path = PathBuf::from(".debug/move-scripts/")
.join(release_package.package_metadata().name.clone())
.with_extension("move");
let script_path = PathBuf::from(".debug/move-scripts").join("proposal").with_extension("move");
// create all parent directories
std::fs::create_dir_all(script_path.parent().unwrap()).map_err(|e| {
ReleaseBundleError::Build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ impl Executor {
}
};

for transaction in metadata_access_transactions.iter() {
debug!("Transaction sender: {:?}", transaction.sender());
}

// reconstruct the block
let block = ExecutableBlock::new(
block.block_id.clone(),
Expand Down Expand Up @@ -174,6 +170,12 @@ impl Executor {
root_hash: HashValue,
version: Version,
) -> LedgerInfoWithSignatures {
let next_epoch = if version >= self.config().chain.dont_increase_epoch_until_version {
epoch + 1
} else {
epoch
};

let block_info = BlockInfo::new(
epoch,
round,
Expand All @@ -182,7 +184,7 @@ impl Executor {
version,
timestamp_microseconds,
Some(EpochState {
epoch,
epoch: next_epoch, // we now increase the epoch
verifier: ValidatorVerifier::new(vec![ValidatorConsensusInfo::new(
self.signer.author(),
self.signer.public_key(),
Expand Down Expand Up @@ -305,6 +307,7 @@ mod tests {
// Loop to simulate the execution of multiple blocks.
for i in 0..10 {
let (epoch, round) = executor.get_next_epoch_and_round()?;
info!("Epoch: {}, Round: {}", epoch, round);

// Generate a random block ID.
let block_id = HashValue::random();
Expand Down Expand Up @@ -362,7 +365,9 @@ mod tests {
// Access the database reader to verify state after execution.
let db_reader = executor.db_reader();
// Get the latest version of the blockchain state from the database.
let latest_version = db_reader.get_synced_version()?;
let latest_version = db_reader.get_latest_ledger_info_version()?;

info!("Latest version: {}", latest_version);
// Verify the transaction by its hash to ensure it was committed.
let transaction_result =
db_reader.get_transaction_by_hash(mint_tx_hash, latest_version, false)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ impl Executor {
let tempdir = tempfile::tempdir()?;

let mut maptos_config = Config::default();
maptos_config.chain.maptos_private_key_signer_identifier = SignerIdentifier::Local(Local {
private_key_hex_bytes: private_key.to_encoded_string()?.to_string(),
});
let raw_private_key_hex = private_key.to_encoded_string()?.to_string();
let prefix_stripped =
raw_private_key_hex.strip_prefix("0x").unwrap_or(&raw_private_key_hex);
maptos_config.chain.maptos_private_key_signer_identifier =
SignerIdentifier::Local(Local { private_key_hex_bytes: prefix_stripped.to_string() });

// replace the db path with the temporary directory
maptos_config.chain.maptos_db_path.replace(tempdir.path().to_path_buf());
Expand Down
12 changes: 12 additions & 0 deletions protocol-units/execution/maptos/util/src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub fn default_known_framework_release_str() -> String {
}
}

pub fn default_dont_increase_epoch_until_version() -> u64 {
match std::env::var("DONT_INCREASE_EPOCH_UNTIL_VERSION") {
Ok(val) => val.parse().unwrap(),
Err(_) => 0,
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Config {
/// The chain id for the Aptos node
Expand Down Expand Up @@ -69,6 +76,10 @@ pub struct Config {
/// The known framework release
#[serde(default = "default_known_framework_release_str")]
pub known_framework_release_str: String,

/// The version to not increase the epoch until
#[serde(default = "default_dont_increase_epoch_until_version")]
pub dont_increase_epoch_until_version: u64,
}

impl Default for Config {
Expand All @@ -87,6 +98,7 @@ impl Default for Config {
genesis_block_hash_hex: default_genesis_block_hash_hex(),
maptos_db_path: None,
known_framework_release_str: default_known_framework_release_str(),
dont_increase_epoch_until_version: default_dont_increase_epoch_until_version(),
}
}
}

0 comments on commit 7030b2f

Please sign in to comment.