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

refactor(header): Validate should check that the raw header's app version is not greater than latest app version #3589

Merged
merged 11 commits into from
Aug 8, 2024
12 changes: 12 additions & 0 deletions core/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package core

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/rand"

"github.com/celestiaorg/celestia-app/pkg/appconsts"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/share"
Expand Down Expand Up @@ -48,3 +51,12 @@ func TestMismatchedDataHash_ComputedRoot(t *testing.T) {
assert.Contains(t, err.Error(), "mismatch between data hash commitment from"+
" core header and computed data root")
}

func TestBadAppVersion(t *testing.T) {
header := headertest.RandExtendedHeader(t)
header.RawHeader.Version.App = appconsts.LatestVersion + 1

err := header.Validate()
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))
}
13 changes: 4 additions & 9 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"github.com/tendermint/tendermint/light"
core "github.com/tendermint/tendermint/types"

v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v2/pkg/da"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/rsmt2d"
Expand Down Expand Up @@ -115,13 +113,10 @@
return fmt.Errorf("ValidateBasic error on RawHeader at height %d: %w", eh.Height(), err)
}

if eh.RawHeader.Version.App != v1.Version && eh.RawHeader.Version.App != v2.Version {
return fmt.Errorf(
"app version mismatch, expected: %d or %d, got %d",
v1.Version,
v2.Version,
eh.RawHeader.Version.App,
)
if eh.RawHeader.Version.App > appconsts.LatestVersion || eh.RawHeader.Version.App == 0 {

Check failure on line 116 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts

Check failure on line 116 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts

Check failure on line 116 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts

Check failure on line 116 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("header received at height %d has version %d, this node supports up "+
"to version %d. Please upgrade to support new version. Note, 0 is not a valid version",
eh.RawHeader.Height, eh.RawHeader.Version.App, appconsts.LatestVersion)

Check failure on line 119 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts (typecheck)

Check failure on line 119 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts) (typecheck)

Check failure on line 119 in header/header.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

undefined: appconsts) (typecheck)
}

err = eh.Commit.ValidateBasic()
Expand Down
4 changes: 3 additions & 1 deletion nodebuilder/blobstream/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package blobstream

import "go.uber.org/fx"
import (
"go.uber.org/fx"
)

func ConstructModule() fx.Option {
return fx.Module("blobstream",
Expand Down
Loading