@@ -38,7 +38,7 @@ pub const CHANNEL_MANAGER_PERSISTENCE_KEY: &str = "manager";
38
38
/// The namespace under which [`ChannelMonitor`]s will be persisted.
39
39
pub const CHANNEL_MONITOR_PERSISTENCE_NAMESPACE : & str = "monitors" ;
40
40
/// The namespace under which [`ChannelMonitorUpdate`]s will be persisted.
41
- pub const CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE : & str = "monitors_updates " ;
41
+ pub const CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE : & str = "monitor_updates " ;
42
42
43
43
/// The namespace under which the [`NetworkGraph`] will be persisted.
44
44
pub const NETWORK_GRAPH_PERSISTENCE_NAMESPACE : & str = "" ;
@@ -153,7 +153,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
153
153
}
154
154
}
155
155
156
- #[ allow( clippy:: type_complexity) ]
157
156
/// Read previously persisted [`ChannelMonitor`]s from the store.
158
157
pub fn read_channel_monitors < K : Deref , ES : Deref , SP : Deref > (
159
158
kv_store : K , entropy_source : ES , signer_provider : SP ,
@@ -202,37 +201,37 @@ where
202
201
203
202
enum KVStoreUpdatingPersisterError {
204
203
/// The monitor name was improperly formatted.
205
- BadMonitorName ( String , String ) ,
204
+ BadMonitorName { reason : String , context : String } ,
206
205
/// The monitor could not be decoded.
207
- MonitorDecodeFailed ( DecodeError , String ) ,
206
+ MonitorDecodeFailed { reason : String , context : String } ,
208
207
/// The update could not be decoded.
209
- UpdateDecodeFailed ( DecodeError , String ) ,
208
+ UpdateDecodeFailed { reason : String , context : String } ,
210
209
/// Storage could not be read.
211
- StorageReadFailed ( io :: Error , String ) ,
210
+ StorageReadFailed { reason : String , context : String } ,
212
211
/// An update could not be applied to a monitor.
213
- UpdateFailed ( String , String ) ,
212
+ UpdateFailed { reason : String , context : String } ,
214
213
}
215
214
216
215
impl From < KVStoreUpdatingPersisterError > for io:: Error {
217
216
fn from ( value : KVStoreUpdatingPersisterError ) -> Self {
218
217
match value {
219
- KVStoreUpdatingPersisterError :: BadMonitorName ( reason, context) => io:: Error :: new (
218
+ KVStoreUpdatingPersisterError :: BadMonitorName { reason, context} => io:: Error :: new (
220
219
io:: ErrorKind :: InvalidInput ,
221
- format ! ( "{reason }, context: {context }'" ) ,
220
+ format ! ( "{}, context: {}'" , reason , context ) ,
222
221
) ,
223
- KVStoreUpdatingPersisterError :: MonitorDecodeFailed ( reason, context) => io:: Error :: new (
222
+ KVStoreUpdatingPersisterError :: MonitorDecodeFailed { reason, context} => io:: Error :: new (
224
223
io:: ErrorKind :: InvalidData ,
225
- format ! ( "{reason }, context: {context:? }'" ) ,
224
+ format ! ( "{}, context: {}'" , reason , context ) ,
226
225
) ,
227
- KVStoreUpdatingPersisterError :: UpdateDecodeFailed ( reason, context) => io:: Error :: new (
226
+ KVStoreUpdatingPersisterError :: UpdateDecodeFailed { reason, context} => io:: Error :: new (
228
227
io:: ErrorKind :: InvalidData ,
229
- format ! ( "{reason }, context: {context:? }'" ) ,
228
+ format ! ( "{}, context: {}'" , reason , context ) ,
230
229
) ,
231
- KVStoreUpdatingPersisterError :: StorageReadFailed ( reason, context) => {
232
- io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "{reason }, context: {context:? }'" ) )
230
+ KVStoreUpdatingPersisterError :: StorageReadFailed { reason, context} => {
231
+ io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "{}, context: {}'" , reason , context ) )
233
232
}
234
- KVStoreUpdatingPersisterError :: UpdateFailed ( reason, context) => {
235
- io:: Error :: new ( io:: ErrorKind :: InvalidData , format ! ( "{reason }, context: {context }'" ) )
233
+ KVStoreUpdatingPersisterError :: UpdateFailed { reason, context} => {
234
+ io:: Error :: new ( io:: ErrorKind :: InvalidData , format ! ( "{}, context: {}'" , reason , context ) )
236
235
}
237
236
}
238
237
}
@@ -253,23 +252,30 @@ impl TryFrom<MonitorName> for OutPoint {
253
252
type Error = std:: io:: Error ;
254
253
255
254
fn try_from ( value : MonitorName ) -> Result < Self , io:: Error > {
256
- let ( txid_hex, index) = value. 0 . split_once ( '_' ) . ok_or_else ( || {
257
- KVStoreUpdatingPersisterError :: BadMonitorName (
258
- "no underscore" . to_string ( ) ,
259
- value. 0 . clone ( ) ,
260
- )
255
+ let mut parts = value. 0 . splitn ( 2 , '_' ) ;
256
+ let txid_hex = parts. next ( ) . ok_or_else ( || {
257
+ KVStoreUpdatingPersisterError :: BadMonitorName {
258
+ reason : "no txid found, maybe there is no underscore" . to_string ( ) ,
259
+ context : value. 0 . clone ( ) ,
260
+ }
261
+ } ) ?;
262
+ let index = parts. next ( ) . ok_or_else ( || {
263
+ KVStoreUpdatingPersisterError :: BadMonitorName {
264
+ reason : "no index value found after underscore" . to_string ( ) ,
265
+ context : value. 0 . clone ( ) ,
266
+ }
261
267
} ) ?;
262
268
let index = index. parse ( ) . map_err ( |e| {
263
- KVStoreUpdatingPersisterError :: BadMonitorName (
264
- format ! ( "bad index value, caused by {e}" ) ,
265
- value. 0 . clone ( ) ,
266
- )
269
+ KVStoreUpdatingPersisterError :: BadMonitorName {
270
+ reason : format ! ( "bad index value, caused by {e}" ) ,
271
+ context : value. 0 . clone ( ) ,
272
+ }
267
273
} ) ?;
268
274
let txid = Txid :: from_hex ( txid_hex) . map_err ( |e| {
269
- KVStoreUpdatingPersisterError :: BadMonitorName (
270
- format ! ( "bad txid, caused by: {e}" ) ,
271
- value. 0 . clone ( ) ,
272
- )
275
+ KVStoreUpdatingPersisterError :: BadMonitorName {
276
+ reason : format ! ( "bad txid, caused by: {e}" ) ,
277
+ context : value. 0 . clone ( ) ,
278
+ }
273
279
} ) ?;
274
280
Ok ( OutPoint { txid, index } )
275
281
}
@@ -307,13 +313,12 @@ where
307
313
logger : L ,
308
314
}
309
315
310
- #[ allow( unused, clippy:: type_complexity) ]
311
316
impl < K : Deref , L : Deref > KVStoreUpdatingPersister < K , L >
312
317
where
313
318
K :: Target : KVStore ,
314
319
L :: Target : Logger ,
315
320
{
316
- fn read_channelmonitors < ES : Deref + Clone , SP : Deref + Clone , B : Deref , F : Deref + Clone > (
321
+ pub fn read_channelmonitors < ES : Deref + Clone , SP : Deref + Clone , B : Deref , F : Deref + Clone > (
317
322
& self ,
318
323
entropy_source : ES ,
319
324
signer_provider : SP ,
@@ -349,10 +354,10 @@ where
349
354
monitor
350
355
. update_monitor ( & update, broadcaster, fee_estimator. clone ( ) , & self . logger )
351
356
. map_err ( |_| {
352
- KVStoreUpdatingPersisterError :: UpdateFailed (
353
- "update_monitor returned Err(())" . to_string ( ) ,
354
- format ! ( "monitor: {:?}" , monitor_name) ,
355
- )
357
+ KVStoreUpdatingPersisterError :: UpdateFailed {
358
+ reason : "update_monitor returned Err(())" . to_string ( ) ,
359
+ context : format ! ( "monitor: {:?}" , monitor_name) ,
360
+ }
356
361
} ) ?;
357
362
}
358
363
}
@@ -374,7 +379,7 @@ where
374
379
375
380
/// List all the names of monitors.
376
381
fn list_monitor_names ( & self ) -> io:: Result < Vec < MonitorName > > {
377
- let mut list = self . kv . list ( CHANNEL_MONITOR_PERSISTENCE_NAMESPACE ) ?;
382
+ let list = self . kv . list ( CHANNEL_MONITOR_PERSISTENCE_NAMESPACE ) ?;
378
383
Ok ( list. into_iter ( ) . map ( MonitorName ) . collect ( ) )
379
384
}
380
385
@@ -409,22 +414,22 @@ where
409
414
& mut self
410
415
. kv
411
416
. read ( CHANNEL_MONITOR_PERSISTENCE_NAMESPACE , & key)
412
- . map_err ( |e| KVStoreUpdatingPersisterError :: StorageReadFailed ( e , key. clone ( ) ) ) ?,
417
+ . map_err ( |e| KVStoreUpdatingPersisterError :: StorageReadFailed { reason : e . to_string ( ) , context : key. clone ( ) } ) ?,
413
418
( & * entropy_source, & * signer_provider) ,
414
419
) {
415
420
Ok ( ( blockhash, channel_monitor) ) => {
416
421
if channel_monitor. get_funding_txo ( ) . 0 . txid != outpoint. txid
417
422
|| channel_monitor. get_funding_txo ( ) . 0 . index != outpoint. index
418
423
{
419
- return Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed (
420
- DecodeError :: InvalidValue ,
421
- key,
422
- )
424
+ return Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed {
425
+ reason : DecodeError :: InvalidValue . to_string ( ) ,
426
+ context : key,
427
+ }
423
428
. into ( ) ) ;
424
429
}
425
430
Ok ( ( blockhash, channel_monitor) )
426
431
}
427
- Err ( e) => Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed ( e , key) . into ( ) ) ,
432
+ Err ( e) => Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed { reason : e . to_string ( ) , context : key} . into ( ) ) ,
428
433
}
429
434
}
430
435
@@ -440,9 +445,9 @@ where
440
445
& mut self
441
446
. kv
442
447
. read ( & ns, & key)
443
- . map_err ( |e| KVStoreUpdatingPersisterError :: StorageReadFailed ( e , key. clone ( ) ) ) ?,
448
+ . map_err ( |e| KVStoreUpdatingPersisterError :: StorageReadFailed { reason : e . to_string ( ) , context : key. clone ( ) } ) ?,
444
449
)
445
- . map_err ( |e| KVStoreUpdatingPersisterError :: UpdateDecodeFailed ( e , key) ) ?)
450
+ . map_err ( |e| KVStoreUpdatingPersisterError :: UpdateDecodeFailed { reason : e . to_string ( ) , context : key} ) ?)
446
451
}
447
452
448
453
/// Delete updates with an update_id lower than the given channel monitor.
0 commit comments