@@ -859,15 +859,23 @@ impl Scanner<RetrieveTransactions, ReceivedPayments> for ReceivableScanner {
859859 "No newly received payments were detected during the scanning process."
860860 ) ;
861861
862- match self
863- . persistent_configuration
864- . set_start_block ( Some ( msg. new_start_block ) )
865- {
866- Ok ( ( ) ) => debug ! ( logger, "Start block updated to {}" , msg. new_start_block) ,
867- Err ( e) => panic ! (
868- "Attempt to set new start block to {} failed due to: {:?}" ,
869- msg. new_start_block, e
870- ) ,
862+ if let Some ( new_start_block) = msg. new_start_block {
863+ let current_start_block = match self . persistent_configuration . start_block ( ) {
864+ Ok ( Some ( current_start_block) ) => current_start_block,
865+ _ => 0u64 ,
866+ } ;
867+ if new_start_block > current_start_block {
868+ match self
869+ . persistent_configuration
870+ . set_start_block ( msg. new_start_block )
871+ {
872+ Ok ( ( ) ) => debug ! ( logger, "Start block updated to {}" , & new_start_block) ,
873+ Err ( e) => panic ! (
874+ "Attempt to set new start block to {} failed due to: {:?}" ,
875+ & new_start_block, e
876+ ) ,
877+ }
878+ }
871879 }
872880 } else {
873881 self . handle_new_received_payments ( & msg, logger)
@@ -912,23 +920,29 @@ impl ReceivableScanner {
912920 . as_mut ( )
913921 . more_money_received ( msg. timestamp , & msg. payments ) ;
914922
915- let new_start_block = msg. new_start_block ;
916- match self
917- . persistent_configuration
918- . set_start_block_from_txn ( new_start_block, & mut txn)
919- {
920- Ok ( ( ) ) => ( ) ,
921- Err ( e) => panic ! (
922- "Attempt to set new start block to {} failed due to: {:?}" ,
923- new_start_block, e
924- ) ,
925- }
926-
927- match txn. commit ( ) {
928- Ok ( _) => {
929- debug ! ( logger, "Updated start block to: {}" , new_start_block)
923+ if let Some ( new_start_block) = msg. new_start_block {
924+ let current_start_block = match self . persistent_configuration . start_block ( ) {
925+ Ok ( Some ( start_block) ) => start_block,
926+ _ => 0u64 ,
927+ } ;
928+ if new_start_block > current_start_block {
929+ match self
930+ . persistent_configuration
931+ . set_start_block_from_txn ( msg. new_start_block , & mut txn)
932+ {
933+ Ok ( ( ) ) => ( ) ,
934+ Err ( e) => panic ! (
935+ "Attempt to set new start block to {} failed due to: {:?}" ,
936+ new_start_block, e
937+ ) ,
938+ }
939+ match txn. commit ( ) {
940+ Ok ( _) => {
941+ debug ! ( logger, "Updated start block to: {}" , new_start_block)
942+ }
943+ Err ( e) => panic ! ( "Commit of received transactions failed: {:?}" , e) ,
944+ }
930945 }
931- Err ( e) => panic ! ( "Commit of received transactions failed: {:?}" , e) ,
932946 }
933947
934948 let total_newly_paid_receivable = msg
@@ -1623,7 +1637,7 @@ mod tests {
16231637 . iter ( )
16241638 . map ( |ppayable| ppayable. hash )
16251639 . collect :: < HashSet < H256 > > ( ) ;
1626- // Not in an ascending order
1640+ // Not in ascending order
16271641 let rowids_and_hashes_from_fingerprints = vec ! [ ( hash_1, 3 ) , ( hash_3, 5 ) , ( hash_2, 6 ) ]
16281642 . iter ( )
16291643 . map ( |( hash, _id) | * hash)
@@ -1875,7 +1889,7 @@ mod tests {
18751889 00000000000000000000000000000000000000000315 failed due to RecordDeletion(\" Gosh, I overslept \
18761890 without an alarm set\" )") ;
18771891 let log_handler = TestLogHandler :: new ( ) ;
1878- // There is a possible situation when we stumble over missing fingerprints and so we log it.
1892+ // There is a possible situation when we stumble over missing fingerprints, so we log it.
18791893 // Here we don't and so any ERROR log shouldn't turn up
18801894 log_handler. exists_no_log_containing ( & format ! ( "ERROR: {}" , test_name) )
18811895 }
@@ -2075,9 +2089,7 @@ mod tests {
20752089 } ;
20762090 let payable_thresholds_gauge = PayableThresholdsGaugeMock :: default ( )
20772091 . is_innocent_age_params ( & is_innocent_age_params_arc)
2078- . is_innocent_age_result (
2079- debt_age_s <= custom_payment_thresholds. maturity_threshold_sec as u64 ,
2080- )
2092+ . is_innocent_age_result ( debt_age_s <= custom_payment_thresholds. maturity_threshold_sec )
20812093 . is_innocent_balance_params ( & is_innocent_balance_params_arc)
20822094 . is_innocent_balance_result (
20832095 balance <= gwei_to_wei ( custom_payment_thresholds. permanent_debt_allowed_gwei ) ,
@@ -2098,7 +2110,7 @@ mod tests {
20982110 assert_eq ! ( debt_age_returned_innocent, debt_age_s) ;
20992111 assert_eq ! (
21002112 curve_derived_time,
2101- custom_payment_thresholds. maturity_threshold_sec as u64
2113+ custom_payment_thresholds. maturity_threshold_sec
21022114 ) ;
21032115 let is_innocent_balance_params = is_innocent_balance_params_arc. lock ( ) . unwrap ( ) ;
21042116 assert_eq ! (
@@ -3043,8 +3055,9 @@ mod tests {
30433055 init_test_logging ( ) ;
30443056 let test_name = "receivable_scanner_aborts_scan_if_no_payments_were_supplied" ;
30453057 let set_start_block_params_arc = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
3046- let new_start_block = 4321 ;
3058+ let new_start_block = Some ( 4321 ) ;
30473059 let persistent_config = PersistentConfigurationMock :: new ( )
3060+ . start_block_result ( Ok ( None ) )
30483061 . set_start_block_params ( & set_start_block_params_arc)
30493062 . set_start_block_result ( Ok ( ( ) ) ) ;
30503063 let mut subject = ReceivableScannerBuilder :: new ( )
@@ -3074,16 +3087,21 @@ mod tests {
30743087 init_test_logging ( ) ;
30753088 let test_name = "no_transactions_received_but_start_block_setting_fails" ;
30763089 let now = SystemTime :: now ( ) ;
3077- let persistent_config = PersistentConfigurationMock :: new ( ) . set_start_block_result ( Err (
3078- PersistentConfigError :: UninterpretableValue ( "Illiterate database manager" . to_string ( ) ) ,
3079- ) ) ;
3090+ let set_start_block_params_arc = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
3091+ let new_start_block = Some ( 6709u64 ) ;
3092+ let persistent_config = PersistentConfigurationMock :: new ( )
3093+ . start_block_result ( Ok ( None ) )
3094+ . set_start_block_params ( & set_start_block_params_arc)
3095+ . set_start_block_result ( Err ( PersistentConfigError :: UninterpretableValue (
3096+ "Illiterate database manager" . to_string ( ) ,
3097+ ) ) ) ;
30803098 let mut subject = ReceivableScannerBuilder :: new ( )
30813099 . persistent_configuration ( persistent_config)
30823100 . build ( ) ;
30833101 let msg = ReceivedPayments {
30843102 timestamp : now,
30853103 payments : vec ! [ ] ,
3086- new_start_block : 6709 ,
3104+ new_start_block,
30873105 response_skeleton_opt : None ,
30883106 } ;
30893107 // Not necessary, rather for preciseness
@@ -3107,6 +3125,7 @@ mod tests {
31073125 . set_arbitrary_id_stamp ( transaction_id) ;
31083126 let transaction = TransactionSafeWrapper :: new_with_builder ( txn_inner_builder) ;
31093127 let persistent_config = PersistentConfigurationMock :: new ( )
3128+ . start_block_result ( Ok ( None ) )
31103129 . set_start_block_from_txn_params ( & set_start_block_from_txn_params_arc)
31113130 . set_start_block_from_txn_result ( Ok ( ( ) ) ) ;
31123131 let receivable_dao = ReceivableDaoMock :: new ( )
@@ -3134,7 +3153,7 @@ mod tests {
31343153 let msg = ReceivedPayments {
31353154 timestamp : now,
31363155 payments : receivables. clone ( ) ,
3137- new_start_block : 7890123 ,
3156+ new_start_block : Some ( 7890123 ) ,
31383157 response_skeleton_opt : None ,
31393158 } ;
31403159 subject. mark_as_started ( SystemTime :: now ( ) ) ;
@@ -3153,7 +3172,7 @@ mod tests {
31533172 let set_by_guest_transaction_params = set_start_block_from_txn_params_arc. lock ( ) . unwrap ( ) ;
31543173 assert_eq ! (
31553174 * set_by_guest_transaction_params,
3156- vec![ ( 7890123 , transaction_id) ]
3175+ vec![ ( Some ( 7890123u64 ) , transaction_id) ]
31573176 ) ;
31583177 let commit_params = commit_params_arc. lock ( ) . unwrap ( ) ;
31593178 assert_eq ! ( * commit_params, vec![ ( ) ] ) ;
@@ -3171,9 +3190,11 @@ mod tests {
31713190 let now = SystemTime :: now ( ) ;
31723191 let txn_inner_builder = TransactionInnerWrapperMockBuilder :: default ( ) ;
31733192 let transaction = TransactionSafeWrapper :: new_with_builder ( txn_inner_builder) ;
3174- let persistent_config = PersistentConfigurationMock :: new ( ) . set_start_block_from_txn_result (
3175- Err ( PersistentConfigError :: DatabaseError ( "Fatigue" . to_string ( ) ) ) ,
3176- ) ;
3193+ let persistent_config = PersistentConfigurationMock :: new ( )
3194+ . start_block_result ( Ok ( None ) )
3195+ . set_start_block_from_txn_result ( Err ( PersistentConfigError :: DatabaseError (
3196+ "Fatigue" . to_string ( ) ,
3197+ ) ) ) ;
31773198 let receivable_dao = ReceivableDaoMock :: new ( ) . more_money_received_result ( transaction) ;
31783199 let mut subject = ReceivableScannerBuilder :: new ( )
31793200 . receivable_dao ( receivable_dao)
@@ -3187,7 +3208,7 @@ mod tests {
31873208 let msg = ReceivedPayments {
31883209 timestamp : now,
31893210 payments : receivables,
3190- new_start_block : 7890123 ,
3211+ new_start_block : Some ( 7890123 ) ,
31913212 response_skeleton_opt : None ,
31923213 } ;
31933214 // Not necessary, rather for preciseness
@@ -3215,8 +3236,9 @@ mod tests {
32153236 let txn_inner_builder =
32163237 TransactionInnerWrapperMockBuilder :: default ( ) . commit_result ( commit_err) ;
32173238 let transaction = TransactionSafeWrapper :: new_with_builder ( txn_inner_builder) ;
3218- let persistent_config =
3219- PersistentConfigurationMock :: new ( ) . set_start_block_from_txn_result ( Ok ( ( ) ) ) ;
3239+ let persistent_config = PersistentConfigurationMock :: new ( )
3240+ . start_block_result ( Ok ( None ) )
3241+ . set_start_block_from_txn_result ( Ok ( ( ) ) ) ;
32203242 let receivable_dao = ReceivableDaoMock :: new ( ) . more_money_received_result ( transaction) ;
32213243 let mut subject = ReceivableScannerBuilder :: new ( )
32223244 . receivable_dao ( receivable_dao)
@@ -3230,7 +3252,7 @@ mod tests {
32303252 let msg = ReceivedPayments {
32313253 timestamp : now,
32323254 payments : receivables,
3233- new_start_block : 7890123 ,
3255+ new_start_block : Some ( 7890123 ) ,
32343256 response_skeleton_opt : None ,
32353257 } ;
32363258 // Not necessary, rather for preciseness
0 commit comments