-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
External transaction fetcher for mempool
The SimpleMempool gets a new (function-type) parameter. It can be set to a function that returns a list of transactions, in which case the mempool will use this function to obtain transactions externally. Signed-off-by: Matej Pavlovic <[email protected]>
- Loading branch information
1 parent
5e984f8
commit 95e97d3
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
pkg/mempool/simplemempool/internal/parts/formbatchesext/formbatches.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package formbatchesext | ||
|
||
import ( | ||
"github.com/filecoin-project/mir/pkg/dsl" | ||
"github.com/filecoin-project/mir/pkg/mempool/simplemempool/internal/common" | ||
mpdsl "github.com/filecoin-project/mir/pkg/pb/mempoolpb/dsl" | ||
mppbtypes "github.com/filecoin-project/mir/pkg/pb/mempoolpb/types" | ||
requestpbtypes "github.com/filecoin-project/mir/pkg/pb/requestpb/types" | ||
t "github.com/filecoin-project/mir/pkg/types" | ||
) | ||
|
||
// IncludeBatchCreation registers event handlers for processing NewRequests and RequestBatch events. | ||
func IncludeBatchCreation( | ||
m dsl.Module, | ||
mc *common.ModuleConfig, | ||
fetchTransactions func() []*requestpbtypes.Request, | ||
) { | ||
|
||
mpdsl.UponTransactionIDsResponse(m, func(txIDs []t.TxID, context *requestTxIDsContext) error { | ||
mpdsl.NewBatch(m, context.origin.Module, txIDs, context.txs, context.origin) | ||
return nil | ||
}) | ||
|
||
mpdsl.UponRequestBatch(m, func(origin *mppbtypes.RequestBatchOrigin) error { | ||
txs := fetchTransactions() | ||
mpdsl.RequestTransactionIDs(m, mc.Self, txs, &requestTxIDsContext{ | ||
txs: txs, | ||
origin: origin, | ||
}) | ||
return nil | ||
}) | ||
} | ||
|
||
// Context data structures | ||
|
||
type requestTxIDsContext struct { | ||
txs []*requestpbtypes.Request | ||
origin *mppbtypes.RequestBatchOrigin | ||
} |
2 changes: 1 addition & 1 deletion
2
...internal/parts/formbatches/formbatches.go → ...ernal/parts/formbatchesint/formbatches.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package formbatches | ||
package formbatchesint | ||
|
||
import ( | ||
"github.com/filecoin-project/mir/pkg/dsl" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters