File tree Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -159,23 +159,37 @@ impl Args {
159
159
bitcoin_rpc_auth,
160
160
) ;
161
161
162
- std :: fs:: create_dir_all ( data_dir. clone ( ) ) ?;
162
+ fs:: create_dir_all ( data_dir. clone ( ) ) ?;
163
163
164
- let chain_store = Store :: open ( data_dir. join ( "protocol.sdb" ) ) ?;
164
+ let proto_db_path = data_dir. join ( "protocol.sdb" ) ;
165
+ let initial_sync = !proto_db_path. exists ( ) ;
166
+
167
+ let chain_store = Store :: open ( proto_db_path) ?;
165
168
let chain = LiveStore {
166
169
state : chain_store. begin ( & genesis) ?,
167
170
store : chain_store,
168
171
} ;
169
172
170
- let block_index = match args. block_index {
171
- true => {
172
- let block_store = Store :: open ( data_dir. join ( "blocks.sdb" ) ) ?;
173
- Some ( LiveStore {
174
- state : block_store. begin ( & genesis) . expect ( "begin block index" ) ,
175
- store : block_store,
176
- } )
173
+ let block_index = if args. block_index {
174
+ let block_db_path = data_dir. join ( "block_index.sdb" ) ;
175
+ if !initial_sync && !block_db_path. exists ( ) {
176
+ return Err ( anyhow:: anyhow!( "Block index must be enabled from the initial sync." ) )
177
177
}
178
- false => None ,
178
+ let block_store = Store :: open ( block_db_path) ?;
179
+ let index = LiveStore {
180
+ state : block_store. begin ( & genesis) . expect ( "begin block index" ) ,
181
+ store : block_store,
182
+ } ;
183
+ {
184
+ let tip_1 = index. state . tip . read ( ) . expect ( "index" ) ;
185
+ let tip_2 = chain. state . tip . read ( ) . expect ( "tip" ) ;
186
+ if tip_1. height != tip_2. height || tip_1. hash != tip_2. hash {
187
+ return Err ( anyhow:: anyhow!( "Protocol and block index states don't match." ) )
188
+ }
189
+ }
190
+ Some ( index)
191
+ } else {
192
+ None
179
193
} ;
180
194
181
195
Ok ( Spaced {
You can’t perform that action at this time.
0 commit comments