Skip to content

Commit

Permalink
chore: update gssmr genesis to v0.9; stub missing ext_ funcs (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Jul 5, 2021
1 parent 22827e7 commit 67304e2
Show file tree
Hide file tree
Showing 34 changed files with 1,150 additions and 629 deletions.
6 changes: 3 additions & 3 deletions chain/dev/genesis-spec.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.

35 changes: 13 additions & 22 deletions chain/gssmr/genesis.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestConfigFromChainFlag(t *testing.T) {
require.Nil(t, err)
cfg, err := createDotConfig(ctx)
require.Nil(t, err)
cfg.System = types.SystemInfo{}
require.Equal(t, c.expected, cfg)
})
}
Expand Down Expand Up @@ -710,6 +711,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {

cfg.Init.Genesis = genFile.Name()
updateDotConfigFromGenesisJSONRaw(*dotConfigToToml(testCfg), cfg)
cfg.System = types.SystemInfo{}
require.Equal(t, expected, cfg)
}

Expand Down Expand Up @@ -760,6 +762,7 @@ func TestUpdateConfigFromGenesisJSON_Default(t *testing.T) {
cfg, err := createDotConfig(ctx)
require.Nil(t, err)
updateDotConfigFromGenesisJSONRaw(*dotConfigToToml(testCfg), cfg)
cfg.System = types.SystemInfo{}
require.Equal(t, expected, cfg)
}

Expand Down Expand Up @@ -830,7 +833,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {

err = updateDotConfigFromGenesisData(ctx, cfg) // name should not be updated if provided as flag value
require.Nil(t, err)

cfg.System = types.SystemInfo{}
require.Equal(t, expected, cfg)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func newTestContext(description string, flags []string, values []interface{}) (*
}
}

ctx := cli.NewContext(nil, set, nil)
ctx := cli.NewContext(app, set, nil)

for i := range values {
switch v := values[i].(type) {
Expand Down
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
4 changes: 2 additions & 2 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 Expand Up @@ -164,9 +165,8 @@ func (cm *AuthorModule) SubmitExtrinsic(r *http.Request, req *Extrinsic, res *Ex
if err != nil {
return err
}
ext := types.Extrinsic(extBytes)
cm.logger.Crit("[rpc]", "extrinsic", ext)

ext := types.Extrinsic(extBytes)
err = cm.coreAPI.HandleSubmittedExtrinsic(ext)
*res = ExtrinsicHashResponse(ext.Hash().String())
return err
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
2 changes: 1 addition & 1 deletion dot/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (h *Handler) startListening() {

err = conn.wsconn.WriteMessage(websocket.TextMessage, msgBytes)
if err != nil {
h.log.Warn("issue while sending telemetry message", "error", err)
h.log.Debug("issue while sending telemetry message", "error", err)
}
}
}()
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
Loading

0 comments on commit 67304e2

Please sign in to comment.