Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jun 26, 2024
1 parent 56edbc6 commit 1cbd0c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
19 changes: 13 additions & 6 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
return nil, err
}

stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, mempool.NewMempoolTx(tx), txBz)
var txGasLimit uint64
if gasTx, ok := tx.(interface {
GetGas() uint64
}); ok {
txGasLimit = gasTx.GetGas()
}

stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, tx, txBz, txGasLimit)
if stop {
break
}
Expand Down Expand Up @@ -325,7 +332,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
return nil, err
}
} else {
stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, memTx.Tx, txBz, memTx.GasWanted)
if stop {
break
}
Expand Down Expand Up @@ -451,7 +458,7 @@ type TxSelector interface {
// a proposal based on inclusion criteria defined by the TxSelector. It must
// return <true> if the caller should halt the transaction selection loop
// (typically over a mempool) or <false> otherwise.
SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx mempool.MempoolTx, txBz []byte) bool
SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool
}

type defaultTxSelector struct {
Expand All @@ -476,16 +483,16 @@ func (ts *defaultTxSelector) Clear() {
ts.selectedTxs = nil
}

func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx mempool.MempoolTx, txBz []byte) bool {
func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool {
txSize := uint64(len(txBz))

// only add the transaction to the proposal if we have enough capacity
if (txSize + ts.totalTxBytes) <= maxTxBytes {
// If there is a max block gas limit, add the tx only if the limit has
// not been met.
if maxBlockGas > 0 {
if (memTx.GasWanted + ts.totalTxGas) <= maxBlockGas {
ts.totalTxGas += memTx.GasWanted
if (gasWanted + ts.totalTxGas) <= maxBlockGas {
ts.totalTxGas += gasWanted
ts.totalTxBytes += txSize
ts.selectedTxs = append(ts.selectedTxs, txBz)
}
Expand Down
12 changes: 1 addition & 11 deletions types/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ type MempoolTx struct {
GasWanted uint64
}

func NewMempoolTx(tx sdk.Tx) MempoolTx {
var txGasLimit uint64
if gasTx, ok := tx.(interface {
GetGas() uint64
}); ok {
txGasLimit = gasTx.GetGas()
}
return NewMempoolTxWithGasWanted(tx, txGasLimit)
}

func NewMempoolTxWithGasWanted(tx sdk.Tx, gasWanted uint64) MempoolTx {
func NewMempoolTx(tx sdk.Tx, gasWanted uint64) MempoolTx {
return MempoolTx{
Tx: tx,
GasWanted: gasWanted,
Expand Down
2 changes: 1 addition & 1 deletion types/mempool/priority_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (mp *PriorityNonceMempool[C]) InsertWithGasWanted(ctx context.Context, tx s
return nil
}

memTx := NewMempoolTxWithGasWanted(tx, gasWanted)
memTx := NewMempoolTx(tx, gasWanted)

sigs, err := mp.cfg.SignerExtractor.GetSigners(tx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion types/mempool/sender_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (snm *SenderNonceMempool) InsertWithGasWanted(_ context.Context, tx sdk.Tx,
return nil
}

memTx := NewMempoolTxWithGasWanted(tx, gasLimit)
memTx := NewMempoolTx(tx, gasLimit)

sigs, err := tx.(signing.SigVerifiableTx).GetSignaturesV2()
if err != nil {
Expand Down

0 comments on commit 1cbd0c9

Please sign in to comment.