diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index d6d2b35..e54d5a2 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -284,6 +284,7 @@ func NewAppKeeper( appKeepers.FeeGrantKeeper = &feeGrantKeeper authzKeeper := authzkeeper.NewKeeper(runtime.NewKVStoreService(appKeepers.keys[authzkeeper.StoreKey]), appCodec, bApp.MsgServiceRouter(), appKeepers.AccountKeeper) + authzKeeper = authzKeeper.SetBankKeeper(appKeepers.BankKeeper) appKeepers.AuthzKeeper = &authzKeeper groupConfig := group.DefaultConfig() diff --git a/app/upgrade.go b/app/upgrade.go index f9ca920..6429fd4 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -22,7 +22,7 @@ import ( opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" ) -const upgradeName = "0.6.5" +const upgradeName = "0.6.6" // RegisterUpgradeHandlers returns upgrade handlers func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { @@ -47,63 +47,68 @@ func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { //////////////////////////// MINIEVM /////////////////////////////////// - // deploy and store erc20 factory contract address - if err := app.EVMKeeper.DeployERC20Factory(ctx); err != nil && + // deploy and store erc20 wrapper contract address + if err := app.EVMKeeper.DeployERC20Wrapper(ctx); err != nil && // ignore contract address collision error (contract already deployed) !strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) { return nil, err } - // deploy and store erc20 wrapper contract address - if err := app.EVMKeeper.DeployERC20Wrapper(ctx); err != nil && + // deploy and store erc20 factory contract address + if err := app.EVMKeeper.DeployERC20Factory(ctx); err != nil && // ignore contract address collision error (contract already deployed) !strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) { return nil, err - } - - code := hexutil.MustDecode(erc20.Erc20MetaData.Bin) - - // runtime code - initCodeOP := common.Hex2Bytes("5ff3fe") - initCodePos := bytes.Index(code, initCodeOP) - code = code[initCodePos+3:] - - // code hash - codeHash := crypto.Keccak256Hash(code).Bytes() - - // iterate all erc20 contracts and replace contract code to new version - err = app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) { - acc := app.AccountKeeper.GetAccount(ctx, contractAddr) - if acc == nil { - return true, fmt.Errorf("account not found for contract address %s", contractAddr) - } - - contractAcc, ok := acc.(*evmtypes.ContractAccount) - if !ok { - return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr) - } - - contractAcc.CodeHash = codeHash - app.AccountKeeper.SetAccount(ctx, contractAcc) - - // set code - codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...) - err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code) + } else if err == nil { + // update erc20 contracts only if erc20 factory contract has been deployed without error. + // + // address collision error is ignored because it means that the contract has already been deployed + // and the erc20 contracts have already been updated. + // + code := hexutil.MustDecode(erc20.Erc20MetaData.Bin) + + // runtime code + initCodeOP := common.Hex2Bytes("5ff3fe") + initCodePos := bytes.Index(code, initCodeOP) + code = code[initCodePos+3:] + + // code hash + codeHash := crypto.Keccak256Hash(code).Bytes() + + // iterate all erc20 contracts and replace contract code to new version + err = app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) { + acc := app.AccountKeeper.GetAccount(ctx, contractAddr) + if acc == nil { + return true, fmt.Errorf("account not found for contract address %s", contractAddr) + } + + contractAcc, ok := acc.(*evmtypes.ContractAccount) + if !ok { + return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr) + } + + contractAcc.CodeHash = codeHash + app.AccountKeeper.SetAccount(ctx, contractAcc) + + // set code + codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...) + err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code) + if err != nil { + return true, err + } + + // set code size + codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...) + err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code)))) + if err != nil { + return true, err + } + + return false, nil + }) if err != nil { - return true, err + return nil, err } - - // set code size - codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...) - err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code)))) - if err != nil { - return true, err - } - - return false, nil - }) - if err != nil { - return nil, err } return versionMap, nil diff --git a/go.mod b/go.mod index 4853541..c92459d 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/hashicorp/go-metrics v0.5.3 github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/holiman/uint256 v1.3.1 - github.com/initia-labs/OPinit v0.6.0 + github.com/initia-labs/OPinit v0.6.1 github.com/initia-labs/initia v0.6.1 github.com/initia-labs/kvindexer v0.1.9 github.com/initia-labs/kvindexer/submodules/block v0.1.0 diff --git a/go.sum b/go.sum index a04a9af..827dcf7 100644 --- a/go.sum +++ b/go.sum @@ -1433,8 +1433,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/initia-labs/OPinit v0.6.0 h1:V9jQf8+PjNctLX31FHMGUsk6fpnygVJO1WYzCmBMzkU= -github.com/initia-labs/OPinit v0.6.0/go.mod h1:gDpCh4Zx94mihwgzP/PLav8eVHLroZBu3dFyzCy8iIs= +github.com/initia-labs/OPinit v0.6.1 h1:G9ebeYeqPlV9Z2s3JdSWfwQAUgIM+nhkcA8xSJUMR7M= +github.com/initia-labs/OPinit v0.6.1/go.mod h1:gDpCh4Zx94mihwgzP/PLav8eVHLroZBu3dFyzCy8iIs= github.com/initia-labs/OPinit/api v0.6.0 h1:Q3hDHpTd9EqlDfY/OryCKIwuXYWJxGJdGfJicV1RjL4= github.com/initia-labs/OPinit/api v0.6.0/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU= github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f h1:PpYBvJ0L58bAgH7KwS/7GBEUphLnhf4fnTLua9uOov8= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 3f0a0ad..127e5ec 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -146,7 +146,7 @@ require ( github.com/iancoleman/strcase v0.3.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/initia-labs/OPinit v0.6.0 // indirect + github.com/initia-labs/OPinit v0.6.1 // indirect github.com/initia-labs/OPinit/api v0.6.0 // indirect github.com/initia-labs/kvindexer v0.1.9 // indirect github.com/initia-labs/kvindexer/submodules/block v0.1.0 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 1a6d8bf..37c8801 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1393,7 +1393,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/initia-labs/OPinit v0.6.0 h1:V9jQf8+PjNctLX31FHMGUsk6fpnygVJO1WYzCmBMzkU= +github.com/initia-labs/OPinit v0.6.1 h1:G9ebeYeqPlV9Z2s3JdSWfwQAUgIM+nhkcA8xSJUMR7M= github.com/initia-labs/OPinit/api v0.6.0 h1:Q3hDHpTd9EqlDfY/OryCKIwuXYWJxGJdGfJicV1RjL4= github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f h1:PpYBvJ0L58bAgH7KwS/7GBEUphLnhf4fnTLua9uOov8= github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f/go.mod h1:y7+6kPknafzWlkSMCekzXC81wpRf1pcVAUnO0wRy9lQ=