Skip to content

Commit

Permalink
block's protocol version verification checks only the major part of t…
Browse files Browse the repository at this point in the history
…he version
  • Loading branch information
pnowosie committed Nov 25, 2024
1 parent c55d90f commit d1f0527
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Reader interface {

var (
ErrParentDoesNotMatchHead = errors.New("block's parent hash does not match head block hash")
supportedStarknetVersion = semver.MustParse("0.13.3")
SupportedStarknetVersion = semver.MustParse("0.13.3")
)

func checkBlockVersion(protocolVersion string) error {
Expand All @@ -62,7 +62,8 @@ func checkBlockVersion(protocolVersion string) error {
return err
}

if blockVer.GreaterThan(supportedStarknetVersion) {
// We only care about major version changes ignoring minor and patch
if blockVer.Major() > SupportedStarknetVersion.Major() {
return errors.New("unsupported block version")
}

Expand Down
17 changes: 17 additions & 0 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ func TestVerifyBlock(t *testing.T) {
require.EqualError(t, chain.Store(mainnetBlock0, &emptyCommitments, mainnetStateUpdate0, nil), "unsupported block version")
})

t.Run("only difference in major protocol version is checked", func(t *testing.T) {
ver := blockchain.SupportedStarknetVersion
majorBumped, minorBUmped, patchBumped := ver.IncMajor(), ver.IncMinor(), ver.IncPatch()

// mismatch at patch is ignored
mainnetBlock0.ProtocolVersion = patchBumped.String()
require.NoError(t, chain.VerifyBlock(mainnetBlock0))

// mismatch at minor is ignored
mainnetBlock0.ProtocolVersion = minorBUmped.String()
require.NoError(t, chain.VerifyBlock(mainnetBlock0))

// mismatch at major cause an error
mainnetBlock0.ProtocolVersion = majorBumped.String()
require.EqualError(t, chain.VerifyBlock(mainnetBlock0), "unsupported block version")
})

t.Run("no error with no version string", func(t *testing.T) {
mainnetBlock0.ProtocolVersion = ""
require.NoError(t, chain.Store(mainnetBlock0, &emptyCommitments, mainnetStateUpdate0, nil))
Expand Down

0 comments on commit d1f0527

Please sign in to comment.