|
1 | 1 | use super::{ |
2 | 2 | ledger_empty_hash_at_depth, |
3 | | - read::LedgerReadResponse, |
4 | | - read::{LedgerReadId, LedgerReadRequest}, |
5 | | - write::CommitResult, |
6 | | - write::LedgerWriteRequest, |
7 | | - write::LedgerWriteResponse, |
| 3 | + read::{LedgerReadId, LedgerReadRequest, LedgerReadResponse}, |
| 4 | + write::{CommitResult, LedgerWriteRequest, LedgerWriteResponse, LedgersToKeep}, |
8 | 5 | LedgerAddress, LedgerEvent, LEDGER_DEPTH, |
9 | 6 | }; |
10 | 7 | use crate::{ |
@@ -65,8 +62,8 @@ use mina_p2p_messages::{ |
65 | 62 | }; |
66 | 63 | use mina_signer::CompressedPubKey; |
67 | 64 | use openmina_core::{ |
68 | | - block::AppliedBlock, |
69 | | - block::ArcBlockWithHash, |
| 65 | + block::{AppliedBlock, ArcBlockWithHash}, |
| 66 | + bug_condition, |
70 | 67 | constants::constraint_constants, |
71 | 68 | snark::{Snark, SnarkJobId}, |
72 | 69 | thread, |
@@ -137,18 +134,18 @@ impl StagedLedgersStorage { |
137 | 134 |
|
138 | 135 | fn retain<F>(&mut self, fun: F) |
139 | 136 | where |
140 | | - F: Fn(&LedgerHash, &[Arc<MinaBaseStagedLedgerHashStableV1>]) -> bool, |
| 137 | + F: Fn(&MinaBaseStagedLedgerHashStableV1) -> bool, |
141 | 138 | { |
142 | | - self.by_merkle_root_hash |
143 | | - .retain(|merkle_root_hash, staged_ledger_hashes| { |
144 | | - let retain = fun(merkle_root_hash, staged_ledger_hashes.as_slice()); |
145 | | - if !retain { |
146 | | - for staged_ledger_hash in staged_ledger_hashes { |
147 | | - self.staged_ledgers.remove(staged_ledger_hash); |
148 | | - } |
| 139 | + self.by_merkle_root_hash.retain(|_, staged_ledger_hashes| { |
| 140 | + staged_ledger_hashes.retain(|hash| { |
| 141 | + if fun(hash) { |
| 142 | + return true; |
149 | 143 | } |
150 | | - retain |
| 144 | + self.staged_ledgers.remove(hash); |
| 145 | + false |
151 | 146 | }); |
| 147 | + !staged_ledger_hashes.is_empty() |
| 148 | + }); |
152 | 149 | } |
153 | 150 |
|
154 | 151 | fn extend<I>(&mut self, iterator: I) |
@@ -857,7 +854,7 @@ impl LedgerCtx { |
857 | 854 |
|
858 | 855 | pub fn commit( |
859 | 856 | &mut self, |
860 | | - ledgers_to_keep: BTreeSet<LedgerHash>, |
| 857 | + ledgers_to_keep: LedgersToKeep, |
861 | 858 | root_snarked_ledger_updates: TransitionFrontierRootSnarkedLedgerUpdates, |
862 | 859 | needed_protocol_states: BTreeMap<StateHash, MinaStateProtocolStateValueStableV2>, |
863 | 860 | new_root: &ArcBlockWithHash, |
@@ -902,13 +899,13 @@ impl LedgerCtx { |
902 | 899 | ); |
903 | 900 |
|
904 | 901 | self.staged_ledgers |
905 | | - .retain(|hash, _| ledgers_to_keep.contains(hash)); |
| 902 | + .retain(|hash| ledgers_to_keep.contains(hash)); |
906 | 903 | self.staged_ledgers.extend( |
907 | 904 | self.sync |
908 | 905 | .staged_ledgers |
909 | 906 | .take() |
910 | 907 | .into_iter() |
911 | | - .filter(|(hash, _)| ledgers_to_keep.contains(&hash.non_snark.ledger_hash)), |
| 908 | + .filter(|(hash, _)| ledgers_to_keep.contains(&**hash)), |
912 | 909 | ); |
913 | 910 |
|
914 | 911 | for ledger_hash in [ |
@@ -973,13 +970,45 @@ impl LedgerCtx { |
973 | 970 | .unwrap_or_default(), |
974 | 971 | ); |
975 | 972 |
|
| 973 | + // self.check_alive_masks(); |
| 974 | + |
976 | 975 | CommitResult { |
977 | 976 | alive_masks: ::ledger::mask::alive_len(), |
978 | 977 | available_jobs, |
979 | 978 | needed_protocol_states, |
980 | 979 | } |
981 | 980 | } |
982 | 981 |
|
| 982 | + #[allow(dead_code)] |
| 983 | + fn check_alive_masks(&mut self) { |
| 984 | + let mut alive: BTreeSet<_> = ::ledger::mask::alive_collect(); |
| 985 | + let staged_ledgers = self |
| 986 | + .staged_ledgers |
| 987 | + .staged_ledgers |
| 988 | + .iter() |
| 989 | + .map(|(hash, ledger)| (&hash.non_snark.ledger_hash, ledger.ledger_ref())); |
| 990 | + |
| 991 | + let alive_ledgers = self |
| 992 | + .snarked_ledgers |
| 993 | + .iter() |
| 994 | + .chain(staged_ledgers) |
| 995 | + .map(|(hash, mask)| { |
| 996 | + let uuid = mask.get_uuid(); |
| 997 | + if !alive.remove(&uuid) { |
| 998 | + bug_condition!("mask not found among alive masks! uuid: {uuid}, hash: {hash}"); |
| 999 | + } |
| 1000 | + (uuid, hash) |
| 1001 | + }) |
| 1002 | + .collect::<Vec<_>>(); |
| 1003 | + openmina_core::debug!(redux::Timestamp::global_now(); "alive_ledgers_after_commit: {alive_ledgers:#?}"); |
| 1004 | + |
| 1005 | + if !alive.is_empty() { |
| 1006 | + bug_condition!( |
| 1007 | + "masks alive which are no longer part of the ledger service: {alive:#?}" |
| 1008 | + ); |
| 1009 | + } |
| 1010 | + } |
| 1011 | + |
983 | 1012 | pub fn get_num_accounts( |
984 | 1013 | &mut self, |
985 | 1014 | ledger_hash: v2::LedgerHash, |
|
0 commit comments