2
2
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
3
3
4
4
use crate :: sql:: { consensus_data, error:: * , migrations} ;
5
- use crate :: { Epoch , Input , InputId , StateManager } ;
5
+ use crate :: { Epoch , Input , InputId , Proof , StateManager } ;
6
6
7
7
use rusqlite:: { Connection , OptionalExtension } ;
8
8
use std:: sync:: Mutex ;
@@ -179,25 +179,35 @@ impl StateManager for PersistentStateAccess {
179
179
Ok ( ( ) )
180
180
}
181
181
182
- fn computation_hash ( & self , epoch_number : u64 ) -> Result < Option < Vec < u8 > > > {
182
+ fn settlement_info ( & self , epoch_number : u64 ) -> Result < Option < ( Vec < u8 > , Vec < u8 > , Proof ) > > {
183
183
let conn = self . connection . lock ( ) . unwrap ( ) ;
184
184
let mut stmt = conn. prepare (
185
185
"\
186
- SELECT computation_hash FROM computation_hashes
186
+ SELECT computation_hash, output_merkle, output_proof FROM settlement_info
187
187
WHERE epoch_number = ?1
188
188
" ,
189
189
) ?;
190
190
191
191
Ok ( stmt
192
- . query_row ( [ epoch_number] , |row| Ok ( row. get ( 0 ) ?) )
192
+ . query_row ( [ epoch_number] , |row| {
193
+ Ok ( ( row. get ( 0 ) ?, row. get ( 1 ) ?, row. get :: < _ , Vec < u8 > > ( 2 ) ?. into ( ) ) )
194
+ } )
193
195
. optional ( ) ?)
194
196
}
195
197
196
- fn add_computation_hash ( & self , computation_hash : & [ u8 ] , epoch_number : u64 ) -> Result < ( ) > {
197
- match self . computation_hash ( epoch_number) ? {
198
- Some ( c) => {
199
- // previous row with same key found, all values should match
198
+ fn add_settlement_info (
199
+ & self ,
200
+ computation_hash : & [ u8 ] ,
201
+ output_merkle : & [ u8 ] ,
202
+ output_proof : & Proof ,
203
+ epoch_number : u64 ,
204
+ ) -> Result < ( ) > {
205
+ match self . settlement_info ( epoch_number) ? {
206
+ Some ( ( c, o_m, o_p) ) => {
207
+ // a row with same key found, all values should match
200
208
assert ! ( c == computation_hash. to_vec( ) ) ;
209
+ assert ! ( o_m == output_merkle. to_vec( ) ) ;
210
+ assert ! ( o_p == * output_proof) ;
201
211
202
212
return Ok ( ( ) ) ;
203
213
}
@@ -206,10 +216,16 @@ impl StateManager for PersistentStateAccess {
206
216
207
217
let conn = self . connection . lock ( ) . unwrap ( ) ;
208
218
let mut sttm = conn. prepare (
209
- "INSERT INTO computation_hashes (epoch_number, computation_hash) VALUES (?1, ?2)" ,
219
+ "INSERT INTO settlement_info (epoch_number, computation_hash, output_merkle, output_proof ) VALUES (?1, ?2, ?3, ?4 )" ,
210
220
) ?;
211
221
212
- if sttm. execute ( ( epoch_number, computation_hash) ) ? != 1 {
222
+ if sttm. execute ( (
223
+ epoch_number,
224
+ computation_hash,
225
+ output_merkle,
226
+ output_proof. flatten ( ) ,
227
+ ) ) ? != 1
228
+ {
213
229
return Err ( PersistentStateAccessError :: InsertionFailed {
214
230
description : "machine computation_hash insertion failed" . to_owned ( ) ,
215
231
} ) ;
@@ -577,17 +593,23 @@ mod tests {
577
593
) ;
578
594
579
595
assert ! (
580
- access. computation_hash ( 0 ) ?. is_none( ) ,
596
+ access. settlement_info ( 0 ) ?. is_none( ) ,
581
597
"computation_hash shouldn't exist"
582
598
) ;
583
599
584
600
let computation_hash_1 = vec ! [ 1 , 2 , 3 , 4 , 5 ] ;
585
- access. add_computation_hash ( & computation_hash_1, 0 ) ?;
601
+ let output_merkle_1 = vec ! [ 1 , 2 , 3 , 4 , 4 ] ;
602
+ let output_proof_1: Proof = vec ! [
603
+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,
604
+ 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
605
+ ]
606
+ . into ( ) ;
607
+ access. add_settlement_info ( & computation_hash_1, & output_merkle_1, & output_proof_1, 0 ) ?;
586
608
587
609
assert_eq ! (
588
- access. computation_hash ( 0 ) ?,
589
- Some ( computation_hash_1) ,
590
- "computation_hash 1 should match"
610
+ access. settlement_info ( 0 ) ?,
611
+ Some ( ( computation_hash_1, output_merkle_1 , output_proof_1 ) ) ,
612
+ "settlement info of epoch 0 should match"
591
613
) ;
592
614
593
615
Ok ( ( ) )
0 commit comments