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: update gssmr genesis to v0.9; stub missing ext_ funcs #1625

Merged
merged 34 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7e3c6df
update gssmr genesis to v0.9; stub missing ext_ funcs
noot Jun 7, 2021
6af7d2a
fix cfg
noot Jun 7, 2021
01e878b
fix life tests
noot Jun 7, 2021
7e423dc
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Jun 7, 2021
793e8ec
add more skips
noot Jun 7, 2021
efa0a3c
lint
noot Jun 7, 2021
52cb97a
Merge branch 'development' into noot/v0.9-runtime
noot Jun 8, 2021
c3fc736
chore: done TestService_HandleTransactionMessage
EclesioMeloJunior Jun 10, 2021
e546f16
chore: done TestHandleChainReorg_WithReorg_Trans
EclesioMeloJunior Jun 10, 2021
24da3ef
chore: done TestService_HandleSubmittedExtrinsic
EclesioMeloJunior Jun 10, 2021
70a487c
update dev genesis to v0.9
noot Jun 10, 2021
d0d45bd
Merge branch 'noot/v0.9-runtime' of github.com:ChainSafe/gossamer int…
noot Jun 10, 2021
87e7695
chore: update centrifue substrate go rpc to version v3
EclesioMeloJunior Jun 10, 2021
e8f9346
Merge branch 'noot/v0.9-runtime' of github.com:ChainSafe/gossamer int…
EclesioMeloJunior Jun 10, 2021
7559981
wip: TestApplyExtrinsic
EclesioMeloJunior Jun 11, 2021
d92009c
set babe runtime logs to debug
noot Jun 15, 2021
2461d82
merge w development
noot Jun 15, 2021
66dc1cf
fix
noot Jun 15, 2021
9c994d9
merge w development
noot Jun 30, 2021
b264b68
fix babe ApplyExtrinsic test
noot Jun 30, 2021
69fb8bb
update HandleSubmittedExtrinsic
noot Jun 30, 2021
d18a525
fix ext encoding
noot Jun 30, 2021
b92a7b8
cleanup
noot Jun 30, 2021
f0afc6a
fix rpc unit tests
noot Jul 1, 2021
149f50f
fix TestNodeRuntime_ValidateTransaction
noot Jul 1, 2021
316840b
cleanup
noot Jul 1, 2021
f6ff98e
merge w development
noot Jul 2, 2021
7ef51a8
add UpgradedDualRefCount key to build-spec
noot Jul 2, 2021
7ca2510
fix cmd tests
noot Jul 2, 2021
8882da8
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Jul 5, 2021
b0950b6
fix rpc, stress tests
noot Jul 5, 2021
d5cd6ba
go mod tidy
noot Jul 5, 2021
3521e53
increase test timeout, bump polkadot.js/api to 4.5.1
noot Jul 5, 2021
ce08ffe
use dev genesis in polkadot.js tests
noot Jul 5, 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
6 changes: 3 additions & 3 deletions chain/dev/genesis-spec.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions chain/dev/genesis.json

Large diffs are not rendered by default.

279 changes: 141 additions & 138 deletions chain/gssmr/genesis-spec.json

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions chain/gssmr/genesis.json

Large diffs are not rendered by default.

95 changes: 44 additions & 51 deletions dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,52 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/scale"

"github.com/centrifuge/go-substrate-rpc-client/v2/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v2/types"
"github.com/centrifuge/go-substrate-rpc-client/v3/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"

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

func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, nonce uint64) types.Extrinsic {
t.Helper()
rawMeta, err := rt.Metadata()
require.NoError(t, err)

decoded, err := scale.Decode(rawMeta, []byte{})
require.NoError(t, err)

meta := &ctypes.Metadata{}
err = ctypes.DecodeFromBytes(decoded.([]byte), meta)
require.NoError(t, err)

rv, err := rt.Version()
require.NoError(t, err)

c, err := ctypes.NewCall(meta, "System.remark", []byte{0xab, 0xcd})
require.NoError(t, err)

ext := ctypes.NewExtrinsic(c)
o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(genHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: false},
GenesisHash: ctypes.Hash(genHash),
Nonce: ctypes.NewUCompactFromUInt(nonce),
SpecVersion: ctypes.U32(rv.SpecVersion()),
Tip: ctypes.NewUCompactFromUInt(0),
TransactionVersion: ctypes.U32(rv.TransactionVersion()),
}

