Repository: safe-global/safe-transaction-service
Issue: block_process_limit = 1 query for two blocks instead of one

**Describe the bug**
When block_process_limit is 1, only one block should be requested to the node, but two blocks are requested.
The request parameter `to-block` is equal `from-block` + `block_process_limit` but to request one block should be `to-block` = `from-block` 

**Expected behavior**
Request only one block.

**Possible solution** 
`to-block` = `from-block` + `block_process_limit` - 1



Changed files:
safe_transaction_service/history/tests/test_erc20_events_indexer.py, safe_transaction_service/history/indexers/ethereum_indexer.py

diff --git a/safe_transaction_service/history/indexers/ethereum_indexer.py b/safe_transaction_service/history/indexers/ethereum_indexer.py
index 341ad79..aa5e5bb 100644
--- a/safe_transaction_service/history/indexers/ethereum_indexer.py
+++ b/safe_transaction_service/history/indexers/ethereum_indexer.py
@@ -145,8 +145,16 @@ class EthereumIndexer(ABC):
         if (from_block_number + self.block_process_limit) >= (
             current_block_number - self.confirmations
         ):
+            reindex_blocks = self.blocks_to_reindex_again
+            if self.blocks_to_reindex_again >= self.block_process_limit:
+                # The following formula ensure that get_to_block_number reach last block
+                reindex_blocks = (
+                    (self.block_process_limit + from_block_number)
+                    - current_block_number
+                ) - 1
+
             # Reindex again when it's almost synced to prevent reorg/missing elements issues
-            from_block_number = max(from_block_number - self.blocks_to_reindex_again, 0)
+            from_block_number = max(from_block_number - reindex_blocks, 0)
 
         if (current_block_number - common_minimum_block_number) <= self.confirmations:
             return  # We don't want problems with reorgs
@@ -165,7 +173,7 @@ class EthereumIndexer(ABC):
         :return: Top block number to process
         """
         return min(
-            from_block_number + self.block_process_limit,
+            from_block_number + self.block_process_limit - 1,
             current_block_number - self.confirmations,
         )
 
diff --git a/safe_transaction_service/history/tests/test_erc20_events_indexer.py b/safe_transaction_service/history/tests/test_erc20_events_indexer.py
index 5d13691..570553a 100644
--- a/safe_transaction_service/history/tests/test_erc20_events_indexer.py
+++ b/safe_transaction_service/history/tests/test_erc20_events_indexer.py
@@ -11,8 +11,14 @@ from .factories import SafeContractFactory
 
 
 class TestErc20EventsIndexer(EthereumTestCaseMixin, TestCase):
+    def setUp(self) -> None:
+        self.erc20_events_indexer = Erc20EventsIndexerProvider()
+
+    def tearDown(self) -> None:
+        Erc20EventsIndexerProvider.del_singleton()
+
     def test_erc20_events_indexer(self):
-        erc20_events_indexer = Erc20EventsIndexerProvider()
+        erc20_events_indexer = self.erc20_events_indexer
         erc20_events_indexer.confirmations = 0
         self.assertEqual(erc20_events_indexer.start(), 0)
 
@@ -96,3 +102,10 @@ class TestErc20EventsIndexer(EthereumTestCaseMixin, TestCase):
             self.assertEqual(
                 erc20_events_indexer._process_decoded_element(event), original_event
             )
+
+    def test_get_to_block_number(self):
+        self.erc20_events_indexer.block_process_limit = 1
+        self.assertEqual(self.erc20_events_indexer.get_to_block_number(5, 100), 5)
+
+        self.erc20_events_indexer.block_process_limit = 2
+        self.assertEqual(self.erc20_events_indexer.get_to_block_number(5, 100), 6)