Skip to content

Commit

Permalink
Merge branch 'feature/firehose-tracer' into release/firehose
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed Jun 19, 2024
2 parents a13290a + ec72741 commit f7dee2a
Show file tree
Hide file tree
Showing 99 changed files with 5,786 additions and 868 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ Types of changes (Stanzas):
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog
# Changelog## v5.5.5
sei-chain
* [#1726](https://github.com/sei-protocol/sei-chain/pull/1726) Handle VM error code properly
* [#1713](https://github.com/sei-protocol/sei-chain/pull/1713) RPC Get Evm Hash
* [#1711](https://github.com/sei-protocol/sei-chain/pull/1711) Add gov proposal v2 for native pointer
* [#1694](https://github.com/sei-protocol/sei-chain/pull/1694) Add native associate tx type


sei-cosmos
* [#511](https://github.com/sei-protocol/sei-cosmos/pull/511) Add error for evm revert


## v5.5.2
sei-chain
* [#1685](https://github.com/sei-protocol/sei-chain/pull/1685) Add EVM support to v5.5.2

## v5.4.0
sei-chain
* [#1671](https://github.com/sei-protocol/sei-chain/pull/1671) Update and fixes to ERC721 contract
Expand Down
2 changes: 1 addition & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk

anteDecorators := []sdk.AnteFullDecorator{
sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator(antedecorators.GetGasMeterSetter(options.ParamsKeeper.(paramskeeper.Keeper)))), // outermost AnteDecorator. SetUpContext must be called first
antedecorators.NewGaslessDecorator([]sdk.AnteFullDecorator{ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.ParamsKeeper.(paramskeeper.Keeper), options.TxFeeChecker)}, *options.OracleKeeper),
antedecorators.NewGaslessDecorator([]sdk.AnteFullDecorator{ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.ParamsKeeper.(paramskeeper.Keeper), options.TxFeeChecker)}, *options.OracleKeeper, options.EVMKeeper),
sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit, antedecorators.GetGasMeterSetter(options.ParamsKeeper.(paramskeeper.Keeper)))), // after setup context to enforce limits early
sdk.DefaultWrappedAnteDecorator(ante.NewRejectExtensionOptionsDecorator()),
oracle.NewSpammingPreventionDecorator(*options.OracleKeeper),
Expand Down
1 change: 0 additions & 1 deletion app/antedecorators/accesscontrol_wasm_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func NewACLWasmDependencyDecorator(aclKeeper aclkeeper.Keeper, wasmKeeper wasm.K
}

func (ad ACLWasmDependencyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {

for _, msg := range tx.GetMsgs() {
switch m := msg.(type) {
case *acltypes.MsgRegisterWasmDependency:
Expand Down
22 changes: 18 additions & 4 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
dextypes "github.com/sei-protocol/sei-chain/x/dex/types"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
)

type GaslessDecorator struct {
wrapped []sdk.AnteFullDecorator
oracleKeeper oraclekeeper.Keeper
evmKeeper *evmkeeper.Keeper
}

func NewGaslessDecorator(wrapped []sdk.AnteFullDecorator, oracleKeeper oraclekeeper.Keeper) GaslessDecorator {
return GaslessDecorator{wrapped: wrapped, oracleKeeper: oracleKeeper}
func NewGaslessDecorator(wrapped []sdk.AnteFullDecorator, oracleKeeper oraclekeeper.Keeper, evmKeeper *evmkeeper.Keeper) GaslessDecorator {
return GaslessDecorator{wrapped: wrapped, oracleKeeper: oracleKeeper, evmKeeper: evmKeeper}
}

func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
originalGasMeter := ctx.GasMeter()
// eagerly set infinite gas meter so that queries performed by IsTxGasless will not incur gas cost
ctx = ctx.WithGasMeter(storetypes.NewNoConsumptionInfiniteGasMeter())

isGasless, err := IsTxGasless(tx, ctx, gd.oracleKeeper)
isGasless, err := IsTxGasless(tx, ctx, gd.oracleKeeper, gd.evmKeeper)
if err != nil {
return ctx, err
}
Expand Down Expand Up @@ -108,7 +111,7 @@ func (gd GaslessDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk
return next(append(txDeps, deps...), tx, txIndex)
}

func IsTxGasless(tx sdk.Tx, ctx sdk.Context, oracleKeeper oraclekeeper.Keeper) (bool, error) {
func IsTxGasless(tx sdk.Tx, ctx sdk.Context, oracleKeeper oraclekeeper.Keeper, evmKeeper *evmkeeper.Keeper) (bool, error) {
if len(tx.GetMsgs()) == 0 {
// empty TX shouldn't be gasless
return false, nil
Expand All @@ -129,6 +132,10 @@ func IsTxGasless(tx sdk.Tx, ctx sdk.Context, oracleKeeper oraclekeeper.Keeper) (
if err != nil || !isGasless {
return false, err
}
case *evmtypes.MsgAssociate:
if !evmAssociateIsGasless(m, ctx, evmKeeper) {
return false, nil
}
default:
return false, nil
}
Expand Down Expand Up @@ -190,3 +197,10 @@ func oracleVoteIsGasless(msg *oracletypes.MsgAggregateExchangeRateVote, ctx sdk.
// otherwise we allow it
return true, nil
}

func evmAssociateIsGasless(msg *evmtypes.MsgAssociate, ctx sdk.Context, keeper *evmkeeper.Keeper) bool {
// not gasless if already associated
seiAddr := sdk.MustAccAddressFromBech32(msg.Sender)
_, associated := keeper.GetEVMAddress(ctx, seiAddr)
return !associated
}
15 changes: 8 additions & 7 deletions app/antedecorators/gasless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/x/dex/types"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -91,9 +92,9 @@ func (t FakeTx) FeeGranter() sdk.AccAddress {
return nil
}

func CallGaslessDecoratorWithMsg(ctx sdk.Context, msg sdk.Msg, oracleKeeper oraclekeeper.Keeper) error {
func CallGaslessDecoratorWithMsg(ctx sdk.Context, msg sdk.Msg, oracleKeeper oraclekeeper.Keeper, evmKeeper *evmkeeper.Keeper) error {
anteDecorators := []sdk.AnteFullDecorator{
antedecorators.NewGaslessDecorator([]sdk.AnteFullDecorator{sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorGasReqd{})}, oracleKeeper),
antedecorators.NewGaslessDecorator([]sdk.AnteFullDecorator{sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorGasReqd{})}, oracleKeeper, evmKeeper),
}
chainedHandler, depGen := sdk.ChainAnteDecorators(anteDecorators...)
fakeTx := FakeTx{
Expand Down Expand Up @@ -140,12 +141,12 @@ func TestOracleVoteGasless(t *testing.T) {
}

// reset gasless
err = CallGaslessDecoratorWithMsg(ctx, &vote1, input.OracleKeeper)
err = CallGaslessDecoratorWithMsg(ctx, &vote1, input.OracleKeeper, nil)
require.Error(t, err)

// reset gasless
gasless = true
err = CallGaslessDecoratorWithMsg(ctx, &vote2, input.OracleKeeper)
err = CallGaslessDecoratorWithMsg(ctx, &vote2, input.OracleKeeper, nil)
require.NoError(t, err)
require.True(t, gasless)
}
Expand All @@ -167,14 +168,14 @@ func TestDexCancelOrderGasless(t *testing.T) {
// not whitelisted
// reset gasless
gasless = true
err := CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &cancelMsg1, oraclekeeper.Keeper{})
err := CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &cancelMsg1, oraclekeeper.Keeper{}, nil)
require.NoError(t, err)
require.False(t, gasless)

// whitelisted
// reset gasless
gasless = true
err = CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &cancelMsg2, oraclekeeper.Keeper{})
err = CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &cancelMsg2, oraclekeeper.Keeper{}, nil)
require.NoError(t, err)
require.True(t, gasless)
}
Expand All @@ -183,7 +184,7 @@ func TestNonGaslessMsg(t *testing.T) {
// this needs to be updated if its changed from constant true
// reset gasless
gasless = true
err := CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &types.MsgRegisterContract{}, oraclekeeper.Keeper{})
err := CallGaslessDecoratorWithMsg(sdk.NewContext(nil, tmproto.Header{}, false, nil).WithIsCheckTx(true), &types.MsgRegisterContract{}, oraclekeeper.Keeper{}, nil)
require.NoError(t, err)
require.False(t, gasless)
}
48 changes: 40 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"math/big"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -17,6 +18,9 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
ethhexutil "github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

"github.com/ethereum/go-ethereum/ethclient"
ethrpc "github.com/ethereum/go-ethereum/rpc"

Expand Down Expand Up @@ -166,6 +170,9 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

// unnamed import of statik for openapi/swagger UI support
_ "github.com/sei-protocol/sei-chain/docs/swagger"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -379,9 +386,10 @@ type App struct {

HardForkManager *upgrades.HardForkManager

encodingConfig appparams.EncodingConfig
evmRPCConfig evmrpc.Config
evmTracer *tracing.Hooks
encodingConfig appparams.EncodingConfig
evmRPCConfig evmrpc.Config
evmTracer *tracing.Hooks
lightInvarianceConfig LightInvarianceConfig
}

// New returns a reference to an initialized blockchain app
Expand Down Expand Up @@ -625,6 +633,11 @@ func New(
}
app.EvmKeeper.EthClient = ethclient.NewClient(rpcclient)
}
lightInvarianceConfig, err := ReadLightInvarianceConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error reading light invariance config due to %s", err))
}
app.lightInvarianceConfig = lightInvarianceConfig

customDependencyGenerators := aclmapping.NewCustomDependencyGenerator()
aclOpts = append(aclOpts, aclkeeper.WithResourceTypeToStoreKeyMap(aclutils.ResourceTypeToStoreKeyMap))
Expand Down Expand Up @@ -1143,7 +1156,8 @@ func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock)
if app.EvmKeeper.EthReplayConfig.Enabled || app.EvmKeeper.EthBlockTestConfig.Enabled {
return &abci.ResponseFinalizeBlock{}, nil
}
app.WriteState()
cms := app.WriteState()
app.LightInvarianceChecks(cms, app.lightInvarianceConfig)
appHash := app.GetWorkingHash()
resp := app.getFinalizeBlockResponse(appHash, app.optimisticProcessingInfo.Events, app.optimisticProcessingInfo.TxRes, app.optimisticProcessingInfo.EndBlockResp)
return &resp, nil
Expand All @@ -1159,7 +1173,8 @@ func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock)
if app.EvmKeeper.EthReplayConfig.Enabled || app.EvmKeeper.EthBlockTestConfig.Enabled {
return &abci.ResponseFinalizeBlock{}, nil
}
app.WriteState()
cms := app.WriteState()
app.LightInvarianceChecks(cms, app.lightInvarianceConfig)
appHash := app.GetWorkingHash()
resp := app.getFinalizeBlockResponse(appHash, events, txResults, endBlockResp)
return &resp, nil
Expand Down Expand Up @@ -1692,7 +1707,7 @@ func (app *App) getFinalizeBlockResponse(appHash []byte, events []abci.Event, tx

// LoadHeight loads a particular height
func (app *App) LoadHeight(height int64) error {
return app.LoadVersion(height)
return app.LoadVersionWithoutInit(height)
}

// ModuleAccountAddrs returns all the app's module account addresses.
Expand Down Expand Up @@ -1757,7 +1772,7 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {

// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
clientCtx := apiSvr.ClientCtx
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
// Register legacy tx routes.
Expand All @@ -1770,6 +1785,12 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(apiSvr.Router)
}

}