// Sign the transaction using Alice's key
err = ext.Sign(signature.TestKeyringPairAlice, o)
require.NoError(t, err)

extEnc, err := ctypes.EncodeToHexString(ext)
require.NoError(t, err)

extBytes := types.Extrinsic(common.MustHexToBytes(extEnc))
return extBytes
}

func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
// TODO: move to sync package
net := new(MockNetwork) // nolint
Expand Down Expand Up @@ -81,54 +122,6 @@ func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
net.AssertCalled(t, "SendMessage", expected)
}

func createExtrinsics(t *testing.T, rt runtime.Instance, genHash common.Hash, nonce uint64) types.Extrinsic {
t.Helper()
rawMeta, err := rt.Metadata()
require.NoError(t, err)

decoded, err := scale.Decode(rawMeta, []byte{})
require.NoError(t, err)

meta := &ctypes.Metadata{}
err = ctypes.DecodeFromBytes(decoded.([]byte), meta)
require.NoError(t, err)

rv, err := rt.Version()
require.NoError(t, err)

keyring, err := keystore.NewSr25519Keyring()
require.NoError(t, err)

bob, err := ctypes.NewAddressFromHexAccountID(keyring.Bob().Public().Hex())
require.NoError(t, err)

c, err := ctypes.NewCall(meta, "Balances.transfer", bob, ctypes.NewUCompactFromUInt(12345))
require.NoError(t, err)

// Create the extrinsic
ext := ctypes.NewExtrinsic(c)

o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(genHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: true},
GenesisHash: ctypes.Hash(genHash),
Nonce: ctypes.NewUCompactFromUInt(nonce),
SpecVersion: ctypes.U32(rv.SpecVersion()),
Tip: ctypes.NewUCompactFromUInt(0),
TransactionVersion: ctypes.U32(rv.TransactionVersion()),
}

// Sign the transaction using Alice's default account
err = ext.Sign(signature.TestKeyringPairAlice, o)
require.NoError(t, err)

extEnc, err := ctypes.EncodeToHexString(ext)
require.NoError(t, err)

extBytes := types.Extrinsic(common.MustHexToBytes(extEnc))
return extBytes
}

