Skip to content

Commit

Permalink
Merge pull request #157 from nspcc-dev/drop-morph-side-chain
Browse files Browse the repository at this point in the history
*: don't use "morph" or "sidechain"
  • Loading branch information
roman-khimov authored Nov 21, 2024
2 parents 0c35d3c + 16ea866 commit 57575b1
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 69 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Changelog for NeoFS Monitor

## [Unreleased]

Please notice that "side_chain_supply" metric was renamed to "fs_chain_supply"
in this release.

## [0.12.1] - 2024-09-03

### Changed
Expand Down
28 changes: 14 additions & 14 deletions cmd/neo-exporter/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"time"

"github.com/nspcc-dev/neo-exporter/pkg/fschain"
"github.com/nspcc-dev/neo-exporter/pkg/fschain/contracts"
"github.com/nspcc-dev/neo-exporter/pkg/model"
"github.com/nspcc-dev/neo-exporter/pkg/monitor"
"github.com/nspcc-dev/neo-exporter/pkg/morphchain"
"github.com/nspcc-dev/neo-exporter/pkg/morphchain/contracts"
"github.com/nspcc-dev/neo-exporter/pkg/pool"
"github.com/nspcc-dev/neo-go/pkg/util"
rpcnns "github.com/nspcc-dev/neofs-contract/rpc/nns"
Expand All @@ -35,23 +35,23 @@ func New(ctx context.Context, cfg *viper.Viper) (*monitor.Monitor, error) {

zap.ReplaceGlobals(logger)

sideChainEndpoints := cfg.GetStringSlice(prefix + delimiter + cfgNeoRPCEndpoint)
sideChainTimeout := cfg.GetDuration(prefix + delimiter + cfgNeoRPCDialTimeout)
sideChainRecheck := cfg.GetDuration(prefix + delimiter + cfgNeoRPCRecheckInterval)
fsChainEndpoints := cfg.GetStringSlice(prefix + delimiter + cfgNeoRPCEndpoint)
fsChainTimeout := cfg.GetDuration(prefix + delimiter + cfgNeoRPCDialTimeout)
fsChainRecheck := cfg.GetDuration(prefix + delimiter + cfgNeoRPCRecheckInterval)

sideNeogoClient, err := pool.NewPool(ctx, pool.PrmPool{
Endpoints: sideChainEndpoints,
DialTimeout: sideChainTimeout,
RecheckInterval: sideChainRecheck,
Endpoints: fsChainEndpoints,
DialTimeout: fsChainTimeout,
RecheckInterval: fsChainRecheck,
})
if err != nil {
return nil, fmt.Errorf("can't create side chain neo-go client: %w", err)
}

var job monitor.Job
if cfg.GetBool(cfgChainFSChain) {
monitor.RegisterSideChainMetrics()
job, err = sideChainJob(cfg, sideNeogoClient, logger)
monitor.RegisterFSChainMetrics()
job, err = fsChainJob(cfg, sideNeogoClient, logger)
} else {
monitor.RegisterMainChainMetrics()
job, err = mainChainJob(cfg, sideNeogoClient, logger)
Expand All @@ -71,7 +71,7 @@ func New(ctx context.Context, cfg *viper.Viper) (*monitor.Monitor, error) {
}

func mainChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger) (*monitor.MainJob, error) {
alphabetFetcher := morphchain.NewMainChainAlphabetFetcher(neogoClient)
alphabetFetcher := fschain.NewMainChainAlphabetFetcher(neogoClient)

balanceFetcher, err := monitor.NewNep17BalanceFetcher(neogoClient)
if err != nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func mainChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger)
}), nil
}

func sideChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger) (*monitor.SideJob, error) {
func fsChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger) (*monitor.FSJob, error) {
netmapContract, err := neogoClient.ResolveContract(rpcnns.NameNetmap)
if err != nil {
return nil, fmt.Errorf("can't read netmap scripthash: %w", err)
Expand All @@ -140,7 +140,7 @@ func sideChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger)
return nil, fmt.Errorf("can't initialize container fetcher: %w", err)
}

alphabetFetcher := morphchain.NewSideChainAlphabetFetcher(neogoClient)
alphabetFetcher := fschain.NewFSChainAlphabetFetcher(neogoClient)

balanceFetcher, err := monitor.NewNep17BalanceFetcher(neogoClient)
if err != nil {
Expand Down Expand Up @@ -194,7 +194,7 @@ func sideChainJob(cfg *viper.Viper, neogoClient *pool.Pool, logger *zap.Logger)
return nil, fmt.Errorf("nep17tracker: %w", err)
}

