Skip to content

Commit

Permalink
fix(header): do not allow version 0
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Aug 8, 2024
1 parent 804b881 commit 207e9bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -56,5 +57,6 @@ func TestBadAppVersion(t *testing.T) {
header.RawHeader.Version.App = appconsts.LatestVersion + 1

err := header.Validate()
assert.Contains(t, err.Error(), "app version must be less than the latest app version")
assert.Contains(t, err.Error(), fmt.Sprintf("has version %d, this node supports up to version %d. Please "+
"upgrade to support new version", header.RawHeader.Version.App, appconsts.LatestVersion))
}
4 changes: 2 additions & 2 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func (eh *ExtendedHeader) Validate() error {
return fmt.Errorf("ValidateBasic error on RawHeader at height %d: %w", eh.Height(), err)
}

if eh.RawHeader.Version.App > appconsts.LatestVersion {
if eh.RawHeader.Version.App > appconsts.LatestVersion || eh.RawHeader.Version.App == 0 {
return fmt.Errorf("header received at height %d has version %d, this node supports up to version %d. "+
"Please upgrade to support new version",
"Please upgrade to support new version. Note, 0 is not a valid version",
eh.RawHeader.Height, eh.RawHeader.Version.App, appconsts.LatestVersion)
}

Expand Down

0 comments on commit 207e9bb

Please sign in to comment.