@@ -12,20 +12,38 @@ import { TransactionValidator } from "../verification/TransactionValidator";
1212import { Tracer } from "../../logging/Tracer" ;
1313import { trace } from "../../logging/trace" ;
1414import { IncomingMessagesService } from "../../settlement/messages/IncomingMessagesService" ;
15+ import { MempoolSorting } from "../sorting/MempoolSorting" ;
16+ import { DefaultMempoolSorting } from "../sorting/DefaultMempoolSorting" ;
17+
18+ type PrivateMempoolConfig = {
19+ type ?: "hybrid" | "private" | "based" ;
20+ } ;
1521
1622@sequencerModule ( )
17- export class PrivateMempool extends SequencerModule implements Mempool {
23+ export class PrivateMempool
24+ extends SequencerModule < PrivateMempoolConfig >
25+ implements Mempool
26+ {
1827 public readonly events = new EventEmitter < MempoolEvents > ( ) ;
1928
29+ private readonly mempoolSorting : MempoolSorting ;
30+
2031 public constructor (
2132 private readonly transactionValidator : TransactionValidator ,
2233 @inject ( "TransactionStorage" )
2334 private readonly transactionStorage : TransactionStorage ,
2435 @inject ( "IncomingMessagesService" , { isOptional : true } )
2536 private readonly messageService : IncomingMessagesService | undefined ,
26- @inject ( "Tracer" ) public readonly tracer : Tracer
37+ @inject ( "Tracer" ) public readonly tracer : Tracer ,
38+ @inject ( "MempoolSorting" , { isOptional : true } )
39+ mempoolSorting : MempoolSorting | undefined
2740 ) {
2841 super ( ) ;
42+ this . mempoolSorting = mempoolSorting ?? new DefaultMempoolSorting ( ) ;
43+ }
44+
45+ private type ( ) {
46+ return this . config . type ?? "hybrid" ;
2947 }
3048
3149 public async length ( ) : Promise < number > {
@@ -36,7 +54,12 @@ export class PrivateMempool extends SequencerModule implements Mempool {
3654 public async add ( tx : PendingTransaction ) : Promise < boolean > {
3755 const [ txValid , error ] = this . transactionValidator . validateTx ( tx ) ;
3856 if ( txValid ) {
39- const success = await this . transactionStorage . pushUserTransaction ( tx ) ;
57+ const sortingValue = this . mempoolSorting ! . presortingPriority ( tx ) ;
58+
59+ const success = await this . transactionStorage . pushUserTransaction (
60+ tx ,
61+ sortingValue
62+ ) ;
4063 if ( success ) {
4164 this . events . emit ( "mempool-transaction-added" , tx ) ;
4265 log . trace ( `Transaction added to mempool: ${ tx . hash ( ) . toString ( ) } ` ) ;
@@ -69,14 +92,27 @@ export class PrivateMempool extends SequencerModule implements Mempool {
6992 offset ?: number ,
7093 limit ?: number
7194 ) : Promise < PendingTransaction [ ] > {
72- return await this . transactionStorage . getPendingUserTransactions (
95+ if ( this . type ( ) === "based" ) {
96+ return [ ] ;
97+ }
98+
99+ let txs = await this . transactionStorage . getPendingUserTransactions (
73100 offset ?? 0 ,
74101 limit
75102 ) ;
103+
104+ if ( this . mempoolSorting . enablePostSorting ( ) ) {
105+ txs = this . mempoolSorting . postSorting ( txs ) ;
106+ }
107+
108+ return txs ;
76109 }
77110
78111 @trace ( "mempool.get_mandatory_txs" )
79112 public async getMandatoryTxs ( ) : Promise < PendingTransaction [ ] > {
113+ if ( this . type ( ) === "private" ) {
114+ return [ ] ;
115+ }
80116 return ( await this . messageService ?. getPendingMessages ( ) ) ?? [ ] ;
81117 }
82118
0 commit comments