diff --git a/lib/runtime/version.go b/lib/runtime/version.go index a2ab51de0d..23f377cde0 100644 --- a/lib/runtime/version.go +++ b/lib/runtime/version.go @@ -28,18 +28,6 @@ type Version struct { TransactionVersion uint32 } -// Encode returns the scale encoding of the version. -// Note the encoding contains all the latest Core_version fields as defined in -// https://spec.polkadot.network/#defn-rt-core-version -// In other words, decoding older version data with missing fields -// and then encoding it will result in a longer encoding due to the -// extra version fields. This however remains compatible since the -// version fields are still encoded in the same order and an older -// decoder would succeed with the longer encoding. -func (v *Version) Encode() (encoded []byte, err error) { - return scale.Marshal(*v) -} - var ( ErrDecodingVersionField = errors.New("decoding version field") ) diff --git a/lib/runtime/version_test.go b/lib/runtime/version_test.go index df28d15b8f..412941995e 100644 --- a/lib/runtime/version_test.go +++ b/lib/runtime/version_test.go @@ -24,51 +24,6 @@ func concatBytes(slices [][]byte) (concatenated []byte) { return concatenated } -func Test_Version_Encode(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - version Version - encoding []byte - errWrapped error - errMessage string - }{ - "all optional fields set": { - version: Version{ - SpecName: []byte{1}, - ImplName: []byte{2}, - AuthoringVersion: 3, - SpecVersion: 4, - ImplVersion: 5, - APIItems: []APIItem{{ - Name: [8]byte{1, 2, 3, 4, 5, 6, 7, 8}, - Ver: 6, - }}, - TransactionVersion: 7, - }, - encoding: []byte{ - 0x4, 0x1, 0x4, 0x2, 0x3, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, - 0x5, 0x0, 0x0, 0x0, 0x4, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, - 0x8, 0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0}, - }, - } - - for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { - t.Parallel() - - encoded, err := testCase.version.Encode() - - assert.ErrorIs(t, err, testCase.errWrapped) - if testCase.errWrapped != nil { - require.EqualError(t, err, testCase.errMessage) - } - assert.Equal(t, testCase.encoding, encoded) - }) - } -} - func Test_DecodeVersion(t *testing.T) { t.Parallel() @@ -200,7 +155,7 @@ func Test_Version_Scale(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - encoded, err := testCase.version.Encode() + encoded, err := scale.Marshal(testCase.version) require.NoError(t, err) require.Equal(t, testCase.encoding, encoded) diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index d1e163f39a..478fc786e2 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -964,12 +964,14 @@ func ext_misc_runtime_version_version_1(context unsafe.Pointer, dataSpan C.int64 return C.int64_t(out) } - // Note: we must call the `Encode` method and NOT - // scale.Marshal or this one would encode the Version - // interface pointer instead of the actual struct implementation. - // Encode also respects the legacy boolean field of the version - // and encodes the version differently if it is set to true. - encodedData, err := version.Encode() + // Note the encoding contains all the latest Core_version fields as defined in + // https://spec.polkadot.network/#defn-rt-core-version + // In other words, decoding older version data with missing fields + // and then encoding it will result in a longer encoding due to the + // extra version fields. This however remains compatible since the + // version fields are still encoded in the same order and an older + // decoder would succeed with the longer encoding. + encodedData, err := scale.Marshal(version) if err != nil { logger.Errorf("failed to encode result: %s", err) return 0