Skip to content

Commit

Permalink
Temporary Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed May 5, 2024
1 parent a38d5de commit 48e18b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
14 changes: 4 additions & 10 deletions x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@ func InitGenesis(
accountKeeper types.AccountKeeper,
data types.GenesisState,
registeredModules []precompile_modules.Module,
// evmKeeper statedb.Keeper,
) []abci.ValidatorUpdate {
//txConfig := statedb.TxConfig{
// BlockHash: common.Hash{},
// TxHash: common.Hash{},
// TxIndex: 0,
// LogIndex: 0,
//}
//stateDB := statedb.New(ctx, evmKeeper, txConfig)

k.WithChainID(ctx)

err := types.ValidatePrecompileRegistration(
Expand All @@ -56,7 +47,10 @@ func InitGenesis(
panic(err)
}

//oldParams := k.GetParams(ctx)
err = k.SyncEnabledPrecompiles(ctx, data.Params.GetEnabledPrecompiles())
if err != nil {
panic(fmt.Errorf("can't sync enabled precompiles: %v", err))
}

err = k.SetParams(ctx, data.Params)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions x/evm/keeper/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package keeper
import (
"bytes"
"fmt"

Check failure on line 5 in x/evm/keeper/precompile.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/x/evm/statedb"
)

const PrecompileNonce uint64 = 1
Expand All @@ -24,6 +26,29 @@ type InitializationConfig struct {
Uninitialize []common.Address
}

func (k *Keeper) SyncEnabledPrecompiles(ctx sdk.Context, enabledPrecompiles []string) error {
txConfig := statedb.TxConfig{
BlockHash: common.Hash{},
TxHash: common.Hash{},
TxIndex: 0,
LogIndex: 0,
}
stateDB := statedb.New(ctx, k, txConfig)

oldParams := k.GetParams(ctx)

return SyncEnabledPrecompiles(stateDB, hexToAddresses(oldParams.EnabledPrecompiles), hexToAddresses(enabledPrecompiles))
}

func hexToAddresses(hexAddrs []string) []common.Address {
addrs := make([]common.Address, len(hexAddrs))
for i, hexAddr := range hexAddrs {
addrs[i] = common.HexToAddress(hexAddr)
}

return addrs
}

func SyncEnabledPrecompiles(stateDB StateDB, old []common.Address, new []common.Address) error {
cfg := DetermineInitializationConfig(old, new)
return ApplyInitializationConfig(stateDB, cfg)
Expand Down

0 comments on commit 48e18b3

Please sign in to comment.