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

chore (pkg/scale): Integrate scale into lib/genesis #1663

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ef559f9
WIP/Integrate new scale pkg
jimjbrettj Jun 28, 2021
114f735
WIP
jimjbrettj Jun 28, 2021
7e9ae99
add new type, that uses scale.Uint128, comparison test
timwu20 Jun 29, 2021
8d200c8
merge and utilize tims changes
jimjbrettj Jun 29, 2021
f59b3cc
integrate scale into genesis
jimjbrettj Jun 29, 2021
2f762d9
integrate scale into rpc modules system-test and added nil check for …
jimjbrettj Jun 29, 2021
a8ca774
use new AccountInfo data type and scale pkg
jimjbrettj Jun 29, 2021
6453df2
clean up
jimjbrettj Jun 29, 2021
f8d5a5e
remove import cycle and comments
jimjbrettj Jun 29, 2021
3127240
update tests for padded uint128
jimjbrettj Jun 29, 2021
a81844e
feat(dot/telemetry): implement telemetry message network_state (#1618)
edwardmack Jun 30, 2021
d975aef
fix error names
jimjbrettj Jul 1, 2021
ea6f60b
WIP/Integrate new scale pkg
jimjbrettj Jun 28, 2021
7ef8f10
WIP
jimjbrettj Jun 28, 2021
d4764b7
add new type, that uses scale.Uint128, comparison test
timwu20 Jun 29, 2021
f66bf4e
merge and utilize tims changes
jimjbrettj Jun 29, 2021
1939f10
integrate scale into genesis
jimjbrettj Jun 29, 2021
e99c183
integrate scale into rpc modules system-test and added nil check for …
jimjbrettj Jun 29, 2021
1a25373
use new AccountInfo data type and scale pkg
jimjbrettj Jun 29, 2021
95471cf
clean up
jimjbrettj Jun 29, 2021
e9dd0e6
remove import cycle and comments
jimjbrettj Jun 29, 2021
6faa331
update tests for padded uint128
jimjbrettj Jun 29, 2021
c2ea3d6
fix error names
jimjbrettj Jul 1, 2021
e103a94
Merge branch 'jimmy/scale-integrate-genesis' of github.com:ChainSafe/…
jimjbrettj Jul 1, 2021
2b49418
WIP/Integrate new scale pkg
jimjbrettj Jun 28, 2021
bdb4a79
WIP
jimjbrettj Jun 28, 2021
c026b5b
add new type, that uses scale.Uint128, comparison test
timwu20 Jun 29, 2021
441fce0
merge and utilize tims changes
jimjbrettj Jun 29, 2021
d056fee
integrate scale into genesis
jimjbrettj Jun 29, 2021
3826742
integrate scale into rpc modules system-test and added nil check for …
jimjbrettj Jun 29, 2021
900c39c
use new AccountInfo data type and scale pkg
jimjbrettj Jun 29, 2021
92af057
clean up
jimjbrettj Jun 29, 2021
84b5fa4
remove import cycle and comments
jimjbrettj Jun 29, 2021
6996341
update tests for padded uint128
jimjbrettj Jun 29, 2021
244ff21
fix error names
jimjbrettj Jul 1, 2021
b343754
WIP/Integrate new scale pkg
jimjbrettj Jun 28, 2021
4f23f65
add new type, that uses scale.Uint128, comparison test
timwu20 Jun 29, 2021
14fc74e
merge and utilize tims changes
jimjbrettj Jun 29, 2021
d7f7fc8
integrate scale into genesis
jimjbrettj Jun 29, 2021
69a8b79
integrate scale into rpc modules system-test and added nil check for …
jimjbrettj Jun 29, 2021
fe8ce5c
use new AccountInfo data type and scale pkg
jimjbrettj Jun 29, 2021
8e4f864
clean up
jimjbrettj Jun 29, 2021
0e392a4
fix error names
jimjbrettj Jul 1, 2021
1e467c4
Merge branch 'jimmy/scale-integrate-genesis' of github.com:ChainSafe/…
jimjbrettj Jul 1, 2021
5476bfa
rebase and lint
jimjbrettj Jul 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions dot/rpc/modules/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -296,13 +296,19 @@ func setupSystemModule(t *testing.T) *SystemModule {
Nonce: 3,
RefCount: 0,
Data: struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
}{},
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
}{
Free: scale.MustNewUint128(big.NewInt(0)),
Reserved: scale.MustNewUint128(big.NewInt(0)),
MiscFrozen: scale.MustNewUint128(big.NewInt(0)),
FreeFrozen: scale.MustNewUint128(big.NewInt(0)),
},
}
aliceAcctEncoded, err := scale.Encode(aliceAcctInfo)

