Skip to content

Commit

Permalink
fix: use height in store for checking upgrade status (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu authored and NathanBSC committed Apr 25, 2023
1 parent 4b8a649 commit cb86304
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (si StoreInfo) GetHash() []byte {
// Hash returns the simple merkle root hash of the stores sorted by name.
func (ci CommitInfo) Hash() []byte {
m := make(map[string][]byte, len(ci.StoreInfos))
if sdk.IsUpgrade(sdk.BEP171) {
if sdk.IsUpgradeWithHeight(sdk.BEP171, ci.Version) {
for _, storeInfo := range ci.StoreInfos {
m[storeInfo.Name] = storeInfo.GetHash()
}
Expand All @@ -443,7 +443,7 @@ func (ci CommitInfo) CommitID() CommitID {

func (ci CommitInfo) toMap() map[string][]byte {
m := make(map[string][]byte, len(ci.StoreInfos))
if sdk.IsUpgrade(sdk.BEP171) {
if sdk.IsUpgradeWithHeight(sdk.BEP171, ci.Version) {
for _, storeInfo := range ci.StoreInfos {
m[storeInfo.Name] = storeInfo.Core.CommitID.Hash
}
Expand Down
9 changes: 9 additions & 0 deletions types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ func IsUpgrade(name string) bool {
return UpgradeMgr.GetHeight() >= upgradeHeight
}

func IsUpgradeWithHeight(name string, height int64) bool {
upgradeHeight := UpgradeMgr.GetUpgradeHeight(name)
if upgradeHeight == 0 {
return false
}

return height >= upgradeHeight
}

func ShouldCommitStore(storeKeyName string) bool {
storeKeyHeight := UpgradeMgr.GetStoreKeyHeight(storeKeyName)
if storeKeyHeight == 0 {
Expand Down

0 comments on commit cb86304

Please sign in to comment.