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

fix: version issue on begin blocker #287

Merged
merged 2 commits into from
Sep 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Contains all the PRs that improved the code without changing the behaviors.
- Fixed module imports
- update module to implement APPModuleBasic and AppModule
- Updated Tests on arkeo module keeper
- version issue on begin blocker

# v1.0.0-Prerelease

Expand Down
21 changes: 19 additions & 2 deletions x/arkeo/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"encoding/json"
"fmt"
"regexp"
"strconv"
"strings"
"time"
Expand All @@ -19,8 +20,6 @@
stringOverrides = map[ConfigName]string{}
)

var SWVersion, _ = strconv.ParseInt(Version, 10, 64)

var BlockTime = 5 * time.Second

// ConfigVals implement ConfigValues interface
Expand Down Expand Up @@ -129,3 +128,21 @@

return json.MarshalIndent(result, "", " ")
}

func GetSWVersion() (int64, error) {
re := regexp.MustCompile(`\d+`) // matches digits
versionParts := re.FindAllString(Version, -1)
var version int64

if len(versionParts) > 0 {
majorVersion, err := strconv.ParseInt(versionParts[0], 10, 64)
if err != nil {
return 0, err
}
version = majorVersion
} else {
version = 1

}

Check failure on line 146 in x/arkeo/configs/config.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
return version, nil
}
12 changes: 9 additions & 3 deletions x/arkeo/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,23 @@ func (k KVStore) SetParams(ctx sdk.Context, params types.Params) {

// TODO: Check Thi Again
func (k KVStore) GetComputedVersion(ctx cosmos.Context) int64 {

versions := make(map[int64]int64) // maps are safe in blockchains, but should be okay in this case
validators, err := k.stakingKeeper.GetBondedValidatorsByPower(ctx)
if err != nil {
k.Logger(ctx).Error(err.Error())
ctx.Logger().Error(fmt.Sprintf("get Bonded Validator error :%s ", err.Error()))

}

// if there is only one validator, no need for consensus. Just return the
// validator's current version. This also helps makes
// integration/regression tests run the latest version
if len(validators) == 1 {
return configs.SWVersion
version, err := configs.GetSWVersion()
if err != nil {
ctx.Logger().Error(fmt.Sprintf("invalid version :%s ", err.Error()))
}
return version
}

currentVersion := k.GetVersion(ctx)
Expand All @@ -215,7 +221,7 @@ func (k KVStore) GetComputedVersion(ctx cosmos.Context) int64 {

valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
k.Logger(ctx).Error(err.Error())
ctx.Logger().Error(fmt.Sprintf("get Validator address codec error : %s ", err.Error()))
}
ver := k.GetVersionForAddress(ctx, valBz)
if _, ok := versions[ver]; !ok {
Expand Down
13 changes: 9 additions & 4 deletions x/arkeo/keeper/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
// if local version is behind the consensus version, panic and don't try to
// create a new block
ver := mgr.keeper.GetComputedVersion(ctx)
if ver > configs.SWVersion {
swVersion, err := configs.GetSWVersion()
if err != nil {
return err
}
ctx.Logger().Info(fmt.Sprintf("current version :%s", swVersion))

Check failure on line 39 in x/arkeo/keeper/manager.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Sprintf format %s has arg swVersion of wrong type int64 (govet)

Check failure on line 39 in x/arkeo/keeper/manager.go

View workflow job for this annotation

GitHub Actions / Run tests

fmt.Sprintf format %s has arg swVersion of wrong type int64
if ver > swVersion {
panic(
fmt.Sprintf("Unsupported Version: update your binary (your version: %d, network consensus version: %d)",
configs.SWVersion,
swVersion,
ver,
),
)
Expand Down Expand Up @@ -239,8 +244,8 @@
}

for _, vote := range votes {
if vote.BlockIdFlag.String() != "BLOCK_ID_FLAG_COMMIT" {
ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address))
if vote.BlockIdFlag.String() == "BLOCK_ID_FLAG_ABSENT" || vote.BlockIdFlag.String() == "BLOCK_ID_FLAG_UNKNOWN" {
ctx.Logger().Info(fmt.Sprintf("validator rewards skipped due to lack of signature: %s, validator : %s ", vote.BlockIdFlag.String(), string(vote.Validator.GetAddress())))
continue
}

Expand Down
2 changes: 1 addition & 1 deletion x/arkeo/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (am AppModule) BeginBlock(ctx context.Context) error {
context := sdk.UnwrapSDKContext(ctx)
mgr := keeper.NewManager(am.keeper, am.stakingKeeper)
if err := mgr.BeginBlock(context); err != nil {
context.Logger().Error("manager beginblock error ", "error", err)
context.Logger().Error(fmt.Sprintf("manager beginblock error: %s", err))
return err
}
return nil
Expand Down
Loading