Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: sdk 50 is not integrated #1331

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ endif
###############################################################################

HTTPS_GIT := https://github.com/crypto-org-chain/cronos.git
protoVer=0.11.6
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand Down
569 changes: 325 additions & 244 deletions app/app.go

Large diffs are not rendered by default.

131 changes: 74 additions & 57 deletions app/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import (
"encoding/binary"
"encoding/json"
"math/big"
"os"
"path/filepath"
"testing"

"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
baseapp "github.com/cosmos/cosmos-sdk/baseapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil/mock"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -37,7 +36,7 @@ func BenchmarkERC20Transfer(b *testing.B) {
benchmarkERC20Transfer(b, db)
})
b.Run("leveldb", func(b *testing.B) {
db, err := dbm.NewGoLevelDB("application", b.TempDir())
db, err := dbm.NewDB("application", dbm.GoLevelDBBackend, b.TempDir())
require.NoError(b, err)
benchmarkERC20Transfer(b, db)
})
Expand All @@ -50,82 +49,106 @@ func BenchmarkERC20Transfer(b *testing.B) {
func benchmarkERC20Transfer(b *testing.B, db dbm.DB) {
txsPerBlock := 1000
gasPrice := big.NewInt(100000000000)
var appOpts servertypes.AppOptions = EmptyAppOptions{}
homePath := b.TempDir()
appOpts := make(AppOptionsMap)
appOpts[flags.FlagHome] = homePath
if db == nil {
appOpts = AppOptionsMap(map[string]interface{}{
memiavlstore.FlagMemIAVL: true,
})
require.NoError(b, os.RemoveAll(filepath.Join(DefaultNodeHome, "data/memiavl.db")))
appOpts[memiavlstore.FlagMemIAVL] = true
appOpts[memiavlstore.FlagCacheSize] = 0
}
encodingConfig := MakeEncodingConfig()
app := New(log.NewNopLogger(), db, nil, true, true, map[int64]bool{}, DefaultNodeHome, 0, encodingConfig, appOpts, baseapp.SetChainID(TestAppChainID))
app := New(log.NewNopLogger(), db, nil, true, appOpts, baseapp.SetChainID(TestAppChainID))
defer app.Close()

priv, err := ethsecp256k1.GenerateKey()
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
signer := tests.NewSigner(priv)
chainID := big.NewInt(777)
ethSigner := ethtypes.LatestSignerForChainID(chainID)
ethSigner := ethtypes.LatestSignerForChainID(TestEthChainID)

signTx := func(msg *evmtypes.MsgEthereumTx) ([]byte, error) {
msg.From = address.Bytes()
if err := msg.Sign(ethSigner, signer); err != nil {
return nil, err
}
require.NoError(b, err)
tx, err := msg.BuildTx(encodingConfig.TxConfig.NewTxBuilder(), evmtypes.DefaultEVMDenom)
tx, err := msg.BuildTx(app.TxConfig().NewTxBuilder(), evmtypes.DefaultEVMDenom)
if err != nil {
return nil, err
}
return encodingConfig.TxConfig.TxEncoder()(tx)
return app.EncodingConfig().TxConfig.TxEncoder()(tx)
}

privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
consAddress := sdk.ConsAddress(pubKey.Address())
require.NoError(b, err)

consAddress := sdk.ConsAddress(pubKey.Address())
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
acc := authtypes.NewBaseAccount(priv.PubKey().Address().Bytes(), priv.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewIntWithDecimal(10000000, 18))),
}
genesisState := NewDefaultGenesisState(encodingConfig.Codec)
genesisState = genesisStateWithValSet(b, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
genesisState, err := simtestutil.GenesisStateWithValSet(
app.AppCodec(),
app.DefaultGenesis(),
valSet,
[]authtypes.GenesisAccount{acc},
balance,
)
require.NoError(b, err)

appState, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(b, err)
app.InitChain(abci.RequestInitChain{
_, err = app.InitChain(&abci.RequestInitChain{
ChainId: TestAppChainID,
AppStateBytes: appState,
ConsensusParams: DefaultConsensusParams,
})
app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: 1,
ChainID: TestAppChainID,
ProposerAddress: consAddress,
},
require.NoError(b, err)

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: 1,
ProposerAddress: consAddress,
})
require.NoError(b, err)

