Skip to content

Commit

Permalink
narrow the scope of log change
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders committed Oct 2, 2023
1 parent 46be651 commit f07c1dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion x/upgrade/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) {
return
}

details, err := plan.UpgradeDetails()
if err != nil {
ctx.Logger().Error("failed to parse upgrade details", "err", err)
}

// If running a pending minor release, apply the upgrade if handler is present
// Minor releases are allowed to run before the scheduled upgrade height, but not required to.
if plan.UpgradeDetails().IsMinorRelease() {
if details.IsMinorRelease() {
// if not yet present, then emit a scheduled log (every 100 blocks, to reduce logs)
if !k.HasHandler(plan.Name) && !k.IsSkipHeight(plan.Height) {
if ctx.BlockHeight()%100 == 0 {
Expand Down
6 changes: 3 additions & 3 deletions x/upgrade/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ type UpgradeDetails struct {

// UpgradeDetails parses and returns a details struct from the Info field of a Plan
// The upgrade.pb.go is generated from proto, so this is separated here
func (p Plan) UpgradeDetails() UpgradeDetails {
func (p Plan) UpgradeDetails() (UpgradeDetails, error) {
var details UpgradeDetails
if err := json.Unmarshal([]byte(p.Info), &details); err != nil {
// invalid json, assume no upgrade details
return UpgradeDetails{}
return UpgradeDetails{}, err
}
return details
return details, nil
}

// IsMinorRelease returns true if the upgrade is a minor release
Expand Down
4 changes: 2 additions & 2 deletions x/upgrade/types/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestUpgradeDetails(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.plan.UpgradeDetails()
got, _ := test.plan.UpgradeDetails()
if got != test.want {
t.Errorf("UpgradeDetails() = %v, want %v", got, test.want)
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestIsMinorRelease(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ud := test.plan.UpgradeDetails()
ud, _ := test.plan.UpgradeDetails()
if got := ud.IsMinorRelease(); got != test.want {
t.Errorf("IsMinorRelease() = %v, want %v", got, test.want)
}
Expand Down

0 comments on commit f07c1dd

Please sign in to comment.