forked from cerc-io/laconicd-deprecated
fix panic when start a node with snapshot (#673)
* fix panic when start a node with snapshot * change the return value of evm.NewKeeper to a pointer, roll back the before change * add changelog * fix importer test
This commit is contained in:
parent
9cbb4dcf6d
commit
ffbb207655
@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
* (evm) [\#672](https://github.com/cosmos/ethermint/issues/672) Fix panic of `wrong Block.Header.AppHash` when restart a node with snapshot
|
||||||
* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent
|
* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent
|
||||||
|
|
||||||
## [v0.4.0] - 2020-12-15
|
## [v0.4.0] - 2020-12-15
|
||||||
|
@ -125,7 +125,7 @@ type EthermintApp struct {
|
|||||||
UpgradeKeeper upgrade.Keeper
|
UpgradeKeeper upgrade.Keeper
|
||||||
ParamsKeeper params.Keeper
|
ParamsKeeper params.Keeper
|
||||||
EvidenceKeeper evidence.Keeper
|
EvidenceKeeper evidence.Keeper
|
||||||
EvmKeeper evm.Keeper
|
EvmKeeper *evm.Keeper
|
||||||
FaucetKeeper faucet.Keeper
|
FaucetKeeper faucet.Keeper
|
||||||
|
|
||||||
// the module manager
|
// the module manager
|
||||||
|
@ -99,7 +99,7 @@ func trapSignals() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint: interfacer
|
// nolint: interfacer
|
||||||
func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.AccountKeeper, evmKeeper evm.Keeper) {
|
func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.AccountKeeper, evmKeeper *evm.Keeper) {
|
||||||
genBlock := ethcore.DefaultGenesisBlock()
|
genBlock := ethcore.DefaultGenesisBlock()
|
||||||
ms := cms.CacheMultiStore()
|
ms := cms.CacheMultiStore()
|
||||||
ctx := sdk.NewContext(ms, abci.Header{}, false, logger)
|
ctx := sdk.NewContext(ms, abci.Header{}, false, logger)
|
||||||
@ -285,7 +285,7 @@ func TestImportBlocks(t *testing.T) {
|
|||||||
// reward. The total reward consists of the static block reward and rewards for
|
// reward. The total reward consists of the static block reward and rewards for
|
||||||
// included uncles. The coinbase of each uncle block is also rewarded.
|
// included uncles. The coinbase of each uncle block is also rewarded.
|
||||||
func accumulateRewards(
|
func accumulateRewards(
|
||||||
config *ethparams.ChainConfig, evmKeeper evm.Keeper,
|
config *ethparams.ChainConfig, evmKeeper *evm.Keeper,
|
||||||
header *ethtypes.Header, uncles []*ethtypes.Header,
|
header *ethtypes.Header, uncles []*ethtypes.Header,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ func accumulateRewards(
|
|||||||
// Code is pulled from go-ethereum 1.9 because the StateDB interface does not include the
|
// Code is pulled from go-ethereum 1.9 because the StateDB interface does not include the
|
||||||
// SetBalance function implementation
|
// SetBalance function implementation
|
||||||
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/consensus/misc/dao.go#L74
|
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/consensus/misc/dao.go#L74
|
||||||
func applyDAOHardFork(evmKeeper evm.Keeper) {
|
func applyDAOHardFork(evmKeeper *evm.Keeper) {
|
||||||
// Retrieve the contract to refund balances into
|
// Retrieve the contract to refund balances into
|
||||||
if !evmKeeper.CommitStateDB.Exist(ethparams.DAORefundContract) {
|
if !evmKeeper.CommitStateDB.Exist(ethparams.DAORefundContract) {
|
||||||
evmKeeper.CommitStateDB.CreateAccount(ethparams.DAORefundContract)
|
evmKeeper.CommitStateDB.CreateAccount(ethparams.DAORefundContract)
|
||||||
@ -339,7 +339,7 @@ func applyDAOHardFork(evmKeeper evm.Keeper) {
|
|||||||
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88
|
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88
|
||||||
func applyTransaction(
|
func applyTransaction(
|
||||||
config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address,
|
config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address,
|
||||||
gp *ethcore.GasPool, evmKeeper evm.Keeper, header *ethtypes.Header,
|
gp *ethcore.GasPool, evmKeeper *evm.Keeper, header *ethtypes.Header,
|
||||||
tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config,
|
tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config,
|
||||||
) (*ethtypes.Receipt, uint64, error) {
|
) (*ethtypes.Receipt, uint64, error) {
|
||||||
msg, err := tx.AsMessage(ethtypes.MakeSigner(config, header.Number))
|
msg, err := tx.AsMessage(ethtypes.MakeSigner(config, header.Number))
|
||||||
|
@ -16,10 +16,10 @@ import (
|
|||||||
func (suite *EvmTestSuite) TestExportImport() {
|
func (suite *EvmTestSuite) TestExportImport() {
|
||||||
var genState types.GenesisState
|
var genState types.GenesisState
|
||||||
suite.Require().NotPanics(func() {
|
suite.Require().NotPanics(func() {
|
||||||
genState = evm.ExportGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper)
|
genState = evm.ExportGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper)
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, genState)
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, genState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *EvmTestSuite) TestInitGenesis() {
|
func (suite *EvmTestSuite) TestInitGenesis() {
|
||||||
@ -102,13 +102,13 @@ func (suite *EvmTestSuite) TestInitGenesis() {
|
|||||||
if tc.expPanic {
|
if tc.expPanic {
|
||||||
suite.Require().Panics(
|
suite.Require().Panics(
|
||||||
func() {
|
func() {
|
||||||
_ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().NotPanics(
|
suite.Require().NotPanics(
|
||||||
func() {
|
func() {
|
||||||
_ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewHandler returns a handler for Ethermint type messages.
|
// NewHandler returns a handler for Ethermint type messages.
|
||||||
func NewHandler(k Keeper) sdk.Handler {
|
func NewHandler(k *Keeper) sdk.Handler {
|
||||||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
||||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
@ -28,7 +28,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleMsgEthereumTx handles an Ethereum specific tx
|
// handleMsgEthereumTx handles an Ethereum specific tx
|
||||||
func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*sdk.Result, error) {
|
func handleMsgEthereumTx(ctx sdk.Context, k *Keeper, msg types.MsgEthereumTx) (*sdk.Result, error) {
|
||||||
// execute state transition
|
// execute state transition
|
||||||
res, err := k.EthereumTx(ctx, msg)
|
res, err := k.EthereumTx(ctx, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,7 +42,7 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleMsgEthermint handles an sdk.StdTx for an Ethereum state transition
|
// handleMsgEthermint handles an sdk.StdTx for an Ethereum state transition
|
||||||
func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk.Result, error) {
|
func handleMsgEthermint(ctx sdk.Context, k *Keeper, msg types.MsgEthermint) (*sdk.Result, error) {
|
||||||
// parse the chainID from a string to a base-10 integer
|
// parse the chainID from a string to a base-10 integer
|
||||||
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
|
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,7 +46,7 @@ func (suite *EvmTestSuite) SetupTest() {
|
|||||||
suite.app = app.Setup(checkTx)
|
suite.app = app.Setup(checkTx)
|
||||||
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
|
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
|
||||||
suite.handler = evm.NewHandler(suite.app.EvmKeeper)
|
suite.handler = evm.NewHandler(suite.app.EvmKeeper)
|
||||||
suite.querier = keeper.NewQuerier(suite.app.EvmKeeper)
|
suite.querier = keeper.NewQuerier(*suite.app.EvmKeeper)
|
||||||
suite.codec = codec.New()
|
suite.codec = codec.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,14 +44,14 @@ type Keeper struct {
|
|||||||
// NewKeeper generates new evm module keeper
|
// NewKeeper generates new evm module keeper
|
||||||
func NewKeeper(
|
func NewKeeper(
|
||||||
cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace, ak types.AccountKeeper,
|
cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace, ak types.AccountKeeper,
|
||||||
) Keeper {
|
) *Keeper {
|
||||||
// set KeyTable if it has not already been set
|
// set KeyTable if it has not already been set
|
||||||
if !paramSpace.HasKeyTable() {
|
if !paramSpace.HasKeyTable() {
|
||||||
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
|
// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
|
||||||
return Keeper{
|
return &Keeper{
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
storeKey: storeKey,
|
storeKey: storeKey,
|
||||||
accountKeeper: ak,
|
accountKeeper: ak,
|
||||||
|
@ -43,7 +43,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
|||||||
|
|
||||||
suite.app = app.Setup(checkTx)
|
suite.app = app.Setup(checkTx)
|
||||||
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
|
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
|
||||||
suite.querier = keeper.NewQuerier(suite.app.EvmKeeper)
|
suite.querier = keeper.NewQuerier(*suite.app.EvmKeeper)
|
||||||
suite.address = ethcmn.HexToAddress(addrHex)
|
suite.address = ethcmn.HexToAddress(addrHex)
|
||||||
|
|
||||||
balance := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.ZeroInt()))
|
balance := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.ZeroInt()))
|
||||||
|
@ -69,12 +69,12 @@ func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
// AppModule implements an application module for the evm module.
|
// AppModule implements an application module for the evm module.
|
||||||
type AppModule struct {
|
type AppModule struct {
|
||||||
AppModuleBasic
|
AppModuleBasic
|
||||||
keeper Keeper
|
keeper *Keeper
|
||||||
ak types.AccountKeeper
|
ak types.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppModule creates a new AppModule Object
|
// NewAppModule creates a new AppModule Object
|
||||||
func NewAppModule(k Keeper, ak types.AccountKeeper) AppModule {
|
func NewAppModule(k *Keeper, ak types.AccountKeeper) AppModule {
|
||||||
return AppModule{
|
return AppModule{
|
||||||
AppModuleBasic: AppModuleBasic{},
|
AppModuleBasic: AppModuleBasic{},
|
||||||
keeper: k,
|
keeper: k,
|
||||||
@ -89,7 +89,7 @@ func (AppModule) Name() string {
|
|||||||
|
|
||||||
// RegisterInvariants interface for registering invariants
|
// RegisterInvariants interface for registering invariants
|
||||||
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||||
keeper.RegisterInvariants(ir, am.keeper)
|
keeper.RegisterInvariants(ir, *am.keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route specifies path for transactions
|
// Route specifies path for transactions
|
||||||
@ -109,7 +109,7 @@ func (am AppModule) QuerierRoute() string {
|
|||||||
|
|
||||||
// NewQuerierHandler sets up new querier handler for module
|
// NewQuerierHandler sets up new querier handler for module
|
||||||
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||||
return keeper.NewQuerier(am.keeper)
|
return keeper.NewQuerier(*am.keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeginBlock function for module at start of each block
|
// BeginBlock function for module at start of each block
|
||||||
@ -126,11 +126,11 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V
|
|||||||
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||||||
var genesisState types.GenesisState
|
var genesisState types.GenesisState
|
||||||
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||||
return InitGenesis(ctx, am.keeper, am.ak, genesisState)
|
return InitGenesis(ctx, *am.keeper, am.ak, genesisState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportGenesis exports the genesis state to be used by daemon
|
// ExportGenesis exports the genesis state to be used by daemon
|
||||||
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||||||
gs := ExportGenesis(ctx, am.keeper, am.ak)
|
gs := ExportGenesis(ctx, *am.keeper, am.ak)
|
||||||
return types.ModuleCdc.MustMarshalJSON(gs)
|
return types.ModuleCdc.MustMarshalJSON(gs)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user