@@ -29,7 +29,7 @@ use bitcoin::hash_types::{BlockHash, Txid};
29
29
use crate :: chain;
30
30
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
31
31
use crate :: chain:: channelmonitor:: {
32
- write_util_internal , Balance , ChannelMonitor , ChannelMonitorUpdate , MonitorEvent , TransactionOutputs ,
32
+ write_chanmon_internal , Balance , ChannelMonitor , ChannelMonitorUpdate , MonitorEvent , TransactionOutputs ,
33
33
WithChannelMonitor ,
34
34
} ;
35
35
use crate :: chain:: transaction:: { OutPoint , TransactionData } ;
@@ -814,8 +814,9 @@ where
814
814
815
815
fn send_peer_storage ( & self , their_node_id : PublicKey ) {
816
816
const MAX_PEER_STORAGE_SIZE : usize = 65531 ;
817
+ const USIZE_LEN : usize = core:: mem:: size_of :: < usize > ( ) ;
817
818
let random_bytes = self . entropy_source . get_secure_random_bytes ( ) ;
818
- let random_usize = usize:: from_le_bytes ( random_bytes[ 0 ..core :: mem :: size_of :: < usize > ( ) ] . try_into ( ) . unwrap ( ) ) ;
819
+ let random_usize = usize:: from_le_bytes ( random_bytes[ 0 ..USIZE_LEN ] . try_into ( ) . unwrap ( ) ) ;
819
820
820
821
let monitors = self . monitors . read ( ) . unwrap ( ) ;
821
822
let mut monitors_list = PeerStorageMonitorHolderList { monitors : Vec :: new ( ) } ;
@@ -835,31 +836,22 @@ where
835
836
let counterparty_node_id = mon. monitor . get_counterparty_node_id ( ) ;
836
837
let chan_mon = mon. monitor . inner . lock ( ) . unwrap ( ) ;
837
838
838
- match write_util_internal ( & chan_mon, true , & mut ser_chan) {
839
- Ok ( _) => {
840
- // Adding size of peer_storage_monitor.
841
- curr_size += ser_chan. 0 . serialized_length ( )
842
- + min_seen_secret. serialized_length ( )
843
- + chan_id. serialized_length ( )
844
- + counterparty_node_id. serialized_length ( ) ;
839
+ write_chanmon_internal ( & chan_mon, true , & mut ser_chan) . expect ( "can not write Channel Monitor for peer storage message" ) ;
845
840
846
- if curr_size > MAX_PEER_STORAGE_SIZE {
847
- break ;
848
- }
841
+ let peer_storage_monitor = PeerStorageMonitorHolder {
842
+ channel_id : * chan_id,
843
+ min_seen_secret,
844
+ counterparty_node_id,
845
+ monitor_bytes : ser_chan. 0 ,
846
+ } ;
849
847
850
- let peer_storage_monitor = PeerStorageMonitorHolder {
851
- channel_id : * chan_id,
852
- min_seen_secret,
853
- counterparty_node_id,
854
- monitor_bytes : ser_chan. 0 ,
855
- } ;
848
+ // Adding size of peer_storage_monitor.
849
+ curr_size += peer_storage_monitor. serialized_length ( ) ;
856
850
857
- monitors_list. monitors . push ( peer_storage_monitor) ;
858
- } ,
859
- Err ( _) => {
860
- panic ! ( "Can not write monitor for {}" , mon. monitor. channel_id( ) )
861
- } ,
851
+ if curr_size > MAX_PEER_STORAGE_SIZE {
852
+ break ;
862
853
}
854
+ monitors_list. monitors . push ( peer_storage_monitor) ;
863
855
}
864
856
865
857
let serialised_channels = monitors_list. encode ( ) ;
0 commit comments