@@ -7,7 +7,10 @@ use std::{
7
7
time:: { self , Duration } ,
8
8
} ;
9
9
10
- use fe_proof_service:: invariant:: Invariant ;
10
+ use fe_proof_service:: {
11
+ invariant:: { Invariant , InvariantHeader } ,
12
+ ProofStatus ,
13
+ } ;
11
14
use indexmap:: { indexmap, IndexMap } ;
12
15
use kevm:: KSpecExecPool ;
13
16
use smol_str:: SmolStr ;
@@ -16,10 +19,7 @@ mod db;
16
19
mod queue;
17
20
18
21
use self :: { db:: Db , queue:: Spec } ;
19
- use self :: {
20
- db:: DbEntry ,
21
- queue:: { ProofStatus , Queue } ,
22
- } ;
22
+ use self :: { db:: DbEntry , queue:: Queue } ;
23
23
24
24
pub struct Server {
25
25
state : Arc < Mutex < ServerState > > ,
@@ -41,9 +41,12 @@ impl Server {
41
41
Self { state }
42
42
}
43
43
44
- pub fn add_invariant ( & mut self , invariant : Invariant ) {
44
+ pub fn check_invariant ( & mut self , invariant : Invariant ) -> ProofStatus {
45
+ let id = invariant. id ( ) ;
45
46
let spec = Spec :: new_from_invariant ( invariant) ;
46
- self . state . lock ( ) . unwrap ( ) . add_spec ( spec)
47
+ self . state . lock ( ) . unwrap ( ) . add_spec ( spec) ;
48
+ self . state . lock ( ) . unwrap ( ) . update ( ) ;
49
+ self . state . lock ( ) . unwrap ( ) . proof_status ( id)
47
50
}
48
51
49
52
// pub fn display<W>(&self, mut writer: W)
@@ -110,11 +113,30 @@ impl ServerState {
110
113
self . queue . push_spec ( spec)
111
114
}
112
115
116
+ pub fn proof_status ( & self , invariant_id : u64 ) -> ProofStatus {
117
+ if let Some ( entry) = self . db . get ( invariant_id) {
118
+ if entry. complete {
119
+ ProofStatus :: Complete
120
+ } else {
121
+ ProofStatus :: Incomplete
122
+ }
123
+ } else {
124
+ for spec in & self . queue . specs {
125
+ if spec. invariant_id == invariant_id {
126
+ return spec. status ;
127
+ }
128
+ }
129
+
130
+ panic ! ( "missing invariant" )
131
+ }
132
+ }
133
+
113
134
pub fn update ( & mut self ) {
114
135
let mut first_indices: IndexMap < u64 , usize > = indexmap ! { } ;
115
136
116
137
let mut renames: Vec < ( usize , SmolStr ) > = vec ! [ ] ;
117
138
let mut removals: Vec < usize > = vec ! [ ] ;
139
+ let mut db_changed = false ;
118
140
119
141
for ( index, spec) in self . queue . specs . iter_mut ( ) . enumerate ( ) {
120
142
if let Some ( first_index) = first_indices. get ( & spec. invariant_id ) {
@@ -157,18 +179,21 @@ impl ServerState {
157
179
self . db
158
180
. update ( spec. invariant_id , DbEntry :: new ( spec. name . clone ( ) , true ) ) ;
159
181
removals. push ( index) ;
182
+ db_changed = true
160
183
}
161
184
ProofStatus :: Incomplete => {
162
185
self . db
163
186
. update ( spec. invariant_id , DbEntry :: new ( spec. name . clone ( ) , false ) ) ;
164
187
removals. push ( index) ;
188
+ db_changed = true
165
189
}
166
190
}
167
191
}
168
192
}
169
193
170
- // todo only write if updated
171
- self . db . write ( ) ;
194
+ if db_changed {
195
+ self . db . write ( ) ;
196
+ }
172
197
173
198
for ( index, name) in renames {
174
199
self . queue . specs [ index] . name = name
0 commit comments