Skip to content

Commit

Permalink
Merge branch 'development' into ed/fix_no-telemetry_flag
Browse files Browse the repository at this point in the history
  • Loading branch information
noot authored Jul 6, 2021
2 parents d48501b + 6fbf2fd commit 6e89d83
Show file tree
Hide file tree
Showing 50 changed files with 2,135 additions and 1,043 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
27 changes: 14 additions & 13 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 @@ -96,7 +97,7 @@ func NewAuthorModule(logger log.Logger, coreAPI CoreAPI, runtimeAPI RuntimeAPI,
}

// InsertKey inserts a key into the keystore
func (cm *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, res *KeyInsertResponse) error {
func (am *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, res *KeyInsertResponse) error {
keyReq := *req

pkDec, err := common.HexToBytes(keyReq[1])
Expand All @@ -118,22 +119,22 @@ func (cm *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, res *K
return fmt.Errorf("generated public key does not equal provide public key")
}

cm.coreAPI.InsertKey(keyPair)
cm.logger.Info("inserted key into keystore", "key", keyPair.Public().Hex())
am.coreAPI.InsertKey(keyPair)
am.logger.Info("inserted key into keystore", "key", keyPair.Public().Hex())
return nil
}

// HasKey Checks if the keystore has private keys for the given public key and key type.
func (cm *AuthorModule) HasKey(r *http.Request, req *[]string, res *bool) error {
func (am *AuthorModule) HasKey(r *http.Request, req *[]string, res *bool) error {
reqKey := *req
var err error
*res, err = cm.coreAPI.HasKey(reqKey[0], reqKey[1])
*res, err = am.coreAPI.HasKey(reqKey[0], reqKey[1])
return err
}

// PendingExtrinsics Returns all pending extrinsics
func (cm *AuthorModule) PendingExtrinsics(r *http.Request, req *EmptyRequest, res *PendingExtrinsicsResponse) error {
pending := cm.txStateAPI.Pending()
func (am *AuthorModule) PendingExtrinsics(r *http.Request, req *EmptyRequest, res *PendingExtrinsicsResponse) error {
pending := am.txStateAPI.Pending()
resp := make([]string, len(pending))
for idx, tx := range pending {
resp[idx] = common.BytesToHex(tx.Extrinsic)
Expand All @@ -144,30 +145,30 @@ func (cm *AuthorModule) PendingExtrinsics(r *http.Request, req *EmptyRequest, re
}

// RemoveExtrinsic Remove given extrinsic from the pool and temporarily ban it to prevent reimporting
func (cm *AuthorModule) RemoveExtrinsic(r *http.Request, req *ExtrinsicOrHashRequest, res *RemoveExtrinsicsResponse) error {
func (am *AuthorModule) RemoveExtrinsic(r *http.Request, req *ExtrinsicOrHashRequest, res *RemoveExtrinsicsResponse) error {
return nil
}

// RotateKeys Generate new session keys and returns the corresponding public keys
func (cm *AuthorModule) RotateKeys(r *http.Request, req *EmptyRequest, res *KeyRotateResponse) error {
func (am *AuthorModule) RotateKeys(r *http.Request, req *EmptyRequest, res *KeyRotateResponse) error {
return nil
}

// SubmitAndWatchExtrinsic Submit and subscribe to watch an extrinsic until unsubscribed
func (cm *AuthorModule) SubmitAndWatchExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicStatus) error {
func (am *AuthorModule) SubmitAndWatchExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicStatus) error {
return nil
}

// SubmitExtrinsic Submit a fully formatted extrinsic for block inclusion
func (cm *AuthorModule) SubmitExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicHashResponse) error {
func (am *AuthorModule) SubmitExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicHashResponse) error {
extBytes, err := common.HexToBytes(req.Data)
if err != nil {
return err
}
ext := types.Extrinsic(extBytes)
cm.logger.Crit("[rpc]", "extrinsic", ext)
am.logger.Crit("[rpc]", "extrinsic", ext)

err = cm.coreAPI.HandleSubmittedExtrinsic(ext)
*res = ExtrinsicHashResponse(ext.Hash().String())
err = am.coreAPI.HandleSubmittedExtrinsic(ext)
return err
}
Loading

0 comments on commit 6e89d83

Please sign in to comment.