-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dot/telemetry): implement notify.finalized telemetry interface (#…
- Loading branch information
1 parent
b53627a
commit de1a60d
Showing
8 changed files
with
308 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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/>. | ||
|
||
package telemetry | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ChainSafe/gossamer/lib/common" | ||
) | ||
|
||
// blockImportTM struct to hold block import telemetry messages | ||
type blockImportTM struct { | ||
BestHash *common.Hash `json:"best"` | ||
Height *big.Int `json:"height"` | ||
Origin string `json:"origin"` | ||
} | ||
|
||
// NewBlockImportTM function to create new Block Import Telemetry Message | ||
func NewBlockImportTM(bestHash *common.Hash, height *big.Int, origin string) Message { | ||
return &blockImportTM{ | ||
BestHash: bestHash, | ||
Height: height, | ||
Origin: origin, | ||
} | ||
} | ||
|
||
func (blockImportTM) messageType() string { | ||
return blockImportMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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/>. | ||
|
||
package telemetry | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ChainSafe/gossamer/lib/common" | ||
libp2phost "github.com/libp2p/go-libp2p-core/host" | ||
) | ||
|
||
// networkStateTM struct to hold network state telemetry messages | ||
type networkStateTM struct { | ||
State map[string]interface{} `json:"state"` | ||
} | ||
|
||
// NewNetworkStateTM function to create new Network State Telemetry Message | ||
func NewNetworkStateTM(host libp2phost.Host, peerInfos []common.PeerInfo) Message { | ||
netState := make(map[string]interface{}) | ||
netState["peerId"] = host.ID() | ||
hostAddrs := make([]string, 0, len(host.Addrs())) | ||
for _, v := range host.Addrs() { | ||
hostAddrs = append(hostAddrs, v.String()) | ||
} | ||
netState["externalAddressess"] = hostAddrs | ||
|
||
netListAddrs := host.Network().ListenAddresses() | ||
listAddrs := make([]string, 0, len(netListAddrs)) | ||
for _, v := range netListAddrs { | ||
listAddrs = append(listAddrs, fmt.Sprintf("%s/p2p/%s", v, host.ID())) | ||
} | ||
netState["listenedAddressess"] = listAddrs | ||
|
||
peers := make(map[string]interface{}) | ||
for _, v := range peerInfos { | ||
p := &peerInfo{ | ||
Roles: v.Roles, | ||
BestHash: v.BestHash.String(), | ||
BestNumber: v.BestNumber, | ||
} | ||
peers[v.PeerID] = *p | ||
} | ||
netState["connectedPeers"] = peers | ||
|
||
return &networkStateTM{ | ||
State: netState, | ||
} | ||
} | ||
|
||
func (networkStateTM) messageType() string { | ||
return systemNetworkStateMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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/>. | ||
|
||
package telemetry | ||
|
||
import ( | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
) | ||
|
||
//nolint | ||
// notifyFinalizedTM holds `notify.finalized` telemetry message, which is | ||
// supposed to be send when a new block gets finalized. | ||
type notifyFinalizedTM struct { | ||
Best common.Hash `json:"best"` | ||
// Height is same as block.Header.Number | ||
Height string `json:"height"` | ||
} | ||
|
||
// NewNotifyFinalizedTM gets a new NotifyFinalizedTM struct. | ||
func NewNotifyFinalizedTM(best common.Hash, height string) Message { | ||
return ¬ifyFinalizedTM{ | ||
Best: best, | ||
Height: height, | ||
} | ||
} | ||
|
||
func (notifyFinalizedTM) messageType() string { | ||
return notifyFinalizedMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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/>. | ||
|
||
package telemetry | ||
|
||
import "github.com/ChainSafe/gossamer/lib/common" | ||
|
||
// systemConnectedTM struct to hold system connected telemetry messages | ||
type systemConnectedTM struct { | ||
Authority bool `json:"authority"` | ||
Chain string `json:"chain"` | ||
GenesisHash *common.Hash `json:"genesis_hash"` | ||
Implementation string `json:"implementation"` | ||
Name string `json:"name"` | ||
NetworkID string `json:"network_id"` | ||
StartupTime string `json:"startup_time"` | ||
Version string `json:"version"` | ||
} | ||
|
||
// NewSystemConnectedTM function to create new System Connected Telemetry Message | ||
func NewSystemConnectedTM(authority bool, chain string, genesisHash *common.Hash, | ||
implementation, name, networkID, startupTime, version string) Message { | ||
return &systemConnectedTM{ | ||
Authority: authority, | ||
Chain: chain, | ||
GenesisHash: genesisHash, | ||
Implementation: implementation, | ||
Name: name, | ||
NetworkID: networkID, | ||
StartupTime: startupTime, | ||
Version: version, | ||
} | ||
} | ||
|
||
func (systemConnectedTM) messageType() string { | ||
return systemConnectedMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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/>. | ||
|
||
package telemetry | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ChainSafe/gossamer/lib/common" | ||
) | ||
|
||
// systemIntervalTM struct to hold system interval telemetry messages | ||
type systemIntervalTM struct { | ||
BandwidthDownload float64 `json:"bandwidth_download,omitempty"` | ||
BandwidthUpload float64 `json:"bandwidth_upload,omitempty"` | ||
Peers int `json:"peers,omitempty"` | ||
BestHash *common.Hash `json:"best,omitempty"` | ||
BestHeight *big.Int `json:"height,omitempty"` | ||
FinalisedHash *common.Hash `json:"finalized_hash,omitempty"` // nolint | ||
FinalisedHeight *big.Int `json:"finalized_height,omitempty"` // nolint | ||
TxCount *big.Int `json:"txcount,omitempty"` | ||
UsedStateCacheSize *big.Int `json:"used_state_cache_size,omitempty"` | ||
} | ||
|
||
// NewBandwidthTM function to create new Bandwidth Telemetry Message | ||
func NewBandwidthTM(bandwidthDownload, bandwidthUpload float64, peers int) Message { | ||
return &systemIntervalTM{ | ||
BandwidthDownload: bandwidthDownload, | ||
BandwidthUpload: bandwidthUpload, | ||
Peers: peers, | ||
} | ||
} | ||
|
||
// NewBlockIntervalTM function to create new Block Interval Telemetry Message | ||
func NewBlockIntervalTM(beshHash *common.Hash, bestHeight *big.Int, finalisedHash *common.Hash, | ||
finalisedHeight, txCount, usedStateCacheSize *big.Int) Message { | ||
return &systemIntervalTM{ | ||
BestHash: beshHash, | ||
BestHeight: bestHeight, | ||
FinalisedHash: finalisedHash, | ||
FinalisedHeight: finalisedHeight, | ||
TxCount: txCount, | ||
UsedStateCacheSize: usedStateCacheSize, | ||
} | ||
} | ||
|
||
func (systemIntervalTM) messageType() string { | ||
return systemIntervalMsg | ||
} |
Oops, something went wrong.