forked from cerc-io/laconicd-deprecated
all: bump SDK to v0.43.0-rc0 (#194)
* all: bump SDK to v0.43.0-rc0 * more updates * keys * accounting * update account * ante changes * readonly * readonly build * minor changes from self review * fixes * evm debug * custom config & rosetta * fix
This commit is contained in:
@@ -25,6 +25,11 @@ func InitGenesis(
|
||||
|
||||
k.SetParams(ctx, data.Params)
|
||||
|
||||
// ensure evm module account is set
|
||||
if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
|
||||
panic("the EVM module account has not been set")
|
||||
}
|
||||
|
||||
for _, account := range data.Accounts {
|
||||
address := ethcmn.HexToAddress(account.Address)
|
||||
accAddress := sdk.AccAddress(address.Bytes())
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package evm_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
"github.com/tharsis/ethermint/x/evm"
|
||||
"github.com/tharsis/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -34,8 +35,7 @@ func (suite *EvmTestSuite) TestInitGenesis() {
|
||||
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes())
|
||||
suite.Require().NotNil(acc)
|
||||
|
||||
err := suite.app.BankKeeper.SetBalance(suite.ctx, address.Bytes(), ethermint.NewPhotonCoinInt64(1))
|
||||
suite.Require().NoError(err)
|
||||
suite.app.EvmKeeper.AddBalance(address, big.NewInt(1))
|
||||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
||||
},
|
||||
&types.GenesisState{
|
||||
|
||||
@@ -28,7 +28,7 @@ type EvmTestSuite struct {
|
||||
ctx sdk.Context
|
||||
handler sdk.Handler
|
||||
app *app.EthermintApp
|
||||
codec codec.BinaryMarshaler
|
||||
codec codec.Codec
|
||||
chainID *big.Int
|
||||
|
||||
signer keyring.Signer
|
||||
|
||||
@@ -246,7 +246,7 @@ func (k Keeper) BlockLogs(c context.Context, req *types.QueryBlockLogsRequest) (
|
||||
|
||||
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) {
|
||||
var txLog types.TransactionLogs
|
||||
k.cdc.MustUnmarshalBinaryBare(value, &txLog)
|
||||
k.cdc.MustUnmarshal(value, &txLog)
|
||||
|
||||
if len(txLog.Logs) > 0 && txLog.Logs[0].BlockHash == req.Hash {
|
||||
if accumulate {
|
||||
|
||||
@@ -34,7 +34,6 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
|
||||
}{
|
||||
{"invalid address",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(0))
|
||||
expAccount = &types.QueryAccountResponse{
|
||||
Balance: "0",
|
||||
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
|
||||
@@ -49,7 +48,9 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
|
||||
{
|
||||
"success",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(100))
|
||||
amt := sdk.Coins{ethermint.NewPhotonCoinInt64(100)}
|
||||
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
|
||||
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
|
||||
expAccount = &types.QueryAccountResponse{
|
||||
Balance: "100",
|
||||
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
|
||||
@@ -96,7 +97,6 @@ func (suite *KeeperTestSuite) TestQueryCosmosAccount() {
|
||||
}{
|
||||
{"invalid address",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(0))
|
||||
expAccount = &types.QueryCosmosAccountResponse{
|
||||
CosmosAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(),
|
||||
}
|
||||
@@ -174,7 +174,6 @@ func (suite *KeeperTestSuite) TestQueryBalance() {
|
||||
}{
|
||||
{"invalid address",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(0))
|
||||
expBalance = "0"
|
||||
req = &types.QueryBalanceRequest{
|
||||
Address: invalidAddress,
|
||||
@@ -185,7 +184,9 @@ func (suite *KeeperTestSuite) TestQueryBalance() {
|
||||
{
|
||||
"success",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(100))
|
||||
amt := sdk.Coins{ethermint.NewPhotonCoinInt64(100)}
|
||||
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
|
||||
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
|
||||
expBalance = "100"
|
||||
req = &types.QueryBalanceRequest{
|
||||
Address: suite.address.String(),
|
||||
@@ -602,7 +603,6 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() {
|
||||
}{
|
||||
{"invalid address",
|
||||
func() {
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, suite.address.Bytes(), ethermint.NewPhotonCoinInt64(0))
|
||||
expAccount = &types.QueryValidatorAccountResponse{
|
||||
AccountAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(),
|
||||
}
|
||||
|
||||
+22
-8
@@ -10,6 +10,7 @@ import (
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/palantir/stacktrace"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
@@ -20,7 +21,7 @@ import (
|
||||
// to the StateDB interface.
|
||||
type Keeper struct {
|
||||
// Protobuf codec
|
||||
cdc codec.BinaryMarshaler
|
||||
cdc codec.BinaryCodec
|
||||
txDecoder sdk.TxDecoder
|
||||
// Store key required for the EVM Prefix KVStore. It is required by:
|
||||
// - storing Account's Storage State
|
||||
@@ -46,9 +47,17 @@ type Keeper struct {
|
||||
|
||||
// NewKeeper generates new evm module keeper
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryMarshaler, txDecoder sdk.TxDecoder, storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace,
|
||||
cdc codec.BinaryCodec, txDecoder sdk.TxDecoder,
|
||||
storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace,
|
||||
ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper,
|
||||
debug bool,
|
||||
) *Keeper {
|
||||
|
||||
// ensure evm module account is set
|
||||
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
|
||||
panic("the EVM module account has not been set")
|
||||
}
|
||||
|
||||
// set KeyTable if it has not already been set
|
||||
if !paramSpace.HasKeyTable() {
|
||||
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
||||
@@ -64,6 +73,7 @@ func NewKeeper(
|
||||
stakingKeeper: sk,
|
||||
storeKey: storeKey,
|
||||
transientKey: transientKey,
|
||||
debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +190,7 @@ func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs {
|
||||
txsLogs := []types.TransactionLogs{}
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var txLog types.TransactionLogs
|
||||
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &txLog)
|
||||
k.cdc.MustUnmarshal(iterator.Value(), &txLog)
|
||||
|
||||
// add a new entry
|
||||
txsLogs = append(txsLogs, txLog)
|
||||
@@ -199,7 +209,7 @@ func (k Keeper) GetTxLogs(txHash common.Hash) []*ethtypes.Log {
|
||||
}
|
||||
|
||||
var logs types.TransactionLogs
|
||||
k.cdc.MustUnmarshalBinaryBare(bz, &logs)
|
||||
k.cdc.MustUnmarshal(bz, &logs)
|
||||
|
||||
return logs.EthLogs()
|
||||
}
|
||||
@@ -209,7 +219,7 @@ func (k Keeper) SetLogs(txHash common.Hash, logs []*ethtypes.Log) {
|
||||
store := prefix.NewStore(k.ctx.KVStore(k.storeKey), types.KeyPrefixLogs)
|
||||
|
||||
txLogs := types.NewTransactionLogsFromEth(txHash, logs)
|
||||
bz := k.cdc.MustMarshalBinaryBare(&txLogs)
|
||||
bz := k.cdc.MustMarshal(&txLogs)
|
||||
|
||||
store.Set(txHash.Bytes(), bz)
|
||||
}
|
||||
@@ -277,9 +287,12 @@ func (k Keeper) ClearBalance(addr sdk.AccAddress) (prevBalance sdk.Coin, err err
|
||||
|
||||
prevBalance = k.bankKeeper.GetBalance(k.ctx, addr, params.EvmDenom)
|
||||
if prevBalance.IsPositive() {
|
||||
err := k.bankKeeper.SubtractCoins(k.ctx, addr, sdk.Coins{prevBalance})
|
||||
if err != nil {
|
||||
return sdk.Coin{}, err
|
||||
if err := k.bankKeeper.SendCoinsFromAccountToModule(k.ctx, addr, types.ModuleName, sdk.Coins{prevBalance}); err != nil {
|
||||
return sdk.Coin{}, stacktrace.Propagate(err, "failed to transfer to module account")
|
||||
}
|
||||
|
||||
if err := k.bankKeeper.BurnCoins(k.ctx, types.ModuleName, sdk.Coins{prevBalance}); err != nil {
|
||||
return sdk.Coin{}, stacktrace.Propagate(err, "failed to burn coins from evm module account")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +309,7 @@ func (k Keeper) ResetAccount(addr common.Address) {
|
||||
k.Logger(k.ctx).Error(
|
||||
"failed to clear balance during account reset",
|
||||
"ethereum-address", addr.Hex(),
|
||||
"error", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
"github.com/tharsis/ethermint/x/evm/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
@@ -59,14 +60,12 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
types.RegisterQueryServer(queryHelper, suite.app.EvmKeeper)
|
||||
suite.queryClient = types.NewQueryClient(queryHelper)
|
||||
|
||||
balance := ethermint.NewPhotonCoin(sdk.ZeroInt())
|
||||
acc := ðermint.EthAccount{
|
||||
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
|
||||
CodeHash: ethcrypto.Keccak256(nil),
|
||||
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(),
|
||||
}
|
||||
|
||||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
||||
suite.app.BankKeeper.SetBalance(suite.ctx, acc.GetAddress(), balance)
|
||||
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
@@ -26,13 +26,13 @@ func (k Keeper) GetChainConfig(ctx sdk.Context) (types.ChainConfig, bool) {
|
||||
}
|
||||
|
||||
var config types.ChainConfig
|
||||
k.cdc.MustUnmarshalBinaryBare(bz, &config)
|
||||
k.cdc.MustUnmarshal(bz, &config)
|
||||
return config, true
|
||||
}
|
||||
|
||||
// SetChainConfig sets the mapping from block consensus hash to block height
|
||||
func (k Keeper) SetChainConfig(ctx sdk.Context, config types.ChainConfig) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := k.cdc.MustMarshalBinaryBare(&config)
|
||||
bz := k.cdc.MustMarshal(&config)
|
||||
store.Set(types.KeyPrefixChainConfig, bz)
|
||||
}
|
||||
|
||||
+27
-7
@@ -69,9 +69,19 @@ func (k *Keeper) AddBalance(addr common.Address, amount *big.Int) {
|
||||
params := k.GetParams(k.ctx)
|
||||
coins := sdk.Coins{sdk.NewCoin(params.EvmDenom, sdk.NewIntFromBigInt(amount))}
|
||||
|
||||
if err := k.bankKeeper.AddCoins(k.ctx, cosmosAddr, coins); err != nil {
|
||||
if err := k.bankKeeper.MintCoins(k.ctx, types.ModuleName, coins); err != nil {
|
||||
k.Logger(k.ctx).Error(
|
||||
"failed to add balance",
|
||||
"failed to mint coins when adding balance",
|
||||
"ethereum-address", addr.Hex(),
|
||||
"cosmos-address", cosmosAddr.String(),
|
||||
"error", err,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if err := k.bankKeeper.SendCoinsFromModuleToAccount(k.ctx, types.ModuleName, cosmosAddr, coins); err != nil {
|
||||
k.Logger(k.ctx).Error(
|
||||
"failed to send from module to account when adding balance",
|
||||
"ethereum-address", addr.Hex(),
|
||||
"cosmos-address", cosmosAddr.String(),
|
||||
"error", err,
|
||||
@@ -102,9 +112,9 @@ func (k *Keeper) SubBalance(addr common.Address, amount *big.Int) {
|
||||
params := k.GetParams(k.ctx)
|
||||
coins := sdk.Coins{sdk.NewCoin(params.EvmDenom, sdk.NewIntFromBigInt(amount))}
|
||||
|
||||
if err := k.bankKeeper.SubtractCoins(k.ctx, cosmosAddr, coins); err != nil {
|
||||
if err := k.bankKeeper.SendCoinsFromAccountToModule(k.ctx, cosmosAddr, types.ModuleName, coins); err != nil {
|
||||
k.Logger(k.ctx).Error(
|
||||
"failed to subtract balance",
|
||||
"failed to send from account to module when subtracting balance",
|
||||
"ethereum-address", addr.Hex(),
|
||||
"cosmos-address", cosmosAddr.String(),
|
||||
"error", err,
|
||||
@@ -113,6 +123,16 @@ func (k *Keeper) SubBalance(addr common.Address, amount *big.Int) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := k.bankKeeper.BurnCoins(k.ctx, types.ModuleName, coins); err != nil {
|
||||
k.Logger(k.ctx).Error(
|
||||
"failed to burn coins when subtracting balance",
|
||||
"ethereum-address", addr.Hex(),
|
||||
"cosmos-address", cosmosAddr.String(),
|
||||
"error", err,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
k.Logger(k.ctx).Debug(
|
||||
"balance subtraction",
|
||||
"ethereum-address", addr.Hex(),
|
||||
@@ -204,7 +224,7 @@ func (k *Keeper) GetCodeHash(addr common.Address) common.Hash {
|
||||
return common.BytesToHash(types.EmptyCodeHash)
|
||||
}
|
||||
|
||||
return common.BytesToHash(ethAccount.CodeHash)
|
||||
return common.HexToHash(ethAccount.CodeHash)
|
||||
}
|
||||
|
||||
// GetCode calls CommitStateDB.GetCode using the passed in context
|
||||
@@ -253,7 +273,7 @@ func (k *Keeper) SetCode(addr common.Address, code []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
ethAccount.CodeHash = hash.Bytes()
|
||||
ethAccount.CodeHash = hash.Hex()
|
||||
k.accountKeeper.SetAccount(k.ctx, ethAccount)
|
||||
|
||||
store := prefix.NewStore(k.ctx.KVStore(k.storeKey), types.KeyPrefixCode)
|
||||
@@ -461,7 +481,7 @@ func (k *Keeper) Empty(addr common.Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
codeHash = ethAccount.CodeHash
|
||||
codeHash = common.HexToHash(ethAccount.CodeHash).Bytes()
|
||||
}
|
||||
|
||||
balance := k.GetBalance(addr)
|
||||
|
||||
+9
-4
@@ -39,14 +39,19 @@ func (AppModuleBasic) Name() string {
|
||||
func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {
|
||||
}
|
||||
|
||||
// ConsensusVersion returns the consensus state-breaking version for the module.
|
||||
func (AppModuleBasic) ConsensusVersion() uint64 {
|
||||
return 1
|
||||
}
|
||||
|
||||
// DefaultGenesis returns default genesis state as raw bytes for the evm
|
||||
// module.
|
||||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
|
||||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
||||
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
||||
}
|
||||
|
||||
// ValidateGenesis is the validation check of the Genesis
|
||||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
||||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
||||
var genesisState types.GenesisState
|
||||
if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
||||
@@ -145,7 +150,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V
|
||||
|
||||
// InitGenesis performs genesis initialization for the evm module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genesisState types.GenesisState
|
||||
|
||||
cdc.MustUnmarshalJSON(data, &genesisState)
|
||||
@@ -155,7 +160,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j
|
||||
|
||||
// ExportGenesis returns the exported genesis state as raw bytes for the evm
|
||||
// module.
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
||||
gs := ExportGenesis(ctx, am.keeper, am.ak)
|
||||
return cdc.MustMarshalJSON(gs)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
// AccountKeeper defines the expected account keeper interface
|
||||
type AccountKeeper interface {
|
||||
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
|
||||
GetModuleAddress(moduleName string) sdk.AccAddress
|
||||
GetAllAccounts(ctx sdk.Context) (accounts []authtypes.AccountI)
|
||||
IterateAccounts(ctx sdk.Context, cb func(account authtypes.AccountI) bool)
|
||||
GetSequence(sdk.Context, sdk.AccAddress) (uint64, error)
|
||||
@@ -21,9 +22,10 @@ type AccountKeeper interface {
|
||||
type BankKeeper interface {
|
||||
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
|
||||
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
|
||||
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error
|
||||
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error
|
||||
SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error
|
||||
// SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
|
||||
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
|
||||
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||
}
|
||||
|
||||
// StakingKeeper returns the historical headers kept in store.
|
||||
|
||||
Reference in New Issue
Block a user