-
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.
- Loading branch information
1 parent
6a19daf
commit 0899725
Showing
16 changed files
with
379 additions
and
260 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
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) | ||
|
||
// SetAnteHandler sets the ante handler for the lane. | ||
func SetAnteHandler(anteHandler sdk.AnteHandler) LaneOption { | ||
return func(l *BaseLane) { l.cfg.AnteHandler = anteHandler } | ||
} | ||
|
||
// SetPrepareLaneHandler 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 SetPrepareLaneHandler(prepareLaneHandler PrepareLaneHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if prepareLaneHandler == nil { | ||
panic("prepare lane handler cannot be nil") | ||
} | ||
|
||
l.prepareLaneHandler = prepareLaneHandler | ||
} | ||
} | ||
|
||
// SetProcessLaneHandler 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 SetProcessLaneHandler(processLaneHandler ProcessLaneHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if processLaneHandler == nil { | ||
panic("process lane handler cannot be nil") | ||
} | ||
|
||
l.processLaneHandler = processLaneHandler | ||
} | ||
} | ||
|
||
// SetMatchHandler 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 SetMatchHandler(matchHandler MatchHandler) LaneOption { | ||
return func(l *BaseLane) { | ||
if matchHandler == nil { | ||
panic("match handler cannot be nil") | ||
} | ||
|
||
l.matchHandler = matchHandler | ||
} | ||
} | ||
|
||
// SetMempool sets the mempool for the lane. This mempool is used to store | ||
// transactions that are waiting to be processed. | ||
func SetMempool(mempool block.LaneMempool) LaneOption { | ||
return func(l *BaseLane) { | ||
if mempool == nil { | ||
panic("mempool cannot be nil") | ||
} | ||
|
||
l.LaneMempool = mempool | ||
} | ||
} | ||
|
||
// SetMempoolWithConfigs 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 SetMempoolWithConfigs[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.