2023-03-29 13:54:15 +00:00
|
|
|
package innerring
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2024-06-18 09:40:38 +00:00
|
|
|
"sync/atomic"
|
2023-03-29 13:54:15 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-29 13:54:15 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/alphabet"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/balance"
|
|
|
|
cont "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/container"
|
2023-03-31 09:52:16 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/frostfs"
|
2023-03-29 13:54:15 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/governance"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap"
|
|
|
|
nodevalidator "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation"
|
|
|
|
addrvalidator "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/maddress"
|
|
|
|
statevalidation "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/state"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
balanceClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/balance"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
|
|
frostfsClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/frostfs"
|
2023-11-20 14:03:19 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/frostfsid"
|
2023-03-29 13:54:15 +00:00
|
|
|
nmClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
|
|
|
controlsrv "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir/server"
|
|
|
|
utilConfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config"
|
2024-06-18 09:40:38 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2023-03-29 13:54:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initNetmapProcessor(ctx context.Context, cfg *viper.Viper,
|
2023-10-31 11:56:55 +00:00
|
|
|
alphaSync event.Handler,
|
|
|
|
) error {
|
2023-03-29 13:54:15 +00:00
|
|
|
locodeValidator, err := s.newLocodeValidator(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
netSettings := (*networkSettings)(s.netmapClient)
|
|
|
|
|
|
|
|
var netMapCandidateStateValidator statevalidation.NetMapCandidateValidator
|
|
|
|
netMapCandidateStateValidator.SetNetworkSettings(netSettings)
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
poolSize := cfg.GetInt("workers.netmap")
|
|
|
|
s.log.Debug(ctx, logs.NetmapNetmapWorkerPool, zap.Int("size", poolSize))
|
|
|
|
|
2023-03-29 13:54:15 +00:00
|
|
|
s.netmapProcessor, err = netmap.New(&netmap.Params{
|
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2024-10-21 13:27:28 +00:00
|
|
|
PoolSize: poolSize,
|
2023-04-27 14:57:27 +00:00
|
|
|
NetmapClient: netmap.NewNetmapClient(s.netmapClient),
|
2023-03-29 13:54:15 +00:00
|
|
|
EpochTimer: s,
|
|
|
|
EpochState: s,
|
|
|
|
AlphabetState: s,
|
|
|
|
CleanupEnabled: cfg.GetBool("netmap_cleaner.enabled"),
|
|
|
|
CleanupThreshold: cfg.GetUint64("netmap_cleaner.threshold"),
|
|
|
|
NotaryDepositHandler: s.onlyAlphabetEventHandler(
|
|
|
|
s.notaryHandler,
|
|
|
|
),
|
2023-03-31 09:52:16 +00:00
|
|
|
AlphabetSyncHandler: s.onlyAlphabetEventHandler(
|
|
|
|
alphaSync,
|
|
|
|
),
|
2023-03-29 13:54:15 +00:00
|
|
|
NodeValidator: nodevalidator.New(
|
|
|
|
&netMapCandidateStateValidator,
|
|
|
|
addrvalidator.New(),
|
|
|
|
locodeValidator,
|
|
|
|
),
|
|
|
|
|
|
|
|
NodeStateSettings: netSettings,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindMorphProcessor(s.netmapProcessor, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) initMainnet(ctx context.Context, cfg *viper.Viper, morphChain *chainParams, errChan chan<- error) error {
|
|
|
|
s.withoutMainNet = cfg.GetBool("without_mainnet")
|
|
|
|
if s.withoutMainNet {
|
|
|
|
// This works as long as event Listener starts listening loop once,
|
|
|
|
// otherwise Server.Start will run two similar routines.
|
|
|
|
// This behavior most likely will not change.
|
|
|
|
s.mainnetListener = s.morphListener
|
|
|
|
s.mainnetClient = s.morphClient
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mainnetChain := morphChain
|
|
|
|
mainnetChain.name = mainnetPrefix
|
|
|
|
mainnetChain.sgn = &transaction.Signer{Scopes: transaction.CalledByEntry}
|
|
|
|
|
|
|
|
fromMainChainBlock, err := s.persistate.UInt32(persistateMainChainLastBlockKey)
|
|
|
|
if err != nil {
|
|
|
|
fromMainChainBlock = 0
|
2024-12-13 08:44:56 +00:00
|
|
|
s.log.Warn(ctx, logs.InnerringCantGetLastProcessedMainChainBlockNumber, zap.Error(err))
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
mainnetChain.from = fromMainChainBlock
|
|
|
|
|
|
|
|
// create mainnet client
|
|
|
|
s.mainnetClient, err = createClient(ctx, mainnetChain, errChan)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// create mainnet listener
|
|
|
|
s.mainnetListener, err = createListener(ctx, s.mainnetClient, mainnetChain)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) enableNotarySupport() error {
|
2023-05-17 14:56:11 +00:00
|
|
|
// enable notary support in the side client
|
|
|
|
err := s.morphClient.EnableNotarySupport(
|
|
|
|
client.WithProxyContract(s.contracts.proxy),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not enable side chain notary support: %w", err)
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 14:56:11 +00:00
|
|
|
s.morphListener.EnableNotarySupport(s.contracts.proxy, s.morphClient.Committee, s.morphClient)
|
|
|
|
|
2023-03-29 13:54:15 +00:00
|
|
|
if !s.mainNotaryConfig.disabled {
|
|
|
|
// enable notary support in the main client
|
|
|
|
err := s.mainnetClient.EnableNotarySupport(
|
|
|
|
client.WithProxyContract(s.contracts.processing),
|
|
|
|
client.WithAlphabetSource(s.morphClient.Committee),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not enable main chain notary support: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (s *Server) initNotaryConfig(ctx context.Context) {
|
2023-05-17 14:56:11 +00:00
|
|
|
s.mainNotaryConfig = notaryConfigs(
|
2023-03-29 13:54:15 +00:00
|
|
|
!s.withoutMainNet && s.mainnetClient.ProbeNotary(), // if mainnet disabled then notary flag must be disabled too
|
|
|
|
)
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
s.log.Info(ctx, logs.InnerringNotarySupport,
|
2023-05-17 14:56:11 +00:00
|
|
|
zap.Bool("sidechain_enabled", true),
|
2023-03-29 13:54:15 +00:00
|
|
|
zap.Bool("mainchain_enabled", !s.mainNotaryConfig.disabled),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) createAlphaSync(cfg *viper.Viper, frostfsCli *frostfsClient.Client, irf irFetcher) (event.Handler, error) {
|
|
|
|
var alphaSync event.Handler
|
|
|
|
|
|
|
|
if s.withoutMainNet || cfg.GetBool("governance.disable") {
|
2024-10-21 09:21:01 +00:00
|
|
|
alphaSync = func(ctx context.Context, _ event.Event) {
|
|
|
|
s.log.Debug(ctx, logs.InnerringAlphabetKeysSyncIsDisabled)
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// create governance processor
|
|
|
|
governanceProcessor, err := governance.New(&governance.Params{
|
2023-05-18 08:19:08 +00:00
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2023-05-18 08:19:08 +00:00
|
|
|
FrostFSClient: frostfsCli,
|
|
|
|
AlphabetState: s,
|
|
|
|
EpochState: s,
|
|
|
|
Voter: s,
|
|
|
|
IRFetcher: irf,
|
|
|
|
MorphClient: s.morphClient,
|
|
|
|
MainnetClient: s.mainnetClient,
|
2023-03-29 13:54:15 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
alphaSync = governanceProcessor.HandleAlphabetSync
|
|
|
|
err = bindMainnetProcessor(governanceProcessor, s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return alphaSync, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) createIRFetcher() irFetcher {
|
|
|
|
var irf irFetcher
|
|
|
|
|
|
|
|
if s.withoutMainNet || !s.mainNotaryConfig.disabled {
|
|
|
|
// if mainchain is disabled we should use NeoFSAlphabetList client method according to its docs
|
|
|
|
// (naming `...WithNotary` will not always be correct)
|
|
|
|
irf = NewIRFetcherWithNotary(s.morphClient)
|
|
|
|
} else {
|
|
|
|
irf = NewIRFetcherWithoutNotary(s.netmapClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
return irf
|
|
|
|
}
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (s *Server) initTimers(ctx context.Context, cfg *viper.Viper) {
|
2023-03-29 13:54:15 +00:00
|
|
|
s.epochTimer = newEpochTimer(&epochTimerArgs{
|
2024-10-21 09:21:01 +00:00
|
|
|
newEpochHandlers: s.newEpochTickHandlers(ctx),
|
2024-11-06 12:25:02 +00:00
|
|
|
epoch: s,
|
2023-03-29 13:54:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
s.addBlockTimer(s.epochTimer)
|
|
|
|
|
|
|
|
// initialize emission timer
|
2024-10-21 13:27:28 +00:00
|
|
|
emissionTimer := newEmissionTimer(ctx, &emitTimerArgs{
|
2023-05-12 07:41:04 +00:00
|
|
|
ap: s.alphabetProcessor,
|
2023-03-29 13:54:15 +00:00
|
|
|
emitDuration: cfg.GetUint32("timers.emit"),
|
|
|
|
})
|
|
|
|
|
|
|
|
s.addBlockTimer(emissionTimer)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initAlphabetProcessor(ctx context.Context, cfg *viper.Viper) error {
|
2023-03-29 13:54:15 +00:00
|
|
|
parsedWallets, err := parseWalletAddressesFromStrings(cfg.GetStringSlice("emit.extra_wallets"))
|
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
poolSize := cfg.GetInt("workers.alphabet")
|
|
|
|
s.log.Debug(ctx, logs.AlphabetAlphabetWorkerPool, zap.Int("size", poolSize))
|
2023-03-29 13:54:15 +00:00
|
|
|
|
|
|
|
// create alphabet processor
|
2023-05-12 07:41:04 +00:00
|
|
|
s.alphabetProcessor, err = alphabet.New(&alphabet.Params{
|
2023-03-29 13:54:15 +00:00
|
|
|
ParsedWallets: parsedWallets,
|
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2024-10-21 13:27:28 +00:00
|
|
|
PoolSize: poolSize,
|
2023-03-29 13:54:15 +00:00
|
|
|
AlphabetContracts: s.contracts.alphabet,
|
|
|
|
NetmapClient: s.netmapClient,
|
|
|
|
MorphClient: s.morphClient,
|
|
|
|
IRList: s,
|
|
|
|
StorageEmission: cfg.GetUint64("emit.storage.amount"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 07:41:04 +00:00
|
|
|
err = bindMorphProcessor(s.alphabetProcessor, s)
|
2023-08-14 11:06:17 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initContainerProcessor(ctx context.Context, cfg *viper.Viper, cnrClient *container.Client, frostfsIDClient *frostfsid.Client) error {
|
|
|
|
poolSize := cfg.GetInt("workers.container")
|
|
|
|
s.log.Debug(ctx, logs.ContainerContainerWorkerPool, zap.Int("size", poolSize))
|
2023-03-29 13:54:15 +00:00
|
|
|
// container processor
|
|
|
|
containerProcessor, err := cont.New(&cont.Params{
|
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2024-10-21 13:27:28 +00:00
|
|
|
PoolSize: poolSize,
|
2023-03-29 13:54:15 +00:00
|
|
|
AlphabetState: s,
|
|
|
|
ContainerClient: cnrClient,
|
2023-05-17 12:43:56 +00:00
|
|
|
MorphClient: cnrClient.Morph(),
|
2023-11-20 14:03:19 +00:00
|
|
|
FrostFSIDClient: frostfsIDClient,
|
2023-03-29 13:54:15 +00:00
|
|
|
NetworkState: s.netmapClient,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindMorphProcessor(containerProcessor, s)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initBalanceProcessor(ctx context.Context, cfg *viper.Viper, frostfsCli *frostfsClient.Client) error {
|
|
|
|
poolSize := cfg.GetInt("workers.balance")
|
|
|
|
s.log.Debug(ctx, logs.BalanceBalanceWorkerPool, zap.Int("size", poolSize))
|
2023-03-29 13:54:15 +00:00
|
|
|
// create balance processor
|
|
|
|
balanceProcessor, err := balance.New(&balance.Params{
|
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2024-10-21 13:27:28 +00:00
|
|
|
PoolSize: poolSize,
|
2023-03-29 13:54:15 +00:00
|
|
|
FrostFSClient: frostfsCli,
|
|
|
|
BalanceSC: s.contracts.balance,
|
|
|
|
AlphabetState: s,
|
|
|
|
Converter: &s.precision,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindMorphProcessor(balanceProcessor, s)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initFrostFSMainnetProcessor(ctx context.Context, cfg *viper.Viper) error {
|
2023-03-29 13:54:15 +00:00
|
|
|
if s.withoutMainNet {
|
|
|
|
return nil
|
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
poolSize := cfg.GetInt("workers.frostfs")
|
|
|
|
s.log.Debug(ctx, logs.FrostFSFrostfsWorkerPool, zap.Int("size", poolSize))
|
2023-03-29 13:54:15 +00:00
|
|
|
|
|
|
|
frostfsProcessor, err := frostfs.New(&frostfs.Params{
|
|
|
|
Log: s.log,
|
2023-06-08 13:37:46 +00:00
|
|
|
Metrics: s.irMetrics,
|
2024-10-21 13:27:28 +00:00
|
|
|
PoolSize: poolSize,
|
2023-03-29 13:54:15 +00:00
|
|
|
FrostFSContract: s.contracts.frostfs,
|
|
|
|
BalanceClient: s.balanceClient,
|
|
|
|
NetmapClient: s.netmapClient,
|
|
|
|
MorphClient: s.morphClient,
|
|
|
|
EpochState: s,
|
|
|
|
AlphabetState: s,
|
|
|
|
Converter: &s.precision,
|
|
|
|
MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"),
|
|
|
|
MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"),
|
|
|
|
MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")),
|
|
|
|
GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindMainnetProcessor(frostfsProcessor, s)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initGRPCServer(ctx context.Context, cfg *viper.Viper, log *logger.Logger, audit *atomic.Bool) error {
|
2023-03-29 13:54:15 +00:00
|
|
|
controlSvcEndpoint := cfg.GetString("control.grpc.endpoint")
|
|
|
|
if controlSvcEndpoint == "" {
|
2024-10-21 13:27:28 +00:00
|
|
|
s.log.Info(ctx, logs.InnerringNoControlServerEndpointSpecified)
|
2023-03-29 13:54:15 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
authKeysStr := cfg.GetStringSlice("control.authorized_keys")
|
|
|
|
authKeys := make([][]byte, 0, len(authKeysStr))
|
|
|
|
|
|
|
|
for i := range authKeysStr {
|
|
|
|
key, err := hex.DecodeString(authKeysStr[i])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not parse Control authorized key %s: %w",
|
|
|
|
authKeysStr[i],
|
|
|
|
err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
authKeys = append(authKeys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
var p controlsrv.Prm
|
|
|
|
|
|
|
|
p.SetPrivateKey(*s.key)
|
|
|
|
p.SetHealthChecker(s)
|
|
|
|
|
2024-06-18 09:40:38 +00:00
|
|
|
controlSvc := controlsrv.NewAuditService(controlsrv.New(p, s.netmapClient, s.containerClient,
|
2023-03-29 13:54:15 +00:00
|
|
|
controlsrv.WithAllowedKeys(authKeys),
|
2024-06-18 09:40:38 +00:00
|
|
|
), log, audit)
|
2023-03-29 13:54:15 +00:00
|
|
|
|
|
|
|
grpcControlSrv := grpc.NewServer()
|
|
|
|
control.RegisterControlServiceServer(grpcControlSrv, controlSvc)
|
|
|
|
|
|
|
|
s.runners = append(s.runners, func(ch chan<- error) error {
|
|
|
|
lis, err := net.Listen("tcp", controlSvcEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
ch <- grpcControlSrv.Serve(lis)
|
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.registerNoErrCloser(grpcControlSrv.GracefulStop)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type serverMorphClients struct {
|
2023-11-20 14:03:19 +00:00
|
|
|
CnrClient *container.Client
|
|
|
|
FrostFSIDClient *frostfsid.Client
|
|
|
|
FrostFSClient *frostfsClient.Client
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) initClientsFromMorph() (*serverMorphClients, error) {
|
|
|
|
result := &serverMorphClients{}
|
|
|
|
var err error
|
|
|
|
|
|
|
|
fee := s.feeConfig.SideChainFee()
|
|
|
|
|
|
|
|
// form morph container client's options
|
2023-04-03 13:11:56 +00:00
|
|
|
morphCnrOpts := make([]container.Option, 0, 3)
|
2023-03-29 13:54:15 +00:00
|
|
|
morphCnrOpts = append(morphCnrOpts,
|
2023-04-03 13:11:56 +00:00
|
|
|
container.AsAlphabet(),
|
2023-03-29 13:54:15 +00:00
|
|
|
)
|
|
|
|
|
2023-04-03 13:11:56 +00:00
|
|
|
result.CnrClient, err = container.NewFromMorph(s.morphClient, s.contracts.container, fee, morphCnrOpts...)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-10-16 15:15:04 +00:00
|
|
|
s.containerClient = result.CnrClient
|
2023-03-29 13:54:15 +00:00
|
|
|
|
2024-12-04 12:25:36 +00:00
|
|
|
s.netmapClient, err = nmClient.NewFromMorph(s.morphClient, s.contracts.netmap, fee, nmClient.AsAlphabet())
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-12-04 12:25:36 +00:00
|
|
|
s.balanceClient, err = balanceClient.NewFromMorph(s.morphClient, s.contracts.balance, fee, balanceClient.AsAlphabet())
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-20 14:03:19 +00:00
|
|
|
result.FrostFSIDClient, err = frostfsid.NewFromMorph(s.morphClient, s.contracts.frostfsID, fee)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-29 13:54:15 +00:00
|
|
|
result.FrostFSClient, err = frostfsClient.NewFromMorph(s.mainnetClient, s.contracts.frostfs,
|
|
|
|
s.feeConfig.MainChainFee(), frostfsClient.TryNotary(), frostfsClient.AsAlphabet())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (s *Server) initProcessors(ctx context.Context, cfg *viper.Viper, morphClients *serverMorphClients) error {
|
2023-03-29 13:54:15 +00:00
|
|
|
irf := s.createIRFetcher()
|
|
|
|
|
|
|
|
s.statusIndex = newInnerRingIndexer(
|
|
|
|
s.morphClient,
|
|
|
|
irf,
|
|
|
|
s.key.PublicKey(),
|
|
|
|
cfg.GetDuration("indexer.cache_timeout"),
|
|
|
|
)
|
|
|
|
|
2023-04-25 06:16:14 +00:00
|
|
|
alphaSync, err := s.createAlphaSync(cfg, morphClients.FrostFSClient, irf)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
err = s.initNetmapProcessor(ctx, cfg, alphaSync)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
err = s.initContainerProcessor(ctx, cfg, morphClients.CnrClient, morphClients.FrostFSIDClient)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
err = s.initBalanceProcessor(ctx, cfg, morphClients.FrostFSClient)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
err = s.initFrostFSMainnetProcessor(ctx, cfg)
|
2023-03-29 13:54:15 +00:00
|
|
|
if err != nil {
|
2023-05-12 07:41:04 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
err = s.initAlphabetProcessor(ctx, cfg)
|
2023-08-14 11:06:17 +00:00
|
|
|
return err
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) initMorph(ctx context.Context, cfg *viper.Viper, errChan chan<- error) (*chainParams, error) {
|
|
|
|
fromSideChainBlock, err := s.persistate.UInt32(persistateSideChainLastBlockKey)
|
|
|
|
if err != nil {
|
|
|
|
fromSideChainBlock = 0
|
2024-12-13 08:44:56 +00:00
|
|
|
s.log.Warn(ctx, logs.InnerringCantGetLastProcessedSideChainBlockNumber, zap.Error(err))
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
morphChain := &chainParams{
|
2023-05-26 09:15:50 +00:00
|
|
|
log: s.log,
|
|
|
|
cfg: cfg,
|
|
|
|
key: s.key,
|
|
|
|
name: morphPrefix,
|
|
|
|
from: fromSideChainBlock,
|
2023-06-08 13:37:46 +00:00
|
|
|
morphCacheMetric: s.irMetrics.MorphCacheMetrics(),
|
2024-10-15 11:46:00 +00:00
|
|
|
multinetMetrics: s.irMetrics.Multinet(),
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create morph client
|
|
|
|
s.morphClient, err = createClient(ctx, morphChain, errChan)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// create morph listener
|
|
|
|
s.morphListener, err = createListener(ctx, s.morphClient, morphChain)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := s.morphClient.SetGroupSignerScope(); err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
morphChain.log.Info(ctx, logs.InnerringFailedToSetGroupSignerScope, zap.Error(err))
|
2023-03-29 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return morphChain, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) initContracts(cfg *viper.Viper) error {
|
|
|
|
var err error
|
|
|
|
// get all script hashes of contracts
|
|
|
|
s.contracts, err = parseContracts(
|
|
|
|
cfg,
|
|
|
|
s.morphClient,
|
|
|
|
s.withoutMainNet,
|
|
|
|
s.mainNotaryConfig.disabled,
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) initKey(cfg *viper.Viper) error {
|
|
|
|
// prepare inner ring node private key
|
|
|
|
acc, err := utilConfig.LoadAccount(
|
|
|
|
cfg.GetString("wallet.path"),
|
|
|
|
cfg.GetString("wallet.address"),
|
|
|
|
cfg.GetString("wallet.password"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ir: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.key = acc.PrivateKey()
|
|
|
|
return nil
|
|
|
|
}
|