node/ledger/
ledger_reducer.rs

1use crate::Substate;
2
3use super::{
4    read::LedgerReadState,
5    write::{LedgerWriteAction, LedgerWriteResponse, LedgerWriteState},
6    LedgerAction, LedgerActionWithMetaRef, LedgerState,
7};
8
9impl LedgerState {
10    pub fn reducer(mut state_context: Substate<Self>, action: LedgerActionWithMetaRef<'_>) {
11        let (action, meta) = action.split();
12
13        match action {
14            LedgerAction::Write(action) => {
15                if let LedgerWriteAction::Success {
16                    response: LedgerWriteResponse::Commit { result, .. },
17                } = action
18                {
19                    if let Ok(state) = state_context.get_substate_mut() {
20                        if result.alive_masks > 294 {
21                            // TODO(binier): should be a bug condition, but can't be
22                            // because we get false positive during testing, since
23                            // multiple nodes/ledger run in the same process.
24                            openmina_core::log::warn!(
25                                meta.time();
26                                "ledger mask leak: more than 294 ledger masks ({}) detected!",
27                                result.alive_masks
28                            );
29                        }
30                        state.alive_masks = result.alive_masks;
31                    }
32                }
33                LedgerWriteState::reducer(
34                    Substate::from_compatible_substate(state_context),
35                    meta.with_action(action),
36                )
37            }
38            LedgerAction::Read(action) => LedgerReadState::reducer(
39                Substate::from_compatible_substate(state_context),
40                meta.with_action(action),
41            ),
42        }
43    }
44}