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
6 changes: 3 additions & 3 deletions blob/commitment_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"fmt"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
"github.com/celestiaorg/go-square/inclusion"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/namespace"

Expand Down Expand Up @@ -98,7 +98,7 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold
// the subtree roots width is defined in ADR-013:
//
//https://github.com/celestiaorg/celestia-app/blob/main/docs/architecture/adr-013-non-interactive-default-rules-for-zero-padding.md
subtreeRootsWidth := shares.SubTreeWidth(numberOfShares, subtreeRootThreshold)
subtreeRootsWidth := inclusion.SubTreeWidth(numberOfShares, subtreeRootThreshold)

// verify the proof of the subtree roots
subtreeRootsCursor := 0
Expand Down
5 changes: 3 additions & 2 deletions blob/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
squareblob "github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBlobsToShares(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof"
"github.com/celestiaorg/go-square/inclusion"
appns "github.com/celestiaorg/go-square/namespace"
Expand Down
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/v2/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))
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/benbjohnson/clock v1.3.5
github.com/celestiaorg/celestia-app v1.13.0
github.com/celestiaorg/celestia-app/v2 v2.0.0
github.com/celestiaorg/go-fraud v0.2.1
github.com/celestiaorg/go-header v0.6.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
github.com/celestiaorg/celestia-app v1.13.0 h1:7MWEox6lim6WDyiP84Y2/ERfWUJxWPfZlKxzO6OFcig=
github.com/celestiaorg/celestia-app v1.13.0/go.mod h1:CF9VZwWAlTU0Is/BOsmxqkbkYnnmrgl0YRlSBIzr0m0=
github.com/celestiaorg/celestia-app/v2 v2.0.0 h1:cGrkLbqbaNqj+g+LhvmQ0iFKFyrD/GdU5z3WQI/bq8E=
github.com/celestiaorg/celestia-app/v2 v2.0.0/go.mod h1:0wP0W+GLghvsODxLhAYToKsy0RFKeg1HdZftQG90W5A=
github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29 h1:HwbA4OegRvXX0aNchBA7Cmu+oIxnH7xRcOhISuDP0ak=
Expand Down
14 changes: 5 additions & 9 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"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/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/da"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/rsmt2d"
Expand Down Expand Up @@ -115,13 +114,10 @@ func (eh *ExtendedHeader) Validate() error {
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 == 0 || eh.RawHeader.Version.App > appconsts.LatestVersion {
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)
}

err = eh.Commit.ValidateBasic()
Expand Down
16 changes: 10 additions & 6 deletions header/headertest/validate_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package headertest

import (
"fmt"
"strconv"
"testing"
"time"
Expand All @@ -19,26 +18,31 @@ import (
func TestValidate(t *testing.T) {
testCases := []struct {
extendedHeader *header.ExtendedHeader
wantErr error
wantErr string
}{
{
extendedHeader: getExtendedHeader(t, 1),
wantErr: nil,
wantErr: "",
},
{
extendedHeader: getExtendedHeader(t, 2),
wantErr: nil,
wantErr: "",
},
{
extendedHeader: getExtendedHeader(t, 3),
wantErr: fmt.Errorf("app version mismatch, expected: 1 or 2, got 3"),
wantErr: "has version 3, this node supports up to version 2. " +
"Please upgrade to support new version. Note, 0 is not a valid version",
},
}

for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
got := tc.extendedHeader.Validate()
assert.Equal(t, tc.wantErr, got)
if tc.wantErr == "" {
assert.NoError(t, got)
return
}
assert.ErrorContains(t, got, tc.wantErr)
})
}
}
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