Skip to content

Commit efa14e1

Browse files
author
Adrian Nagy
committed
chore: fix typo + cleanup some if statements
1 parent fda6e9c commit efa14e1

File tree

4 files changed

+53
-46
lines changed

4 files changed

+53
-46
lines changed

mina-p2p-messages/src/v2/manual.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ pub type NonZeroCurvePoint = Base58CheckOfBinProt<
726726
>;
727727

728728
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite)]
729-
pub enum ArchiveTransitionFronntierDiff {
729+
pub enum ArchiveTransitionFrontierDiff {
730730
BreadcrumbAdded {
731731
block: (MinaBlockBlockStableV2, (Option<StateBodyHash>, StateHash)),
732732
accounts_accessed: List<(crate::number::UInt64, MinaBaseAccountBinableArgStableV2)>,
@@ -740,11 +740,11 @@ pub enum ArchiveTransitionFronntierDiff {
740740
BoostrapOf(()),
741741
}
742742

743-
impl ArchiveTransitionFronntierDiff {
743+
impl ArchiveTransitionFrontierDiff {
744744
pub fn block(&self) -> Option<MinaBlockBlockStableV2> {
745745
match self {
746746
// TODO(adonagy): maybe we should use Arc here instead of cloning
747-
ArchiveTransitionFronntierDiff::BreadcrumbAdded { block, .. } => Some(block.0.clone()),
747+
ArchiveTransitionFrontierDiff::BreadcrumbAdded { block, .. } => Some(block.0.clone()),
748748
_ => None,
749749
}
750750
}
@@ -753,7 +753,7 @@ impl ArchiveTransitionFronntierDiff {
753753
&self,
754754
) -> List<(crate::number::UInt64, MinaBaseAccountBinableArgStableV2)> {
755755
match self {
756-
ArchiveTransitionFronntierDiff::BreadcrumbAdded {
756+
ArchiveTransitionFrontierDiff::BreadcrumbAdded {
757757
accounts_accessed, ..
758758
} => accounts_accessed.clone(),
759759
_ => List::new(),
@@ -762,7 +762,7 @@ impl ArchiveTransitionFronntierDiff {
762762

763763
pub fn accounts_created(&self) -> List<(MinaBaseAccountIdStableV2, CurrencyFeeStableV1)> {
764764
match self {
765-
ArchiveTransitionFronntierDiff::BreadcrumbAdded {
765+
ArchiveTransitionFrontierDiff::BreadcrumbAdded {
766766
accounts_created, ..
767767
} => accounts_created.clone(),
768768
_ => List::new(),
@@ -773,7 +773,7 @@ impl ArchiveTransitionFronntierDiff {
773773
&self,
774774
) -> List<(MinaBaseTokenIdStableV2, Option<MinaBaseAccountIdStableV2>)> {
775775
match self {
776-
ArchiveTransitionFronntierDiff::BreadcrumbAdded { tokens_used, .. } => {
776+
ArchiveTransitionFrontierDiff::BreadcrumbAdded { tokens_used, .. } => {
777777
tokens_used.clone()
778778
}
779779
_ => List::new(),
@@ -783,7 +783,7 @@ impl ArchiveTransitionFronntierDiff {
783783

784784
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite)]
785785
pub enum ArchiveRpc {
786-
SendDiff(ArchiveTransitionFronntierDiff),
786+
SendDiff(ArchiveTransitionFrontierDiff),
787787
}
788788

789789
#[derive(Clone, Debug, PartialEq, BinProtRead, BinProtWrite)]
@@ -1889,7 +1889,7 @@ mod test {
18891889
fn test_archive_breadcrumb_deserialization() {
18901890
let breadcrumb_bytes = include_bytes!("../../../tests/files/archive-breadcrumb/3NK56ZbCS31qb8SvCtCCYza4beRDtKgXA2JL6s3evKouG2KkKtiy.bin");
18911891
let result =
1892-
v2::ArchiveTransitionFronntierDiff::binprot_read(&mut breadcrumb_bytes.as_slice());
1892+
v2::ArchiveTransitionFrontierDiff::binprot_read(&mut breadcrumb_bytes.as_slice());
18931893

18941894
assert!(result.is_ok());
18951895
}

node/common/src/service/archive/mod.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,24 @@ impl ArchiveServiceClients {
111111
key = key.clone()
112112
);
113113

114-
let precomputed_block: PrecomputedBlock = if let Ok(precomputed_block) =
115-
breadcrumb.try_into()
116-
{
117-
precomputed_block
118-
} else {
119-
node::core::warn!(summary = "Failed to convert breadcrumb to precomputed block");
120-
return;
114+
let precomputed_block: PrecomputedBlock = match breadcrumb.try_into() {
115+
Ok(block) => block,
116+
Err(_) => {
117+
node::core::warn!(summary = "Failed to convert breadcrumb to precomputed block");
118+
return;
119+
}
121120
};
122121

123-
let data = serde_json::to_vec(&precomputed_block).unwrap();
122+
let data = match serde_json::to_vec(&precomputed_block) {
123+
Ok(data) => data,
124+
Err(e) => {
125+
node::core::warn!(
126+
summary = "Failed to serialize precomputed block",
127+
error = e.to_string()
128+
);
129+
return;
130+
}
131+
};
124132

125133
if options.uses_local_precomputed_storage() {
126134
// TODO(adonagy): Cleanup the unwraps (fn that returns a Result + log the error)
@@ -163,37 +171,32 @@ impl ArchiveServiceClients {
163171
async fn handle_archiver_process(breadcrumb: &BlockApplyResult, socket_addr: &SocketAddr) {
164172
let mut retries = ARCHIVE_SEND_RETRIES;
165173

166-
let archive_transition_frontier_diff: v2::ArchiveTransitionFronntierDiff =
174+
let archive_transition_frontier_diff: v2::ArchiveTransitionFrontierDiff =
167175
breadcrumb.clone().try_into().unwrap();
168176

169-
while retries > 0 {
177+
for _ in 0..ARCHIVE_SEND_RETRIES {
170178
match rpc::send_diff(
171179
*socket_addr,
172180
v2::ArchiveRpc::SendDiff(archive_transition_frontier_diff.clone()),
173181
) {
174-
Ok(result) => {
175-
if result.should_retry() {
176-
node::core::warn!(
177-
summary = "Archive suddenly closed connection, retrying..."
178-
);
179-
retries -= 1;
180-
tokio::time::sleep(std::time::Duration::from_millis(RETRY_INTERVAL_MS))
181-
.await;
182-
} else {
183-
node::core::warn!(summary = "Successfully sent diff to archive");
184-
break;
185-
}
182+
Ok(result) if result.should_retry() => {
183+
node::core::warn!(summary = "Archive closed connection, retrying...");
184+
tokio::time::sleep(tokio::time::Duration::from_millis(RETRY_INTERVAL_MS)).await;
185+
}
186+
Ok(_) => {
187+
node::core::info!(summary = "Successfully sent diff to archive");
188+
return;
186189
}
187190
Err(e) => {
188191
node::core::warn!(
189192
summary = "Failed sending diff to archive",
190193
error = e.to_string(),
191194
retries = retries
192195
);
193-
retries -= 1;
194-
tokio::time::sleep(std::time::Duration::from_millis(RETRY_INTERVAL_MS)).await;
196+
tokio::time::sleep(tokio::time::Duration::from_millis(RETRY_INTERVAL_MS)).await;
195197
}
196198
}
199+
retries -= 1;
197200
}
198201
}
199202
}
@@ -209,11 +212,15 @@ impl ArchiveService {
209212
options: ArchiveStorageOptions,
210213
work_dir: String,
211214
) {
212-
let clients = if let Ok(clients) = ArchiveServiceClients::new(&options, work_dir).await {
213-
clients
214-
} else {
215-
node::core::error!(summary = "Failed to initialize archive service clients");
216-
return;
215+
let clients = match ArchiveServiceClients::new(&options, work_dir).await {
216+
Ok(clients) => clients,
217+
Err(e) => {
218+
node::core::error!(
219+
summary = "Failed to initialize archive service clients",
220+
error = e.to_string()
221+
);
222+
return;
223+
}
217224
};
218225

219226
while let Some(breadcrumb) = archive_receiver.recv().await {

node/src/ledger/write/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ pub struct BlockApplyResultArchive {
9898
pub sender_receipt_chains_from_parent_ledger: Vec<(AccountId, v2::ReceiptChainHash)>,
9999
}
100100

101-
impl TryFrom<BlockApplyResult> for v2::ArchiveTransitionFronntierDiff {
101+
impl TryFrom<BlockApplyResult> for v2::ArchiveTransitionFrontierDiff {
102102
type Error = String;
103103

104104
fn try_from(value: BlockApplyResult) -> Result<Self, Self::Error> {
105105
(&value).try_into()
106106
}
107107
}
108108

109-
impl TryFrom<&BlockApplyResult> for v2::ArchiveTransitionFronntierDiff {
109+
impl TryFrom<&BlockApplyResult> for v2::ArchiveTransitionFrontierDiff {
110110
type Error = String;
111111

112112
fn try_from(value: &BlockApplyResult) -> Result<Self, Self::Error> {
@@ -174,7 +174,7 @@ impl TryFrom<&BlockApplyResult> for v2::PrecomputedBlock {
174174
type Error = String;
175175

176176
fn try_from(value: &BlockApplyResult) -> Result<Self, Self::Error> {
177-
let archive_transition_frontier_diff: v2::ArchiveTransitionFronntierDiff =
177+
let archive_transition_frontier_diff: v2::ArchiveTransitionFrontierDiff =
178178
value.try_into()?;
179179

180180
let res = Self {

tools/archive-breadcrumb-compare/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mina_p2p_messages::v2::ArchiveTransitionFronntierDiff;
1+
use mina_p2p_messages::v2::ArchiveTransitionFrontierDiff;
22
use std::{collections::HashSet, path::PathBuf};
33

44
use anyhow::Result;
@@ -289,26 +289,26 @@ async fn compare_binary_diffs(
289289
}
290290
}
291291

292-
fn load_and_deserialize(path: &PathBuf) -> Result<ArchiveTransitionFronntierDiff> {
292+
fn load_and_deserialize(path: &PathBuf) -> Result<ArchiveTransitionFrontierDiff> {
293293
let data = std::fs::read(path)?;
294294
let diff = binprot::BinProtRead::binprot_read(&mut data.as_slice())?;
295295
Ok(diff)
296296
}
297297

298298
fn compare_diffs(
299-
ocaml: &ArchiveTransitionFronntierDiff,
300-
openmina: &ArchiveTransitionFronntierDiff,
299+
ocaml: &ArchiveTransitionFrontierDiff,
300+
openmina: &ArchiveTransitionFrontierDiff,
301301
) -> Option<String> {
302302
match (ocaml, openmina) {
303303
(
304-
ArchiveTransitionFronntierDiff::BreadcrumbAdded {
304+
ArchiveTransitionFrontierDiff::BreadcrumbAdded {
305305
block: (b1, (body_hash1, state_hash1)),
306306
accounts_accessed: a1,
307307
accounts_created: c1,
308308
tokens_used: t1,
309309
sender_receipt_chains_from_parent_ledger: s1,
310310
},
311-
ArchiveTransitionFronntierDiff::BreadcrumbAdded {
311+
ArchiveTransitionFrontierDiff::BreadcrumbAdded {
312312
block: (b2, (body_hash2, state_hash2)),
313313
accounts_accessed: a2,
314314
accounts_created: c2,

0 commit comments

Comments
 (0)