blockchain: chore clippy

This commit is contained in:
skoupidi
2025-06-28 17:10:53 +03:00
parent ea6139cead
commit 00e9d7cff3
17 changed files with 99 additions and 109 deletions

View File

@@ -511,10 +511,7 @@ impl BlockStore {
/// returning a collection of block heights with their associated [`HeaderHash`]s.
pub fn get_order_by_range(&self, start: u32, end: u32) -> Result<Vec<(u32, HeaderHash)>> {
if start >= end {
return Err(Error::DatabaseError(format!(
"Heights range is invalid: {}..{}",
start, end
)))
return Err(Error::DatabaseError(format!("Heights range is invalid: {start}..{end}")))
}
let mut blocks = vec![];

View File

@@ -91,7 +91,7 @@ impl ContractStore {
contract_id: &ContractId,
tree_name: &str,
) -> Result<sled::Tree> {
debug!(target: "blockchain::contractstore", "Looking up state tree for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstore", "Looking up state tree for {contract_id}:{tree_name}");
// A guard to make sure we went through init()
let contract_id_bytes = serialize(contract_id);
@@ -122,7 +122,7 @@ impl ContractStore {
/// NOTE: this function is not used right now, we keep it for future proofing,
/// and its obviously untested.
pub fn remove(&self, db: &sled::Db, contract_id: &ContractId, tree_name: &str) -> Result<()> {
debug!(target: "blockchain::contractstore", "Removing state tree for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstore", "Removing state tree for {contract_id}:{tree_name}");
// A guard to make sure we went through init()
let contract_id_bytes = serialize(contract_id);
@@ -158,7 +158,7 @@ impl ContractStore {
contract_id: &ContractId,
zkas_ns: &str,
) -> Result<(ZkBinary, VerifyingKey)> {
debug!(target: "blockchain::contractstore", "Looking up \"{}:{}\" zkas circuit & vk", contract_id, zkas_ns);
debug!(target: "blockchain::contractstore", "Looking up \"{contract_id}:{zkas_ns}\" zkas circuit & vk");
let zkas_tree = self.lookup(db, contract_id, SMART_CONTRACT_ZKAS_DB_NAME)?;
@@ -219,7 +219,7 @@ impl ContractStore {
tree_name: &str,
key: &[u8],
) -> Result<Vec<u8>> {
debug!(target: "blockchain::contractstore", "Looking up state tree value for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstore", "Looking up state tree value for {contract_id}:{tree_name}");
// Grab the state tree
let state_tree = self.lookup(db, contract_id, tree_name)?;
@@ -228,8 +228,7 @@ impl ContractStore {
match state_tree.get(key)? {
Some(value) => Ok(value.to_vec()),
None => Err(Error::DatabaseError(format!(
"State tree {}:{} doesn't contain key: {:?}",
contract_id, tree_name, key
"State tree {contract_id}:{tree_name} doesn't contain key: {key:?}"
))),
}
}
@@ -242,7 +241,7 @@ impl ContractStore {
contract_id: &ContractId,
tree_name: &str,
) -> Result<BTreeMap<Vec<u8>, Vec<u8>>> {
debug!(target: "blockchain::contractstore", "Looking up state tree records for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstore", "Looking up state tree records for {contract_id}:{tree_name}");
// Grab the state tree
let state_tree = self.lookup(db, contract_id, tree_name)?;
@@ -344,7 +343,7 @@ impl ContractStoreOverlay {
if let Err(e) =
self.0.lock().unwrap().insert(SLED_BINCODE_TREE, &serialize(&contract_id), bincode)
{
error!(target: "blockchain::contractstoreoverlay", "Failed to insert bincode to Wasm tree: {}", e);
error!(target: "blockchain::contractstoreoverlay", "Failed to insert bincode to Wasm tree: {e}");
return Err(e.into())
}
@@ -362,7 +361,7 @@ impl ContractStoreOverlay {
/// the main `ContractStateStoreOverlay` tree and a handle to it will be
/// returned.
pub fn init(&self, contract_id: &ContractId, tree_name: &str) -> Result<[u8; 32]> {
debug!(target: "blockchain::contractstoreoverlay", "Initializing state overlay tree for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstoreoverlay", "Initializing state overlay tree for {contract_id}:{tree_name}");
let mut lock = self.0.lock().unwrap();
// See if there are existing state trees.
@@ -395,7 +394,7 @@ impl ContractStoreOverlay {
/// state has been found, a handle to it will be returned. Otherwise, we
/// return an error.
pub fn lookup(&self, contract_id: &ContractId, tree_name: &str) -> Result<[u8; 32]> {
debug!(target: "blockchain::contractstoreoverlay", "Looking up state tree for {}:{}", contract_id, tree_name);
debug!(target: "blockchain::contractstoreoverlay", "Looking up state tree for {contract_id}:{tree_name}");
let mut lock = self.0.lock().unwrap();
// A guard to make sure we went through init()
@@ -426,7 +425,7 @@ impl ContractStoreOverlay {
contract_id: &ContractId,
zkas_ns: &str,
) -> Result<(ZkBinary, VerifyingKey)> {
debug!(target: "blockchain::contractstore", "Looking up \"{}:{}\" zkas circuit & vk", contract_id, zkas_ns);
debug!(target: "blockchain::contractstore", "Looking up \"{contract_id}:{zkas_ns}\" zkas circuit & vk");
let zkas_tree = self.lookup(contract_id, SMART_CONTRACT_ZKAS_DB_NAME)?;

View File

@@ -187,7 +187,7 @@ impl fmt::Display for Header {
self.pow_data,
);
write!(f, "{}", s)
write!(f, "{s}")
}
}

View File

@@ -171,7 +171,7 @@ impl Blockchain {
/// Retrieve [`BlockInfo`]s by given heights. Does not fail if any of them are not found.
pub fn get_blocks_by_heights(&self, heights: &[u32]) -> Result<Vec<BlockInfo>> {
debug!(target: "blockchain", "get_blocks_by_heights(): {:?}", heights);
debug!(target: "blockchain", "get_blocks_by_heights(): {heights:?}");
let blockhashes = self.blocks.get_order(heights, false)?;
let mut hashes = vec![];
@@ -184,7 +184,7 @@ impl Blockchain {
/// Retrieve n headers before given block height.
pub fn get_headers_before(&self, height: u32, n: usize) -> Result<Vec<Header>> {
debug!(target: "blockchain", "get_headers_before(): {} -> {}", height, n);
debug!(target: "blockchain", "get_headers_before(): {height} -> {n}");
let hashes = self.blocks.get_before(height, n)?;
let headers = self.headers.get(&hashes, true)?;
Ok(headers.iter().map(|h| h.clone().unwrap()).collect())

View File

@@ -100,8 +100,8 @@ fn test_keccak_serde() {
let mut digest2 = [0u8; 32];
de.finalize(&mut digest2);
println!("{:?}", digest1);
println!("{:?}", digest2);
println!("{digest1:?}");
println!("{digest2:?}");
assert_eq!(digest1, digest2);
}

View File

@@ -41,15 +41,13 @@ pub fn cn_fast_hash2(hash1: &Hash, hash2: &Hash) -> Hash {
fn tree_hash_count(count: usize) -> Result<usize> {
if count < 3 {
return Err(Error::MoneroHashingError(format!(
"Cannot calculate tree hash root. Expected count to be >3 but got {}",
count
"Cannot calculate tree hash root. Expected count to be >3 but got {count}"
)));
}
if count > 0x10000000 {
return Err(Error::MoneroHashingError(format!(
"Cannot calculate tree hash root. Expected count to be less than 0x10000000 but got {}",
count
"Cannot calculate tree hash root. Expected count to be less than 0x10000000 but got {count}"
)));
}

View File

@@ -134,7 +134,7 @@ impl DaoExecCall {
Witness::Base(Value::known(self.signature_secret.inner())),
]);
debug!(target: "contract::dao::client::exec", "proposal_bulla: {:?}", proposal_bulla);
debug!(target: "contract::dao::client::exec", "proposal_bulla: {proposal_bulla:?}");
let public_inputs = vec![
proposal_bulla.inner(),
proposal_auth_calls_commit,

View File

@@ -790,10 +790,10 @@ fn count_votes(
true => "yes",
false => "no",
};
info!("Voter {} voted {} with {} tokens in vote", i, vote_result, all_vote_value);
info!("Voter {i} voted {vote_result} with {all_vote_value} tokens in vote");
}
info!("Vote outcome = {} / {}", total_yes_vote_value, total_all_vote_value);
info!("Vote outcome = {total_yes_vote_value} / {total_all_vote_value}");
assert!(
blind_total_vote.all_vote_commit ==

View File

@@ -130,7 +130,7 @@ impl GenesisMintCallBuilder {
blind: Blind::random(&mut OsRng),
};
debug!(target: "contract::money::client::genesis_mint", "Creating token mint proof for output {}", i);
debug!(target: "contract::money::client::genesis_mint", "Creating token mint proof for output {i}");
let (proof, public_inputs) = create_transfer_mint_proof(
&self.mint_zkbin,
&self.mint_pk,

View File

@@ -99,7 +99,7 @@ impl TransferCallBuilder {
let signature_secret = SecretKey::random(&mut OsRng);
signature_secrets.push(signature_secret);
debug!(target: "contract::money::client::transfer::build", "Creating transfer burn proof for input {}", i);
debug!(target: "contract::money::client::transfer::build", "Creating transfer burn proof for input {i}");
let (proof, public_inputs) = create_transfer_burn_proof(
&self.burn_zkbin,
&self.burn_pk,
@@ -139,7 +139,7 @@ impl TransferCallBuilder {
output_blinds.push(value_blind);
debug!(target: "contract::money::client::transfer::build", "Creating transfer mint proof for output {}", i);
debug!(target: "contract::money::client::transfer::build", "Creating transfer mint proof for output {i}");
let (proof, public_inputs) = create_transfer_mint_proof(
&self.mint_zkbin,
&self.mint_pk,

View File

@@ -175,7 +175,7 @@ pub fn create_transfer_mint_proof(
user_data,
blind: coin_blind,
};
debug!(target: "contract::money::client::transfer::proof", "Created coin: {:?}", coin);
debug!(target: "contract::money::client::transfer::proof", "Created coin: {coin:?}");
let coin = coin.to_coin();
let public_inputs = TransferMintRevealed { coin, value_commit, token_commit };

View File

@@ -105,7 +105,7 @@ impl TestHarness {
holders: &[Holder],
) -> Result<Vec<OwnCoin>> {
// Build the POW reward transaction
info!("Building PoWReward transaction for {:?}", miner);
info!("Building PoWReward transaction for {miner:?}");
let (tx, params) = self.pow_reward(miner, None, None, None).await?;
// Fetch the last block in the blockchain

View File

@@ -78,7 +78,7 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
let mut vks = None;
if pks_path.exists() {
debug!("Found {:?}", pks_path);
debug!("Found {pks_path:?}");
let mut f = File::open(pks_path.clone())?;
let mut data = vec![];
f.read_to_end(&mut data)?;
@@ -86,8 +86,8 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
let known_hash = blake3::Hash::from_hex(PKS_HASH)?;
let found_hash = blake3::hash(&data);
debug!("Known PKS hash: {}", known_hash);
debug!("Found PKS hash: {}", found_hash);
debug!("Known PKS hash: {known_hash}");
debug!("Found PKS hash: {found_hash}");
if known_hash == found_hash {
pks = Some(deserialize(&data)?)
@@ -97,7 +97,7 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
}
if vks_path.exists() {
debug!("Found {:?}", vks_path);
debug!("Found {vks_path:?}");
let mut f = File::open(vks_path.clone())?;
let mut data = vec![];
f.read_to_end(&mut data)?;
@@ -105,8 +105,8 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
let known_hash = blake3::Hash::from_hex(VKS_HASH)?;
let found_hash = blake3::hash(&data);
debug!("Known VKS hash: {}", known_hash);
debug!("Found VKS hash: {}", found_hash);
debug!("Known VKS hash: {known_hash}");
debug!("Found VKS hash: {found_hash}");
if known_hash == found_hash {
vks = Some(deserialize(&data)?)
@@ -161,18 +161,18 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
vks.push((bincode.to_vec(), zkbin.namespace.clone(), vk_buf));
}
debug!("Writing PKs to {:?}", pks_path);
debug!("Writing PKs to {pks_path:?}");
let mut f = File::create(&pks_path)?;
let ser = serialize(&pks);
let hash = blake3::hash(&ser);
debug!("{:?} {}", pks_path, hash);
debug!("{pks_path:?} {hash}");
f.write_all(&ser)?;
debug!("Writing VKs to {:?}", vks_path);
debug!("Writing VKs to {vks_path:?}");
let mut f = File::create(&vks_path)?;
let ser = serialize(&vks);
let hash = blake3::hash(&ser);
debug!("{:?} {}", vks_path, hash);
debug!("{vks_path:?} {hash}");
f.write_all(&ser)?;
Ok((pks, vks))
@@ -216,7 +216,7 @@ pub fn inject(sled_db: &sled::Db, vks: &Vks) -> Result<()> {
dao_tree.insert(key, value)?;
}
x => panic!("Found unhandled zkas namespace {}", x),
x => panic!("Found unhandled zkas namespace {x}"),
}
}

View File

@@ -252,7 +252,7 @@ impl Consensus {
// Check its length
let length = fork.proposals.len();
if length < self.confirmation_threshold {
debug!(target: "validator::consensus::confirmation", "Nothing to confirme yet, best fork size: {}", length);
debug!(target: "validator::consensus::confirmation", "Nothing to confirme yet, best fork size: {length}");
drop(forks);
return Ok(None)
}
@@ -859,7 +859,7 @@ impl Fork {
{
Ok(gas_values) => gas_values,
Err(e) => {
debug!(target: "validator::consensus::unproposed_txs", "Transaction verification failed: {}", e);
debug!(target: "validator::consensus::unproposed_txs", "Transaction verification failed: {e}");
overlay.lock().unwrap().revert_to_checkpoint()?;
continue
}
@@ -875,8 +875,7 @@ impl Fork {
if accumulated_gas_usage > BLOCK_GAS_LIMIT {
warn!(
target: "validator::consensus::unproposed_txs",
"Retrieving transaction {} would exceed configured unproposed transaction gas limit: {} - {}",
tx, accumulated_gas_usage, BLOCK_GAS_LIMIT,
"Retrieving transaction {tx} would exceed configured unproposed transaction gas limit: {accumulated_gas_usage} - {BLOCK_GAS_LIMIT}"
);
overlay.lock().unwrap().revert_to_checkpoint()?;
break

View File

@@ -383,7 +383,7 @@ impl Validator {
let mut state_inverse_diffs = vec![];
info!(target: "validator::confirmation", "Confirming proposals:");
for (index, proposal) in confirmed_proposals.iter().enumerate() {
info!(target: "validator::confirmation", "\t{} - {}", proposal, confirmed_blocks[index].header.height);
info!(target: "validator::confirmation", "\t{proposal} - {}", confirmed_blocks[index].header.height);
fork.overlay.lock().unwrap().overlay.lock().unwrap().apply_diff(&diffs[index])?;
let next_difficulty = module.next_difficulty()?;
module.append(confirmed_blocks[index].header.timestamp, &next_difficulty);
@@ -464,7 +464,7 @@ impl Validator {
// Skip already existing block
Err(Error::BlockAlreadyExists(_)) => continue,
Err(e) => {
error!(target: "validator::add_checkpoint_blocks", "Erroneous block found in set: {}", e);
error!(target: "validator::add_checkpoint_blocks", "Erroneous block found in set: {e}");
overlay.lock().unwrap().overlay.lock().unwrap().purge_new_trees()?;
return Err(Error::BlockIsInvalid(block.hash().as_string()))
}
@@ -578,7 +578,7 @@ impl Validator {
continue
}
Err(e) => {
error!(target: "validator::add_test_blocks", "Erroneous block found in set: {}", e);
error!(target: "validator::add_test_blocks", "Erroneous block found in set: {e}");
overlay.lock().unwrap().overlay.lock().unwrap().purge_new_trees()?;
return Err(Error::BlockIsInvalid(block.hash().as_string()))
}
@@ -720,7 +720,7 @@ impl Validator {
)
.await
{
warn!(target: "validator::add_test_producer_transaction", "Transaction verification failed: {}", e);
warn!(target: "validator::add_test_producer_transaction", "Transaction verification failed: {e}");
erroneous_txs.push(tx.clone());
}

View File

@@ -344,10 +344,10 @@ pub fn mine_block(
) -> Result<()> {
let miner_setup = Instant::now();
debug!(target: "validator::pow::mine_block", "[MINER] Mine target: 0x{:064x}", target);
debug!(target: "validator::pow::mine_block", "[MINER] Mine target: 0x{target:064x}");
// Get the PoW input. The key changes with every mined block.
let input = miner_block.header.previous;
debug!(target: "validator::pow::mine_block", "[MINER] PoW input: {}", input);
debug!(target: "validator::pow::mine_block", "[MINER] PoW input: {input}");
let flags = RandomXFlags::default() | RandomXFlags::FULLMEM;
debug!(target: "validator::pow::mine_block", "[MINER] Initializing RandomX dataset...");
let dataset = Arc::new(RandomXDataset::new(flags, input.inner(), threads).unwrap());
@@ -368,19 +368,19 @@ pub fn mine_block(
let stop_signal = stop_signal.clone();
handles.push(thread::spawn(move || {
debug!(target: "validator::pow::mine_block", "[MINER] Initializing RandomX VM #{}...", t);
debug!(target: "validator::pow::mine_block", "[MINER] Initializing RandomX VM #{t}...");
let mut miner_nonce = t;
let vm = RandomXVM::new_fast(flags, &dataset).unwrap();
loop {
// Check if stop signal was received
if stop_signal.is_full() {
debug!(target: "validator::pow::mine_block", "[MINER] Stop signal received, thread #{} exiting", t);
debug!(target: "validator::pow::mine_block", "[MINER] Stop signal received, thread #{t} exiting");
break
}
block.header.nonce = miner_nonce;
if found_block.load(Ordering::SeqCst) {
debug!(target: "validator::pow::mine_block", "[MINER] Block found, thread #{} exiting", t);
debug!(target: "validator::pow::mine_block", "[MINER] Block found, thread #{t} exiting");
break
}
@@ -389,11 +389,9 @@ pub fn mine_block(
if out_hash <= target {
found_block.store(true, Ordering::SeqCst);
found_nonce.store(miner_nonce, Ordering::SeqCst);
debug!(target: "validator::pow::mine_block", "[MINER] Thread #{} found block using nonce {}",
t, miner_nonce
);
debug!(target: "validator::pow::mine_block", "[MINER] Thread #{t} found block using nonce {miner_nonce}");
debug!(target: "validator::pow::mine_block", "[MINER] Block hash {}", block.hash());
debug!(target: "validator::pow::mine_block", "[MINER] RandomX output: 0x{:064x}", out_hash);
debug!(target: "validator::pow::mine_block", "[MINER] RandomX output: 0x{out_hash:064x}");
break
}
@@ -463,9 +461,9 @@ mod tests {
let res = module.next_difficulty()?;
if res != difficulty {
eprintln!("Wrong wide difficulty for block {}", n);
eprintln!("Expected: {}", difficulty);
eprintln!("Found: {}", res);
eprintln!("Wrong wide difficulty for block {n}");
eprintln!("Expected: {difficulty}");
eprintln!("Found: {res}");
assert!(res == difficulty);
}

View File

@@ -58,7 +58,7 @@ pub async fn verify_genesis_block(
block_target: u32,
) -> Result<()> {
let block_hash = block.hash().as_string();
debug!(target: "validator::verification::verify_genesis_block", "Validating genesis block {}", block_hash);
debug!(target: "validator::verification::verify_genesis_block", "Validating genesis block {block_hash}");
// Check if block already exists
if overlay.lock().unwrap().has_block(block)? {
@@ -136,7 +136,7 @@ pub async fn verify_genesis_block(
// Insert block
overlay.lock().unwrap().add_block(block)?;
debug!(target: "validator::verification::verify_genesis_block", "Genesis block {} verified successfully", block_hash);
debug!(target: "validator::verification::verify_genesis_block", "Genesis block {block_hash} verified successfully");
Ok(())
}
@@ -209,7 +209,7 @@ pub async fn verify_block(
verify_fees: bool,
) -> Result<()> {
let block_hash = block.hash();
debug!(target: "validator::verification::verify_block", "Validating block {}", block_hash);
debug!(target: "validator::verification::verify_block", "Validating block {block_hash}");
// Check if block already exists
if overlay.lock().unwrap().has_block(block)? {
@@ -279,7 +279,7 @@ pub async fn verify_block(
// Insert block
overlay.lock().unwrap().add_block(block)?;
debug!(target: "validator::verification::verify_block", "Block {} verified successfully", block_hash);
debug!(target: "validator::verification::verify_block", "Block {block_hash} verified successfully");
Ok(())
}
@@ -292,7 +292,7 @@ pub async fn verify_checkpoint_block(
block_target: u32,
) -> Result<()> {
let block_hash = block.hash();
debug!(target: "validator::verification::verify_checkpoint_block", "Validating block {}", block_hash);
debug!(target: "validator::verification::verify_checkpoint_block", "Validating block {block_hash}");
// Check if block already exists
if overlay.lock().unwrap().has_block(block)? {
@@ -357,7 +357,7 @@ pub async fn verify_checkpoint_block(
// Insert block
overlay.lock().unwrap().add_block(block)?;
debug!(target: "validator::verification::verify_checkpoint_block", "Block {} verified successfully", block_hash);
debug!(target: "validator::verification::verify_checkpoint_block", "Block {block_hash} verified successfully");
Ok(())
}
@@ -365,7 +365,7 @@ pub async fn verify_checkpoint_block(
/// over blocks header hash.
pub fn verify_producer_signature(block: &BlockInfo, public_key: &PublicKey) -> Result<()> {
if !public_key.verify(block.header.hash().inner(), &block.signature) {
warn!(target: "validator::verification::verify_producer_signature", "Proposer {} signature could not be verified", public_key);
warn!(target: "validator::verification::verify_producer_signature", "Proposer {public_key} signature could not be verified");
return Err(Error::InvalidSignature)
}
@@ -385,7 +385,7 @@ pub async fn verify_producer_transaction(
tree: &mut MerkleTree,
) -> Result<PublicKey> {
let tx_hash = tx.hash();
debug!(target: "validator::verification::verify_producer_transaction", "Validating producer transaction {}", tx_hash);
debug!(target: "validator::verification::verify_producer_transaction", "Validating producer transaction {tx_hash}");
// Transaction must be a PoW reward one
if !tx.is_pow_reward() {
@@ -480,24 +480,24 @@ pub async fn verify_producer_transaction(
// When we're done executing over the tx's contract call, we now move on with verification.
// First we verify the signatures as that's cheaper, and then finally we verify the ZK proofs.
debug!(target: "validator::verification::verify_producer_transaction", "Verifying signatures for transaction {}", tx_hash);
debug!(target: "validator::verification::verify_producer_transaction", "Verifying signatures for transaction {tx_hash}");
if sig_table.len() != tx.signatures.len() {
error!(target: "validator::verification::verify_producer_transaction", "Incorrect number of signatures in tx {}", tx_hash);
error!(target: "validator::verification::verify_producer_transaction", "Incorrect number of signatures in tx {tx_hash}");
return Err(TxVerifyFailed::MissingSignatures.into())
}
// TODO: Go through the ZK circuits that have to be verified and account for the opcodes.
if let Err(e) = tx.verify_sigs(sig_table) {
error!(target: "validator::verification::verify_producer_transaction", "Signature verification for tx {} failed: {}", tx_hash, e);
error!(target: "validator::verification::verify_producer_transaction", "Signature verification for tx {tx_hash} failed: {e}");
return Err(TxVerifyFailed::InvalidSignature.into())
}
debug!(target: "validator::verification::verify_producer_transaction", "Signature verification successful");
debug!(target: "validator::verification::verify_producer_transaction", "Verifying ZK proofs for transaction {}", tx_hash);
debug!(target: "validator::verification::verify_producer_transaction", "Verifying ZK proofs for transaction {tx_hash}");
if let Err(e) = tx.verify_zkps(&verifying_keys, zkp_table).await {
error!(target: "validator::verification::verify_producer_transaction", "ZK proof verification for tx {} failed: {}", tx_hash, e);
error!(target: "validator::verification::verify_producer_transaction", "ZK proof verification for tx {tx_hash} failed: {e}");
return Err(TxVerifyFailed::InvalidZkProof.into())
}
debug!(target: "validator::verification::verify_producer_transaction", "ZK proof verification successful");
@@ -505,7 +505,7 @@ pub async fn verify_producer_transaction(
// Append hash to merkle tree
append_tx_to_merkle_tree(tree, tx);
debug!(target: "validator::verification::verify_producer_transaction", "Producer transaction {} verified successfully", tx_hash);
debug!(target: "validator::verification::verify_producer_transaction", "Producer transaction {tx_hash} verified successfully");
Ok(signature_public_key)
}
@@ -520,7 +520,7 @@ pub async fn apply_producer_transaction(
tree: &mut MerkleTree,
) -> Result<PublicKey> {
let tx_hash = tx.hash();
debug!(target: "validator::verification::apply_producer_transaction", "Applying producer transaction {}", tx_hash);
debug!(target: "validator::verification::apply_producer_transaction", "Applying producer transaction {tx_hash}");
// Producer transactions must contain a single, non-empty call
if !tx.is_single_call() {
@@ -582,7 +582,7 @@ pub async fn apply_producer_transaction(
// Append hash to merkle tree
append_tx_to_merkle_tree(tree, tx);
debug!(target: "validator::verification::apply_producer_transaction", "Producer transaction {} executed successfully", tx_hash);
debug!(target: "validator::verification::apply_producer_transaction", "Producer transaction {tx_hash} executed successfully");
Ok(signature_public_key)
}
@@ -600,7 +600,7 @@ pub async fn verify_transaction(
verify_fee: bool,
) -> Result<GasData> {
let tx_hash = tx.hash();
debug!(target: "validator::verification::verify_transaction", "Validating transaction {}", tx_hash);
debug!(target: "validator::verification::verify_transaction", "Validating transaction {tx_hash}");
// Create a FeeData instance to hold the calculated fee data
let mut gas_data = GasData::default();
@@ -638,7 +638,7 @@ pub async fn verify_transaction(
if !found_fee {
error!(
target: "validator::verification::verify_transcation",
"[VALIDATOR] Transaction {} does not contain fee payment call", tx_hash,
"[VALIDATOR] Transaction {tx_hash} does not contain fee payment call"
);
return Err(TxVerifyFailed::InvalidFee.into())
}
@@ -653,7 +653,7 @@ pub async fn verify_transaction(
// Iterate over all calls to get the metadata
for (idx, call) in tx.calls.iter().enumerate() {
debug!(target: "validator::verification::verify_transaction", "Executing contract call {}", idx);
debug!(target: "validator::verification::verify_transaction", "Executing contract call {idx}");
// Transaction must not contain a Pow reward call
if call.data.is_money_pow_reward() {
@@ -687,7 +687,7 @@ pub async fn verify_transaction(
if decoder.position() != metadata.len() as u64 {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] Failed decoding entire metadata buffer for {}:{}", tx_hash, idx,
"[VALIDATOR] Failed decoding entire metadata buffer for {tx_hash}:{idx}"
);
return Err(TxVerifyFailed::ErroneousTxs(vec![tx.clone()]).into())
}
@@ -754,14 +754,14 @@ pub async fn verify_transaction(
deploy_runtime.deploy(&deploy_params.ix)?;
let deploy_gas_used = deploy_runtime.gas_used();
debug!(target: "validator::verification::verify_transaction", "The gas used for deployment call {:?} of transaction {}: {}", call, tx_hash, deploy_gas_used);
debug!(target: "validator::verification::verify_transaction", "The gas used for deployment call {call:?} of transaction {tx_hash}: {deploy_gas_used}");
gas_data.deployments += deploy_gas_used;
}
// At this point we're done with the call and move on to the next one.
// Accumulate the WASM gas used.
let wasm_gas_used = runtime.gas_used();
debug!(target: "validator::verification::verify_transaction", "The gas used for WASM call {:?} of transaction {}: {}", call, tx_hash, wasm_gas_used);
debug!(target: "validator::verification::verify_transaction", "The gas used for WASM call {call:?} of transaction {tx_hash}: {wasm_gas_used}");
// Append the used wasm gas
gas_data.wasm += wasm_gas_used;
@@ -770,12 +770,12 @@ pub async fn verify_transaction(
// The signature fee is tx_size + fixed_sig_fee * n_signatures
gas_data.signatures = (PALLAS_SCHNORR_SIGNATURE_FEE * tx.signatures.len() as u64) +
serialize_async(tx).await.len() as u64;
debug!(target: "validator::verification::verify_transaction", "The gas used for signature of transaction {}: {}", tx_hash, gas_data.signatures);
debug!(target: "validator::verification::verify_transaction", "The gas used for signature of transaction {tx_hash}: {}", gas_data.signatures);
// The ZK circuit fee is calculated using a function in validator/fees.rs
for zkbin in circuits_to_verify.iter() {
let zk_circuit_gas_used = circuit_gas_use(zkbin);
debug!(target: "validator::verification::verify_transaction", "The gas used for ZK circuit in namespace {} of transaction {}: {}", zkbin.namespace, tx_hash, zk_circuit_gas_used);
debug!(target: "validator::verification::verify_transaction", "The gas used for ZK circuit in namespace {} of transaction {tx_hash}: {zk_circuit_gas_used}", zkbin.namespace);
// Append the used zk circuit gas
gas_data.zk_circuits += zk_circuit_gas_used;
@@ -791,7 +791,7 @@ pub async fn verify_transaction(
Err(e) => {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] Failed deserializing tx {} fee call: {}", tx_hash, e,
"[VALIDATOR] Failed deserializing tx {tx_hash} fee call: {e}"
);
return Err(TxVerifyFailed::InvalidFee.into())
}
@@ -804,12 +804,11 @@ pub async fn verify_transaction(
if required_fee > fee {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] Transaction {} has insufficient fee. Required: {}, Paid: {}",
tx_hash, required_fee, fee,
"[VALIDATOR] Transaction {tx_hash} has insufficient fee. Required: {required_fee}, Paid: {fee}"
);
return Err(TxVerifyFailed::InsufficientFee.into())
}
debug!(target: "validator::verification::verify_transaction", "The gas paid for transaction {}: {}", tx_hash, gas_data.paid);
debug!(target: "validator::verification::verify_transaction", "The gas paid for transaction {tx_hash}: {}", gas_data.paid);
// Store paid fee
gas_data.paid = fee;
@@ -819,11 +818,11 @@ pub async fn verify_transaction(
// (optionally) made sure that enough fee was paid, we now move on with
// verification. First we verify the transaction signatures and then we
// verify any accompanying ZK proofs.
debug!(target: "validator::verification::verify_transaction", "Verifying signatures for transaction {}", tx_hash);
debug!(target: "validator::verification::verify_transaction", "Verifying signatures for transaction {tx_hash}");
if sig_table.len() != tx.signatures.len() {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] Incorrect number of signatures in tx {}", tx_hash,
"[VALIDATOR] Incorrect number of signatures in tx {tx_hash}"
);
return Err(TxVerifyFailed::MissingSignatures.into())
}
@@ -831,17 +830,17 @@ pub async fn verify_transaction(
if let Err(e) = tx.verify_sigs(sig_table) {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] Signature verification for tx {} failed: {}", tx_hash, e,
"[VALIDATOR] Signature verification for tx {tx_hash} failed: {e}"
);
return Err(TxVerifyFailed::InvalidSignature.into())
}
debug!(target: "validator::verification::verify_transaction", "Signature verification successful");
debug!(target: "validator::verification::verify_transaction", "Verifying ZK proofs for transaction {}", tx_hash);
debug!(target: "validator::verification::verify_transaction", "Verifying ZK proofs for transaction {tx_hash}");
if let Err(e) = tx.verify_zkps(verifying_keys, zkp_table).await {
error!(
target: "validator::verification::verify_transaction",
"[VALIDATOR] ZK proof verification for tx {} failed: {}", tx_hash, e,
"[VALIDATOR] ZK proof verification for tx {tx_hash} failed: {e}"
);
return Err(TxVerifyFailed::InvalidZkProof.into())
}
@@ -850,8 +849,8 @@ pub async fn verify_transaction(
// Append hash to merkle tree
append_tx_to_merkle_tree(tree, tx);
debug!(target: "validator::verification::verify_transaction", "The total gas used for transaction {}: {}", tx_hash, total_gas_used);
debug!(target: "validator::verification::verify_transaction", "Transaction {} verified successfully", tx_hash);
debug!(target: "validator::verification::verify_transaction", "The total gas used for transaction {tx_hash}: {total_gas_used}");
debug!(target: "validator::verification::verify_transaction", "Transaction {tx_hash} verified successfully");
Ok(gas_data)
}
@@ -865,7 +864,7 @@ pub async fn apply_transaction(
tree: &mut MerkleTree,
) -> Result<()> {
let tx_hash = tx.hash();
debug!(target: "validator::verification::apply_transaction", "Applying transaction {}", tx_hash);
debug!(target: "validator::verification::apply_transaction", "Applying transaction {tx_hash}");
// Write the transaction calls payload data
let mut payload = vec![];
@@ -873,7 +872,7 @@ pub async fn apply_transaction(
// Iterate over all calls to get the metadata
for (idx, call) in tx.calls.iter().enumerate() {
debug!(target: "validator::verification::apply_transaction", "Executing contract call {}", idx);
debug!(target: "validator::verification::apply_transaction", "Executing contract call {idx}");
debug!(target: "validator::verification::apply_transaction", "Instantiating WASM runtime");
let wasm = overlay.lock().unwrap().contracts.get(call.data.contract_id)?;
@@ -927,7 +926,7 @@ pub async fn apply_transaction(
// Append hash to merkle tree
append_tx_to_merkle_tree(tree, tx);
debug!(target: "validator::verification::apply_transaction", "Transaction {} applied successfully", tx_hash);
debug!(target: "validator::verification::apply_transaction", "Transaction {tx_hash} applied successfully");
Ok(())
}
@@ -983,7 +982,7 @@ pub async fn verify_transactions(
{
Ok(gas_values) => gas_values,
Err(e) => {
warn!(target: "validator::verification::verify_transactions", "Transaction verification failed: {}", e);
warn!(target: "validator::verification::verify_transactions", "Transaction verification failed: {e}");
erroneous_txs.push(tx.clone());
overlay.lock().unwrap().revert_to_checkpoint()?;
continue
@@ -1000,8 +999,8 @@ pub async fn verify_transactions(
if accumulated_gas_usage > BLOCK_GAS_LIMIT {
warn!(
target: "validator::verification::verify_transactions",
"Transaction {} exceeds configured transaction gas limit: {} - {}",
tx.hash(), accumulated_gas_usage, BLOCK_GAS_LIMIT,
"Transaction {} exceeds configured transaction gas limit: {accumulated_gas_usage} - {BLOCK_GAS_LIMIT}",
tx.hash()
);
erroneous_txs.push(tx.clone());
overlay.lock().unwrap().revert_to_checkpoint()?;
@@ -1044,7 +1043,7 @@ async fn apply_transactions(
if let Err(e) =
apply_transaction(overlay, verifying_block_height, block_target, tx, tree).await
{
warn!(target: "validator::verification::apply_transactions", "Transaction apply failed: {}", e);
warn!(target: "validator::verification::apply_transactions", "Transaction apply failed: {e}");
erroneous_txs.push(tx.clone());
overlay.lock().unwrap().revert_to_checkpoint()?;
};
@@ -1072,8 +1071,8 @@ pub async fn verify_proposal(
let proposal_hash = proposal.block.hash();
if proposal.hash != proposal_hash {
warn!(
target: "validator::verification::verify_proposal", "Received proposal contains mismatched hashes: {} - {}",
proposal.hash, proposal_hash
target: "validator::verification::verify_proposal", "Received proposal contains mismatched hashes: {} - {proposal_hash}",
proposal.hash
);
return Err(Error::ProposalHashesMissmatchError)
}
@@ -1118,8 +1117,8 @@ pub async fn verify_fork_proposal(
let proposal_hash = proposal.block.hash();
if proposal.hash != proposal_hash {
warn!(
target: "validator::verification::verify_fork_proposal", "Received proposal contains mismatched hashes: {} - {}",
proposal.hash, proposal_hash
target: "validator::verification::verify_fork_proposal", "Received proposal contains mismatched hashes: {} - {proposal_hash}",
proposal.hash
);
return Err(Error::ProposalHashesMissmatchError)
}