// deploy contract
ctx := app.GetContextForDeliverTx(nil)
contractAddr, err := app.CronosKeeper.DeployModuleCRC21(ctx, "test")
require.NoError(b, err)
ctx := app.NewUncachedContext(false, cmtproto.Header{
ChainID: TestAppChainID,
Height: 1,
ProposerAddress: consAddress,
})

// mint to sender
var contractAddr common.Address
amount := int64(100000000)
_, err = app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "mint_by_cronos_module", address, big.NewInt(amount))
require.NoError(b, err)
{
ctx, write := ctx.CacheContext()
contractAddr, err = app.CronosKeeper.DeployModuleCRC21(ctx, "test")
require.NoError(b, err)

// check balance
ret, err := app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
// mint to sender
_, err = app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "mint_by_cronos_module", address, big.NewInt(amount))
require.NoError(b, err)

// check balance
ret, err := app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
require.NoError(b, err)
require.Equal(b, uint64(amount), binary.BigEndian.Uint64(ret[32-8:]))
write()
}

_, err = app.Commit()
require.NoError(b, err)
require.Equal(b, uint64(amount), binary.BigEndian.Uint64(ret[32-8:]))

app.EndBlock(abci.RequestEndBlock{})
app.Commit()
// check remaining balance
ctx = app.GetContextForCheckTx(nil)

codeRsp, err := app.EvmKeeper.Code(ctx, &evmtypes.QueryCodeRequest{
Address: contractAddr.Hex(),
})
require.NoError(b, err)
require.NotEmpty(b, codeRsp.Code)

// prepare transactions
var transferTxs [][]byte
Expand All @@ -135,36 +158,30 @@ func benchmarkERC20Transfer(b *testing.B, db dbm.DB) {
recipient := common.BigToAddress(big.NewInt(idx))
data, err := types.ModuleCRC21Contract.ABI.Pack("transfer", recipient, big.NewInt(1))
require.NoError(b, err)
bz, err := signTx(evmtypes.NewTx(chainID, uint64(idx), &contractAddr, big.NewInt(0), 210000, gasPrice, nil, nil, data, nil))
bz, err := signTx(evmtypes.NewTx(TestEthChainID, uint64(idx), &contractAddr, big.NewInt(0), 210000, gasPrice, nil, nil, data, nil))
require.NoError(b, err)
transferTxs = append(transferTxs, bz)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: int64(i) + 2,
ChainID: TestAppChainID,
ProposerAddress: consAddress,
},
rsp, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
Txs: transferTxs[i*txsPerBlock : (i+1)*txsPerBlock],
Height: int64(i) + 2,
ProposerAddress: consAddress,
})
for j := 0; j < txsPerBlock; j++ {
idx := i*txsPerBlock + j
res := app.DeliverTx(abci.RequestDeliverTx{
Tx: transferTxs[idx],
})
require.Equal(b, 0, int(res.Code))
require.NoError(b, err)
for _, txResult := range rsp.TxResults {
require.Equal(b, abci.CodeTypeOK, txResult.Code)
}
_, err = app.Commit()
require.NoError(b, err)

// check remaining balance
ctx := app.GetContextForDeliverTx(nil)
ret, err = app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
ctx := app.GetContextForCheckTx(nil)
ret, err := app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
require.NoError(b, err)
require.Equal(b, uint64(amount)-uint64((i+1)*txsPerBlock), binary.BigEndian.Uint64(ret[32-8:]))

app.EndBlock(abci.RequestEndBlock{})
app.Commit()
}
}
11 changes: 8 additions & 3 deletions app/block_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

// BlockAddressesDecorator block addresses from sending transactions
Expand All @@ -19,10 +20,14 @@ func NewBlockAddressesDecorator(blacklist map[string]struct{}) BlockAddressesDec

func (bad BlockAddressesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if ctx.IsCheckTx() {
for _, msg := range tx.GetMsgs() {
for _, signer := range msg.GetSigners() {
if sigTx, ok := tx.(signing.SigVerifiableTx); ok {
signers, err := sigTx.GetSigners()
if err != nil {
return ctx, err
}
for _, signer := range signers {
if _, ok := bad.blockedMap[string(signer)]; ok {
return ctx, fmt.Errorf("signer is blocked: %s", signer.String())
return ctx, fmt.Errorf("signer is blocked: %s", sdk.AccAddress(signer).String())
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions app/encoding.go

This file was deleted.

Loading
Loading