Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the symbol minimum length to 2 #811

Merged
merged 3 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
33 changes: 19 additions & 14 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
}
}

Expand Down
20 changes: 18 additions & 2 deletions common/types/mini_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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")
}

Expand Down Expand Up @@ -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))
}
Expand Down
20 changes: 18 additions & 2 deletions common/types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
Expand All @@ -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")
}

Expand Down Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions common/types/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions common/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down