Skip to content

Commit 6032885

Browse files
renaynaycmwaters
andauthored
refactor(header): Validate should check that the raw header's app version is not greater than latest app version (#3589)
Co-authored-by: Callum Waters <[email protected]>
1 parent 3a8eff2 commit 6032885

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

blob/commitment_proof.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"bytes"
55
"fmt"
66

7-
"github.com/celestiaorg/celestia-app/pkg/appconsts"
8-
"github.com/celestiaorg/celestia-app/pkg/shares"
7+
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
98
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
9+
"github.com/celestiaorg/go-square/inclusion"
1010
"github.com/celestiaorg/nmt"
1111
"github.com/celestiaorg/nmt/namespace"
1212

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

103103
// verify the proof of the subtree roots
104104
subtreeRootsCursor := 0

blob/helper_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"bytes"
55
"testing"
66

7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
710
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
811
squareblob "github.com/celestiaorg/go-square/blob"
912
"github.com/celestiaorg/go-square/namespace"
10-
"github.com/stretchr/testify/assert"
11-
"github.com/stretchr/testify/require"
1213
)
1314

1415
func TestBlobsToShares(t *testing.T) {

blob/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"go.opentelemetry.io/otel/codes"
1717
"go.opentelemetry.io/otel/trace"
1818

19-
"github.com/celestiaorg/celestia-app/pkg/appconsts"
19+
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
2020
pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof"
2121
"github.com/celestiaorg/go-square/inclusion"
2222
appns "github.com/celestiaorg/go-square/namespace"

core/header_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package core
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910
"github.com/tendermint/tendermint/libs/rand"
1011

12+
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
13+
1114
"github.com/celestiaorg/celestia-node/header"
1215
"github.com/celestiaorg/celestia-node/header/headertest"
1316
"github.com/celestiaorg/celestia-node/share"
@@ -48,3 +51,12 @@ func TestMismatchedDataHash_ComputedRoot(t *testing.T) {
4851
assert.Contains(t, err.Error(), "mismatch between data hash commitment from"+
4952
" core header and computed data root")
5053
}
54+
55+
func TestBadAppVersion(t *testing.T) {
56+
header := headertest.RandExtendedHeader(t)
57+
header.RawHeader.Version.App = appconsts.LatestVersion + 1
58+
59+
err := header.Validate()
60+
assert.Contains(t, err.Error(), fmt.Sprintf("has version %d, this node supports up to version %d. Please "+
61+
"upgrade to support new version", header.RawHeader.Version.App, appconsts.LatestVersion))
62+
}

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/BurntSushi/toml v1.4.0
99
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
1010
github.com/benbjohnson/clock v1.3.5
11-
github.com/celestiaorg/celestia-app v1.13.0
1211
github.com/celestiaorg/celestia-app/v2 v2.0.0
1312
github.com/celestiaorg/go-fraud v0.2.1
1413
github.com/celestiaorg/go-header v0.6.2

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC
354354
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
355355
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
356356
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
357-
github.com/celestiaorg/celestia-app v1.13.0 h1:7MWEox6lim6WDyiP84Y2/ERfWUJxWPfZlKxzO6OFcig=
358-
github.com/celestiaorg/celestia-app v1.13.0/go.mod h1:CF9VZwWAlTU0Is/BOsmxqkbkYnnmrgl0YRlSBIzr0m0=
359357
github.com/celestiaorg/celestia-app/v2 v2.0.0 h1:cGrkLbqbaNqj+g+LhvmQ0iFKFyrD/GdU5z3WQI/bq8E=
360358
github.com/celestiaorg/celestia-app/v2 v2.0.0/go.mod h1:0wP0W+GLghvsODxLhAYToKsy0RFKeg1HdZftQG90W5A=
361359
github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29 h1:HwbA4OegRvXX0aNchBA7Cmu+oIxnH7xRcOhISuDP0ak=

header/header.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
"github.com/tendermint/tendermint/light"
1212
core "github.com/tendermint/tendermint/types"
1313

14-
v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
15-
v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
14+
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
1615
"github.com/celestiaorg/celestia-app/v2/pkg/da"
1716
libhead "github.com/celestiaorg/go-header"
1817
"github.com/celestiaorg/rsmt2d"
@@ -115,13 +114,10 @@ func (eh *ExtendedHeader) Validate() error {
115114
return fmt.Errorf("ValidateBasic error on RawHeader at height %d: %w", eh.Height(), err)
116115
}
117116

118-
if eh.RawHeader.Version.App != v1.Version && eh.RawHeader.Version.App != v2.Version {
119-
return fmt.Errorf(
120-
"app version mismatch, expected: %d or %d, got %d",
121-
v1.Version,
122-
v2.Version,
123-
eh.RawHeader.Version.App,
124-
)
117+
if eh.RawHeader.Version.App == 0 || eh.RawHeader.Version.App > appconsts.LatestVersion {
118+
return fmt.Errorf("header received at height %d has version %d, this node supports up "+
119+
"to version %d. Please upgrade to support new version. Note, 0 is not a valid version",
120+
eh.RawHeader.Height, eh.RawHeader.Version.App, appconsts.LatestVersion)
125121
}
126122

127123
err = eh.Commit.ValidateBasic()

header/headertest/validate_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package headertest
22

33
import (
4-
"fmt"
54
"strconv"
65
"testing"
76
"time"
@@ -19,26 +18,31 @@ import (
1918
func TestValidate(t *testing.T) {
2019
testCases := []struct {
2120
extendedHeader *header.ExtendedHeader
22-
wantErr error
21+
wantErr string
2322
}{
2423
{
2524
extendedHeader: getExtendedHeader(t, 1),
26-
wantErr: nil,
25+
wantErr: "",
2726
},
2827
{
2928
extendedHeader: getExtendedHeader(t, 2),
30-
wantErr: nil,
29+
wantErr: "",
3130
},
3231
{
3332
extendedHeader: getExtendedHeader(t, 3),
34-
wantErr: fmt.Errorf("app version mismatch, expected: 1 or 2, got 3"),
33+
wantErr: "has version 3, this node supports up to version 2. " +
34+
"Please upgrade to support new version. Note, 0 is not a valid version",
3535
},
3636
}
3737

3838
for i, tc := range testCases {
3939
t.Run(strconv.Itoa(i), func(t *testing.T) {
4040
got := tc.extendedHeader.Validate()
41-
assert.Equal(t, tc.wantErr, got)
41+
if tc.wantErr == "" {
42+
assert.NoError(t, got)
43+
return
44+
}
45+
assert.ErrorContains(t, got, tc.wantErr)
4246
})
4347
}
4448
}

nodebuilder/blobstream/module.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package blobstream
22

3-
import "go.uber.org/fx"
3+
import (
4+
"go.uber.org/fx"
5+
)
46

57
func ConstructModule() fx.Option {
68
return fx.Module("blobstream",

0 commit comments

Comments
 (0)