mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-13 08:40:45 +08:00
chore: Fix clippy::perf warnings in ./testnet/stacks-node (except large_enum_variant and result_large_err)
This commit is contained in:
@@ -2122,7 +2122,7 @@ impl ParsedUTXO {
|
||||
}
|
||||
|
||||
pub fn serialized_btc_to_sat(amount: &str) -> Option<u64> {
|
||||
let comps: Vec<&str> = amount.split(".").collect();
|
||||
let comps: Vec<&str> = amount.split('.').collect();
|
||||
match comps[..] {
|
||||
[lhs, rhs] => {
|
||||
if rhs.len() > 8 {
|
||||
@@ -2198,7 +2198,7 @@ impl BitcoinRPCRequest {
|
||||
_ => None,
|
||||
};
|
||||
let url = config.burnchain.get_rpc_url(wallet_id);
|
||||
Url::parse(&url).expect(&format!("Unable to parse {} as a URL", url))
|
||||
Url::parse(&url).unwrap_or_else(|_| panic!("Unable to parse {} as a URL", url))
|
||||
};
|
||||
debug!(
|
||||
"BitcoinRPC builder '{}': {:?}:{:?}@{}",
|
||||
|
||||
@@ -868,7 +868,7 @@ impl Config {
|
||||
None => default_burnchain_config,
|
||||
};
|
||||
|
||||
let supported_modes = vec![
|
||||
let supported_modes = [
|
||||
"mocknet",
|
||||
"helium",
|
||||
"neon",
|
||||
@@ -1057,10 +1057,12 @@ impl Config {
|
||||
pub fn get_estimates_path(&self) -> PathBuf {
|
||||
let mut path = self.get_chainstate_path();
|
||||
path.push("estimates");
|
||||
fs::create_dir_all(&path).expect(&format!(
|
||||
"Failed to create `estimates` directory at {}",
|
||||
path.to_string_lossy()
|
||||
));
|
||||
fs::create_dir_all(&path).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Failed to create `estimates` directory at {}",
|
||||
path.to_string_lossy()
|
||||
)
|
||||
});
|
||||
path
|
||||
}
|
||||
|
||||
@@ -1846,7 +1848,7 @@ impl NodeConfig {
|
||||
}
|
||||
|
||||
pub fn add_bootstrap_node(&mut self, bootstrap_node: &str, chain_id: u32, peer_version: u32) {
|
||||
let parts: Vec<&str> = bootstrap_node.split("@").collect();
|
||||
let parts: Vec<&str> = bootstrap_node.split('@').collect();
|
||||
if parts.len() != 2 {
|
||||
panic!(
|
||||
"Invalid bootstrap node '{}': expected PUBKEY@IP:PORT",
|
||||
@@ -1855,7 +1857,7 @@ impl NodeConfig {
|
||||
}
|
||||
let (pubkey_str, hostport) = (parts[0], parts[1]);
|
||||
let pubkey = Secp256k1PublicKey::from_hex(pubkey_str)
|
||||
.expect(&format!("Invalid public key '{}'", pubkey_str));
|
||||
.unwrap_or_else(|_| panic!("Invalid public key '{}'", pubkey_str));
|
||||
info!("Resolve '{}'", &hostport);
|
||||
let sockaddr = hostport.to_socket_addrs().unwrap().next().unwrap();
|
||||
let neighbor = NodeConfig::default_neighbor(sockaddr, pubkey, chain_id, peer_version);
|
||||
@@ -1868,7 +1870,7 @@ impl NodeConfig {
|
||||
chain_id: u32,
|
||||
peer_version: u32,
|
||||
) {
|
||||
let parts: Vec<&str> = bootstrap_nodes.split(",").collect();
|
||||
let parts: Vec<&str> = bootstrap_nodes.split(',').collect();
|
||||
for part in parts.into_iter() {
|
||||
if part.len() > 0 {
|
||||
self.add_bootstrap_node(&part, chain_id, peer_version);
|
||||
@@ -1888,7 +1890,7 @@ impl NodeConfig {
|
||||
}
|
||||
|
||||
pub fn set_deny_nodes(&mut self, deny_nodes: String, chain_id: u32, peer_version: u32) {
|
||||
let parts: Vec<&str> = deny_nodes.split(",").collect();
|
||||
let parts: Vec<&str> = deny_nodes.split(',').collect();
|
||||
for part in parts.into_iter() {
|
||||
if part.len() > 0 {
|
||||
self.add_deny_node(&part, chain_id, peer_version);
|
||||
@@ -2415,7 +2417,7 @@ impl EventKeyType {
|
||||
|
||||
let comps: Vec<_> = raw_key.split("::").collect();
|
||||
if comps.len() == 1 {
|
||||
let split: Vec<_> = comps[0].split(".").collect();
|
||||
let split: Vec<_> = comps[0].split('.').collect();
|
||||
if split.len() != 3 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -116,15 +116,13 @@ impl EventObserver {
|
||||
};
|
||||
|
||||
let url = {
|
||||
let joined_components = match path.starts_with("/") {
|
||||
let joined_components = match path.starts_with('/') {
|
||||
true => format!("{}{}", &self.endpoint, path),
|
||||
false => format!("{}/{}", &self.endpoint, path),
|
||||
};
|
||||
let url = format!("http://{}", joined_components);
|
||||
Url::parse(&url).expect(&format!(
|
||||
"Event dispatcher: unable to parse {} as a URL",
|
||||
url
|
||||
))
|
||||
Url::parse(&url)
|
||||
.unwrap_or_else(|_| panic!("Event dispatcher: unable to parse {} as a URL", url))
|
||||
};
|
||||
|
||||
let backoff = Duration::from_millis((1.0 * 1_000.0) as u64);
|
||||
|
||||
@@ -120,10 +120,10 @@ impl Keychain {
|
||||
/// `block_height` must be the _same_ block height called to make_vrf_keypair()
|
||||
pub fn generate_proof(&self, block_height: u64, bytes: &[u8; 32]) -> VRFProof {
|
||||
let (pk, sk) = self.make_vrf_keypair(block_height);
|
||||
let proof = VRF::prove(&sk, &bytes.to_vec());
|
||||
let proof = VRF::prove(&sk, bytes.as_ref());
|
||||
|
||||
// Ensure that the proof is valid by verifying
|
||||
let is_valid = match VRF::verify(&pk, &proof, &bytes.to_vec()) {
|
||||
let is_valid = match VRF::verify(&pk, &proof, bytes.as_ref()) {
|
||||
Ok(v) => v,
|
||||
Err(_) => false,
|
||||
};
|
||||
|
||||
@@ -188,10 +188,9 @@ impl BlockMinerThread {
|
||||
) {
|
||||
Ok(Some(chunk)) => {
|
||||
// Propose the block to the observing signers through the .miners stackerdb instance
|
||||
let rpc_sock = self.config.node.rpc_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&self.config.node.rpc_bind
|
||||
));
|
||||
let rpc_sock = self.config.node.rpc_bind.parse().unwrap_or_else(|_| {
|
||||
panic!("Failed to parse socket: {}", &self.config.node.rpc_bind)
|
||||
});
|
||||
|
||||
let miner_contract_id = boot_code_id(MINERS_NAME, self.config.is_mainnet());
|
||||
let mut miners_stackerdb =
|
||||
@@ -716,10 +715,12 @@ impl ParentStacksBlockInfo {
|
||||
&stacks_tip_header.index_block_hash(),
|
||||
|conn| StacksChainState::get_account(conn, &principal),
|
||||
)
|
||||
.expect(&format!(
|
||||
"BUG: stacks tip block {} no longer exists after we queried it",
|
||||
&stacks_tip_header.index_block_hash(),
|
||||
));
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"BUG: stacks tip block {} no longer exists after we queried it",
|
||||
&stacks_tip_header.index_block_hash()
|
||||
)
|
||||
});
|
||||
account.nonce
|
||||
};
|
||||
|
||||
|
||||
@@ -172,14 +172,16 @@ impl PeerThread {
|
||||
let chainstate =
|
||||
open_chainstate_with_faults(&config).expect("FATAL: could not open chainstate DB");
|
||||
|
||||
let p2p_sock: SocketAddr = config.node.p2p_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.p2p_bind
|
||||
));
|
||||
let rpc_sock = config.node.rpc_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.rpc_bind
|
||||
));
|
||||
let p2p_sock: SocketAddr = config
|
||||
.node
|
||||
.p2p_bind
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.p2p_bind));
|
||||
let rpc_sock = config
|
||||
.node
|
||||
.rpc_bind
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.rpc_bind));
|
||||
|
||||
net.bind(&p2p_sock, &rpc_sock)
|
||||
.expect("BUG: PeerNetwork could not bind or is already bound");
|
||||
|
||||
@@ -3280,10 +3280,12 @@ impl ParentStacksBlockInfo {
|
||||
&StacksBlockHeader::make_index_block_hash(mine_tip_ch, mine_tip_bh),
|
||||
|conn| StacksChainState::get_account(conn, &principal),
|
||||
)
|
||||
.expect(&format!(
|
||||
"BUG: stacks tip block {}/{} no longer exists after we queried it",
|
||||
mine_tip_ch, mine_tip_bh
|
||||
));
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"BUG: stacks tip block {}/{} no longer exists after we queried it",
|
||||
mine_tip_ch, mine_tip_bh
|
||||
)
|
||||
});
|
||||
account.nonce
|
||||
};
|
||||
|
||||
@@ -3384,14 +3386,16 @@ impl PeerThread {
|
||||
let chainstate =
|
||||
open_chainstate_with_faults(&config).expect("FATAL: could not open chainstate DB");
|
||||
|
||||
let p2p_sock: SocketAddr = config.node.p2p_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.p2p_bind
|
||||
));
|
||||
let rpc_sock = config.node.rpc_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.rpc_bind
|
||||
));
|
||||
let p2p_sock: SocketAddr = config
|
||||
.node
|
||||
.p2p_bind
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.p2p_bind));
|
||||
let rpc_sock = config
|
||||
.node
|
||||
.rpc_bind
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.rpc_bind));
|
||||
|
||||
net.bind(&p2p_sock, &rpc_sock)
|
||||
.expect("BUG: PeerNetwork could not bind or is already bound");
|
||||
@@ -3689,14 +3693,16 @@ impl StacksNode {
|
||||
warn!("Without a peer to bootstrap from, the node will start mining a new chain");
|
||||
}
|
||||
|
||||
let p2p_sock: SocketAddr = config.node.p2p_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.p2p_bind
|
||||
));
|
||||
let p2p_addr: SocketAddr = config.node.p2p_address.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&config.node.p2p_address
|
||||
));
|
||||
let p2p_sock: SocketAddr = config
|
||||
.node
|
||||
.p2p_bind
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.p2p_bind));
|
||||
let p2p_addr: SocketAddr = config
|
||||
.node
|
||||
.p2p_address
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.p2p_address));
|
||||
let node_privkey = Secp256k1PrivateKey::from_seed(&config.node.local_peer_seed);
|
||||
|
||||
let mut peerdb = PeerDB::connect(
|
||||
|
||||
@@ -413,18 +413,17 @@ impl Node {
|
||||
|
||||
println!("BOOTSTRAP WITH {:?}", initial_neighbors);
|
||||
|
||||
let rpc_sock: SocketAddr = self.config.node.rpc_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&self.config.node.rpc_bind
|
||||
));
|
||||
let p2p_sock: SocketAddr = self.config.node.p2p_bind.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&self.config.node.p2p_bind
|
||||
));
|
||||
let p2p_addr: SocketAddr = self.config.node.p2p_address.parse().expect(&format!(
|
||||
"Failed to parse socket: {}",
|
||||
&self.config.node.p2p_address
|
||||
));
|
||||
let rpc_sock: SocketAddr =
|
||||
self.config.node.rpc_bind.parse().unwrap_or_else(|_| {
|
||||
panic!("Failed to parse socket: {}", &self.config.node.rpc_bind)
|
||||
});
|
||||
let p2p_sock: SocketAddr =
|
||||
self.config.node.p2p_bind.parse().unwrap_or_else(|_| {
|
||||
panic!("Failed to parse socket: {}", &self.config.node.p2p_bind)
|
||||
});
|
||||
let p2p_addr: SocketAddr = self.config.node.p2p_address.parse().unwrap_or_else(|_| {
|
||||
panic!("Failed to parse socket: {}", &self.config.node.p2p_address)
|
||||
});
|
||||
let node_privkey = {
|
||||
let mut re_hashed_seed = self.config.node.local_peer_seed.clone();
|
||||
let my_private_key = loop {
|
||||
@@ -774,16 +773,20 @@ impl Node {
|
||||
&anchored_block.header.parent_block,
|
||||
consensus_hash,
|
||||
)
|
||||
.expect(&format!(
|
||||
"BUG: could not query chainstate to find parent consensus hash of {}/{}",
|
||||
consensus_hash,
|
||||
&anchored_block.block_hash()
|
||||
))
|
||||
.expect(&format!(
|
||||
"BUG: no such parent of block {}/{}",
|
||||
consensus_hash,
|
||||
&anchored_block.block_hash()
|
||||
));
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"BUG: could not query chainstate to find parent consensus hash of {}/{}",
|
||||
consensus_hash,
|
||||
&anchored_block.block_hash()
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"BUG: no such parent of block {}/{}",
|
||||
consensus_hash,
|
||||
&anchored_block.block_hash()
|
||||
)
|
||||
});
|
||||
|
||||
// Preprocess the anchored block
|
||||
self.chain_state
|
||||
|
||||
@@ -125,7 +125,7 @@ impl RunLoopCallbacks {
|
||||
match &tx.payload {
|
||||
TransactionPayload::Coinbase(..) => println!(" Coinbase"),
|
||||
TransactionPayload::SmartContract(contract, ..) => println!(" Publish smart contract\n**************************\n{:?}\n**************************", contract.code_body),
|
||||
TransactionPayload::TokenTransfer(recipent, amount, _) => println!(" Transfering {} µSTX to {}", amount, recipent.to_string()),
|
||||
TransactionPayload::TokenTransfer(recipent, amount, _) => println!(" Transfering {} µSTX to {}", amount, recipent),
|
||||
_ => println!(" {:?}", tx.payload)
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ pub fn announce_boot_receipts(
|
||||
boot_receipts,
|
||||
&StacksBlockId::sentinel(),
|
||||
Txid([0x00; 32]),
|
||||
&vec![],
|
||||
&[],
|
||||
None,
|
||||
block_header_0.burn_header_hash.clone(),
|
||||
block_header_0.burn_header_height,
|
||||
|
||||
@@ -344,7 +344,7 @@ impl PoxSyncWatchdog {
|
||||
) -> f64 {
|
||||
let this_reward_cycle = burnchain
|
||||
.block_height_to_reward_cycle(tip_height)
|
||||
.expect(&format!("BUG: no reward cycle for {}", tip_height));
|
||||
.unwrap_or_else(|| panic!("BUG: no reward cycle for {}", tip_height));
|
||||
let prev_reward_cycle = this_reward_cycle.saturating_sub(1);
|
||||
|
||||
let start_height = burnchain.reward_cycle_to_block_height(prev_reward_cycle);
|
||||
@@ -372,7 +372,7 @@ impl PoxSyncWatchdog {
|
||||
) -> f64 {
|
||||
let this_reward_cycle = burnchain
|
||||
.block_height_to_reward_cycle(tip_height)
|
||||
.expect(&format!("BUG: no reward cycle for {}", tip_height));
|
||||
.unwrap_or_else(|| panic!("BUG: no reward cycle for {}", tip_height));
|
||||
let prev_reward_cycle = this_reward_cycle.saturating_sub(1);
|
||||
|
||||
let start_height = burnchain.reward_cycle_to_block_height(prev_reward_cycle);
|
||||
|
||||
Reference in New Issue
Block a user