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

Commit

Permalink
fixunjail
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Jan 29, 2024
1 parent ec7dffc commit 41657e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
39 changes: 23 additions & 16 deletions cosmos/runtime/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sync"
"time"

"github.com/cosmos/gogoproto/proto"
mempool "github.com/cosmos/cosmos-sdk/types/mempool"

"github.com/berachain/polaris/eth"
"github.com/berachain/polaris/eth/core"
Expand All @@ -48,8 +48,10 @@ type Miner struct {
bc core.Blockchain

valTxSelector baseapp.TxSelector
txVerifier baseapp.ProposalTxVerifier
serializer EnvelopeSerializer
allowedValMsgs map[string]sdk.Msg
cmdsMempool mempool.Mempool
currentPayload *miner.Payload

blockBuilderMu *sync.RWMutex
Expand All @@ -58,15 +60,18 @@ type Miner struct {
// New produces a cosmos miner from a geth miner.
func New(
miner eth.Miner, app TxDecoder, allowedValMsgs map[string]sdk.Msg,
bc core.Blockchain, blockBuilderMu *sync.RWMutex,
bc core.Blockchain, blockBuilderMu *sync.RWMutex, cmdsMempool mempool.Mempool,
txVerifier baseapp.ProposalTxVerifier,
) *Miner {
return &Miner{
miner: miner,
app: app,
bc: bc,
allowedValMsgs: allowedValMsgs,
valTxSelector: baseapp.NewDefaultTxSelector(),
txVerifier: txVerifier,
blockBuilderMu: blockBuilderMu,
cmdsMempool: cmdsMempool,
}
}

Expand Down Expand Up @@ -168,28 +173,30 @@ func (m *Miner) processValidatorMsgs(
}
blockGasRemaining := uint64(b.MaxGas) - ethGasUsed

for _, txBz := range txs {
tx, err := m.app.TxDecode(txBz)
if err != nil {
continue
}
iterator := m.cmdsMempool.Select(ctx, txs)
for iterator != nil {
memTx := iterator.Tx()

includeTx := true
for _, msg := range tx.GetMsgs() {
if _, ok := m.allowedValMsgs[proto.MessageName(msg)]; !ok {
includeTx = false
break
// NOTE: Since transaction verification was already executed in CheckTx,
// which calls mempool.Insert, in theory everything in the pool should be
// valid. But some mempool implementations may insert invalid txs, so we
// check again.
txBz, err := m.txVerifier.PrepareProposalVerifyTx(memTx)
if err != nil {
err := m.cmdsMempool.Remove(memTx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
return nil, err
}
}

if includeTx {
} else {
stop := m.valTxSelector.SelectTxForProposal(
ctx, uint64(maxTxBytes), blockGasRemaining, tx, txBz,
ctx, uint64(maxTxBytes), blockGasRemaining, memTx, txBz,
)
if stop {
break
}
}

iterator = iterator.Next()
}
return m.valTxSelector.SelectedTxs(ctx), nil
}
5 changes: 4 additions & 1 deletion cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

cometabci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
Expand Down Expand Up @@ -70,6 +71,7 @@ type CosmosApp interface {
CommitMultiStore() storetypes.CommitMultiStore
PreBlocker(sdk.Context, *cometabci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error)
BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error)
baseapp.ProposalTxVerifier
}

// Polaris is a struct that wraps the Polaris struct from the polar package.
Expand Down Expand Up @@ -143,7 +145,8 @@ func (p *Polaris) Build(
// Wrap the geth miner and txpool with the cosmos miner and txpool.
p.WrappedMiner = miner.New(
p.ExecutionLayer.Backend().Miner(), app, allowedValMsgs,
p.Backend().Blockchain(), &p.blockBuilderMu,
p.Backend().Blockchain(), &p.blockBuilderMu, p.WrappedTxPool,
app,
)
p.WrappedBlockchain = chain.New(
p.ExecutionLayer.Backend().Blockchain(), app,
Expand Down
10 changes: 7 additions & 3 deletions cosmos/runtime/txpool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type GethTxPool interface {
type Mempool struct {
eth.TxPool
lifetime int64
cmdsPool mempool.Mempool
chain core.ChainReader
handler Lifecycle
crc CometRemoteCache
Expand All @@ -84,6 +85,7 @@ func New(
crc: newCometRemoteCache(),
blockBuilderMu: blockBuilderMu,
priceLimit: priceLimit,
cmdsPool: mempool.DefaultPriorityMempool(),
}
}

Expand Down Expand Up @@ -117,7 +119,7 @@ func (m *Mempool) Insert(ctx context.Context, sdkTx sdk.Tx) error {
wet, ok := utils.GetAs[*types.WrappedEthereumTransaction](msgs[0])
if !ok {
// We have to return nil for non-ethereum transactions as to not fail check-tx.
return nil
return m.cmdsPool.Insert(ctx, sdkTx)
}

// Add the eth tx to the Geth txpool.
Expand Down Expand Up @@ -161,7 +163,7 @@ func (m *Mempool) Remove(tx sdk.Tx) error {
if len(msgs) == 1 {
env, ok := utils.GetAs[*types.WrappedPayloadEnvelope](msgs[0])
if !ok {
return nil
goto remove
}

// Unwrap the payload to unpack the individual eth transactions to remove from the txpool.
Expand All @@ -175,6 +177,8 @@ func (m *Mempool) Remove(tx sdk.Tx) error {
// Remove the eth tx from comet seen tx cache.
m.crc.DropRemoteTx(txHash)
}
return nil
}
return nil
remove:
return m.Remove(tx)
}

0 comments on commit 41657e0

Please sign in to comment.