-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * lint * update mock * cr * readme nit (cherry picked from commit db58154) # Conflicts: # block/base/lane.go # block/mempool_test.go # block/mocks/lane.go
- Loading branch information
1 parent
6735692
commit cdd87a6
Showing
19 changed files
with
768 additions
and
273 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
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
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
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
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,42 @@ | ||
package base | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// DefaultMatchHandler returns a default implementation of the MatchHandler. It matches all | ||
// transactions. | ||
func DefaultMatchHandler() MatchHandler { | ||
return func(ctx sdk.Context, tx sdk.Tx) bool { | ||
return true | ||
} | ||
} | ||
|
||
// VerifyNoMatches returns an error if any of the transactions match the lane. | ||
func (l *BaseLane) VerifyNoMatches(ctx sdk.Context, txs []sdk.Tx) error { | ||
for _, tx := range txs { | ||
if l.Match(ctx, tx) { | ||
return fmt.Errorf("transaction belongs to lane when it should not") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewMatchHandler returns a match handler that matches transactions | ||
// that match the lane and do not match with any of the provided match handlers. | ||
// In the context of building an application, you would want to use this to | ||
// ignore the match handlers of other lanes in the application. | ||
func NewMatchHandler(mh MatchHandler, ignoreMHs ...MatchHandler) MatchHandler { | ||
return func(ctx sdk.Context, tx sdk.Tx) bool { | ||
for _, ignoreMH := range ignoreMHs { | ||
if ignoreMH(ctx, tx) { | ||
return false | ||
} | ||
} | ||
|
||
return mh(ctx, tx) | ||
} | ||
} |
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,80 @@ | ||
package base | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/skip-mev/block-sdk/block" | ||
) | ||
|
||
// LaneOption defines a function that can be used to set options on a lane. | ||
type LaneOption func(*BaseLane) | ||
|
||
// WithAnteHandler sets the ante handler for the lane. | ||
func WithAnteHandler(anteHandler sdk.AnteHandler) LaneOption { | ||
return func(l *BaseLane) { l.cfg.AnteHandler = anteHandler } | ||
} | ||
|
||
// WithPrepareLaneHandler sets the prepare lane handler for the lane. This handler | ||
// is called when a new proposal is being requested and the lane needs to submit | ||
// transactions it wants included in the block. | ||
func WithPrepareLaneHandler(prepareLaneHandler PrepareLaneHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if prepareLaneHandler == nil { | ||
panic("prepare lane handler cannot be nil") | ||
} | ||
|
||
l.prepareLaneHandler = prepareLaneHandler | ||
} | ||
} | ||
|
||
// WithProcessLaneHandler sets the process lane handler for the lane. This handler | ||
// is called when a new proposal is being verified and the lane needs to verify | ||
// that the transactions included in the proposal are valid respecting the verification | ||
// logic of the lane. | ||
func WithProcessLaneHandler(processLaneHandler ProcessLaneHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if processLaneHandler == nil { | ||
panic("process lane handler cannot be nil") | ||
} | ||
|
||
l.processLaneHandler = processLaneHandler | ||
} | ||
} | ||
|
||
// WithMatchHandler sets the match handler for the lane. This handler is called | ||
// when a new transaction is being submitted to the lane and the lane needs to | ||
// determine if the transaction should be processed by the lane. | ||
func WithMatchHandler(matchHandler MatchHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if matchHandler == nil { | ||
panic("match handler cannot be nil") | ||
} | ||
|
||
l.matchHandler = matchHandler | ||
} | ||
} | ||
|
||
// WithMempool sets the mempool for the lane. This mempool is used to store | ||
// transactions that are waiting to be processed. | ||
func WithMempool(mempool block.LaneMempool) LaneOption { | ||
return func(l *BaseLane) { | ||
if mempool == nil { | ||
panic("mempool cannot be nil") | ||
} | ||
|
||
l.LaneMempool = mempool | ||
} | ||
} | ||
|
||
// WithMempoolConfigs sets the mempool for the lane with the given lane config | ||
// and TxPriority struct. This mempool is used to store transactions that are waiting | ||
// to be processed. | ||
func WithMempoolConfigs[C comparable](cfg LaneConfig, txPriority TxPriority[C]) LaneOption { | ||
return func(l *BaseLane) { | ||
l.LaneMempool = NewMempool( | ||
txPriority, | ||
cfg.TxEncoder, | ||
cfg.SignerExtractor, | ||
cfg.MaxTxs, | ||
) | ||
} | ||
} |
Oops, something went wrong.