1
- use std:: sync:: Arc ;
2
-
3
- use mina_p2p_messages:: v2:: { MinaBlockBlockStableV2 , StateHash } ;
1
+ use mina_p2p_messages:: v2:: StateHash ;
4
2
use openmina_core:: block:: prevalidate:: BlockPrevalidationError ;
5
- use openmina_core:: block:: { ArcBlockWithHash , BlockWithHash } ;
3
+ use openmina_core:: block:: ArcBlockWithHash ;
6
4
use openmina_core:: consensus:: consensus_take;
7
5
use openmina_core:: { action_event, ActionEvent } ;
8
6
use serde:: { Deserialize , Serialize } ;
9
7
use snark:: block_verify:: SnarkBlockVerifyError ;
10
8
11
9
use crate :: snark:: block_verify:: SnarkBlockVerifyId ;
12
10
13
- use super :: TransitionFrontierCandidateStatus ;
14
-
15
11
pub type TransitionFrontierCandidateActionWithMeta =
16
12
redux:: ActionWithMeta < TransitionFrontierCandidateAction > ;
17
13
pub type TransitionFrontierCandidateActionWithMetaRef < ' a > =
@@ -22,10 +18,11 @@ pub type TransitionFrontierCandidateActionWithMetaRef<'a> =
22
18
#[ derive( Serialize , Deserialize , Debug , Clone , ActionEvent ) ]
23
19
#[ action_event( level = debug, fields( debug( hash) , debug( error) ) ) ]
24
20
pub enum TransitionFrontierCandidateAction {
25
- #[ action_event( level = info) ]
21
+ P2pBestTipUpdate {
22
+ best_tip : ArcBlockWithHash ,
23
+ } ,
26
24
BlockReceived {
27
- hash : StateHash ,
28
- block : Arc < MinaBlockBlockStableV2 > ,
25
+ block : ArcBlockWithHash ,
29
26
chain_proof : Option < ( Vec < StateHash > , ArcBlockWithHash ) > ,
30
27
} ,
31
28
BlockPrevalidateSuccess {
@@ -52,131 +49,49 @@ pub enum TransitionFrontierCandidateAction {
52
49
hash : StateHash ,
53
50
error : SnarkBlockVerifyError ,
54
51
} ,
55
- DetectForkRange {
56
- hash : StateHash ,
57
- } ,
58
- ShortRangeForkResolve {
59
- hash : StateHash ,
60
- } ,
61
- LongRangeForkResolve {
62
- hash : StateHash ,
63
- } ,
64
- #[ action_event( level = info) ]
65
- BestTipUpdate {
66
- hash : StateHash ,
67
- } ,
68
52
TransitionFrontierSyncTargetUpdate ,
69
- P2pBestTipUpdate {
70
- best_tip : BlockWithHash < Arc < MinaBlockBlockStableV2 > > ,
71
- } ,
72
53
Prune ,
73
54
}
74
55
75
56
impl redux:: EnablingCondition < crate :: State > for TransitionFrontierCandidateAction {
76
57
fn is_enabled ( & self , state : & crate :: State , _time : redux:: Timestamp ) -> bool {
77
58
match self {
78
- TransitionFrontierCandidateAction :: BlockReceived { hash, block, .. } => {
79
- let block = ArcBlockWithHash {
80
- hash : hash. clone ( ) ,
81
- block : block. clone ( )
82
- } ;
83
- !block. is_genesis ( ) && !state. transition_frontier . candidates . blocks . contains_key ( hash)
84
- } ,
59
+ TransitionFrontierCandidateAction :: P2pBestTipUpdate { .. } => true ,
60
+ TransitionFrontierCandidateAction :: BlockReceived { block, .. } => {
61
+ !block. is_genesis ( ) && !state. transition_frontier . candidates . contains ( block. hash ( ) )
62
+ }
85
63
TransitionFrontierCandidateAction :: BlockPrevalidateSuccess { hash }
86
64
| TransitionFrontierCandidateAction :: BlockPrevalidateError { hash, .. } => state
87
- . transition_frontier . candidates
88
- . blocks
65
+ . transition_frontier
66
+ . candidates
89
67
. get ( hash)
90
68
. is_some_and ( |block| block. status . is_received ( ) ) ,
91
- TransitionFrontierCandidateAction :: BlockChainProofUpdate { hash, .. } => {
92
- ( state. transition_frontier . candidates . best_tip . as_ref ( ) == Some ( hash)
93
- && state. transition_frontier . candidates . best_tip_chain_proof . is_none ( ) )
94
- || state. transition_frontier
95
- . candidates
96
- . blocks
97
- . get ( hash)
98
- . is_some_and ( |b| b. status . is_pending ( ) && b. chain_proof . is_none ( ) )
99
- } ,
69
+ TransitionFrontierCandidateAction :: BlockChainProofUpdate { hash, .. } => state
70
+ . transition_frontier
71
+ . candidates
72
+ . is_chain_proof_needed ( hash) ,
100
73
TransitionFrontierCandidateAction :: BlockSnarkVerifyPending { req_id, hash } => {
101
74
state
102
75
. transition_frontier
103
76
. candidates
104
- . blocks
105
77
. get ( hash)
106
- . is_some_and ( |block| block. status . is_prevalidated ( ) )
78
+ . is_some_and ( |block| block. status . is_prevalidated ( ) )
107
79
&& state. snark . block_verify . jobs . contains ( * req_id)
108
- } ,
109
- TransitionFrontierCandidateAction :: BlockSnarkVerifySuccess { hash } => {
110
- state
111
- . transition_frontier
112
- . candidates
113
- . blocks
114
- . get ( hash)
115
- . is_some_and ( |block| block. status . is_snark_verify_pending ( ) )
116
- } ,
117
- TransitionFrontierCandidateAction :: BlockSnarkVerifyError { hash, .. } => {
118
- state
119
- . transition_frontier
120
- . candidates
121
- . blocks
122
- . get ( hash)
123
- . is_some_and ( |block| block. status . is_snark_verify_pending ( ) )
124
- } ,
125
- TransitionFrontierCandidateAction :: DetectForkRange { hash } => {
126
- state
127
- . transition_frontier
128
- . candidates
129
- . blocks
130
- . get ( hash)
131
- . is_some_and ( |block| {
132
- matches ! (
133
- block. status,
134
- TransitionFrontierCandidateStatus :: SnarkVerifySuccess { .. }
135
- )
136
- } )
137
- } ,
138
- TransitionFrontierCandidateAction :: ShortRangeForkResolve { hash } => {
139
- state
140
- . transition_frontier
141
- . candidates
142
- . blocks
143
- . get ( hash)
144
- . is_some_and ( |block| match state. transition_frontier . candidates . best_tip ( ) {
145
- Some ( tip) => {
146
- matches ! (
147
- & block. status,
148
- TransitionFrontierCandidateStatus :: ForkRangeDetected { compared_with, short_fork, .. }
149
- if compared_with. as_ref( ) == Some ( tip. hash) && * short_fork
150
- )
151
- }
152
- None => true ,
153
- } )
154
- } ,
155
- TransitionFrontierCandidateAction :: LongRangeForkResolve { hash } => {
156
- state
157
- . transition_frontier
158
- . candidates
159
- . blocks
160
- . get ( hash)
161
- . is_some_and ( |block| match state. transition_frontier . candidates . best_tip ( ) {
162
- Some ( tip) => {
163
- matches ! (
164
- & block. status,
165
- TransitionFrontierCandidateStatus :: ForkRangeDetected { compared_with, short_fork, .. }
166
- if compared_with. as_ref( ) == Some ( tip. hash) && !* short_fork
167
- )
168
- }
169
- None => false ,
170
- } )
171
- } ,
172
- TransitionFrontierCandidateAction :: BestTipUpdate { hash } => {
173
- state
174
- . transition_frontier
175
- . candidates
176
- . is_candidate_decided_to_use_as_tip ( hash)
177
- } ,
80
+ }
81
+ TransitionFrontierCandidateAction :: BlockSnarkVerifySuccess { hash } => state
82
+ . transition_frontier
83
+ . candidates
84
+ . get ( hash)
85
+ . is_some_and ( |block| block. status . is_snark_verify_pending ( ) ) ,
86
+ TransitionFrontierCandidateAction :: BlockSnarkVerifyError { hash, .. } => state
87
+ . transition_frontier
88
+ . candidates
89
+ . get ( hash)
90
+ . is_some_and ( |block| block. status . is_snark_verify_pending ( ) ) ,
178
91
TransitionFrontierCandidateAction :: TransitionFrontierSyncTargetUpdate => {
179
- let Some ( best_tip) = state. transition_frontier . candidates . best_tip_block_with_hash ( ) else {
92
+ let Some ( best_candidate) =
93
+ state. transition_frontier . candidates . best_verified_block ( )
94
+ else {
180
95
return false ;
181
96
} ;
182
97
// do not need to update transition frontier sync target.
@@ -185,18 +100,28 @@ impl redux::EnablingCondition<crate::State> for TransitionFrontierCandidateActio
185
100
state. transition_frontier . sync . best_tip ( ) ,
186
101
] )
187
102
. flatten ( )
188
- . any ( |b| b. hash ( ) == best_tip. hash ( )
189
- || !consensus_take ( b. consensus_state ( ) , best_tip. consensus_state ( ) , b. hash ( ) , best_tip. hash ( ) ) ) {
103
+ . any ( |b| {
104
+ b. hash ( ) == best_candidate. hash ( )
105
+ || !consensus_take (
106
+ b. consensus_state ( ) ,
107
+ best_candidate. consensus_state ( ) ,
108
+ b. hash ( ) ,
109
+ best_candidate. hash ( ) ,
110
+ )
111
+ } ) {
190
112
return false ;
191
113
}
192
114
193
115
// has enough data
194
- state. transition_frontier . candidates . best_tip_chain_proof ( & state. transition_frontier ) . is_some ( )
195
- } ,
196
- TransitionFrontierCandidateAction :: P2pBestTipUpdate { .. } => true ,
116
+ state
117
+ . transition_frontier
118
+ . candidates
119
+ . best_verified_block_chain_proof ( & state. transition_frontier )
120
+ . is_some ( )
121
+ }
197
122
TransitionFrontierCandidateAction :: Prune => {
198
- state. transition_frontier . candidates . best_tip ( ) . is_some ( )
199
- } ,
123
+ state. transition_frontier . candidates . best ( ) . is_some ( )
124
+ }
200
125
}
201
126
}
202
127
}
0 commit comments