From 16ea866deb59bc43c4ed9673dbac4ef27776e920 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 19 Nov 2024 18:25:30 +0300 Subject: [PATCH] *: don't use "morph" or "sidechain" We have main chain, we have FS chain. That's it. Signed-off-by: Roman Khimov --- CHANGELOG.md | 3 ++ cmd/neo-exporter/monitor.go | 28 +++++++------- config/config.yaml | 2 +- .../contracts/container.go | 0 .../contracts/netmap.go | 4 +- .../contracts/netmap_test.go | 0 pkg/{morphchain => fschain}/contracts/nns.go | 0 .../contracts/utils.go | 0 pkg/fschain/fschain_alphabet.go | 26 +++++++++++++ .../mainchain_alphabet.go | 2 +- pkg/monitor/{side_job.go => fs_job.go} | 38 +++++++++---------- pkg/monitor/metrics.go | 12 +++--- pkg/morphchain/sidechain_alphabet.go | 26 ------------- 13 files changed, 72 insertions(+), 69 deletions(-) rename pkg/{morphchain => fschain}/contracts/container.go (100%) rename pkg/{morphchain => fschain}/contracts/netmap.go (98%) rename pkg/{morphchain => fschain}/contracts/netmap_test.go (100%) rename pkg/{morphchain => fschain}/contracts/nns.go (100%) rename pkg/{morphchain => fschain}/contracts/utils.go (100%) create mode 100644 pkg/fschain/fschain_alphabet.go rename pkg/{morphchain => fschain}/mainchain_alphabet.go (97%) rename pkg/monitor/{side_job.go => fs_job.go} (91%) delete mode 100644 pkg/morphchain/sidechain_alphabet.go diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7731f..d5e00fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/neo-exporter/monitor.go b/cmd/neo-exporter/monitor.go index bbd353a..679f409 100644 --- a/cmd/neo-exporter/monitor.go +++ b/cmd/neo-exporter/monitor.go @@ -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" @@ -35,14 +35,14 @@ 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) @@ -50,8 +50,8 @@ func New(ctx context.Context, cfg *viper.Viper) (*monitor.Monitor, error) { 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) @@ -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 { @@ -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) @@ -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 { @@ -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, diff --git a/config/config.yaml b/config/config.yaml index 251c4e9..208c897 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -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 diff --git a/pkg/morphchain/contracts/container.go b/pkg/fschain/contracts/container.go similarity index 100% rename from pkg/morphchain/contracts/container.go rename to pkg/fschain/contracts/container.go diff --git a/pkg/morphchain/contracts/netmap.go b/pkg/fschain/contracts/netmap.go similarity index 98% rename from pkg/morphchain/contracts/netmap.go rename to pkg/fschain/contracts/netmap.go index 3ed4479..bce3d5c 100644 --- a/pkg/morphchain/contracts/netmap.go +++ b/pkg/fschain/contracts/netmap.go @@ -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, @@ -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 } diff --git a/pkg/morphchain/contracts/netmap_test.go b/pkg/fschain/contracts/netmap_test.go similarity index 100% rename from pkg/morphchain/contracts/netmap_test.go rename to pkg/fschain/contracts/netmap_test.go diff --git a/pkg/morphchain/contracts/nns.go b/pkg/fschain/contracts/nns.go similarity index 100% rename from pkg/morphchain/contracts/nns.go rename to pkg/fschain/contracts/nns.go diff --git a/pkg/morphchain/contracts/utils.go b/pkg/fschain/contracts/utils.go similarity index 100% rename from pkg/morphchain/contracts/utils.go rename to pkg/fschain/contracts/utils.go diff --git a/pkg/fschain/fschain_alphabet.go b/pkg/fschain/fschain_alphabet.go new file mode 100644 index 0000000..dd301c8 --- /dev/null +++ b/pkg/fschain/fschain_alphabet.go @@ -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() +} diff --git a/pkg/morphchain/mainchain_alphabet.go b/pkg/fschain/mainchain_alphabet.go similarity index 97% rename from pkg/morphchain/mainchain_alphabet.go rename to pkg/fschain/mainchain_alphabet.go index 75da011..de2b406 100644 --- a/pkg/morphchain/mainchain_alphabet.go +++ b/pkg/fschain/mainchain_alphabet.go @@ -1,4 +1,4 @@ -package morphchain +package fschain import ( "fmt" diff --git a/pkg/monitor/side_job.go b/pkg/monitor/fs_job.go similarity index 91% rename from pkg/monitor/side_job.go rename to pkg/monitor/fs_job.go index 18c2629..560ad11 100644 --- a/pkg/monitor/side_job.go +++ b/pkg/monitor/fs_job.go @@ -12,7 +12,7 @@ import ( ) type ( - SideJobArgs struct { + FSJobArgs struct { Logger *zap.Logger Balance util.Uint160 Proxy *util.Uint160 @@ -27,7 +27,7 @@ type ( Nep17tracker *Nep17tracker } - SideJob struct { + FSJob struct { logger *zap.Logger nmFetcher NetmapFetcher irFetcher InnerRingFetcher @@ -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, @@ -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 { @@ -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() @@ -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) @@ -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()), @@ -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 { @@ -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)) @@ -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 { @@ -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)) @@ -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() @@ -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 } diff --git a/pkg/monitor/metrics.go b/pkg/monitor/metrics.go index c44187d..78c60c8 100644 --- a/pkg/monitor/metrics.go +++ b/pkg/monitor/metrics.go @@ -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", }, ) @@ -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) @@ -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) diff --git a/pkg/morphchain/sidechain_alphabet.go b/pkg/morphchain/sidechain_alphabet.go deleted file mode 100644 index def69b2..0000000 --- a/pkg/morphchain/sidechain_alphabet.go +++ /dev/null @@ -1,26 +0,0 @@ -package morphchain - -import ( - "github.com/nspcc-dev/neo-go/pkg/crypto/keys" -) - -// Committeer must provide side chain committee public keys. -type Committeer interface { - GetCommittee() (keys.PublicKeys, error) -} - -type ( - SideChainAlphabetFetcher struct { - committeer Committeer - } -) - -func NewSideChainAlphabetFetcher(committeer Committeer) *SideChainAlphabetFetcher { - return &SideChainAlphabetFetcher{ - committeer: committeer, - } -} - -func (a SideChainAlphabetFetcher) FetchAlphabet() (keys.PublicKeys, error) { - return a.committeer.GetCommittee() -}