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

feat(telemetry): send telemetry messages when GRANDPA receieves commit or vote messages #2015

Merged
merged 11 commits into from
Nov 30, 2021
Merged
69 changes: 69 additions & 0 deletions dot/telemetry/afg_received.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package telemetry

import "github.com/ChainSafe/gossamer/lib/common"

// AfG ("Al's Finality Gadget") is synonymous with GRANDPA.
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

type afgReceivedTM struct {
TargetHash common.Hash `json:"target_hash"`
TargetNumber string `json:"target_number"`
Voter string `json:"voter"`
}

// afgReceivedPrecommitTM holds `afg.received_precommit` telemetry message which is
// supposed to be sent when grandpa client receives a precommit.
type afgReceivedPrecommitTM afgReceivedTM

// NewAfgReceivedPrecommitTM gets a new afgReceivedPrecommitTM struct.
func NewAfgReceivedPrecommitTM(targetHash common.Hash, targetNumber, voter string) Message {
return &afgReceivedPrecommitTM{
TargetHash: targetHash,
TargetNumber: targetNumber,
Voter: voter,
}
}

func (afgReceivedPrecommitTM) messageType() string {
return afgReceivedPrecommitMsg
}

// afgReceivedPrevoteTM holds `afg.received_prevote` telemetry message which is
// supposed to be sent when grandpa client receives a prevote.
type afgReceivedPrevoteTM afgReceivedTM

// NewAfgReceivedPrevoteTM gets a new afgReceivedPrevoteTM struct.
func NewAfgReceivedPrevoteTM(targetHash common.Hash, targetNumber, voter string) Message {
return &afgReceivedPrevoteTM{
TargetHash: targetHash,
TargetNumber: targetNumber,
Voter: voter,
}
}

func (afgReceivedPrevoteTM) messageType() string {
return afgReceivedPrevoteMsg
}

// afgReceivedCommitTM holds `afg.received_commit` telemetry message which is
// supposed to be sent when grandpa client receives a commit.
type afgReceivedCommitTM struct {
TargetHash common.Hash `json:"target_hash"`
TargetNumber string `json:"target_number"`
ContainsPrecommitsSignedBy []string `json:"contains_precommits_signed_by"`
}

// NewAfgReceivedCommitTM gets a new afgReceivedCommitTM struct.
func NewAfgReceivedCommitTM(targetHash common.Hash, targetNumber string, containsPrecommitsSignedBy []string) Message {
return &afgReceivedCommitTM{
TargetHash: targetHash,
TargetNumber: targetNumber,
ContainsPrecommitsSignedBy: containsPrecommitsSignedBy,
}
}

