@@ -752,36 +752,50 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
752
752
* @param latestBlock - The block number the chain was pruned to.
753
753
*/
754
754
private async handlePruneL2Blocks ( latestBlock : number ) : Promise < void > {
755
- const txsToDelete : TxHash [ ] = [ ] ;
755
+ // NOTE: temporary fix for alphanet, deleting ALL txs that were in the epoch from the pool #13723
756
+ // TODO: undo once fixed: #13770
757
+ const txsToDelete = new Set < TxHash > ( ) ;
758
+ const minedTxs = await this . txPool . getMinedTxHashes ( ) ;
759
+ for ( const [ txHash , blockNumber ] of minedTxs ) {
760
+ if ( blockNumber > latestBlock ) {
761
+ txsToDelete . add ( txHash ) ;
762
+ }
763
+ }
764
+
765
+ // Find transactions that reference pruned blocks in their historical header
756
766
for ( const tx of await this . txPool . getAllTxs ( ) ) {
757
767
// every tx that's been generated against a block that has now been pruned is no longer valid
758
768
if ( tx . data . constants . historicalHeader . globalVariables . blockNumber . toNumber ( ) > latestBlock ) {
759
- txsToDelete . push ( await tx . getTxHash ( ) ) ;
769
+ const txHash = await tx . getTxHash ( ) ;
770
+ txsToDelete . add ( txHash ) ;
760
771
}
761
772
}
762
773
763
774
this . log . info (
764
775
`Detected chain prune. Removing invalid txs count=${
765
- txsToDelete . length
776
+ txsToDelete . size
766
777
} newLatestBlock=${ latestBlock } previousLatestBlock=${ await this . getSyncedLatestBlockNum ( ) } `,
767
778
) ;
768
779
769
780
// delete invalid txs (both pending and mined)
770
- await this . txPool . deleteTxs ( txsToDelete ) ;
781
+ await this . txPool . deleteTxs ( Array . from ( txsToDelete ) ) ;
771
782
772
783
// everything left in the mined set was built against a block on the proven chain so its still valid
773
784
// move back to pending the txs that were reorged out of the chain
774
785
// NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
775
786
// (see this.keepProvenTxsFor)
776
- const txsToMoveToPending : TxHash [ ] = [ ] ;
777
- for ( const [ txHash , blockNumber ] of await this . txPool . getMinedTxHashes ( ) ) {
778
- if ( blockNumber > latestBlock ) {
779
- txsToMoveToPending . push ( txHash ) ;
780
- }
781
- }
782
787
783
- this . log . info ( `Moving ${ txsToMoveToPending . length } mined txs back to pending` ) ;
784
- await this . txPool . markMinedAsPending ( txsToMoveToPending ) ;
788
+ // NOTE: given current fix for alphanet, the code below is redundant as all these txs will be deleted.
789
+ // TODO: bring back once fixed: #13770
790
+ // const txsToMoveToPending: TxHash[] = [];
791
+ // for (const [txHash, blockNumber] of minedTxs) {
792
+ // if (blockNumber > latestBlock) {
793
+ // txsToMoveToPending.push(txHash);
794
+ // }
795
+ // }
796
+
797
+ // this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
798
+ // await this.txPool.markMinedAsPending(txsToMoveToPending);
785
799
786
800
await this . synchedLatestBlockNumber . set ( latestBlock ) ;
787
801
// no need to update block hashes, as they will be updated as new blocks are added
0 commit comments