Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
based ante handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Bear committed Oct 31, 2023
1 parent 4715a34 commit cca0785
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func New(
}

// Wrap the geth miner and txpool with the cosmos miner and txpool.
p.WrappedTxPool = txpool.New(p.TxPool())
p.WrappedTxPool = txpool.New(p.Blockchain(), p.TxPool())
p.WrappedMiner = miner.New(p.Miner())

return p
Expand Down
26 changes: 23 additions & 3 deletions cosmos/txpool/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/txpool"

"pkg.berachain.dev/polaris/cosmos/x/evm/types"
"pkg.berachain.dev/polaris/eth/common"
coretypes "pkg.berachain.dev/polaris/eth/core/types"
"pkg.berachain.dev/polaris/lib/utils"
)
Expand All @@ -53,9 +54,28 @@ func (m *Mempool) AnteHandle(

// shouldEject returns true if the transaction should be ejected from the CometBFT mempool.
func (m *Mempool) shouldEject(tx *coretypes.Transaction) bool {
txHash := tx.Hash()
if tx == nil {
return false
}
txStatus := m.txStatus(tx.Hash())

// Ejection conditions
// 1. If the transaction has been included in a block.
// TODO: we should add somemore conditons later.
return m.txpool.Status(txHash) == txpool.TxStatusIncluded
// 2. If the transaction is unknown to the node.
return txStatus == txpool.TxStatusIncluded || txStatus == txpool.TxStatusUnknown
}

// txStatus returns the status of the transaction.
func (m *Mempool) txStatus(hash common.Hash) txpool.TxStatus {
// Looking for the transaction in txpool first.
status := m.txpool.Status(hash)

// If the transaction is unknown to the pool, try looking it up locally.
if status == txpool.TxStatusUnknown {
lookup := m.chain.GetTransactionLookup(hash)
if lookup != nil {
status = txpool.TxStatusIncluded
}
}
return status
}
5 changes: 4 additions & 1 deletion cosmos/txpool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"pkg.berachain.dev/polaris/cosmos/x/evm/types"
"pkg.berachain.dev/polaris/eth"
"pkg.berachain.dev/polaris/eth/core"
coretypes "pkg.berachain.dev/polaris/eth/core/types"
"pkg.berachain.dev/polaris/lib/utils"
)
Expand Down Expand Up @@ -60,13 +61,15 @@ type GethTxPool interface {
// geth txpool during `CheckTx`, that is the only purpose of `Mempool“.
type Mempool struct {
txpool eth.TxPool
chain core.ChainReader
handler Lifecycle
}

// NewMempool creates a new Mempool.
func New(txpool eth.TxPool) *Mempool {
func New(chain core.ChainReader, txpool eth.TxPool) *Mempool {
return &Mempool{
txpool: txpool,
chain: chain,
}
}

Expand Down

0 comments on commit cca0785

Please sign in to comment.