feat(v1): Init vote extension handlers (#95)
This commit is contained in:
parent
ee0ab98c97
commit
c8f0f1bb3e
@ -15,7 +15,9 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Mempool interface {
|
||||
// ProposalMempool contains the methods required by the ProposalHandler
|
||||
// to interact with the local mempool.
|
||||
ProposalMempool interface {
|
||||
sdkmempool.Mempool
|
||||
AuctionBidSelect(ctx context.Context) sdkmempool.Iterator
|
||||
GetBundledTransactions(tx sdk.Tx) ([][]byte, error)
|
||||
@ -23,8 +25,10 @@ type (
|
||||
IsAuctionTx(tx sdk.Tx) (bool, error)
|
||||
}
|
||||
|
||||
// ProposalHandler contains the functionality and handlers required to\
|
||||
// process, validate and build blocks.
|
||||
ProposalHandler struct {
|
||||
mempool Mempool
|
||||
mempool ProposalMempool
|
||||
logger log.Logger
|
||||
anteHandler sdk.AnteHandler
|
||||
txEncoder sdk.TxEncoder
|
||||
@ -32,8 +36,10 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewProposalHandler returns a ProposalHandler that contains the functionality and handlers
|
||||
// required to process, validate and build blocks.
|
||||
func NewProposalHandler(
|
||||
mp Mempool,
|
||||
mp ProposalMempool,
|
||||
logger log.Logger,
|
||||
anteHandler sdk.AnteHandler,
|
||||
txEncoder sdk.TxEncoder,
|
||||
@ -265,6 +271,13 @@ func (h *ProposalHandler) ProcessProposalVerifyTx(ctx sdk.Context, txBz []byte)
|
||||
return tx, h.verifyTx(ctx, tx)
|
||||
}
|
||||
|
||||
// RemoveTx removes a transaction from the application-side mempool.
|
||||
func (h *ProposalHandler) RemoveTx(tx sdk.Tx) {
|
||||
if err := h.mempool.Remove(tx); err != nil && !errors.Is(err, sdkmempool.ErrTxNotFound) {
|
||||
panic(fmt.Errorf("failed to remove invalid transaction from the mempool: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyTx verifies a transaction against the application's state.
|
||||
func (h *ProposalHandler) verifyTx(ctx sdk.Context, tx sdk.Tx) error {
|
||||
if h.anteHandler != nil {
|
||||
@ -274,9 +287,3 @@ func (h *ProposalHandler) verifyTx(ctx sdk.Context, tx sdk.Tx) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ProposalHandler) RemoveTx(tx sdk.Tx) {
|
||||
if err := h.mempool.Remove(tx); err != nil && !errors.Is(err, sdkmempool.ErrTxNotFound) {
|
||||
panic(fmt.Errorf("failed to remove invalid transaction from the mempool: %w", err))
|
||||
}
|
||||
}
|
||||
58
abci/vote_extensions.go
Normal file
58
abci/vote_extensions.go
Normal file
@ -0,0 +1,58 @@
|
||||
package abci
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
|
||||
)
|
||||
|
||||
type (
|
||||
// VoteExtensionMempool contains the methods required by the VoteExtensionHandler
|
||||
// to interact with the local mempool.
|
||||
VoteExtensionMempool interface {
|
||||
Remove(tx sdk.Tx) error
|
||||
AuctionBidSelect(ctx context.Context) sdkmempool.Iterator
|
||||
IsAuctionTx(tx sdk.Tx) (bool, error)
|
||||
}
|
||||
|
||||
// VoteExtensionHandler contains the functionality and handlers required to
|
||||
// process, validate and build vote extensions.
|
||||
VoteExtensionHandler struct {
|
||||
mempool VoteExtensionMempool
|
||||
txDecoder sdk.TxDecoder
|
||||
txEncoder sdk.TxEncoder
|
||||
anteHandler sdk.AnteHandler
|
||||
}
|
||||
)
|
||||
|
||||
// NewVoteExtensionHandler returns an VoteExtensionHandler that contains the functionality and handlers
|
||||
// required to inject, process, and validate vote extensions.
|
||||
func NewVoteExtensionHandler(mp VoteExtensionMempool, txDecoder sdk.TxDecoder,
|
||||
txEncoder sdk.TxEncoder, ah sdk.AnteHandler,
|
||||
) *VoteExtensionHandler {
|
||||
return &VoteExtensionHandler{
|
||||
mempool: mp,
|
||||
txDecoder: txDecoder,
|
||||
txEncoder: txEncoder,
|
||||
anteHandler: ah,
|
||||
}
|
||||
}
|
||||
|
||||
// ExtendVoteHandler returns the ExtendVoteHandler ABCI handler that extracts
|
||||
// the top bidding valid auction transaction from a validator's local mempool and
|
||||
// returns it in its vote extension.
|
||||
func (h *VoteExtensionHandler) ExtendVoteHandler() ExtendVoteHandler {
|
||||
return func(ctx sdk.Context, req *RequestExtendVote) (*ResponseExtendVote, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyVoteExtensionHandler returns the VerifyVoteExtensionHandler ABCI handler
|
||||
// that verifies the vote extension included in RequestVerifyVoteExtension.
|
||||
// In particular, it verifies that the vote extension is a valid auction transaction.
|
||||
func (h *VoteExtensionHandler) VerifyVoteExtensionHandler() VerifyVoteExtensionHandler {
|
||||
return func(ctx sdk.Context, req *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
}
|
||||
1
abci/vote_extensions_test.go
Normal file
1
abci/vote_extensions_test.go
Normal file
@ -0,0 +1 @@
|
||||
package abci_test
|
||||
Loading…
Reference in New Issue
Block a user