return monitor.NewSideJob(monitor.SideJobArgs{
return monitor.NewFSJob(monitor.FSJobArgs{
Logger: logger,
Balance: balance,
Proxy: proxy,
Expand Down
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Neo RPC related configuration.
chain:
# If true, monitor connects to the NeoFS chain, otherwise, to the Neo chain.
# Set to true when using monitor with FS chain which adds FS-specific metrics, false if using it with any other N3 chain.
fschain: false
rpc:
dial_timeout: 60s
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type (
}
)

// NewNetmap creates Netmap to interact with 'netmap' contract in morph chain.
// NewNetmap creates Netmap to interact with 'netmap' contract in FS chain.
func NewNetmap(p NetmapArgs) (*Netmap, error) {
return &Netmap{
pool: p.Pool,
Expand Down Expand Up @@ -151,7 +151,7 @@ func processNode(logger *zap.Logger, node *netmap.NodeInfo) (*monitor.Node, erro
func(mAddr string) bool {
addr, err := multiAddrToIPStringWithoutPort(mAddr)
if err != nil {
logger.Debug("morphchain", zap.Error(err))
logger.Debug("FS chain", zap.Error(err))
return false
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions pkg/fschain/fschain_alphabet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fschain

import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
)

// Committeer provides FS chain committee public keys.
type Committeer interface {
GetCommittee() (keys.PublicKeys, error)
}

type (
FSChainAlphabetFetcher struct {
committeer Committeer
}
)

func NewFSChainAlphabetFetcher(committeer Committeer) *FSChainAlphabetFetcher {
return &FSChainAlphabetFetcher{
committeer: committeer,
}
}

func (a FSChainAlphabetFetcher) FetchAlphabet() (keys.PublicKeys, error) {
return a.committeer.GetCommittee()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package morphchain
package fschain

import (
"fmt"
Expand Down
38 changes: 19 additions & 19 deletions pkg/monitor/side_job.go → pkg/monitor/fs_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type (
SideJobArgs struct {
FSJobArgs struct {
Logger *zap.Logger
Balance util.Uint160
Proxy *util.Uint160
Expand All @@ -27,7 +27,7 @@ type (
Nep17tracker *Nep17tracker
}

SideJob struct {
FSJob struct {
logger *zap.Logger
nmFetcher NetmapFetcher
irFetcher InnerRingFetcher
Expand Down Expand Up @@ -102,8 +102,8 @@ type (
}
)

func NewSideJob(args SideJobArgs) *SideJob {
return &SideJob{
func NewFSJob(args FSJobArgs) *FSJob {
return &FSJob{
logger: args.Logger,
nmFetcher: args.NmFetcher,
irFetcher: args.IRFetcher,
Expand All @@ -119,8 +119,8 @@ func NewSideJob(args SideJobArgs) *SideJob {
}
}

func (m *SideJob) Process() {
m.logger.Debug("retrieving data from side chain")
func (m *FSJob) Process() {
m.logger.Debug("retrieving data from FS chain")

netmap, err := m.nmFetcher.FetchNetmap()
if err != nil {
Expand All @@ -145,13 +145,13 @@ func (m *SideJob) Process() {
m.processProxyContract()
}

m.processSideChainSupply()
m.processFSChainSupply()

if alphabet, err := m.alphabetFetcher.FetchAlphabet(); err != nil {
m.logger.Warn("can't read NeoFS ALphabet members", zap.Error(err))
} else {
processAlphabetPublicKeys(alphabet)
m.processSideAlphabet(alphabet)
m.processFSAlphabet(alphabet)
}

m.processContainersNumber()
Expand All @@ -161,13 +161,13 @@ func (m *SideJob) Process() {
m.processNep17tracker()
}

func (m *SideJob) processNep17tracker() {
func (m *FSJob) processNep17tracker() {
if m.nep17tracker != nil {
m.nep17tracker.Process(nep17tracker, nep17trackerTotal)
}
}

func (m *SideJob) processNetworkMap(nm NetmapInfo, candidates NetmapCandidatesInfo) {
func (m *FSJob) processNetworkMap(nm NetmapInfo, candidates NetmapCandidatesInfo) {
currentNetmapLen := len(nm.Nodes)

exportCountries := make(map[nodeLocation]int, currentNetmapLen)
Expand Down Expand Up @@ -242,7 +242,7 @@ func (m *SideJob) processNetworkMap(nm NetmapInfo, candidates NetmapCandidatesIn
}
}

func (m *SideJob) logNodes(msg string, nodes []*Node) {
func (m *FSJob) logNodes(msg string, nodes []*Node) {
for _, node := range nodes {
fields := []zap.Field{zap.Uint64("id", node.ID), zap.String("address", node.Address),
zap.String("public key", node.PublicKey.String()),
Expand All @@ -256,7 +256,7 @@ func (m *SideJob) logNodes(msg string, nodes []*Node) {
}
}

func (m *SideJob) processInnerRing(ir keys.PublicKeys) {
func (m *FSJob) processInnerRing(ir keys.PublicKeys) {
exportBalances := make(map[string]float64, len(ir))

for _, key := range ir {
Expand All @@ -280,7 +280,7 @@ func (m *SideJob) processInnerRing(ir keys.PublicKeys) {
}
}

func (m *SideJob) processProxyContract() {
func (m *FSJob) processProxyContract() {
balance, err := m.balanceFetcher.Fetch(gas.Hash, *m.proxy)
if err != nil {
m.logger.Debug("can't fetch proxy contract balance", zap.Stringer("address", m.proxy), zap.Error(err))
Expand All @@ -290,7 +290,7 @@ func (m *SideJob) processProxyContract() {
proxyBalance.Set(balance)
}

func (m *SideJob) processSideAlphabet(alphabet keys.PublicKeys) {
func (m *FSJob) processFSAlphabet(alphabet keys.PublicKeys) {
exportNotaryBalances := make(map[string]float64, len(alphabet))

for _, key := range alphabet {
Expand All @@ -310,17 +310,17 @@ func (m *SideJob) processSideAlphabet(alphabet keys.PublicKeys) {
}
}

func (m *SideJob) processSideChainSupply() {
func (m *FSJob) processFSChainSupply() {
balance, err := m.balanceFetcher.FetchTotalSupply(m.balance)
if err != nil {
m.logger.Debug("can't fetch balance contract total supply", zap.Stringer("address", m.balance), zap.Error(err))
return
}

sideChainSupply.Set(balance)
fsChainSupply.Set(balance)
}

func (m *SideJob) processContainersNumber() {
func (m *FSJob) processContainersNumber() {
total, err := m.cnrFetcher.Total()
if err != nil {
m.logger.Warn("can't fetch number of available containers", zap.Error(err))
Expand All @@ -330,7 +330,7 @@ func (m *SideJob) processContainersNumber() {
containersNumber.Set(float64(total))
}

func (m *SideJob) processChainHeight() uint32 {
func (m *FSJob) processChainHeight() uint32 {
var minHeight uint32
heightData := m.heightFetcher.FetchHeight()

Expand All @@ -345,7 +345,7 @@ func (m *SideJob) processChainHeight() uint32 {
return minHeight
}

func (m *SideJob) processChainState(height uint32) {
func (m *FSJob) processChainState(height uint32) {
if height == 0 {
return
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/monitor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ var (
},
)

sideChainSupply = prometheus.NewGauge(
fsChainSupply = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "side_chain_supply",
Help: "Side chain total supply of balance contract",
Name: "fs_chain_supply",
Help: "FS chain total supply of balance contract",
},
)

Expand Down Expand Up @@ -201,8 +201,8 @@ var (
)
)

// RegisterSideChainMetrics inits prometheus metrics for side chain. Panics if can't do it.
func RegisterSideChainMetrics() {
// RegisterFSChainMetrics inits prometheus metrics for side chain. Panics if can't do it.
func RegisterFSChainMetrics() {
prometheus.MustRegister(binaryVersion)
prometheus.MustRegister(locationPresent)
prometheus.MustRegister(droppedNodesCount)
Expand All @@ -213,7 +213,7 @@ func RegisterSideChainMetrics() {
prometheus.MustRegister(innerRingBalances)
prometheus.MustRegister(alphabetNotaryBalances)
prometheus.MustRegister(proxyBalance)
prometheus.MustRegister(sideChainSupply)
prometheus.MustRegister(fsChainSupply)
prometheus.MustRegister(alphabetPubKeys) // used for both monitors
prometheus.MustRegister(containersNumber)
prometheus.MustRegister(chainHeight)
Expand Down
26 changes: 0 additions & 26 deletions pkg/morphchain/sidechain_alphabet.go

This file was deleted.

0 comments on commit 57575b1

Please sign in to comment.