@@ -38,7 +38,7 @@ pub const CHANNEL_MANAGER_PERSISTENCE_KEY: &str = "manager";
3838/// The namespace under which [`ChannelMonitor`]s will be persisted.
3939pub const CHANNEL_MONITOR_PERSISTENCE_NAMESPACE : & str = "monitors" ;
4040/// 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 " ;
4242
4343/// The namespace under which the [`NetworkGraph`] will be persisted.
4444pub const NETWORK_GRAPH_PERSISTENCE_NAMESPACE : & str = "" ;
@@ -153,7 +153,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
153153 }
154154}
155155
156- #[ allow( clippy:: type_complexity) ]
157156/// Read previously persisted [`ChannelMonitor`]s from the store.
158157pub fn read_channel_monitors < K : Deref , ES : Deref , SP : Deref > (
159158 kv_store : K , entropy_source : ES , signer_provider : SP ,
@@ -202,37 +201,37 @@ where
202201
203202enum KVStoreUpdatingPersisterError {
204203 /// The monitor name was improperly formatted.
205- BadMonitorName ( String , String ) ,
204+ BadMonitorName { reason : String , context : String } ,
206205 /// The monitor could not be decoded.
207- MonitorDecodeFailed ( DecodeError , String ) ,
206+ MonitorDecodeFailed { reason : String , context : String } ,
208207 /// The update could not be decoded.
209- UpdateDecodeFailed ( DecodeError , String ) ,
208+ UpdateDecodeFailed { reason : String , context : String } ,
210209 /// Storage could not be read.
211- StorageReadFailed ( io :: Error , String ) ,
210+ StorageReadFailed { reason : String , context : String } ,
212211 /// An update could not be applied to a monitor.
213- UpdateFailed ( String , String ) ,
212+ UpdateFailed { reason : String , context : String } ,
214213}
215214
216215impl From < KVStoreUpdatingPersisterError > for io:: Error {
217216 fn from ( value : KVStoreUpdatingPersisterError ) -> Self {
218217 match value {
219- KVStoreUpdatingPersisterError :: BadMonitorName ( reason, context) => io:: Error :: new (
218+ KVStoreUpdatingPersisterError :: BadMonitorName { reason, context} => io:: Error :: new (
220219 io:: ErrorKind :: InvalidInput ,
221- format ! ( "{reason }, context: {context }'" ) ,
220+ format ! ( "{}, context: {}'" , reason , context ) ,
222221 ) ,
223- KVStoreUpdatingPersisterError :: MonitorDecodeFailed ( reason, context) => io:: Error :: new (
222+ KVStoreUpdatingPersisterError :: MonitorDecodeFailed { reason, context} => io:: Error :: new (
224223 io:: ErrorKind :: InvalidData ,
225- format ! ( "{reason }, context: {context:? }'" ) ,
224+ format ! ( "{}, context: {}'" , reason , context ) ,
226225 ) ,
227- KVStoreUpdatingPersisterError :: UpdateDecodeFailed ( reason, context) => io:: Error :: new (
226+ KVStoreUpdatingPersisterError :: UpdateDecodeFailed { reason, context} => io:: Error :: new (
228227 io:: ErrorKind :: InvalidData ,
229- format ! ( "{reason }, context: {context:? }'" ) ,
228+ format ! ( "{}, context: {}'" , reason , context ) ,
230229 ) ,
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 ) )
233232 }
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 ) )
236235 }
237236 }
238237 }
@@ -253,23 +252,30 @@ impl TryFrom<MonitorName> for OutPoint {
253252 type Error = std:: io:: Error ;
254253
255254 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+ }
261267 } ) ?;
262268 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+ }
267273 } ) ?;
268274 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+ }
273279 } ) ?;
274280 Ok ( OutPoint { txid, index } )
275281 }
@@ -307,13 +313,12 @@ where
307313 logger : L ,
308314}
309315
310- #[ allow( unused, clippy:: type_complexity) ]
311316impl < K : Deref , L : Deref > KVStoreUpdatingPersister < K , L >
312317where
313318 K :: Target : KVStore ,
314319 L :: Target : Logger ,
315320{
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 > (
317322 & self ,
318323 entropy_source : ES ,
319324 signer_provider : SP ,
@@ -349,10 +354,10 @@ where
349354 monitor
350355 . update_monitor ( & update, broadcaster, fee_estimator. clone ( ) , & self . logger )
351356 . 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+ }
356361 } ) ?;
357362 }
358363 }
@@ -374,7 +379,7 @@ where
374379
375380 /// List all the names of monitors.
376381 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 ) ?;
378383 Ok ( list. into_iter ( ) . map ( MonitorName ) . collect ( ) )
379384 }
380385
@@ -409,22 +414,22 @@ where
409414 & mut self
410415 . kv
411416 . 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 ( ) } ) ?,
413418 ( & * entropy_source, & * signer_provider) ,
414419 ) {
415420 Ok ( ( blockhash, channel_monitor) ) => {
416421 if channel_monitor. get_funding_txo ( ) . 0 . txid != outpoint. txid
417422 || channel_monitor. get_funding_txo ( ) . 0 . index != outpoint. index
418423 {
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+ }
423428 . into ( ) ) ;
424429 }
425430 Ok ( ( blockhash, channel_monitor) )
426431 }
427- Err ( e) => Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed ( e , key) . into ( ) ) ,
432+ Err ( e) => Err ( KVStoreUpdatingPersisterError :: MonitorDecodeFailed { reason : e . to_string ( ) , context : key} . into ( ) ) ,
428433 }
429434 }
430435
@@ -440,9 +445,9 @@ where
440445 & mut self
441446 . kv
442447 . 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 ( ) } ) ?,
444449 )
445- . map_err ( |e| KVStoreUpdatingPersisterError :: UpdateDecodeFailed ( e , key) ) ?)
450+ . map_err ( |e| KVStoreUpdatingPersisterError :: UpdateDecodeFailed { reason : e . to_string ( ) , context : key} ) ?)
446451 }
447452
448453 /// Delete updates with an update_id lower than the given channel monitor.
0 commit comments