@@ -534,7 +534,7 @@ def remove_transaction(self, tx: BaseTransaction) -> None:
534
534
if self .with_index :
535
535
assert self .all_index is not None
536
536
537
- self .del_from_indexes (tx , relax_assert = True )
537
+ self .del_from_indexes (tx , relax_assert = True , del_blocks = True )
538
538
# TODO Move it to self.del_from_indexes. We cannot simply do it because
539
539
# this method is used by the consensus algorithm which does not
540
540
# expect to have it removed from self.all_index.
@@ -810,7 +810,7 @@ def add_to_indexes(self, tx: BaseTransaction) -> None:
810
810
raise NotImplementedError
811
811
812
812
@abstractmethod
813
- def del_from_indexes (self , tx : BaseTransaction , * , relax_assert : bool = False ) -> None :
813
+ def del_from_indexes (self , tx : BaseTransaction , * , relax_assert : bool = False , del_blocks : bool = False ) -> None :
814
814
raise NotImplementedError
815
815
816
816
@abstractmethod
@@ -1170,16 +1170,20 @@ def add_to_indexes(self, tx: BaseTransaction) -> None:
1170
1170
if self .tx_index .add_tx (tx ):
1171
1171
self ._cache_tx_count += 1
1172
1172
1173
- def del_from_indexes (self , tx : BaseTransaction , * , relax_assert : bool = False ) -> None :
1173
+ def del_from_indexes (self , tx : BaseTransaction , * , relax_assert : bool = False , del_blocks : bool = False ) -> None :
1174
1174
if not self .with_index :
1175
1175
raise NotImplementedError
1176
1176
assert self .block_index is not None
1177
1177
assert self .tx_index is not None
1178
1178
if self .tokens_index :
1179
1179
self .tokens_index .del_tx (tx )
1180
1180
if tx .is_block :
1181
- if self .block_index .del_tx (tx , relax_assert = relax_assert ):
1182
- self ._cache_block_count -= 1
1181
+ # This is the code to remove the block from the indexes.
1182
+ # But we cannot remove blocks from index because they are used to validate
1183
+ # block rewards.
1184
+ if del_blocks :
1185
+ if self .block_index .del_tx (tx , relax_assert = relax_assert ):
1186
+ self ._cache_block_count -= 1
1183
1187
else :
1184
1188
if self .tx_index .del_tx (tx , relax_assert = relax_assert ):
1185
1189
self ._cache_tx_count -= 1
0 commit comments