aliceAcctEncoded, err := scale.Marshal(aliceAcctInfo)
require.NoError(t, err)
ts.Set(aliceAcctStoKey, aliceAcctEncoded)

Expand Down
10 changes: 5 additions & 5 deletions dot/types/account.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// AccountInfo Information of an account.
Expand All @@ -13,9 +13,9 @@ type AccountInfo struct {
RefCount uint32
// The additional data that belongs to this account. Used to store the balance(s) in a lot of chains.
Data struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
noot marked this conversation as resolved.
Show resolved Hide resolved
}
}
55 changes: 31 additions & 24 deletions lib/genesis/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"math/big"
"path/filepath"
"reflect"
Expand All @@ -32,8 +33,8 @@ import (
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// NewGenesisFromJSONRaw parses a JSON formatted genesis file
Expand Down Expand Up @@ -209,7 +210,7 @@ func buildRawArrayInterface(a []interface{}, kv *keyValue) {
kv.iVal = append(kv.iVal, tba)
case float64:
// TODO: determine how to handle this error
encVal, _ := scale.Encode(uint64(v2))
encVal, _ := scale.Marshal(uint64(v2))
kv.value = kv.value + fmt.Sprintf("%x", encVal)
kv.iVal = append(kv.iVal, big.NewInt(int64(v2)))
}
Expand Down Expand Up @@ -244,7 +245,7 @@ func formatValue(kv *keyValue) (string, error) {
switch {
case reflect.DeepEqual([]string{"grandpa", "authorities"}, kv.key):
if kv.valueLen != nil {
lenEnc, err := scale.Encode(kv.valueLen)
lenEnc, err := scale.Marshal(kv.valueLen)
if err != nil {
return "", err
}
Expand All @@ -256,7 +257,7 @@ func formatValue(kv *keyValue) (string, error) {
return kv.value, nil
default:
if kv.valueLen != nil {
lenEnc, err := scale.Encode(kv.valueLen)
lenEnc, err := scale.Marshal(kv.valueLen)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -284,19 +285,19 @@ func buildBalances(kv *keyValue, res map[string]string) error {
Nonce: 0,
RefCount: 0,
Data: struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
}{
Free: *common.Uint128FromBigInt(kv.iVal[i+1].(*big.Int)),
Reserved: *common.Uint128FromBigInt(big.NewInt(0)),
MiscFrozen: *common.Uint128FromBigInt(big.NewInt(0)),
FreeFrozen: *common.Uint128FromBigInt(big.NewInt(0)),
Free: scale.MustNewUint128(kv.iVal[i+1].(*big.Int)),
Reserved: scale.MustNewUint128(big.NewInt(0)),
MiscFrozen: scale.MustNewUint128(big.NewInt(0)),
FreeFrozen: scale.MustNewUint128(big.NewInt(0)),
},
}

encBal, err := scale.Encode(accInfo)
encBal, err := scale.Marshal(accInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -357,34 +358,40 @@ func addAuthoritiesValues(k1, k2 string, kt crypto.KeyType, value []byte, gen *G

// decode authorities values into []interface that will be decoded into json array
ava := [][]interface{}{}
buf := &bytes.Buffer{}
sd := scale.Decoder{Reader: buf}
_, err := buf.Write(value)
reader := new(bytes.Buffer)
_, err := reader.Write(value)
if err != nil {
return err
}

alen, err := sd.DecodeInteger()
var alen int
err = scale.Unmarshal(value, &alen)
if err != nil {
return err
}
for i := 0; i < int(alen); i++ {
for i := 0; i < alen; i++ {
auth := []interface{}{}
buf := make([]byte, 32)
if _, err = sd.Reader.Read(buf); err == nil {
if _, err = reader.Read(buf); err == nil {
var arr = [32]byte{}
copy(arr[:], buf)
pa, err := bytesToAddress(kt, arr[:])
if err != nil {
return err
pa, e := bytesToAddress(kt, arr[:])
jimjbrettj marked this conversation as resolved.
Show resolved Hide resolved
if e != nil {
return e
}
auth = append(auth, pa)
}
iv, err := sd.DecodeFixedWidthInt(uint64(0))
b := make([]byte, 8)
if _, err = reader.Read(b); err != nil {
log.Fatal(err)
}
var iv uint64
err = scale.Unmarshal(b, &iv)

if err != nil {
return err
}
auth = append(auth, iv.(uint64))
auth = append(auth, iv)
ava = append(ava, auth)
}

Expand Down
74 changes: 41 additions & 33 deletions lib/runtime/wasmer/exports_test.go

Large diffs are not rendered by default.

Loading