func TestService_HandleTransactionMessage(t *testing.T) {
kp, err := sr25519.GenerateKeypair()
require.NoError(t, err)
Expand All @@ -154,7 +147,7 @@ func TestService_HandleTransactionMessage(t *testing.T) {
err = s.rt.InitializeBlock(header)
require.NoError(t, err)

extBytes := createExtrinsics(t, s.rt, genHash, 0)
extBytes := createExtrinsic(t, s.rt, genHash, 0)
msg := &network.TransactionMessage{Extrinsics: []types.Extrinsic{extBytes}}
b, err := s.HandleTransactionMessage(msg)
require.NoError(t, err)
Expand Down
18 changes: 6 additions & 12 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,13 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {
// currently we are attempting to re-add inherents, causing lots of "'Bad input data provided to validate_transaction" errors.
for _, ext := range exts {
logger.Debug("validating transaction on re-org chain", "extrinsic", ext)
encExt, err := scale.Encode(ext)
if err != nil {
return err
}

decExt := &types.ExtrinsicData{}
err = decExt.DecodeVersion(ext)
err = decExt.DecodeVersion(encExt)
if err != nil {
return err
}
Expand All @@ -443,11 +447,6 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {
continue
}

encExt, err := scale.Encode(ext)
if err != nil {
return err
}

externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, encExt...))
txv, err := s.rt.ValidateTransaction(externalExt)
if err != nil {
Expand Down Expand Up @@ -540,14 +539,9 @@ func (s *Service) GetRuntimeVersion(bhash *common.Hash) (runtime.Version, error)

// HandleSubmittedExtrinsic is used to send a Transaction message containing a Extrinsic @ext
func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error {
logger.Crit("HandleSubmittedExtrinsic")
if s.net == nil {
return nil
}

// the transaction source is External
// validate the transaction
externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, ext...))

txv, err := s.rt.ValidateTransaction(externalExt)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestHandleChainReorg_WithReorg_Trans(t *testing.T) {
nonce := uint64(1)

// Add extrinsic to block `block31`
ext := createExtrinsics(t, s.rt, bs.GenesisHash(), nonce)
ext := createExtrinsic(t, s.rt, bs.GenesisHash(), nonce)

block41 := sync.BuildBlock(t, s.rt, block31.Header, ext)
err = bs.AddBlock(block41)
Expand Down Expand Up @@ -435,13 +435,13 @@ func TestService_HandleSubmittedExtrinsic(t *testing.T) {
header, err := types.NewHeader(parentHash, common.Hash{}, common.Hash{}, big.NewInt(1), types.NewEmptyDigest())
require.NoError(t, err)

extBytes := createExtrinsic(t, s.rt, parentHash, 0)

//initialise block header
err = s.rt.InitializeBlock(header)
require.NoError(t, err)

ext := types.Extrinsic(common.MustHexToBytes("0x410284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d015a3e258da3ea20581b68fe1264a35d1f62d6a0debb1a44e836375eb9921ba33e3d0f265f2da33c9ca4e10490b03918300be902fcb229f806c9cf99af4cc10f8c0000000600ff8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480b00c465f14670"))

err = s.HandleSubmittedExtrinsic(ext)
err = s.HandleSubmittedExtrinsic(extBytes)
require.NoError(t, err)
}

Expand Down
1 change: 1 addition & 0 deletions dot/rpc/modules/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/keystore"

log "github.com/ChainSafe/log15"
)

Expand Down
13 changes: 5 additions & 8 deletions dot/rpc/modules/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ package modules
import (
"bytes"
"errors"
"fmt"
"math/big"
"net/http"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto"
"github.com/ChainSafe/gossamer/lib/scale"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v2/types"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

// SystemModule is an RPC module providing access to core API points
Expand Down Expand Up @@ -171,15 +170,13 @@ func (sm *SystemModule) AccountNextIndex(r *http.Request, req *StringRequest, re
found := false
for _, v := range pending {
var ext ctypes.Extrinsic
err := ctypes.DecodeFromBytes(v.Extrinsic[1:], &ext)
err := ctypes.DecodeFromBytes(v.Extrinsic, &ext)
if err != nil {
return err
}
extSigner, err := common.HexToBytes(fmt.Sprintf("0x%x", ext.Signature.Signer.AsAccountID))
if err != nil {
return err
}
if bytes.Equal(extSigner, addressPubKey) {

extSigner := [32]byte(ext.Signature.Signer.AsID)
if bytes.Equal(extSigner[:], addressPubKey) {
found = true
sigNonce := big.Int(ext.Signature.Nonce)
if sigNonce.Uint64() > nonce {
Expand Down
10 changes: 5 additions & 5 deletions dot/rpc/modules/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ func TestSystemModule_AccountNextIndex_StoragePending(t *testing.T) {
}
err := sys.AccountNextIndex(nil, &req, res)
require.NoError(t, err)

require.Equal(t, expectedStored, *res)

// extrinsic for transfer signed by alice, nonce 4 (created with polkadot.js/api test_transaction)
signedExt := common.MustHexToBytes("0x022d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d018c35943da8a04f06a36db9fadc7b2f02ccdef38dd89f88835c0af16b5fce816b117d8073aca078984d5b81bcf86e89cfa3195e5ec3c457d4282370b854f430850010000600ff90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22e5c0")
signedExt := common.MustHexToBytes("0xad018400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0146d0050619728683af4e9659bf202aeb2b8b13b48a875adb663f449f1a71453903546f3252193964185eb91c482cf95caf327db407d57ebda95046b5ef890187001000000108abcd")
vtx := &transaction.ValidTransaction{
Extrinsic: types.NewExtrinsic(signedExt),
Validity: new(transaction.Validity),
Expand Down Expand Up @@ -269,7 +268,7 @@ func TestSystemModule_AccountNextIndex_Pending(t *testing.T) {
}

// extrinsic for transfer signed by alice, nonce 4 (created with polkadot.js/api test_transaction)
signedExt := common.MustHexToBytes("0x022d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d018c35943da8a04f06a36db9fadc7b2f02ccdef38dd89f88835c0af16b5fce816b117d8073aca078984d5b81bcf86e89cfa3195e5ec3c457d4282370b854f430850010000600ff90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22e5c0")
signedExt := common.MustHexToBytes("0xad018400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0146d0050619728683af4e9659bf202aeb2b8b13b48a875adb663f449f1a71453903546f3252193964185eb91c482cf95caf327db407d57ebda95046b5ef890187001000000108abcd")
vtx := &transaction.ValidTransaction{
Extrinsic: types.NewExtrinsic(signedExt),
Validity: new(transaction.Validity),
Expand All @@ -292,9 +291,10 @@ func setupSystemModule(t *testing.T) *SystemModule {

aliceAcctStoKey, err := common.HexToBytes("0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d")
require.NoError(t, err)

aliceAcctInfo := types.AccountInfo{
Nonce: 3,
RefCount: 0,
Nonce: 3,
//RefCount: 0,
Data: struct {
Free common.Uint128
Reserved common.Uint128
Expand Down
7 changes: 3 additions & 4 deletions dot/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
// AccountInfo Information of an account.
type AccountInfo struct {
// The number of transactions this account has sent.
Nonce uint32
// The number of other modules that currently depend on this account's existence. The account
// cannot be reaped until this is zero.
RefCount uint32
Nonce uint32
Consumers uint32
Producers 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
Expand Down
4 changes: 2 additions & 2 deletions dot/types/extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"bytes"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/centrifuge/go-substrate-rpc-client/v2/scale"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v2/types"
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

// Extrinsic is a generic transaction whose format is verified in the runtime
Expand Down
18 changes: 4 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@ module github.com/ChainSafe/gossamer

require (
github.com/ChainSafe/chaindb v0.1.5-0.20210608140454-9606fe8c3985
github.com/ChainSafe/go-schnorrkel v0.0.0-20210222182958-bd440c890782
github.com/ChainSafe/go-schnorrkel v0.0.0-20210318173838-ccb5cd955283
github.com/ChainSafe/log15 v1.0.0
github.com/OneOfOne/xxhash v1.2.5
github.com/btcsuite/btcutil v1.0.2
github.com/bytecodealliance/wasmtime-go v0.20.0
github.com/centrifuge/go-substrate-rpc-client/v2 v2.0.1
github.com/centrifuge/go-substrate-rpc-client/v3 v3.0.0
github.com/chyeh/pubip v0.0.0-20170203095919-b7e679cf541c
github.com/cosmos/go-bip39 v1.0.0
github.com/dgraph-io/badger/v2 v2.2007.2
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de
github.com/disiqueira/gotree v1.0.0
github.com/docker/docker v1.13.1
github.com/elastic/gosigar v0.14.0 // indirect
github.com/ethereum/go-ethereum v1.9.7
github.com/ethereum/go-ethereum v1.10.2
github.com/go-playground/validator/v10 v10.4.1
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.5 // indirect
github.com/gorilla/mux v1.7.4
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
github.com/gtank/merlin v0.1.1
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3
github.com/huin/goupnp v1.0.1-0.20200620063722-49508fba0031 // indirect
github.com/ipfs/go-ds-badger2 v0.1.0
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jpillora/ipfilter v1.2.2
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/libp2p/go-libp2p v0.14.2
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-discovery v0.5.0
Expand All @@ -43,18 +37,14 @@ require (
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/multiformats/go-multiaddr v0.3.1
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/perlin-network/life v0.0.0-20191203030451-05c0e0f7eaea
github.com/rs/cors v1.7.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
github.com/urfave/cli v1.20.0
github.com/urfave/cli v1.22.1
github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/protobuf v1.26.0-rc.1
)

Expand Down
Loading