Skip to content

Commit

Permalink
chore: use stream instead of tendermint wsconn
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta92115 committed Mar 22, 2024
1 parent fede36a commit 02882b1
Show file tree
Hide file tree
Showing 41 changed files with 1,816 additions and 1,314 deletions.
5 changes: 2 additions & 3 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

storetypes "cosmossdk.io/store/types"

"swisstronik/app"
"swisstronik/app/ante"
"swisstronik/crypto/ethsecp256k1"
"swisstronik/encoding"
Expand All @@ -38,7 +37,7 @@ import (
)

func (suite AnteTestSuite) TestAnteHandler() {
var acc authtypes.AccountI
var acc sdk.AccountI
addr, privKey := tests.RandomEthAddressWithPrivateKey()
to := tests.RandomEthAddress()

Expand Down Expand Up @@ -1078,7 +1077,7 @@ func (suite AnteTestSuite) TestAnteHandlerWithParams() {
func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
params := authtypes.DefaultParams()
msg := []byte{1, 2, 3, 4}
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
cdc := encodingConfig.Amino

p := authtypes.DefaultParams()
Expand Down
3 changes: 1 addition & 2 deletions app/ante/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/ethereum/go-ethereum/params"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ func TestSDKTxFeeChecker(t *testing.T) {
// with extension option
// without extension option
// london hardfork enableness
encodingConfig := encoding.MakeConfig(module.NewBasicManager())
encodingConfig := encoding.MakeConfig()
minGasPrices := sdk.NewDecCoins(sdk.NewDecCoin("uswtr", sdkmath.NewInt(10)))

genesisCtx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
4 changes: 2 additions & 2 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (suite *AnteTestSuite) SetupTest() {
err = suite.app.StakingKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
// We're using TestMsg amino encoding in some tests, so register it here.
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
eip712.SetEncodingConfig(encodingConfig)
Expand Down Expand Up @@ -581,7 +581,7 @@ func createNestedMsgExec(a sdk.AccAddress, nestedLvl int, lastLvlMsgs []sdk.Msg)
}

func createTx(priv cryptotypes.PrivKey, msgs ...sdk.Msg) (sdk.Tx, error) {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
txBuilder := encodingConfig.TxConfig.NewTxBuilder()

txBuilder.SetGasLimit(1000000)
Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func New(
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
encodingConfig := encoding.MakeConfig(ModuleBasics)
encodingConfig := encoding.MakeConfig()
appCodec := encodingConfig.Codec
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -921,7 +921,7 @@ func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
cfg := encoding.MakeConfig(ModuleBasics)
cfg := encoding.MakeConfig()
return cfg.TxConfig
}

Expand Down
2 changes: 1 addition & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() simapp.GenesisState {
encCfg := encoding.MakeConfig(ModuleBasics)
encCfg := encoding.MakeConfig()
return ModuleBasics.DefaultGenesis(encCfg.Codec)
}
10 changes: 3 additions & 7 deletions cmd/swisstronikd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/simapp"
confixcmd "cosmossdk.io/tools/confix/cmd"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -78,7 +77,7 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
// Initialize the SDK config the first before doing anything else.
InitSDKConfig()

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down Expand Up @@ -161,12 +160,9 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {

evmmoduleserver.AddCommands(
rootCmd,
simapp.DefaultNodeHome,
a.newApp,
evmmoduleserver.NewDefaultStartCmdOptions(a.newApp, app.DefaultNodeHome),
evmmoduleserver.NewDefaultStartOptions(a.newApp, app.DefaultNodeHome),
a.appExport,
addModuleInitFlags,
)
addModuleInitFlags)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
Expand Down
3 changes: 1 addition & 2 deletions encoding/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
amino "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/ethereum/go-ethereum/common"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -48,7 +47,7 @@ func customGetSignerFn(path string) func(msg proto.Message) ([][]byte, error) {
}

// MakeConfig creates an EncodingConfig for testing
func MakeConfig(mb module.BasicManager) ethermint.EncodingConfig {
func MakeConfig() ethermint.EncodingConfig {
cdc := amino.NewLegacyAmino()
signingOptions := signing.Options{
AddressCodec: address.Bech32Codec{
Expand Down
3 changes: 1 addition & 2 deletions encoding/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

ethtypes "github.com/ethereum/go-ethereum/core/types"

"swisstronik/app"
"swisstronik/encoding"
"swisstronik/tests"
evmtypes "swisstronik/x/evm/types"
Expand All @@ -25,7 +24,7 @@ func TestTxEncoding(t *testing.T) {
err := msg.Sign(ethSigner, signer)
require.NoError(t, err)

cfg := encoding.MakeConfig(app.ModuleBasics)
cfg := encoding.MakeConfig()

_, err = cfg.TxConfig.TxEncoder()(msg)
require.Error(t, err, "encoding failed")
Expand Down
3 changes: 1 addition & 2 deletions ethereum/eip712/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"swisstronik/app"
"swisstronik/encoding"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -56,7 +55,7 @@ func TestEIP712TestSuite(t *testing.T) {

// Set up test env to replicate prod. environment
func (suite *EIP712TestSuite) SetupTest() {
suite.config = encoding.MakeConfig(app.ModuleBasics)
suite.config = encoding.MakeConfig()
suite.clientCtx = client.Context{}.WithTxConfig(suite.config.TxConfig)

sdk.GetConfig().SetBech32PrefixForAccount("ethm", "")
Expand Down
3 changes: 1 addition & 2 deletions ethereum/eip712/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"
"testing"

"swisstronik/app"
"swisstronik/encoding"
"swisstronik/ethereum/eip712"
"swisstronik/tests"
Expand All @@ -27,7 +26,7 @@ import (
var (
chainId = "ethermint_9000-1"
ctx = client.Context{}.WithTxConfig(
encoding.MakeConfig(app.ModuleBasics).TxConfig,
encoding.MakeConfig().TxConfig,
)
)
var feePayerAddress = "ethm17xpfvakm2amg962yls6f84z3kell8c5lthdzgl"
Expand Down
3 changes: 1 addition & 2 deletions indexer/kv_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"math/big"
"testing"

"swisstronik/app"
"swisstronik/crypto/ethsecp256k1"
evmenc "swisstronik/encoding"
"swisstronik/indexer"
Expand Down Expand Up @@ -187,5 +186,5 @@ func TestKVIndexer(t *testing.T) {

// MakeEncodingConfig creates the EncodingConfig
func MakeEncodingConfig() ethermint.EncodingConfig {
return evmenc.MakeConfig(app.ModuleBasics)
return evmenc.MakeConfig()
}
29 changes: 14 additions & 15 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import (
"swisstronik/rpc/namespaces/ethereum/txpool"
"swisstronik/rpc/namespaces/ethereum/web3"
"swisstronik/rpc/namespaces/utils"
"swisstronik/rpc/stream"
ethermint "swisstronik/types"

rpcclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
)

// RPC namespaces and API version
Expand Down Expand Up @@ -65,7 +64,7 @@ const (
type APICreator = func(
ctx *server.Context,
clientCtx client.Context,
tendermintWebsocketClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API
Expand All @@ -77,7 +76,7 @@ func init() {
apiCreators = map[string]APICreator{
EthNamespace: func(ctx *server.Context,
clientCtx client.Context,
tmWSClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -92,12 +91,12 @@ func init() {
{
Namespace: EthNamespace,
Version: apiVersion,
Service: filters.NewPublicAPI(ctx.Logger, clientCtx, tmWSClient, evmBackend),
Service: filters.NewPublicAPI(ctx.Logger, clientCtx, stream, evmBackend),
Public: true,
},
}
},
Web3Namespace: func(*server.Context, client.Context, *rpcclient.WSClient, bool, ethermint.EVMTxIndexer) []rpc.API {
Web3Namespace: func(*server.Context, client.Context, *stream.RPCStream, bool, ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: Web3Namespace,
Expand All @@ -107,7 +106,7 @@ func init() {
},
}
},
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *stream.RPCStream, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: NetNamespace,
Expand All @@ -119,7 +118,7 @@ func init() {
},
PersonalNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -133,7 +132,7 @@ func init() {
},
}
},
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *stream.RPCStream, _ bool, _ ethermint.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: TxPoolNamespace,
Expand All @@ -145,7 +144,7 @@ func init() {
},
DebugNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -161,7 +160,7 @@ func init() {
},
MinerNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -177,7 +176,7 @@ func init() {
},
DidNamespace: func(ctx *server.Context,
clientCtx client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -193,7 +192,7 @@ func init() {
},
UtilsNamespace: func(_ *server.Context,
_ client.Context,
_ *rpcclient.WSClient,
_ *stream.RPCStream,
_ bool,
_ ethermint.EVMTxIndexer,
) []rpc.API {
Expand All @@ -212,7 +211,7 @@ func init() {
// GetRPCAPIs returns the list of all APIs
func GetRPCAPIs(ctx *server.Context,
clientCtx client.Context,
tmWSClient *rpcclient.WSClient,
stream *stream.RPCStream,
allowUnprotectedTxs bool,
indexer ethermint.EVMTxIndexer,
selectedAPIs []string,
Expand All @@ -221,7 +220,7 @@ func GetRPCAPIs(ctx *server.Context,

for _, ns := range selectedAPIs {
if creator, ok := apiCreators[ns]; ok {
apis = append(apis, creator(ctx, clientCtx, tmWSClient, allowUnprotectedTxs, indexer)...)
apis = append(apis, creator(ctx, clientCtx, stream, allowUnprotectedTxs, indexer)...)
} else {
ctx.Logger.Error("invalid namespace value", "namespace", ns)
}
Expand Down
7 changes: 3 additions & 4 deletions rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/suite"

"swisstronik/app"
"swisstronik/crypto/ethsecp256k1"
"swisstronik/crypto/hd"
"swisstronik/encoding"
Expand Down Expand Up @@ -68,7 +67,7 @@ func (suite *BackendTestSuite) SetupTest() {
suite.signer = tests.NewTestSigner(priv)
suite.Require().NoError(err)

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
clientCtx := client.Context{}.WithChainID(ChainID).
WithHeight(1).
WithTxConfig(encodingConfig.TxConfig).
Expand All @@ -86,7 +85,7 @@ func (suite *BackendTestSuite) SetupTest() {
suite.backend.ctx = rpctypes.ContextWithHeight(1)

// Add codec
encCfg := encoding.MakeConfig(app.ModuleBasics)
encCfg := encoding.MakeConfig()
suite.backend.clientCtx.Codec = encCfg.Codec
}

Expand Down Expand Up @@ -168,7 +167,7 @@ func (suite *BackendTestSuite) buildFormattedBlock(

func (suite *BackendTestSuite) generateTestKeyring(clientDir string) (keyring.Keyring, error) {
buf := bufio.NewReader(os.Stdin)
encCfg := encoding.MakeConfig(app.ModuleBasics)
encCfg := encoding.MakeConfig()
return keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, encCfg.Codec, []keyring.Option{hd.EthSecp256k1Option()}...)
}

Expand Down
Loading

0 comments on commit 02882b1

Please sign in to comment.