@@ -3839,6 +3839,13 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
3839
3839
create_announced_chan_between_nodes ( & nodes, 2 , 0 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3840
3840
let ( _, _, channel_id, funding_tx) = create_announced_chan_between_nodes ( & nodes, 0 , 3 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3841
3841
3842
+ let mut node_0_stale_monitors_serialized = Vec :: new ( ) ;
3843
+ for monitor in nodes[ 0 ] . chan_monitor . simple_monitor . monitors . lock ( ) . unwrap ( ) . iter ( ) {
3844
+ let mut writer = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
3845
+ monitor. 1 . write_for_disk ( & mut writer) . unwrap ( ) ;
3846
+ node_0_stale_monitors_serialized. push ( writer. 0 ) ;
3847
+ }
3848
+
3842
3849
let ( our_payment_preimage, _) = route_payment ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] , 1000000 ) ;
3843
3850
3844
3851
// Serialize the ChannelManager here, but the monitor we keep up-to-date
@@ -3861,6 +3868,15 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
3861
3868
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
3862
3869
new_chan_monitor = test_utils:: TestChannelMonitor :: new ( nodes[ 0 ] . chain_monitor . clone ( ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , Arc :: new ( test_utils:: TestLogger :: new ( ) ) , & fee_estimator) ;
3863
3870
nodes[ 0 ] . chan_monitor = & new_chan_monitor;
3871
+
3872
+ let mut node_0_stale_monitors = Vec :: new ( ) ;
3873
+ for serialized in node_0_stale_monitors_serialized. iter ( ) {
3874
+ let mut read = & serialized[ ..] ;
3875
+ let ( _, monitor) = <( Sha256dHash , ChannelMonitor < EnforcingChannelKeys > ) >:: read ( & mut read, Arc :: new ( test_utils:: TestLogger :: new ( ) ) ) . unwrap ( ) ;
3876
+ assert ! ( read. is_empty( ) ) ;
3877
+ node_0_stale_monitors. push ( monitor) ;
3878
+ }
3879
+
3864
3880
let mut node_0_monitors = Vec :: new ( ) ;
3865
3881
for serialized in node_0_monitors_serialized. iter ( ) {
3866
3882
let mut read = & serialized[ ..] ;
@@ -3869,17 +3885,38 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
3869
3885
node_0_monitors. push ( monitor) ;
3870
3886
}
3871
3887
3872
- let mut nodes_0_read = & nodes_0_serialized[ ..] ;
3873
3888
keys_manager = test_utils:: TestKeysInterface :: new ( & nodes[ 0 ] . node_seed , Network :: Testnet , Arc :: new ( test_utils:: TestLogger :: new ( ) ) ) ;
3874
- let ( _, nodes_0_deserialized_tmp) = <( Sha256dHash , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChannelMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator > ) >:: read ( & mut nodes_0_read, ChannelManagerReadArgs {
3889
+
3890
+ let mut nodes_0_read = & nodes_0_serialized[ ..] ;
3891
+ let read_args = ChannelManagerReadArgs {
3892
+ default_config : UserConfig :: default ( ) ,
3893
+ keys_manager : & keys_manager,
3894
+ fee_estimator : & fee_estimator,
3895
+ monitor : nodes[ 0 ] . chan_monitor ,
3896
+ tx_broadcaster : nodes[ 0 ] . tx_broadcaster . clone ( ) ,
3897
+ logger : Arc :: new ( test_utils:: TestLogger :: new ( ) ) ,
3898
+ channel_monitors : & mut node_0_stale_monitors. iter_mut ( ) . map ( |monitor| { ( monitor. get_funding_txo ( ) . unwrap ( ) , monitor) } ) . collect ( ) ,
3899
+ } ;
3900
+
3901
+ if let Err ( msgs:: DecodeError :: InvalidValue ) =
3902
+ <( Sha256dHash , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChannelMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator > ) >:: read ( & mut nodes_0_read, read_args) {
3903
+ } else {
3904
+ panic ! ( "If the monitor(s) are stale, this indicates a bug and we should get an Err return" ) ;
3905
+ } ;
3906
+
3907
+ let mut nodes_0_read = & nodes_0_serialized[ ..] ;
3908
+ let read_args = ChannelManagerReadArgs {
3875
3909
default_config : UserConfig :: default ( ) ,
3876
3910
keys_manager : & keys_manager,
3877
3911
fee_estimator : & fee_estimator,
3878
3912
monitor : nodes[ 0 ] . chan_monitor ,
3879
3913
tx_broadcaster : nodes[ 0 ] . tx_broadcaster . clone ( ) ,
3880
3914
logger : Arc :: new ( test_utils:: TestLogger :: new ( ) ) ,
3881
3915
channel_monitors : & mut node_0_monitors. iter_mut ( ) . map ( |monitor| { ( monitor. get_funding_txo ( ) . unwrap ( ) , monitor) } ) . collect ( ) ,
3882
- } ) . unwrap ( ) ;
3916
+ } ;
3917
+
3918
+ let ( _, nodes_0_deserialized_tmp) =
3919
+ <( Sha256dHash , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChannelMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator > ) >:: read ( & mut nodes_0_read, read_args) . unwrap ( ) ;
3883
3920
nodes_0_deserialized = nodes_0_deserialized_tmp;
3884
3921
assert ! ( nodes_0_read. is_empty( ) ) ;
3885
3922
0 commit comments