Skip to content

Commit 3c812cf

Browse files
committed
Fix logs to use inplace formatting in stacks node
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 72d45f5 commit 3c812cf

31 files changed

+727
-982
lines changed

stackslib/src/chainstate/stacks/tests/mod.rs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn path_join(dir: &str, path: &str) -> String {
8181

8282
// copy src to dest
8383
pub fn copy_dir(src_dir: &str, dest_dir: &str) -> Result<(), io::Error> {
84-
eprintln!("Copy directory {} to {}", src_dir, dest_dir);
84+
eprintln!("Copy directory {src_dir} to {dest_dir}");
8585

8686
let mut dir_queue = VecDeque::new();
8787
dir_queue.push_back("/".to_string());
@@ -91,7 +91,7 @@ pub fn copy_dir(src_dir: &str, dest_dir: &str) -> Result<(), io::Error> {
9191
let next_src_dir = path_join(&src_dir, &next_dir);
9292
let next_dest_dir = path_join(&dest_dir, &next_dir);
9393

94-
eprintln!("mkdir {}", &next_dest_dir);
94+
eprintln!("mkdir {next_dest_dir}");
9595
fs::create_dir_all(&next_dest_dir)?;
9696

9797
for dirent_res in fs::read_dir(&next_src_dir)? {
@@ -100,11 +100,11 @@ pub fn copy_dir(src_dir: &str, dest_dir: &str) -> Result<(), io::Error> {
100100
let md = fs::metadata(&path)?;
101101
if md.is_dir() {
102102
let frontier = path_join(&next_dir, &dirent.file_name().to_str().unwrap());
103-
eprintln!("push {}", &frontier);
103+
eprintln!("push {frontier}");
104104
dir_queue.push_back(frontier);
105105
} else {
106106
let dest_path = path_join(&next_dest_dir, &dirent.file_name().to_str().unwrap());
107-
eprintln!("copy {} to {}", &path.to_str().unwrap(), &dest_path);
107+
eprintln!("copy {} to {dest_path}", &path.to_str().unwrap());
108108
fs::copy(path, dest_path)?;
109109
}
110110
}
@@ -583,11 +583,10 @@ impl TestStacksNode {
583583
);
584584

585585
test_debug!(
586-
"Miner {}: Block commit transaction builds on {},{} (parent snapshot is {:?})",
586+
"Miner {}: Block commit transaction builds on {},{} (parent snapshot is {parent_block_snapshot_opt:?})",
587587
miner.id,
588588
block_commit_op.parent_block_ptr,
589-
block_commit_op.parent_vtxindex,
590-
&parent_block_snapshot_opt
589+
block_commit_op.parent_vtxindex
591590
);
592591
self.commit_ops.insert(
593592
block_commit_op.block_header_hash.clone(),
@@ -767,16 +766,15 @@ pub fn preprocess_stacks_block_data(
767766
{
768767
Some(sn) => sn,
769768
None => {
770-
test_debug!("Block commit did not win sorition: {:?}", block_commit_op);
769+
test_debug!("Block commit did not win sorition: {block_commit_op:?}");
771770
return None;
772771
}
773772
};
774773

775774
// "discover" this stacks block
776775
test_debug!(
777-
"\n\nPreprocess Stacks block {}/{} ({})",
776+
"\n\nPreprocess Stacks block {}/{block_hash} ({})",
778777
&commit_snapshot.consensus_hash,
779-
&block_hash,
780778
StacksBlockHeader::make_index_block_hash(&commit_snapshot.consensus_hash, &block_hash)
781779
);
782780
let block_res = node
@@ -793,8 +791,7 @@ pub fn preprocess_stacks_block_data(
793791
// "discover" this stacks microblock stream
794792
for mblock in stacks_microblocks.iter() {
795793
test_debug!(
796-
"Preprocess Stacks microblock {}-{} (seq {})",
797-
&block_hash,
794+
"Preprocess Stacks microblock {block_hash}-{} (seq {})",
798795
mblock.block_hash(),
799796
mblock.header.sequence
800797
);
@@ -828,11 +825,9 @@ pub fn check_block_state_index_root(
828825
.read_block_root_hash(&index_block_hash)
829826
.unwrap();
830827
test_debug!(
831-
"checking {}/{} state root: expecting {}, got {}",
832-
consensus_hash,
828+
"checking {consensus_hash}/{} state root: expecting {}, got {state_root}",
833829
&stacks_header.block_hash(),
834-
&stacks_header.state_index_root,
835-
&state_root
830+
&stacks_header.state_index_root
836831
);
837832
state_root == stacks_header.state_index_root
838833
}
@@ -888,9 +883,8 @@ pub fn check_mining_reward(
888883

889884
let mut total: u128 = 10_000_000_000 - spent_total;
890885
test_debug!(
891-
"Miner {} has spent {} in total so far",
892-
&miner.origin_address().unwrap(),
893-
spent_total
886+
"Miner {} has spent {spent_total} in total so far",
887+
&miner.origin_address().unwrap()
894888
);
895889

896890
if block_height >= MINER_REWARD_MATURITY {
@@ -908,23 +902,19 @@ pub fn check_mining_reward(
908902
let reward = recipient.coinbase + anchored + (3 * streamed / 5);
909903

910904
test_debug!(
911-
"Miner {} received a reward {} = {} + {} + {} at block {}",
905+
"Miner {} received a reward {reward} = {} + {anchored} + {} at block {i}",
912906
&recipient.address.to_string(),
913-
reward,
914907
recipient.coinbase,
915-
anchored,
916908
(3 * streamed / 5),
917-
i
918909
);
919910
total += reward;
920911
found = true;
921912
}
922913
}
923914
if !found {
924915
test_debug!(
925-
"Miner {} received no reward at block {}",
926-
miner.origin_address().unwrap(),
927-
i
916+
"Miner {} received no reward at block {i}",
917+
miner.origin_address().unwrap()
928918
);
929919
}
930920
}
@@ -945,11 +935,9 @@ pub fn check_mining_reward(
945935
&parent_reward.block_hash,
946936
);
947937
test_debug!(
948-
"Miner {} received a produced-stream reward {} from {} confirmed at {}",
938+
"Miner {} received a produced-stream reward {parent_streamed} from {} confirmed at {confirmed_block_height}",
949939
miner.origin_address().unwrap().to_string(),
950-
parent_streamed,
951-
heights.get(&parent_ibh).unwrap(),
952-
confirmed_block_height
940+
heights.get(&parent_ibh).unwrap()
953941
);
954942
total += parent_streamed;
955943
}
@@ -967,7 +955,7 @@ pub fn check_mining_reward(
967955
return total == 0;
968956
} else {
969957
if amount != total {
970-
test_debug!("Amount {} != {}", amount, total);
958+
test_debug!("Amount {amount} != {total}");
971959
return false;
972960
}
973961
return true;
@@ -1091,16 +1079,14 @@ pub fn make_smart_contract_with_version(
10911079
(begin (var-set bar (/ x y)) (ok (var-get bar))))";
10921080

10931081
test_debug!(
1094-
"Make smart contract block at hello-world-{}-{}",
1095-
burnchain_height,
1096-
stacks_block_height
1082+
"Make smart contract block at hello-world-{burnchain_height}-{stacks_block_height}"
10971083
);
10981084

10991085
let mut tx_contract = StacksTransaction::new(
11001086
TransactionVersion::Testnet,
11011087
miner.as_transaction_auth().unwrap(),
11021088
TransactionPayload::new_smart_contract(
1103-
&format!("hello-world-{}-{}", burnchain_height, stacks_block_height),
1089+
&format!("hello-world-{burnchain_height}-{stacks_block_height}"),
11041090
&contract.to_string(),
11051091
version,
11061092
)
@@ -1140,7 +1126,7 @@ pub fn make_contract_call(
11401126
miner.as_transaction_auth().unwrap(),
11411127
TransactionPayload::new_contract_call(
11421128
addr.clone(),
1143-
&format!("hello-world-{}-{}", burnchain_height, stacks_block_height),
1129+
&format!("hello-world-{burnchain_height}-{stacks_block_height}"),
11441130
"set-bar",
11451131
vec![Value::Int(arg1), Value::Int(arg2)],
11461132
)

0 commit comments

Comments
 (0)