Skip to content

Commit

Permalink
Fix PR comments and build
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed May 10, 2024
1 parent 0bec7fb commit cc66564
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
File renamed without changes.
45 changes: 45 additions & 0 deletions app/ante/system_tx_priority_decorator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ante_test

import (
"math"
"math/rand"
"testing"
"time"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/app/ante"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestSystemTxPriorityDecorator_AnteHandle(t *testing.T) {
txConfig := app.MakeEncodingConfig().TxConfig

testPrivKey, _ := sample.PrivKeyAddressPair()

decorator := ante.NewSystemPriorityDecorator()
mmd := MockAnteHandler{}
// set priority to 10 before ante handler
ctx := sdk.Context{}.WithIsCheckTx(true).WithPriority(10)

tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txConfig,
[]sdk.Msg{},
sdk.NewCoins(),
simtestutil.DefaultGenTxGas,
"testing-chain-id",
[]uint64{0},
[]uint64{0},
testPrivKey,
)
require.NoError(t, err)
ctx, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
require.NoError(t, err)

// check that priority is set to max int64
priorityAfter := ctx.Priority()
require.Equal(t, math.MaxInt64, int(priorityAfter))
}
6 changes: 5 additions & 1 deletion app/custom_proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

// This proposal handler is taken from https://github.com/cosmos/cosmos-sdk/blob/v0.47.10/baseapp/abci_utils.go
// Only difference is extraction of senders and nonce from tx. In latest version of cosmos, there is a way to provide adapter for this, but in 0.47.10 this is the only way.
// TODO: remove this once we upgrade cosmos
// TODO: remove this once cosmos is upgraded: https://github.com/zeta-chain/node/issues/2156

import (
"fmt"
Expand Down Expand Up @@ -75,6 +75,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
return func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
var maxBlockGas uint64
if b := ctx.ConsensusParams().Block; b != nil {
// #nosec G701 range checked, cosmos-sdk forked code
maxBlockGas = uint64(b.MaxGas)
}

Expand All @@ -90,6 +91,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
// XXX: We pass nil as the memTx because we have no way of decoding the
// txBz. We'd need to break (update) the ProposalTxVerifier interface.
// As a result, we CANNOT account for block max gas.
// #nosec G701 range checked, cosmos-sdk forked code
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, nil, txBz)
if stop {
break
Expand Down Expand Up @@ -149,6 +151,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
panic(err)
}
} else {
// #nosec G701 range checked, cosmos-sdk forked code
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
if stop {
break
Expand Down Expand Up @@ -218,6 +221,7 @@ func (h *CustomProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHand
totalTxGas += gasTx.GetGas()
}

// #nosec G701 range checked, cosmos-sdk forked code
if totalTxGas > uint64(maxBlockGas) {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
Expand Down
6 changes: 3 additions & 3 deletions app/mempool/priority_nonce_mempool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This proposal handler is taken from https://github.com/cosmos/cosmos-sdk/blob/v0.47.10/types/mempool/priority_nonce.go
// Only difference is extraction of senders and nonce from tx. In latest version of cosmos, there is a way to provide adapter for this, but in 0.47.10 this is the only way.
// TODO: remove this once we upgrade cosmos
// TODO: remove this once cosmos is upgraded: https://github.com/zeta-chain/node/issues/2156

package mempool

Expand Down Expand Up @@ -422,7 +422,7 @@ func IsEmpty(mempool mempool.Mempool) error {
return fmt.Errorf("priorityIndex not empty")
}

var countKeys []int64
var countKeys = make([]int64, 0, len(mp.priorityCounts))
for k := range mp.priorityCounts {
countKeys = append(countKeys, k)
}
Expand All @@ -433,7 +433,7 @@ func IsEmpty(mempool mempool.Mempool) error {
}
}

var senderKeys []string
var senderKeys = make([]string, 0, len(mp.senderIndices))
for k := range mp.senderIndices {
senderKeys = append(senderKeys, k)
}
Expand Down
10 changes: 8 additions & 2 deletions app/mempool/senders_with_nonce.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: use with signer extractor once available https://github.com/zeta-chain/node/issues/2156

package mempool

import (
Expand All @@ -9,13 +11,16 @@ import (
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

// GetSendersWithNonce is used to extract sender and nonce information txs
// if tx is ethermint, it is extracted using from and nonce field
// if it's cosmos tx, default cosmos way using signatures is used
func GetSendersWithNonce(tx sdk.Tx) ([]SenderWithNonce, error) {
const extensionOptionsEthereumTxTypeUrl = "/ethermint.evm.v1.ExtensionOptionsEthereumTx"

Check warning on line 18 in app/mempool/senders_with_nonce.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: const extensionOptionsEthereumTxTypeUrl should be extensionOptionsEthereumTxTypeURL (revive)
if txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx); ok {
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 && opts[0].GetTypeUrl() == "/ethermint.evm.v1.ExtensionOptionsEthereumTx" {
if len(opts) > 0 && opts[0].GetTypeUrl() == extensionOptionsEthereumTxTypeUrl {
for _, msg := range tx.GetMsgs() {
if ethMsg, ok := msg.(*evmtypes.MsgEthereumTx); ok {

return []SenderWithNonce{
{
Sender: ethMsg.GetFrom().String(),
Expand All @@ -35,6 +40,7 @@ type SenderWithNonce struct {
Nonce uint64
}

// getSendersWithNonceDefault gets senders and nonces from signatures in cosmos txs
func getSendersWithNonceDefault(tx sdk.Tx) ([]SenderWithNonce, error) {
sendersWithNonce := []SenderWithNonce{}

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [2100](https://github.com/zeta-chain/node/pull/2100) - cosmos v0.47 upgrade
* [2145](https://github.com/zeta-chain/node/pull/2145) - add `ibc` and `ibc-transfer` modules
* [2135](https://github.com/zeta-chain/node/pull/2135) - add develop build version logic
* [2152](https://github.com/zeta-chain/node/pull/2152) - custom priority nonce mempool

### Refactor

Expand Down

0 comments on commit cc66564

Please sign in to comment.