Skip to content

Commit 6089375

Browse files
author
Adrian Nagy
committed
Send only the BlockApplyStatus to the archiver service
1 parent 18d6fb3 commit 6089375

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -863,30 +863,6 @@ impl PrecomputedBlock {
863863
}
864864
}
865865

866-
impl TryFrom<ArchiveTransitionFronntierDiff> for PrecomputedBlock {
867-
type Error = String;
868-
869-
fn try_from(value: ArchiveTransitionFronntierDiff) -> Result<Self, Self::Error> {
870-
let block = value
871-
.block()
872-
.ok_or("Block not found in archive transition frontier diff")?;
873-
let res = Self {
874-
scheduled_time: block.header.protocol_state.body.blockchain_state.timestamp,
875-
protocol_state: block.header.protocol_state.clone(),
876-
protocol_state_proof: block.header.protocol_state_proof.as_ref().clone().into(),
877-
staged_ledger_diff: block.body.staged_ledger_diff,
878-
// TODO(adonagy): add the actual delta transition chain proof
879-
delta_transition_chain_proof: (LedgerHash::zero(), List::new()),
880-
protocol_version: block.header.current_protocol_version.clone(),
881-
proposed_protocol_version: None,
882-
accounts_accessed: value.accounts_accessed(),
883-
accounts_created: value.accounts_created(),
884-
tokens_used: value.tokens_used(),
885-
};
886-
Ok(res)
887-
}
888-
}
889-
890866
#[cfg(test)]
891867
mod tests {
892868
use std::fmt::Debug;

node/common/src/service/archive.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bitflags::bitflags;
22
use mina_p2p_messages::v2::{self, ArchiveTransitionFronntierDiff};
33
use node::core::{channels::mpsc, thread};
4+
use node::ledger::write::BlockApplyResult;
45
use std::env;
56
use std::net::SocketAddr;
67

@@ -84,7 +85,7 @@ impl ArchiveStorageOptions {
8485
}
8586

8687
pub struct ArchiveService {
87-
archive_sender: mpsc::UnboundedSender<ArchiveTransitionFronntierDiff>,
88+
archive_sender: mpsc::UnboundedSender<BlockApplyResult>,
8889
}
8990

9091
struct ArchiveServiceClients {
@@ -116,13 +117,13 @@ impl ArchiveServiceClients {
116117
}
117118

118119
impl ArchiveService {
119-
fn new(archive_sender: mpsc::UnboundedSender<ArchiveTransitionFronntierDiff>) -> Self {
120+
fn new(archive_sender: mpsc::UnboundedSender<BlockApplyResult>) -> Self {
120121
Self { archive_sender }
121122
}
122123

123124
#[cfg(not(target_arch = "wasm32"))]
124125
async fn run(
125-
mut archive_receiver: mpsc::UnboundedReceiver<ArchiveTransitionFronntierDiff>,
126+
mut archive_receiver: mpsc::UnboundedReceiver<BlockApplyResult>,
126127
address: SocketAddr,
127128
options: ArchiveStorageOptions,
128129
) {
@@ -133,8 +134,15 @@ impl ArchiveService {
133134
while let Some(breadcrumb) = archive_receiver.blocking_recv() {
134135
if options.uses_archiver_process() {
135136
let mut retries = ARCHIVE_SEND_RETRIES;
137+
138+
let archive_transition_frontier_diff: v2::ArchiveTransitionFronntierDiff =
139+
breadcrumb.clone().try_into().unwrap();
140+
136141
while retries > 0 {
137-
match rpc::send_diff(address, v2::ArchiveRpc::SendDiff(breadcrumb.clone())) {
142+
match rpc::send_diff(
143+
address,
144+
v2::ArchiveRpc::SendDiff(archive_transition_frontier_diff.clone()),
145+
) {
138146
Ok(result) => {
139147
if result.should_retry() {
140148
node::core::warn!(
@@ -202,8 +210,7 @@ impl ArchiveService {
202210
}
203211

204212
pub fn start(address: SocketAddr, options: ArchiveStorageOptions) -> Self {
205-
let (archive_sender, archive_receiver) =
206-
mpsc::unbounded_channel::<ArchiveTransitionFronntierDiff>();
213+
let (archive_sender, archive_receiver) = mpsc::unbounded_channel::<BlockApplyResult>();
207214

208215
let runtime = tokio::runtime::Builder::new_current_thread()
209216
.enable_all()
@@ -222,9 +229,9 @@ impl ArchiveService {
222229
}
223230

224231
impl node::transition_frontier::archive::archive_service::ArchiveService for NodeService {
225-
fn send_to_archive(&mut self, data: ArchiveTransitionFronntierDiff) {
232+
fn send_to_archive(&mut self, data: BlockApplyResult) {
226233
if let Some(archive) = self.archive.as_mut() {
227-
if let Err(e) = archive.archive_sender.send(data.clone()) {
234+
if let Err(e) = archive.archive_sender.send(data) {
228235
node::core::warn!(
229236
summary = "Failed sending diff to archive service",
230237
error = e.to_string()

node/src/ledger/write/mod.rs

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

101+
impl TryFrom<BlockApplyResult> for v2::ArchiveTransitionFronntierDiff {
102+
type Error = String;
103+
104+
fn try_from(value: BlockApplyResult) -> Result<Self, Self::Error> {
105+
value.try_into()
106+
}
107+
}
108+
101109
impl TryFrom<&BlockApplyResult> for v2::ArchiveTransitionFronntierDiff {
102110
type Error = String;
103111

@@ -260,6 +268,14 @@ pub enum LedgerToKeep<'a> {
260268
Staged(&'a v2::MinaBaseStagedLedgerHashStableV1),
261269
}
262270

271+
impl TryFrom<BlockApplyResult> for v2::PrecomputedBlock {
272+
type Error = String;
273+
274+
fn try_from(value: BlockApplyResult) -> Result<Self, Self::Error> {
275+
value.try_into()
276+
}
277+
}
278+
263279
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
264280
pub struct CommitResult {
265281
pub alive_masks: usize,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use mina_p2p_messages::v2::ArchiveTransitionFronntierDiff;
1+
use crate::ledger::write::BlockApplyResult;
22

33
pub trait ArchiveService: redux::Service {
4-
fn send_to_archive(&mut self, data: ArchiveTransitionFronntierDiff);
4+
fn send_to_archive(&mut self, data: BlockApplyResult);
55
}

node/src/transition_frontier/sync/transition_frontier_sync_effects.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,7 @@ impl TransitionFrontierSyncAction {
324324
}
325325
}
326326
TransitionFrontierSyncAction::BlocksSendToArchive { data, .. } => {
327-
// Should be safe to unwrap because archive mode contains the necessary data, and this action is only called in archive mode
328-
if let Ok(data) = data.try_into() {
329-
store.service().send_to_archive(data);
330-
}
327+
store.service().send_to_archive(data.clone());
331328
}
332329
TransitionFrontierSyncAction::BlocksSuccess => {}
333330
// Bootstrap/Catchup is practically complete at this point.

node/testing/src/service/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use ledger::scan_state::transaction_logic::{verifiable, WithStatus};
1212
use ledger::Mask;
1313
use mina_p2p_messages::string::ByteString;
1414
use mina_p2p_messages::v2::{
15-
ArchiveTransitionFronntierDiff, CurrencyFeeStableV1, LedgerHash, LedgerProofProdStableV2,
16-
MinaBaseProofStableV2, MinaStateSnarkedLedgerStateWithSokStableV2, NonZeroCurvePoint,
15+
CurrencyFeeStableV1, LedgerHash, LedgerProofProdStableV2, MinaBaseProofStableV2,
16+
MinaStateSnarkedLedgerStateWithSokStableV2, NonZeroCurvePoint,
1717
ProverExtendBlockchainInputStableV2, SnarkWorkerWorkerRpcsVersionedGetWorkV2TResponseA0Single,
1818
StateHash, TransactionSnarkStableV2, TransactionSnarkWorkTStableV2Proofs,
1919
};
@@ -24,6 +24,7 @@ use node::core::channels::mpsc;
2424
use node::core::invariants::InvariantsState;
2525
use node::core::snark::{Snark, SnarkJobId};
2626
use node::external_snark_worker_effectful::ExternalSnarkWorkerEvent;
27+
use node::ledger::write::BlockApplyResult;
2728
use node::p2p::service_impl::webrtc_with_libp2p::P2pServiceWebrtcWithLibp2p;
2829
use node::p2p::P2pCryptoService;
2930
use node::recorder::Recorder;
@@ -501,7 +502,7 @@ impl BlockProducerVrfEvaluatorService for NodeTestingService {
501502
}
502503

503504
impl ArchiveService for NodeTestingService {
504-
fn send_to_archive(&mut self, data: ArchiveTransitionFronntierDiff) {
505+
fn send_to_archive(&mut self, data: BlockApplyResult) {
505506
self.real.send_to_archive(data);
506507
}
507508
}

0 commit comments

Comments
 (0)