diff --git a/account/account_test.go b/account/account_test.go index de5a81cffa..831a75d67c 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -612,7 +612,7 @@ func TestAccountKey(t *testing.T) { acc := NewCoinsAccount(types.NewChain33Config(types.GetDefaultCfgstring())) addr := "0x6c0d7BE0d2C8350042890a77393158181716b0d6" - addr1 := address.ToLower(addr) + addr1 := address.FormatEthAddress(addr) accKey := acc.accountReadKey(addr) require.Equal(t, accKey, acc.AccountKey(addr)) require.Equal(t, accKey, acc.AccountKey(addr1)) diff --git a/cmd/chain33/chain33.fork.toml b/cmd/chain33/chain33.fork.toml index f73c0a932f..434226c1c7 100644 --- a/cmd/chain33/chain33.fork.toml +++ b/cmd/chain33/chain33.fork.toml @@ -24,6 +24,7 @@ ForkCacheDriver=2580000 ForkTicketFundAddrV1=3350000 ForkRootHash=4500000 ForkFormatAddressKey=0 +ForkEthAddressFormat=0 ForkCheckEthTxSort=0 ForkProxyExec=0 ForkMaxTxFeeV1=0 diff --git a/cmd/chain33/chain33.system.fork.toml b/cmd/chain33/chain33.system.fork.toml index e926a3f028..e4a7dd7acb 100644 --- a/cmd/chain33/chain33.system.fork.toml +++ b/cmd/chain33/chain33.system.fork.toml @@ -24,6 +24,7 @@ ForkCacheDriver=2580000 ForkTicketFundAddrV1=3350000 ForkRootHash=4500000 ForkFormatAddressKey=0 +ForkEthAddressFormat=0 ForkCheckEthTxSort=0 ForkProxyExec=0 -ForkMaxTxFeeV1=0 \ No newline at end of file +ForkMaxTxFeeV1=0 diff --git a/common/address/util.go b/common/address/util.go index 26d28cc4a4..538517ea16 100644 --- a/common/address/util.go +++ b/common/address/util.go @@ -9,14 +9,17 @@ import ( // ForkFormatAddressKey 地址key格式化分叉名称,主要针对eth地址 const ForkFormatAddressKey = "ForkFormatAddressKey" +// ForkEthAddressFormat eth地址统一格式化 +const ForkEthAddressFormat = "ForkEthAddressFormat" + // IsEthAddress verifies whether a string can represent // a valid hex-encoded eth address func IsEthAddress(addr string) bool { return common.IsHexAddress(addr) } -// ToLower to lower case string -func ToLower(addr string) string { +// FormatEthAddress eth地址格式化 +func FormatEthAddress(addr string) string { return strings.ToLower(addr) } diff --git a/common/address/util_test.go b/common/address/util_test.go index 6988d92656..ebecf13060 100644 --- a/common/address/util_test.go +++ b/common/address/util_test.go @@ -17,7 +17,7 @@ func TestFormatAddrKey(t *testing.T) { addrKey1 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr1)) addrKey2 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr2)) - expect := fmt.Sprintf("%s:%s", "addrKey:", string(FormatAddrKey(ToLower(addr1)))) + expect := fmt.Sprintf("%s:%s", "addrKey:", string(FormatAddrKey(FormatEthAddress(addr1)))) require.Equal(t, expect, addrKey1) require.Equal(t, expect, addrKey2) diff --git a/system/address/eth/address.go b/system/address/eth/address.go index 66fb8208e9..40588730da 100644 --- a/system/address/eth/address.go +++ b/system/address/eth/address.go @@ -2,7 +2,6 @@ package eth import ( "errors" - "github.com/33cn/chain33/common/crypto/client" "github.com/33cn/chain33/common/address" @@ -82,7 +81,7 @@ func (e *eth) FormatAddr(addr string) string { func formatAddr(addr string) string { ctx := client.GetCryptoContext() if ctx.API == nil || ctx.API.GetConfig().IsFork(ctx.CurrBlockHeight, address.ForkFormatAddressKey) { - return address.ToLower(addr) + return address.FormatEthAddress(addr) } return addr } diff --git a/system/address/eth/address_test.go b/system/address/eth/address_test.go index 6d6e7d1cbd..0370776bed 100644 --- a/system/address/eth/address_test.go +++ b/system/address/eth/address_test.go @@ -29,7 +29,7 @@ func TestFormatEthAddr(t *testing.T) { err = ethDriver.ValidateAddr(ethAddr) require.Nil(t, err) addr := ethDriver.PubKeyToAddr(chain33Priv.PubKey().Bytes()) - require.Equal(t, address.ToLower(ethAddr), addr) + require.Equal(t, address.FormatEthAddress(ethAddr), addr) } require.Equal(t, eth.Name, ethDriver.GetName()) } diff --git a/system/dapp/manage/executor/exec.go b/system/dapp/manage/executor/exec.go index fcdd8d2ff5..60fe1cb0f7 100644 --- a/system/dapp/manage/executor/exec.go +++ b/system/dapp/manage/executor/exec.go @@ -42,7 +42,7 @@ func (c *Manage) Exec_Modify(manageAction *types.ModifyConfig, tx *types.Transac } } action := newAction(c, tx, int32(index)) - if !IsSuperManager(cfg, action.fromaddr) { + if !IsSuperManager(cfg, action.fromaddr, c.GetHeight()) { return nil, mty.ErrNoPrivilege } return action.modifyConfig(manageAction) diff --git a/system/dapp/manage/executor/manage.go b/system/dapp/manage/executor/manage.go index 80e7c26922..fbca840d9f 100644 --- a/system/dapp/manage/executor/manage.go +++ b/system/dapp/manage/executor/manage.go @@ -6,6 +6,7 @@ package executor import ( + "github.com/33cn/chain33/common/address" log "github.com/33cn/chain33/common/log/log15" drivers "github.com/33cn/chain33/system/dapp" "github.com/33cn/chain33/types" @@ -57,9 +58,12 @@ func (c *Manage) CheckTx(tx *types.Transaction, index int) error { } // IsSuperManager is supper manager or not -func IsSuperManager(cfg *types.Chain33Config, addr string) bool { +func IsSuperManager(cfg *types.Chain33Config, addr string, height int64) bool { conf := types.ConfSub(cfg, driverName) for _, m := range conf.GStrList("superManager") { + if address.IsEthAddress(m) && cfg.IsFork(height, address.ForkEthAddressFormat) { + m = address.FormatEthAddress(addr) + } if addr == m { return true } diff --git a/types/config.go b/types/config.go index 360bb74a93..2ad8c9f412 100644 --- a/types/config.go +++ b/types/config.go @@ -219,7 +219,7 @@ func (c *Chain33Config) chain33CfgInit(cfg *Config) { if c.forks == nil { c.forks = &Forks{} } - c.forks.SetTestNetFork() + c.forks.RegisterSystemFork() if cfg != nil { if c.isLocal() { diff --git a/types/fork.go b/types/fork.go index b01b6c78eb..b8aa9a3741 100644 --- a/types/fork.go +++ b/types/fork.go @@ -5,9 +5,8 @@ package types import ( - "strings" - "github.com/33cn/chain33/common/address" + "strings" ) /* @@ -115,8 +114,8 @@ func (f *Forks) IsDappFork(height int64, dapp, fork string) bool { return f.IsFork(height, dapp+"."+fork) } -// SetTestNetFork bityuan test net fork -func (f *Forks) SetTestNetFork() { +// RegisterSystemFork 注册系统分叉, 部分分叉高度设为测试网分叉值 +func (f *Forks) RegisterSystemFork() { f.SetFork("ForkChainParamV1", 110000) f.SetFork("ForkChainParamV2", 1692674) f.SetFork("ForkCheckTxDup", 75260) @@ -142,6 +141,7 @@ func (f *Forks) SetTestNetFork() { f.SetFork("ForkTicketFundAddrV1", 3350000) f.SetFork("ForkRootHash", 4500000) f.SetFork(address.ForkFormatAddressKey, 0) + f.SetFork(address.ForkEthAddressFormat, 0) f.setFork("ForkCheckEthTxSort", 0) f.setFork("ForkProxyExec", 0) f.setFork("ForkMaxTxFeeV1", 0)