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
82 changes: 82 additions & 0 deletions dot/telemetry/afg_received.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2021 ChainSafe Systems (ON) Corp.
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
// 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/>.

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
15 changes: 14 additions & 1 deletion dot/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ func TestHandler_SendMulti(t *testing.T) {
[]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:lll
[]byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`), //nolint:lll //nolint:lll
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
[]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
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.Sprintf("%d", msg.Vote.Number),
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
containsPrecommitsSignedBy,
),
)
if err != nil {
logger.Debugf("problem sending afg.received_commit telemetry message, err: %s", err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

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.Sprintf("%d", vm.Message.Number),
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
vm.Message.AuthorityID.String(),
),
)
if err != nil {
logger.Debugf("problem sending afg.received_prevote telemetry message, err: %s", err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}
case precommit:
err := telemetry.GetInstance().SendMessage(
telemetry.NewAfgReceivedPrecommitTM(
vm.Message.Hash,
fmt.Sprintf("%d", vm.Message.Number),
vm.Message.AuthorityID.String(),
),
)
if err != nil {
logger.Debugf("problem sending afg.received_precommit telemetry message err: %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