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 24 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
9 changes: 7 additions & 2 deletions chain/dev/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"id": "dev",
"chainType": "Local",
"bootNodes": [],
"telemetryEndpoints": null,
"telemetryEndpoints": [
[
"wss://telemetry.polkadot.io/submit/",
0
]
],
"protocolId": "/gossamer/dev/0",
"genesis": {
"raw": {
Expand Down Expand Up @@ -32,4 +37,4 @@
"forkBlocks": null,
"badBlocks": null,
"consensusEngine": ""
}
}
8 changes: 7 additions & 1 deletion chain/gssmr/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"id": "gssmr",
"chainType": "Local",
"bootNodes": [],
"telemetryEndpoints": [
[
"wss://telemetry.polkadot.io/submit/",
0
]
],
"protocolId": "/gossamer/gssmr/0",
"genesis": {
"raw": {
Expand Down Expand Up @@ -40,4 +46,4 @@
"forkBlocks": null,
"badBlocks": null,
"consensusEngine": ""
}
}
5 changes: 5 additions & 0 deletions dot/core/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (s *Service) HandleTransactionMessage(msg *network.TransactionMessage) (boo

return len(msg.Extrinsics) > 0, nil
}

// TransactionsCount returns number for pending transactions in pool
func (s *Service) TransactionsCount() int {
return len(s.transactionState.PendingInPool())
}
6 changes: 3 additions & 3 deletions dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

. "github.com/ChainSafe/gossamer/dot/core/mocks"
. "github.com/ChainSafe/gossamer/dot/core/mocks" // nolint
"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
Expand All @@ -38,7 +38,7 @@ import (

func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
// TODO: move to sync package
net := new(MockNetwork)
net := new(MockNetwork) // nolint

cfg := &Config{
Network: net,
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestService_HandleTransactionMessage(t *testing.T) {
ks := keystore.NewGlobalKeystore()
ks.Acco.Insert(kp)

bp := new(MockBlockProducer)
bp := new(MockBlockProducer) // nolint
blockC := make(chan types.Block)
bp.On("GetBlockChannel", nil).Return(blockC)

Expand Down
14 changes: 14 additions & 0 deletions dot/network/mock_transaction_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"io"
"math/big"
"os"
"sync"
"time"
Expand Down Expand Up @@ -315,11 +316,12 @@ main:

case <-ticker.C:
o := s.host.bwc.GetBandwidthTotals()
err := telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("bandwidth_download", o.RateIn),
telemetry.NewKeyValue("bandwidth_upload", o.RateOut),
telemetry.NewKeyValue("msg", "system.interval"),
telemetry.NewKeyValue("peers", s.host.peerCount())))
err := telemetry.GetInstance().SendMessage(telemetry.NewBandwidthTM(o.RateIn, o.RateOut, s.host.peerCount()))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}

err = telemetry.GetInstance().SendMessage(telemetry.NewNetworkStateTM(s.host.h, s.Peers()))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}
Expand All @@ -333,19 +335,22 @@ func (s *Service) sentBlockIntervalTelemetry() {
if err != nil {
continue
}
bestHash := best.Hash()

finalized, err := s.blockState.GetFinalizedHeader(0, 0) //nolint
if err != nil {
continue
}

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("best", best.Hash().String()),
telemetry.NewKeyValue("finalized_hash", finalized.Hash().String()), //nolint
telemetry.NewKeyValue("finalized_height", finalized.Number), //nolint
telemetry.NewKeyValue("height", best.Number),
telemetry.NewKeyValue("msg", "system.interval"),
telemetry.NewKeyValue("txcount", 0), // todo (ed) determine where to get tx count
telemetry.NewKeyValue("used_state_cache_size", 0))) // todo (ed) determine where to get used_state_cache_size
finalizedHash := finalized.Hash()

err = telemetry.GetInstance().SendMessage(telemetry.NewBlockIntervalTM(
&bestHash,
best.Number,
&finalizedHash,
finalized.Number,
big.NewInt(int64(s.transactionHandler.TransactionsCount())),
big.NewInt(0), // todo (ed) determine where to get used_state_cache_size
))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}
Expand Down
1 change: 1 addition & 0 deletions dot/network/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func createTestService(t *testing.T, cfg *Config) (srvc *Service) {
if cfg.TransactionHandler == nil {
mocktxhandler := &MockTransactionHandler{}
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*TransactionMessage")).Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
cfg.TransactionHandler = mocktxhandler
}

Expand Down
1 change: 1 addition & 0 deletions dot/network/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ type Syncer interface {
// TransactionHandler is the interface used by the transactions sub-protocol
type TransactionHandler interface {
HandleTransactionMessage(*TransactionMessage) (bool, error)
TransactionsCount() int
}
1 change: 1 addition & 0 deletions dot/network/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewMockSyncer() *MockSyncer {
func NewMockTransactionHandler() *MockTransactionHandler {
mocktxhandler := new(MockTransactionHandler)
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
return mocktxhandler
}

Expand Down
1 change: 1 addition & 0 deletions dot/network/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestHandleTransactionMessage(t *testing.T) {
basePath := utils.NewTestBasePath(t, "nodeA")
mockhandler := &MockTransactionHandler{}
mockhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(true, nil)
mockhandler.On("TransactionsCount").Return(0)

config := &Config{
BasePath: basePath,
Expand Down
21 changes: 10 additions & 11 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,16 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
}

telemetry.GetInstance().AddConnections(gd.TelemetryEndpoints)

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("authority", cfg.Core.GrandpaAuthority),
telemetry.NewKeyValue("chain", sysSrvc.ChainName()),
telemetry.NewKeyValue("genesis_hash", stateSrvc.Block.GenesisHash().String()),
telemetry.NewKeyValue("implementation", sysSrvc.SystemName()),
telemetry.NewKeyValue("msg", "system.connected"),
telemetry.NewKeyValue("name", cfg.Global.Name),
telemetry.NewKeyValue("network_id", networkSrvc.NetworkState().PeerID),
telemetry.NewKeyValue("startup_time", strconv.FormatInt(time.Now().UnixNano(), 10)),
telemetry.NewKeyValue("version", sysSrvc.SystemVersion())))
genesisHash := stateSrvc.Block.GenesisHash()
err = telemetry.GetInstance().SendMessage(telemetry.NewSystemConnectedTM(
cfg.Core.GrandpaAuthority,
sysSrvc.ChainName(),
&genesisHash,
sysSrvc.SystemName(),
cfg.Global.Name,
networkSrvc.NetworkState().PeerID,
strconv.FormatInt(time.Now().UnixNano(), 10),
sysSrvc.SystemVersion()))
if err != nil {
logger.Debug("problem sending system.connected telemetry message", "err", err)
}
Expand Down
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
12 changes: 6 additions & 6 deletions dot/sync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ func (s *Service) handleBlock(block *types.Block) error {

logger.Debug("🔗 imported block", "number", block.Header.Number, "hash", block.Header.Hash())

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage( // nolint
telemetry.NewKeyValue("best", block.Header.Hash().String()),
telemetry.NewKeyValue("height", block.Header.Number.Uint64()),
telemetry.NewKeyValue("msg", "block.import"),
telemetry.NewKeyValue("origin", "NetworkInitialSync")))
blockHash := block.Header.Hash()
err = telemetry.GetInstance().SendMessage(telemetry.NewBlockImportTM(
&blockHash,
block.Header.Number,
"NetworkInitialSync"))
if err != nil {
logger.Trace("problem sending block.import telemetry message", "error", err)
logger.Debug("problem sending block.import telemetry message", "error", err)
}

return nil
Expand Down
Loading