From ee9ec6094109ac09754e608914b911e97fec86b2 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Thu, 11 Nov 2021 22:23:43 +0530 Subject: [PATCH 1/9] Added more telemetry messages in grandpa client Added telemetry messges of types `afg.finalized_blocks_up_to` and `afg.authority_set` Closes #1841 Closes #1842 --- dot/telemetry/afg_authority_set.go | 44 +++++++++++++++++++++ dot/telemetry/afg_finalized.go | 27 +++++++++++++ dot/telemetry/afg_finalized_blocks_up_to.go | 40 +++++++++++++++++++ dot/telemetry/notify_finalized.go | 2 +- dot/telemetry/telemetry.go | 12 +++--- lib/grandpa/grandpa.go | 34 ++++++++++++++++ 6 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 dot/telemetry/afg_authority_set.go create mode 100644 dot/telemetry/afg_finalized.go create mode 100644 dot/telemetry/afg_finalized_blocks_up_to.go diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go new file mode 100644 index 0000000000..3b36555465 --- /dev/null +++ b/dot/telemetry/afg_authority_set.go @@ -0,0 +1,44 @@ +// Copyright 2021 ChainSafe Systems (ON) Corp. +// This file is part of gossamer. +// +// The gossamer library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The gossamer library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the gossamer library. If not, see . + +package telemetry + +// afgAuthoritySetTM is a telemetry message of type `afg.authority_set` which is +// meant to be sent when authority set changes (generally when a round is initiated) +type afgAuthoritySetTM struct { + // finalized hash and finalized number are sent by substrate, but not ready by + // substrate telemetry + // FinalizedHash *common.Hash `json:"hash"` + // FinalizedNumber string `json:"number"` + AuthorityID string `json:"authority_id"` + AuthoritySetID string `json:"authority_set_id"` + // Substrate creates an array of string of authority IDs. It JSON-serializes + // that array and send that as a string. + Authorities string `json:"authorities"` +} + +// NewAfgAuthoritySetTM creates a new afgAuthoritySetTM struct. +func NewAfgAuthoritySetTM(authorityID, authoritySetID string, authorities string) Message { + return &afgAuthoritySetTM{ + AuthorityID: authorityID, + AuthoritySetID: authoritySetID, + Authorities: authorities, + } +} + +func (afgAuthoritySetTM) messageType() string { + return afgAuthoritySetMsg +} diff --git a/dot/telemetry/afg_finalized.go b/dot/telemetry/afg_finalized.go new file mode 100644 index 0000000000..cde13e5fa1 --- /dev/null +++ b/dot/telemetry/afg_finalized.go @@ -0,0 +1,27 @@ +// Copyright 2021 ChainSafe Systems (ON) Corp. +// This file is part of gossamer. +// +// The gossamer library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The gossamer library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the gossamer library. If not, see . + +package telemetry + +import ( + "github.com/ChainSafe/gossamer/lib/common" +) + +// TODO: Why is this not being sent by substrate? +type afgFinalizedTM struct { + FinalizedHash *common.Hash `json:"finalized_hash"` + FinalizedNumber string `json:"finalized_number"` +} diff --git a/dot/telemetry/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go new file mode 100644 index 0000000000..cef2bbd556 --- /dev/null +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -0,0 +1,40 @@ +// Copyright 2021 ChainSafe Systems (ON) Corp. +// This file is part of gossamer. +// +// The gossamer library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The gossamer library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the gossamer library. If not, see . + +package telemetry + +import ( + "github.com/ChainSafe/gossamer/lib/common" +) + +// afgFinalizedBlocksUpToTM holds telemetry message of type `afg.finalized_blocks_up_to`, +// which is supposed to be send GRANDPA client finalizes new blocks. +type afgFinalizedBlocksUpToTM struct { + Hash common.Hash `json:"hash"` + Number string `json:"number"` +} + +// NewAfgFinalizedBlocksUpToTM creates a new afgFinalizedBlocksUpToTM struct. +func NewAfgFinalizedBlocksUpToTM(hash common.Hash, number string) Message { + return &afgFinalizedBlocksUpToTM{ + Hash: hash, + Number: number, + } +} + +func (afgFinalizedBlocksUpToTM) messageType() string { + return afgFinalizedBlocksUpToMsg +} diff --git a/dot/telemetry/notify_finalized.go b/dot/telemetry/notify_finalized.go index 9f29c3df38..e3769ecb3f 100644 --- a/dot/telemetry/notify_finalized.go +++ b/dot/telemetry/notify_finalized.go @@ -29,7 +29,7 @@ type notifyFinalizedTM struct { Height string `json:"height"` } -// NewNotifyFinalizedTM gets a new NotifyFinalizedTM struct. +// NewNotifyFinalizedTM gets a new notifyFinalizedTM struct. func NewNotifyFinalizedTM(best common.Hash, height string) Message { return ¬ifyFinalizedTM{ Best: best, diff --git a/dot/telemetry/telemetry.go b/dot/telemetry/telemetry.go index 1d52e09d2b..dd086bb9d0 100644 --- a/dot/telemetry/telemetry.go +++ b/dot/telemetry/telemetry.go @@ -29,11 +29,13 @@ import ( // telemetry message types const ( - notifyFinalizedMsg = "notify.finalized" - blockImportMsg = "block.import" - systemNetworkStateMsg = "system.network_state" - systemConnectedMsg = "system.connected" - systemIntervalMsg = "system.interval" + notifyFinalizedMsg = "notify.finalized" + blockImportMsg = "block.import" + systemNetworkStateMsg = "system.network_state" + systemConnectedMsg = "system.connected" + systemIntervalMsg = "system.interval" + afgFinalizedBlocksUpToMsg = "afg.finalized_blocks_up_to" + afgAuthoritySetMsg = "afg.authority_set" ) type telemetryConnection struct { diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 8d5132a478..3850623e2c 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -19,6 +19,7 @@ package grandpa import ( "bytes" "context" + "encoding/json" "errors" "fmt" "math/big" @@ -26,6 +27,7 @@ import ( "sync/atomic" "time" + "github.com/ChainSafe/gossamer/dot/telemetry" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/blocktree" @@ -263,6 +265,29 @@ func (s *Service) updateAuthorities() error { s.state.voters = nextAuthorities s.state.setID = currSetID s.state.round = 0 // round resets to 1 after a set ID change, setting to 0 before incrementing indicates the setID has been increased + + authorityID := s.keypair.Public().Hex() + authorities := make([]string, len(s.state.voters)) + for i, voter := range s.state.voters { + authorities[i] = fmt.Sprintf("%d", voter.ID) + } + + authoritiesBytes, err := json.Marshal(authorities) + if err != nil { + return err + } + + err = telemetry.GetInstance().SendMessage( + telemetry.NewAfgAuthoritySetTM( + authorityID, + fmt.Sprintf("%d", s.state.setID), + string(authoritiesBytes), + ), + ) + if err != nil { + logger.Debugf("problem sending afg.authority_set telemetry message: %s", err) + } + return nil } @@ -612,6 +637,15 @@ func (s *Service) attemptToFinalize() error { logger.Debugf("sending CommitMessage: %v", cm) s.network.GossipMessage(msg) + + err = telemetry.GetInstance().SendMessage(telemetry.NewAfgFinalizedBlocksUpToTM( + s.head.Hash(), + s.head.Number.String(), + )) + if err != nil { + logger.Debugf("problem sending `afg.finalized_blocks_up_to` telemetry message: %s", err) + } + return nil } } From 1b4035f8010ea5b18e5999d128566698e8fff6c7 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Mon, 15 Nov 2021 19:35:35 +0530 Subject: [PATCH 2/9] fixed lint --- dot/telemetry/afg_authority_set.go | 5 ++-- dot/telemetry/afg_finalized.go | 27 --------------------- dot/telemetry/afg_finalized_blocks_up_to.go | 1 + 3 files changed, 4 insertions(+), 29 deletions(-) delete mode 100644 dot/telemetry/afg_finalized.go diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go index 3b36555465..6fc444dc1a 100644 --- a/dot/telemetry/afg_authority_set.go +++ b/dot/telemetry/afg_authority_set.go @@ -19,13 +19,14 @@ package telemetry // afgAuthoritySetTM is a telemetry message of type `afg.authority_set` which is // meant to be sent when authority set changes (generally when a round is initiated) type afgAuthoritySetTM struct { - // finalized hash and finalized number are sent by substrate, but not ready by + //nolint + // finalized hash and finalized number are sent by substrate, but not read by // substrate telemetry // FinalizedHash *common.Hash `json:"hash"` // FinalizedNumber string `json:"number"` AuthorityID string `json:"authority_id"` AuthoritySetID string `json:"authority_set_id"` - // Substrate creates an array of string of authority IDs. It JSON-serializes + // Substrate creates an array of string of authority IDs. It JSON-serialises // that array and send that as a string. Authorities string `json:"authorities"` } diff --git a/dot/telemetry/afg_finalized.go b/dot/telemetry/afg_finalized.go deleted file mode 100644 index cde13e5fa1..0000000000 --- a/dot/telemetry/afg_finalized.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) Corp. -// This file is part of gossamer. -// -// The gossamer library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The gossamer library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the gossamer library. If not, see . - -package telemetry - -import ( - "github.com/ChainSafe/gossamer/lib/common" -) - -// TODO: Why is this not being sent by substrate? -type afgFinalizedTM struct { - FinalizedHash *common.Hash `json:"finalized_hash"` - FinalizedNumber string `json:"finalized_number"` -} diff --git a/dot/telemetry/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go index cef2bbd556..0c0834eeb1 100644 --- a/dot/telemetry/afg_finalized_blocks_up_to.go +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -20,6 +20,7 @@ import ( "github.com/ChainSafe/gossamer/lib/common" ) +//nolint // afgFinalizedBlocksUpToTM holds telemetry message of type `afg.finalized_blocks_up_to`, // which is supposed to be send GRANDPA client finalizes new blocks. type afgFinalizedBlocksUpToTM struct { From 472bebdf7d3d372fdb1fbd31ce410c84a1fe9cc9 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Mon, 15 Nov 2021 19:41:57 +0530 Subject: [PATCH 3/9] Added tests --- dot/telemetry/telemetry_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dot/telemetry/telemetry_test.go b/dot/telemetry/telemetry_test.go index 5785f80d93..7aef395781 100644 --- a/dot/telemetry/telemetry_test.go +++ b/dot/telemetry/telemetry_test.go @@ -53,6 +53,8 @@ func TestHandler_SendMulti(t *testing.T) { []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`), []byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`), []byte(`{"future":2,"msg":"txpool.import","ready":1,"ts":`), + []byte(`{"authorities":"json-stringified-ids-of-authorities","authority_id":"authority_id","authority_set_id":"authority_set_id","msg":"afg.authority_set","ts`), + []byte(`{"hash":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","msg":"afg.finalized_blocks_up_to","number":"1","ts":`), } messages := []Message{ @@ -78,6 +80,8 @@ func TestHandler_SendMulti(t *testing.T) { NewNotifyFinalizedTM(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "32375"), NewPreparedBlockForProposingTM(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1"), + NewAfgAuthoritySetTM("authority_id", "authority_set_id", "json-stringified-ids-of-authorities"), + NewAfgFinalizedBlocksUpToTM(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), } resultCh = make(chan []byte) From c519d6688ad21fa9cbaa89b32e6111485e20fa4b Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Tue, 16 Nov 2021 19:19:56 +0530 Subject: [PATCH 4/9] Send afg.authority_set once every grandpa round --- lib/grandpa/grandpa.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 6dd9ddb283..651a0cb36c 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -253,6 +253,14 @@ func (s *Service) updateAuthorities() error { s.state.setID = currSetID s.state.round = 0 // round resets to 1 after a set ID change, setting to 0 before incrementing indicates the setID has been increased + return nil +} + +func (s *Service) publicKeyBytes() ed25519.PublicKeyBytes { + return s.keypair.Public().(*ed25519.PublicKey).AsBytes() +} + +func (s *Service) sendTelemetryAuthoritySet() { authorityID := s.keypair.Public().Hex() authorities := make([]string, len(s.state.voters)) for i, voter := range s.state.voters { @@ -261,7 +269,8 @@ func (s *Service) updateAuthorities() error { authoritiesBytes, err := json.Marshal(authorities) if err != nil { - return err + logger.Debugf("could not marshal authorities: %s", err) + return } err = telemetry.GetInstance().SendMessage( @@ -274,12 +283,6 @@ func (s *Service) updateAuthorities() error { if err != nil { logger.Debugf("problem sending afg.authority_set telemetry message: %s", err) } - - return nil -} - -func (s *Service) publicKeyBytes() ed25519.PublicKeyBytes { - return s.keypair.Public().(*ed25519.PublicKey).AsBytes() } func (s *Service) initiateRound() error { @@ -289,6 +292,8 @@ func (s *Service) initiateRound() error { return err } + s.sendTelemetryAuthoritySet() + round, setID, err := s.blockState.GetHighestRoundAndSetID() if err != nil { return err From 281d5cbb2fbd780f1c4985fad012c07dc8857c66 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 24 Nov 2021 21:41:25 +0530 Subject: [PATCH 5/9] Addressed some reviews --- dot/telemetry/afg_authority_set.go | 1 - dot/telemetry/afg_finalized_blocks_up_to.go | 3 +-- lib/grandpa/grandpa.go | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go index 6fc444dc1a..bb460ae152 100644 --- a/dot/telemetry/afg_authority_set.go +++ b/dot/telemetry/afg_authority_set.go @@ -19,7 +19,6 @@ package telemetry // afgAuthoritySetTM is a telemetry message of type `afg.authority_set` which is // meant to be sent when authority set changes (generally when a round is initiated) type afgAuthoritySetTM struct { - //nolint // finalized hash and finalized number are sent by substrate, but not read by // substrate telemetry // FinalizedHash *common.Hash `json:"hash"` diff --git a/dot/telemetry/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go index 0c0834eeb1..c192a858c5 100644 --- a/dot/telemetry/afg_finalized_blocks_up_to.go +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -20,9 +20,8 @@ import ( "github.com/ChainSafe/gossamer/lib/common" ) -//nolint // afgFinalizedBlocksUpToTM holds telemetry message of type `afg.finalized_blocks_up_to`, -// which is supposed to be send GRANDPA client finalizes new blocks. +// which is supposed to be send GRANDPA client finalises new blocks. type afgFinalizedBlocksUpToTM struct { Hash common.Hash `json:"hash"` Number string `json:"number"` diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 054d4c8a3f..093801b3fe 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -252,6 +252,8 @@ func (s *Service) updateAuthorities() error { s.state.setID = currSetID s.state.round = 0 // round resets to 1 after a set ID change, setting to 0 before incrementing indicates the setID has been increased + s.sendTelemetryAuthoritySet() + return nil } @@ -291,8 +293,6 @@ func (s *Service) initiateRound() error { return err } - s.sendTelemetryAuthoritySet() - round, setID, err := s.blockState.GetHighestRoundAndSetID() if err != nil { return err From dddf967ac56683c0f7bcc8091bbab8d756949dcd Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Fri, 26 Nov 2021 19:13:45 +0530 Subject: [PATCH 6/9] fix linting --- dot/telemetry/telemetry_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dot/telemetry/telemetry_test.go b/dot/telemetry/telemetry_test.go index 782a886aeb..6a38ce9dc7 100644 --- a/dot/telemetry/telemetry_test.go +++ b/dot/telemetry/telemetry_test.go @@ -79,7 +79,8 @@ func TestHandler_SendMulti(t *testing.T) { ), NewAfgAuthoritySetTM("authority_id", "authority_set_id", "json-stringified-ids-of-authorities"), - NewAfgFinalizedBlocksUpToTM(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), + NewAfgFinalizedBlocksUpToTM( + common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), NewNotifyFinalizedTM( common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "32375"), From 02c073da73c6b0fdeb3367694379980e449856f5 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Fri, 26 Nov 2021 20:14:54 +0530 Subject: [PATCH 7/9] addressed reviews --- dot/telemetry/afg_authority_set.go | 19 +++---------------- dot/telemetry/afg_finalized_blocks_up_to.go | 19 +++---------------- dot/telemetry/telemetry_test.go | 8 ++++---- dot/telemetry/txpool_import.go | 17 ++--------------- lib/grandpa/grandpa.go | 6 +++--- 5 files changed, 15 insertions(+), 54 deletions(-) diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go index bb460ae152..6599b02ba2 100644 --- a/dot/telemetry/afg_authority_set.go +++ b/dot/telemetry/afg_authority_set.go @@ -1,18 +1,5 @@ -// Copyright 2021 ChainSafe Systems (ON) Corp. -// This file is part of gossamer. -// -// The gossamer library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The gossamer library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the gossamer library. If not, see . +// Copyright 2021 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only package telemetry @@ -31,7 +18,7 @@ type afgAuthoritySetTM struct { } // NewAfgAuthoritySetTM creates a new afgAuthoritySetTM struct. -func NewAfgAuthoritySetTM(authorityID, authoritySetID string, authorities string) Message { +func NewAfgAuthoritySetTM(authorityID, authoritySetID, authorities string) Message { return &afgAuthoritySetTM{ AuthorityID: authorityID, AuthoritySetID: authoritySetID, diff --git a/dot/telemetry/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go index c192a858c5..0b63c8559d 100644 --- a/dot/telemetry/afg_finalized_blocks_up_to.go +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -1,18 +1,5 @@ -// Copyright 2021 ChainSafe Systems (ON) Corp. -// This file is part of gossamer. -// -// The gossamer library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The gossamer library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the gossamer library. If not, see . +// Copyright 2021 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only package telemetry @@ -21,7 +8,7 @@ import ( ) // afgFinalizedBlocksUpToTM holds telemetry message of type `afg.finalized_blocks_up_to`, -// which is supposed to be send GRANDPA client finalises new blocks. +// which is supposed to be sent when GRANDPA client finalises new blocks. type afgFinalizedBlocksUpToTM struct { Hash common.Hash `json:"hash"` Number string `json:"number"` diff --git a/dot/telemetry/telemetry_test.go b/dot/telemetry/telemetry_test.go index 6a38ce9dc7..14ab12aca4 100644 --- a/dot/telemetry/telemetry_test.go +++ b/dot/telemetry/telemetry_test.go @@ -47,14 +47,14 @@ func TestMain(m *testing.M) { func TestHandler_SendMulti(t *testing.T) { expected := [][]byte{ []byte(`{"authority":false,"chain":"chain","genesis_hash":"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3","implementation":"systemName","msg":"system.connected","name":"nodeName","network_id":"netID","startup_time":"startTime","ts":`), //nolint:lll - []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":2,"msg":"block.import","origin":"NetworkInitialSync","ts":`), //nolint //nolint:lll + []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":2,"msg":"block.import","origin":"NetworkInitialSync","ts":`), //nolint:lll []byte(`{"bandwidth_download":2,"bandwidth_upload":3,"msg":"system.interval","peers":1,"ts":`), []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","finalized_hash":"0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2","finalized_height":32256,"height":32375,"msg":"system.interval","ts":`), //nolint:lll []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`), //nolint:lll - []byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`), //nolint //nolint:lll + []byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`), //nolint:lll []byte(`{"future":2,"msg":"txpool.import","ready":1,"ts":`), - []byte(`{"authorities":"json-stringified-ids-of-authorities","authority_id":"authority_id","authority_set_id":"authority_set_id","msg":"afg.authority_set","ts`), //nolint - []byte(`{"hash":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","msg":"afg.finalized_blocks_up_to","number":"1","ts":`), //nolint + []byte(`{"authorities":"json-stringified-ids-of-authorities","authority_id":"authority_id","authority_set_id":"authority_set_id","msg":"afg.authority_set","ts`), //nolint:lll + []byte(`{"hash":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","msg":"afg.finalized_blocks_up_to","number":"1","ts":`), //nolint:lll } messages := []Message{ diff --git a/dot/telemetry/txpool_import.go b/dot/telemetry/txpool_import.go index eb5abec889..9da38c1a58 100644 --- a/dot/telemetry/txpool_import.go +++ b/dot/telemetry/txpool_import.go @@ -1,18 +1,5 @@ -// Copyright 2021 ChainSafe Systems (ON) Corp. -// This file is part of gossamer. -// -// The gossamer library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The gossamer library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the gossamer library. If not, see . +// Copyright 2021 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only package telemetry diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 26d3578cef..a0dd83cc6b 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -274,19 +274,19 @@ func (s *Service) sendTelemetryAuthoritySet() { authorityID := s.keypair.Public().Hex() authorities := make([]string, len(s.state.voters)) for i, voter := range s.state.voters { - authorities[i] = fmt.Sprintf("%d", voter.ID) + authorities[i] = fmt.Sprint(voter.ID) } authoritiesBytes, err := json.Marshal(authorities) if err != nil { - logger.Debugf("could not marshal authorities: %s", err) + logger.Warnf("could not marshal authorities: %s", err) return } err = telemetry.GetInstance().SendMessage( telemetry.NewAfgAuthoritySetTM( authorityID, - fmt.Sprintf("%d", s.state.setID), + fmt.Sprint(s.state.setID), string(authoritiesBytes), ), ) From 1f735a8f49bc3cea99601682b7286992aeef929d Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Fri, 26 Nov 2021 20:20:24 +0530 Subject: [PATCH 8/9] change ordering --- dot/telemetry/telemetry.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dot/telemetry/telemetry.go b/dot/telemetry/telemetry.go index 06b2e7e08d..4b1b31da26 100644 --- a/dot/telemetry/telemetry.go +++ b/dot/telemetry/telemetry.go @@ -16,13 +16,13 @@ import ( // telemetry message types const ( - notifyFinalizedMsg = "notify.finalized" + afgAuthoritySetMsg = "afg.authority_set" + afgFinalizedBlocksUpToMsg = "afg.finalized_blocks_up_to" blockImportMsg = "block.import" - systemNetworkStateMsg = "system.network_state" + notifyFinalizedMsg = "notify.finalized" systemConnectedMsg = "system.connected" systemIntervalMsg = "system.interval" - afgFinalizedBlocksUpToMsg = "afg.finalized_blocks_up_to" - afgAuthoritySetMsg = "afg.authority_set" + systemNetworkStateMsg = "system.network_state" txPoolImportMsg = "txpool.import" preparedBlockForProposingMsg = "prepared_block_for_proposing" ) From 6a7cdfb27fe4afac7c786b3393fa0aaa46c92208 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 1 Dec 2021 00:08:04 +0530 Subject: [PATCH 9/9] addressed reviews --- dot/telemetry/afg_authority_set.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go index 6599b02ba2..233df980cc 100644 --- a/dot/telemetry/afg_authority_set.go +++ b/dot/telemetry/afg_authority_set.go @@ -6,10 +6,6 @@ package telemetry // afgAuthoritySetTM is a telemetry message of type `afg.authority_set` which is // meant to be sent when authority set changes (generally when a round is initiated) type afgAuthoritySetTM struct { - // finalized hash and finalized number are sent by substrate, but not read by - // substrate telemetry - // FinalizedHash *common.Hash `json:"hash"` - // FinalizedNumber string `json:"number"` AuthorityID string `json:"authority_id"` AuthoritySetID string `json:"authority_set_id"` // Substrate creates an array of string of authority IDs. It JSON-serialises