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

Commit

Permalink
Merge branch 'main' into fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Bear authored Oct 21, 2023
2 parents 4dbc8fa + 8a2aff3 commit 19e8689
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
28 changes: 22 additions & 6 deletions cosmos/lib/ante/eject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@
package ante

import (
"fmt"
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"

"pkg.berachain.dev/polaris/cosmos/x/evm/types"
"pkg.berachain.dev/polaris/eth/common"
"pkg.berachain.dev/polaris/lib/utils"
)

// NewAnteHandler creates a new instance of AnteHandler with EjectOnRecheckTxDecorator.
func NewAnteHandler() sdk.AnteHandler {
anteDecorators := []sdk.AnteDecorator{
&EjectOnRecheckTxDecorator{},
ante.NewSetUpContextDecorator(),
&EjectOnRecheckTxDecorator{
seen: make(map[common.Hash]uint64),
},
}

return sdk.ChainAnteDecorators(anteDecorators...)
Expand All @@ -39,14 +47,22 @@ func NewAnteHandler() sdk.AnteHandler {
// This is used to forcibly eject transactions from the CometBFT mempool after they
// have been passed down to the application, as we want to prevent the comet mempool
// from growing in size.
type EjectOnRecheckTxDecorator struct{}
type EjectOnRecheckTxDecorator struct {
seen map[common.Hash]uint64
}

// Antehandle implements sdk.AnteHandler.
func (EjectOnRecheckTxDecorator) AnteHandle(
func (e *EjectOnRecheckTxDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (sdk.Context, error) {
if ctx.ExecMode() == sdk.ExecModeReCheck {
return ctx, fmt.Errorf("recheck tx")
msgs := tx.GetMsgs()
if wet, ok := utils.GetAs[*types.WrappedEthereumTransaction](msgs[0]); ok {
hash := wet.Unwrap().Hash()
e.seen[hash]++
if e.seen[hash] > 25 { //nolint:gomnd // temp fix.
delete(e.seen, hash) // prevent leak
return ctx, errors.New("recheck tx")
}
}

return next(ctx, tx, simulate)
Expand Down
2 changes: 0 additions & 2 deletions cosmos/x/evm/plugins/state/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (p *plugin) Prepare(ctx context.Context) {
// Reset implements `core.StatePlugin`.
func (p *plugin) Reset(ctx context.Context) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

// We have to build a custom `SnapMulti` to use with the StateDB. This is because the
// ethereum utilizes the concept of snapshots, whereas the current implementation of the
// Cosmos-SDK `CacheKV` uses "wraps".
Expand Down Expand Up @@ -527,7 +526,6 @@ func (p *plugin) IterateBalances(fn func(common.Address, *big.Int) bool) {
// StateAtBlockNumber implements `core.StatePlugin`.
func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) {
var ctx sdk.Context

// Ensure the query context function is set.
if p.qfn == nil {
return nil, errors.New("no query context function set in host chain")
Expand Down
14 changes: 12 additions & 2 deletions e2e/localnet/network/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,29 @@ var _ = Describe("JSON RPC tests", func() {
Expect(tf.WaitForNextBlock()).To(Succeed())

// send a transaction and make sure pending nonce is incremented
_, err = contract.ConsumeGas(tf.GenerateTransactOpts("alice"), big.NewInt(10000))
var tx *coretypes.Transaction
tx, err = contract.ConsumeGas(tf.GenerateTransactOpts("alice"), big.NewInt(10000))
Expect(err).NotTo(HaveOccurred())

// Pending nonce should be 1 more than the current nonce
alicePendingNonce, err := client.PendingNonceAt(context.Background(), tf.Address("alice"))
Expect(err).NotTo(HaveOccurred())
Expect(alicePendingNonce).To(Equal(aliceCurrNonce + 1))

// The nonce on disk should still be equal to the nonce prior to the consume gas txn
// being included in a block.
acn, err := client.NonceAt(context.Background(), tf.Address("alice"), nil)
Expect(err).NotTo(HaveOccurred())
Expect(acn).To(Equal(aliceCurrNonce))

Expect(tf.WaitForNextBlock()).To(Succeed())
// Wait for block inclusion.
ExpectSuccessReceipt(client, tx)

// NonceAt and PendingNonce should be equal after inclusion
aliceCurrNonce, err = client.NonceAt(context.Background(), tf.Address("alice"), nil)
Expect(err).NotTo(HaveOccurred())
alicePendingNonce, err = client.PendingNonceAt(context.Background(), tf.Address("alice"))
Expect(err).NotTo(HaveOccurred())
Expect(aliceCurrNonce).To(Equal(alicePendingNonce))
})

Expand Down
2 changes: 0 additions & 2 deletions e2e/testapp/polard/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ func initCometBFTConfig() *cmtcfg.Config {
consensus.TimeoutPrecommit = time.Second * 2
consensus.TimeoutCommit = time.Second * 2

// Disable the indexer
cfg.TxIndex.Indexer = "null"
return cfg
}

Expand Down
2 changes: 1 addition & 1 deletion eth/core/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ func NewChain(
func (bc *blockchain) LoadLastState(ctx context.Context, number uint64) error {
// ctx here is the one created from app.CommitMultistore().
bc.PreparePlugins(ctx)
bc.sp.Prepare(ctx)

return bc.loadLastState(number)
}

func (bc *blockchain) PreparePlugins(ctx context.Context) {
bc.sp.Prepare(ctx)
bc.sp.Reset(ctx)
bc.bp.Prepare(ctx)
if bc.hp != nil {
Expand Down

0 comments on commit 19e8689

Please sign in to comment.