// RegisterTxService implements the Application.RegisterTxService method.
Expand Down Expand Up @@ -1813,6 +1834,17 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
}
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.NewWithNamespace("swagger")
if err != nil {
panic(err)
}

staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

func (app *App) checkTotalBlockGasWanted(ctx sdk.Context, txs [][]byte) bool {
totalGasWanted := uint64(0)
for _, tx := range txs {
Expand All @@ -1826,7 +1858,7 @@ func (app *App) checkTotalBlockGasWanted(ctx sdk.Context, txs [][]byte) bool {
// such tx will not be processed and thus won't consume gas. Skipping
continue
}
isGasless, err := antedecorators.IsTxGasless(decoded, ctx, app.OracleKeeper)
isGasless, err := antedecorators.IsTxGasless(decoded, ctx, app.OracleKeeper, &app.EvmKeeper)
if err != nil {
ctx.Logger().Error("error checking if tx is gasless", "error", err)
continue
Expand Down
73 changes: 73 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import (
"context"
"encoding/hex"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server/api"
cosmosConfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"math/big"
"reflect"
"testing"
"time"

Expand Down Expand Up @@ -405,3 +411,70 @@ func TestDecodeTransactionsConcurrently(t *testing.T) {
require.Nil(t, typedTxs[1])
require.NotNil(t, typedTxs[2])
}

func TestApp_RegisterAPIRoutes(t *testing.T) {
type args struct {
apiSvr *api.Server
apiConfig cosmosConfig.APIConfig
}
tests := []struct {
name string
args args
wantSwagger bool
}{
{
name: "swagger added to the router if configured",
args: args{
apiSvr: &api.Server{
ClientCtx: client.Context{},
Router: &mux.Router{},
GRPCGatewayRouter: runtime.NewServeMux(),
},
apiConfig: cosmosConfig.APIConfig{
Swagger: true,
},
},
wantSwagger: true,
},
{
name: "swagger not added to the router if not configured",
args: args{
apiSvr: &api.Server{
ClientCtx: client.Context{},
Router: &mux.Router{},
GRPCGatewayRouter: runtime.NewServeMux(),
},
apiConfig: cosmosConfig.APIConfig{},
},
wantSwagger: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
seiApp := &app.App{}
seiApp.RegisterAPIRoutes(tt.args.apiSvr, tt.args.apiConfig)
routes := tt.args.apiSvr.Router
gotSwagger := isSwaggerRouteAdded(routes)

if !reflect.DeepEqual(gotSwagger, tt.wantSwagger) {
t.Errorf("Run() gotSwagger = %v, want %v", gotSwagger, tt.wantSwagger)
}
})

}
}

func isSwaggerRouteAdded(router *mux.Router) bool {
var isAdded bool
err := router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
pathTemplate, err := route.GetPathTemplate()
if err == nil && pathTemplate == "/swagger/" {
isAdded = true
}
return nil
})
if err != nil {
return false
}
return isAdded
}
Loading

0 comments on commit f7dee2a

Please sign in to comment.