func (afgReceivedCommitTM) messageType() string {
return afgReceivedCommitMsg
}
9 changes: 6 additions & 3 deletions dot/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import (

// telemetry message types
const (
notifyFinalizedMsg = "notify.finalized"
blockImportMsg = "block.import"
systemNetworkStateMsg = "system.network_state"
systemConnectedMsg = "system.connected"
systemIntervalMsg = "system.interval"
systemNetworkStateMsg = "system.network_state"
blockImportMsg = "block.import"
notifyFinalizedMsg = "notify.finalized"
afgReceivedPrecommitMsg = "afg.received_precommit"
afgReceivedPrevoteMsg = "afg.received_prevote"
afgReceivedCommitMsg = "afg.received_commit"
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
txPoolImportMsg = "txpool.import"
preparedBlockForProposingMsg = "prepared_block_for_proposing"
)
Expand Down
13 changes: 13 additions & 0 deletions dot/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func TestHandler_SendMulti(t *testing.T) {
[]byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`), //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(`{"contains_precommits_signed_by":[],"msg":"afg.received_commit","target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","ts":`), //nolint:lll
[]byte(`{"msg":"afg.received_precommit","target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","ts":`), //nolint:lll
[]byte(`{"msg":"afg.received_prevote","target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","ts":`), //nolint:lll
}

messages := []Message{
Expand All @@ -76,6 +79,16 @@ func TestHandler_SendMulti(t *testing.T) {
common.MustHexToHash("0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2"),
),

NewAfgReceivedCommitTM(
common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"),
"1", []string{}),
NewAfgReceivedPrecommitTM(
common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"),
"1", ""),
NewAfgReceivedPrevoteTM(
common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"),
"1", ""),

NewNotifyFinalizedTM(
common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"),
"32375"),
Expand Down
17 changes: 2 additions & 15 deletions dot/telemetry/txpool_import.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package telemetry

Expand Down
4 changes: 3 additions & 1 deletion lib/grandpa/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ func (s *Service) playGrandpaRound() error {
go s.sendVoteMessage(prevote, vm, roundComplete)

logger.Debug("receiving pre-commit messages...")
// through goroutine s.receiveMessages(ctx)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(s.interval)

if s.paused.Load().(bool) {
Expand Down Expand Up @@ -526,9 +527,10 @@ func (s *Service) sendVoteMessage(stage Subround, msg *VoteMessage, roundComplet

if err := s.sendMessage(msg); err != nil {
logger.Warnf("could not send message for stage %s: %s", stage, err)
} else {
logger.Tracef("sent vote message for stage %s: %s", stage, msg.Message)
}

logger.Tracef("sent vote message for stage %s: %s", stage, msg.Message)
select {
case <-roundComplete:
return
Expand Down
20 changes: 19 additions & 1 deletion lib/grandpa/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/telemetry"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/blocktree"
"github.com/ChainSafe/gossamer/lib/common"
Expand Down Expand Up @@ -91,7 +92,24 @@ func (h *MessageHandler) handleNeighbourMessage(msg *NeighbourMessage) error {
}

func (h *MessageHandler) handleCommitMessage(msg *CommitMessage) error {
logger.Debugf("received commit message %v", msg)
logger.Debugf("received commit message, msg: %+v", msg)

containsPrecommitsSignedBy := make([]string, len(msg.AuthData))
for i, authData := range msg.AuthData {
containsPrecommitsSignedBy[i] = authData.AuthorityID.String()
}

err := telemetry.GetInstance().SendMessage(
telemetry.NewAfgReceivedCommitTM(
msg.Vote.Hash,
fmt.Sprint(msg.Vote.Number),
containsPrecommitsSignedBy,
),
)
if err != nil {
logger.Debugf("problem sending afg.received_commit telemetry message: %s", err)
}

if has, _ := h.blockState.HasFinalisedBlock(msg.Round, h.grandpa.state.setID); has {
return nil
}
Expand Down
29 changes: 29 additions & 0 deletions lib/grandpa/vote_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"bytes"
"context"
"errors"
"fmt"

"github.com/ChainSafe/gossamer/dot/telemetry"
"github.com/ChainSafe/gossamer/lib/blocktree"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/pkg/scale"
Expand Down Expand Up @@ -36,6 +38,33 @@ func (s *Service) receiveMessages(ctx context.Context) {
logger.Tracef("received vote message %v from %s", msg.msg, msg.from)
vm := msg.msg

switch vm.Message.Stage {
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
case prevote:
err := telemetry.GetInstance().SendMessage(
telemetry.NewAfgReceivedPrevoteTM(
vm.Message.Hash,
fmt.Sprint(vm.Message.Number),
vm.Message.AuthorityID.String(),
),
)
if err != nil {
logger.Debugf("problem sending afg.received_prevote telemetry message: %s", err)
}
case precommit:
err := telemetry.GetInstance().SendMessage(
telemetry.NewAfgReceivedPrecommitTM(
vm.Message.Hash,
fmt.Sprint(vm.Message.Number),
vm.Message.AuthorityID.String(),
),
)
if err != nil {
logger.Debugf("problem sending afg.received_precommit telemetry message: %s", err)
}
default:
logger.Warnf("unsupported stage %s", vm.Message.Stage.String())
}

v, err := s.validateMessage(msg.from, vm)
if err != nil {
logger.Debugf("failed to validate vote message %v: %s", vm, err)
Expand Down