diff --git a/app/app.go b/app/app.go index dc59e7382..8020245fc 100644 --- a/app/app.go +++ b/app/app.go @@ -321,6 +321,8 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) { upgrade.Mgr.AddUpgradeHeight(upgrade.BEP67, upgradeConfig.BEP67Height) upgrade.Mgr.AddUpgradeHeight(upgrade.BEP70, upgradeConfig.BEP70Height) + upgrade.Mgr.AddUpgradeHeight(upgrade.AdjustTokenSymbolLength, upgradeConfig.AdjustTokenSymbolLengthHeight) + // register store keys of upgrade upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name()) upgrade.Mgr.RegisterStoreKeys(upgrade.BEP3, common.AtomicSwapStoreKey.Name()) diff --git a/app/config/config.go b/app/config/config.go index d9493c3ca..30558f9a6 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -73,6 +73,8 @@ BEP8Height = {{ .UpgradeConfig.BEP8Height }} BEP67Height = {{ .UpgradeConfig.BEP67Height }} # Block height of BEP70 upgrade BEP70Height = {{ .UpgradeConfig.BEP70Height }} +# Block height of token length adjustment upgrade +AdjustTokenSymbolLengthHeight = {{ .UpgradeConfig.AdjustTokenSymbolLengthHeight }} [query] # ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"] @@ -493,25 +495,28 @@ type UpgradeConfig struct { BEP8Height int64 `mapstructure:"BEP8Height"` BEP67Height int64 `mapstructure:"BEP67Height"` BEP70Height int64 `mapstructure:"BEP70Height"` + + AdjustTokenSymbolLengthHeight int64 `mapstructure:"AdjustTokenSymbolLengthHeight"` } func defaultUpgradeConfig() *UpgradeConfig { // make the upgraded functions enabled by default return &UpgradeConfig{ - BEP6Height: 1, - BEP9Height: 1, - BEP10Height: 1, - BEP19Height: 1, - BEP12Height: 1, - BEP3Height: 1, - FixSignBytesOverflowHeight: 1, - LotSizeUpgradeHeight: 1, - ListingRuleUpgradeHeight: 1, - FixZeroBalanceHeight: 1, - BEP8Height: 1, - BEP67Height: 1, - BEP70Height: 1, - LaunchBscUpgradeHeight: math.MaxInt64, + BEP6Height: 1, + BEP9Height: 1, + BEP10Height: 1, + BEP19Height: 1, + BEP12Height: 1, + BEP3Height: 1, + FixSignBytesOverflowHeight: 1, + LotSizeUpgradeHeight: 1, + ListingRuleUpgradeHeight: 1, + FixZeroBalanceHeight: 1, + BEP8Height: 1, + BEP67Height: 1, + BEP70Height: 1, + LaunchBscUpgradeHeight: 1, + AdjustTokenSymbolLengthHeight: math.MaxInt64, } } diff --git a/common/types/mini_token.go b/common/types/mini_token.go index e02227a7b..1cb7842cb 100644 --- a/common/types/mini_token.go +++ b/common/types/mini_token.go @@ -9,12 +9,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/binance-chain/node/common/upgrade" "github.com/binance-chain/node/common/utils" ) const ( MiniTokenSymbolMaxLen = 8 MiniTokenSymbolMinLen = 3 + MiniTokenSymbolNewMinLen = 2 MiniTokenSymbolSuffixLen = 4 // probably enough. if it collides (unlikely) the issuer can just use another tx. MiniTokenSymbolTxHashSuffixLen = 3 // probably enough. if it collides (unlikely) the issuer can just use another tx. MiniTokenSymbolMSuffix = "M" @@ -158,6 +160,8 @@ func IsValidMiniTokenSymbol(symbol string) bool { return ValidateMiniTokenSymbol(symbol) == nil } +// This function is used by both client and server side, and the client needs to use MiniTokenSymbolNewMinLen for the validation. +// If the UpgradeMgr.GetHeight == 0, that indicates the function is invoked by client side, and we should use MiniTokenSymbolNewMinLen func ValidateIssueMiniSymbol(symbol string) error { if len(symbol) == 0 { return errors.New("token symbol cannot be empty") @@ -169,7 +173,12 @@ func ValidateIssueMiniSymbol(symbol string) error { } // check len without suffix - if symbolLen := len(symbol); symbolLen > MiniTokenSymbolMaxLen || symbolLen < MiniTokenSymbolMinLen { + symbolLen := len(symbol) + if sdk.UpgradeMgr.GetHeight() == 0 || sdk.IsUpgrade(upgrade.AdjustTokenSymbolLength) { + if symbolLen > MiniTokenSymbolMaxLen || symbolLen < MiniTokenSymbolNewMinLen { + return errors.New("length of token symbol is limited to 2~8") + } + } else if symbolLen > MiniTokenSymbolMaxLen || symbolLen < MiniTokenSymbolMinLen { return errors.New("length of token symbol is limited to 3~8") } @@ -197,9 +206,16 @@ func ValidateMiniTokenSymbol(symbol string) error { symbolPart := parts[0] // check len without suffix - if len(symbolPart) < MiniTokenSymbolMinLen { + // This function is used by both client and server side, and the client needs to use MiniTokenSymbolNewMinLen for the validation. + // If the UpgradeMgr.GetHeight == 0, that indicates the function is invoked by client side, and we should use MiniTokenSymbolNewMinLen + if sdk.UpgradeMgr.GetHeight() == 0 || sdk.IsUpgrade(upgrade.AdjustTokenSymbolLength) { + if len(symbolPart) < MiniTokenSymbolNewMinLen { + return fmt.Errorf("mini-token symbol part is too short, got %d chars", len(symbolPart)) + } + } else if len(symbolPart) < MiniTokenSymbolMinLen { return fmt.Errorf("mini-token symbol part is too short, got %d chars", len(symbolPart)) } + if len(symbolPart) > MiniTokenSymbolMaxLen { return fmt.Errorf("mini-token symbol part is too long, got %d chars", len(symbolPart)) } diff --git a/common/types/token.go b/common/types/token.go index 8e4be05d9..ccc81b2ce 100644 --- a/common/types/token.go +++ b/common/types/token.go @@ -9,12 +9,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/binance-chain/node/common/upgrade" "github.com/binance-chain/node/common/utils" ) const ( TokenSymbolMaxLen = 8 TokenSymbolMinLen = 3 + TokenSymbolNewMinLen = 2 TokenSymbolTxHashSuffixLen = 3 // probably enough. if it collides (unlikely) the issuer can just use another tx. TokenSymbolDotBSuffix = ".B" @@ -125,6 +127,8 @@ func (token Token) String() string { token.Name, token.Symbol, token.TotalSupply, token.Owner, token.Mintable) } +// This function is used by both client and server side, and the client needs to use TokenSymbolNewMinLen for the validation. +// If the UpgradeMgr.GetHeight == 0, that indicates the function is invoked by client side, and we should use TokenSymbolNewMinLen func ValidateIssueSymbol(symbol string) error { if len(symbol) == 0 { return errors.New("token symbol cannot be empty") @@ -135,7 +139,12 @@ func ValidateIssueSymbol(symbol string) error { } // check len without .B suffix - if symbolLen := len(symbol); symbolLen > TokenSymbolMaxLen || symbolLen < TokenSymbolMinLen { + symbolLen := len(symbol) + if sdk.UpgradeMgr.GetHeight() == 0 || sdk.IsUpgrade(upgrade.AdjustTokenSymbolLength) { + if symbolLen > TokenSymbolMaxLen || symbolLen < TokenSymbolNewMinLen { + return errors.New("length of token symbol is limited to 2~8") + } + } else if symbolLen > TokenSymbolMaxLen || symbolLen < TokenSymbolMinLen { return errors.New("length of token symbol is limited to 3~8") } @@ -185,9 +194,16 @@ func ValidateTokenSymbol(symbol string) error { } // check len without .B suffix - if len(symbolPart) < TokenSymbolMinLen { + // This function is used by both client and server side, and the client needs to use TokenSymbolNewMinLen for the validation. + // If the UpgradeMgr.GetHeight == 0, that indicates the function is invoked by client side, and we should use TokenSymbolNewMinLen + if sdk.UpgradeMgr.GetHeight() == 0 || sdk.IsUpgrade(upgrade.AdjustTokenSymbolLength) { + if len(symbolPart) < TokenSymbolNewMinLen { + return fmt.Errorf("token symbol part is too short, got %d chars", len(symbolPart)) + } + } else if len(symbolPart) < TokenSymbolMinLen { return fmt.Errorf("token symbol part is too short, got %d chars", len(symbolPart)) } + if len(symbolPart) > TokenSymbolMaxLen { return fmt.Errorf("token symbol part is too long, got %d chars", len(symbolPart)) } diff --git a/common/types/token_test.go b/common/types/token_test.go index e0e1f34da..50b847c92 100644 --- a/common/types/token_test.go +++ b/common/types/token_test.go @@ -67,6 +67,7 @@ var tokenMapperSymbolTestCases = []struct { } func TestNewToken(t *testing.T) { + sdk.UpgradeMgr.SetHeight(1) for _, tt := range tokenMapperSymbolTestCases { t.Run(tt.symbol, func(t *testing.T) { _, err := types.NewToken(tt.symbol, tt.symbol, 100000, sdk.AccAddress{}, false) diff --git a/common/upgrade/upgrade.go b/common/upgrade/upgrade.go index cb75de802..e0e0474fb 100644 --- a/common/upgrade/upgrade.go +++ b/common/upgrade/upgrade.go @@ -30,6 +30,8 @@ const ( BEP8 = sdk.BEP8 // https://github.com/binance-chain/BEPs/pull/69 Mini token upgrade BEP67 = "BEP67" // https://github.com/binance-chain/BEPs/pull/67 Expiry time upgrade BEP70 = "BEP70" // https://github.com/binance-chain/BEPs/pull/70 BUSD Pair Upgrade + + AdjustTokenSymbolLength = "AdjustTokenSymbolLength" ) func UpgradeBEP10(before func(), after func()) {