[#486] innerring: Adopt disabled notary work flow

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-29 16:50:46 +03:00 committed by Alex Vanin
parent f2562e8c47
commit 5a167f3991
5 changed files with 111 additions and 68 deletions

View file

@ -49,6 +49,7 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("metrics.shutdown_ttl", "30s") cfg.SetDefault("metrics.shutdown_ttl", "30s")
cfg.SetDefault("without_mainnet", false) cfg.SetDefault("without_mainnet", false)
cfg.SetDefault("without_notary", false)
cfg.SetDefault("morph.endpoint.client", "") cfg.SetDefault("morph.endpoint.client", "")
cfg.SetDefault("morph.endpoint.notification", "") cfg.SetDefault("morph.endpoint.notification", "")
@ -58,7 +59,6 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("mainnet.endpoint.client", "") cfg.SetDefault("mainnet.endpoint.client", "")
cfg.SetDefault("mainnet.endpoint.notification", "") cfg.SetDefault("mainnet.endpoint.notification", "")
cfg.SetDefault("mainnet.dial_timeout", "10s") cfg.SetDefault("mainnet.dial_timeout", "10s")
cfg.SetDefault("mainnet.notary_deposit", true)
cfg.SetDefault("key", "") // inner ring node key cfg.SetDefault("key", "") // inner ring node key

View file

@ -26,6 +26,8 @@ type (
epochTimerArgs struct { epochTimerArgs struct {
l *zap.Logger l *zap.Logger
notaryDisabled bool
nm *netmap.Processor // to handle new epoch tick nm *netmap.Processor // to handle new epoch tick
cnrWrapper *container.Wrapper // to invoke stop container estimation cnrWrapper *container.Wrapper // to invoke stop container estimation
@ -93,7 +95,14 @@ func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
return return
} }
err := args.cnrWrapper.StopEstimationNotary(epochN - 1) var err error
if args.notaryDisabled {
err = args.cnrWrapper.StopEstimation(epochN - 1)
} else {
err = args.cnrWrapper.StopEstimationNotary(epochN - 1)
}
if err != nil { if err != nil {
args.l.Warn("can't stop epoch estimation", args.l.Warn("can't stop epoch estimation",
zap.Uint64("epoch", epochN), zap.Uint64("epoch", epochN),

View file

@ -57,9 +57,10 @@ type (
precision precision.Fixed8Converter precision precision.Fixed8Converter
auditClient *auditWrapper.ClientWrapper auditClient *auditWrapper.ClientWrapper
notaryDisabled bool
feeConfig *config.FeeConfig
notaryDepositAmount fixedn.Fixed8 notaryDepositAmount fixedn.Fixed8
notaryDuration uint32 notaryDuration uint32
notaryMainDeposit bool
// internal variables // internal variables
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
@ -122,7 +123,7 @@ const (
) )
var ( var (
errDepositTimeout = errors.New("notary deposit didn't appeared in the network") errDepositTimeout = errors.New("notary deposit didn't appear in the network")
errDepositFail = errors.New("notary tx has faulted") errDepositFail = errors.New("notary tx has faulted")
) )
@ -139,18 +140,20 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
return err return err
} }
// make an initial deposit to notary contract to enable it if !s.notaryDisabled {
mainTx, sideTx, err := s.depositNotary() // make an initial deposit to notary contract to enable it
if err != nil { mainTx, sideTx, err := s.depositNotary()
return err if err != nil {
} return err
}
// wait a bit for notary contract deposit // wait a bit for notary contract deposit
s.log.Info("waiting to accept notary deposit") s.log.Info("waiting to accept notary deposit")
err = s.awaitNotaryDeposit(ctx, mainTx, sideTx) err = s.awaitNotaryDeposit(ctx, mainTx, sideTx)
if err != nil { if err != nil {
return err return err
}
} }
// vote for sidechain validator if it is prepared in config // vote for sidechain validator if it is prepared in config
@ -233,6 +236,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
var err error var err error
server := &Server{log: log} server := &Server{log: log}
// parse notary support
server.notaryDisabled = cfg.GetBool("without_notary")
if server.notaryDisabled {
server.feeConfig = config.NewFeeConfig(cfg)
}
// prepare inner ring node private key // prepare inner ring node private key
server.key, err = crypto.LoadPrivateKey(cfg.GetString("key")) server.key, err = crypto.LoadPrivateKey(cfg.GetString("key"))
if err != nil { if err != nil {
@ -271,9 +280,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
} }
// enable notary support in the client // enable notary support in the client
err = server.morphClient.EnableNotarySupport(server.contracts.proxy) if !server.notaryDisabled {
if err != nil { err = server.morphClient.EnableNotarySupport(server.contracts.proxy)
return nil, err if err != nil {
return nil, err
}
} }
withoutMainNet := cfg.GetBool("without_mainnet") withoutMainNet := cfg.GetBool("without_mainnet")
@ -301,12 +312,14 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
} }
// enable notary support in the client // enable notary support in the client
err = server.mainnetClient.EnableNotarySupport( if !server.notaryDisabled {
server.contracts.processing, err = server.mainnetClient.EnableNotarySupport(
client.WithAlphabetSource(server.morphClient.Committee), server.contracts.processing,
) client.WithAlphabetSource(server.morphClient.Committee),
if err != nil { )
return nil, err if err != nil {
return nil, err
}
} }
} }
@ -323,27 +336,27 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err return nil, err
} }
server.auditClient, err = invoke.NewAuditClient(server.morphClient, server.contracts.audit) server.auditClient, err = invoke.NewAuditClient(server.morphClient, server.contracts.audit, server.feeConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
cnrClient, err := invoke.NewContainerClient(server.morphClient, server.contracts.container) cnrClient, err := invoke.NewContainerClient(server.morphClient, server.contracts.container, server.feeConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nmClient, err := invoke.NewNetmapClient(server.morphClient, server.contracts.netmap) nmClient, err := invoke.NewNetmapClient(server.morphClient, server.contracts.netmap, server.feeConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
balClient, err := invoke.NewBalanceClient(server.morphClient, server.contracts.balance) balClient, err := invoke.NewBalanceClient(server.morphClient, server.contracts.balance, server.feeConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
repClient, err := invoke.NewReputationClient(server.morphClient, server.contracts.reputation) repClient, err := invoke.NewReputationClient(server.morphClient, server.contracts.reputation, server.feeConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -387,6 +400,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
AuditContract: server.contracts.audit, AuditContract: server.contracts.audit,
MorphClient: server.morphClient, MorphClient: server.morphClient,
IRList: server, IRList: server,
FeeProvider: server.feeConfig,
ClientCache: clientCache, ClientCache: clientCache,
Key: server.key, Key: server.key,
RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"), RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"),
@ -399,13 +413,14 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// create settlement processor dependencies // create settlement processor dependencies
settlementDeps := &settlementDeps{ settlementDeps := &settlementDeps{
globalConfig: globalConfig, globalConfig: globalConfig,
log: server.log, log: server.log,
cnrSrc: cnrClient, cnrSrc: cnrClient,
auditClient: server.auditClient, auditClient: server.auditClient,
nmSrc: nmClient, nmSrc: nmClient,
clientCache: clientCache, clientCache: clientCache,
balanceClient: balClient, balanceClient: balClient,
notaryDisabled: server.notaryDisabled,
} }
auditCalcDeps := &auditSettlementDeps{ auditCalcDeps := &auditSettlementDeps{
@ -447,13 +462,16 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// create governance processor // create governance processor
governanceProcessor, err := governance.New(&governance.Params{ governanceProcessor, err := governance.New(&governance.Params{
Log: log, Log: log,
NeoFSContract: server.contracts.neofs, NeoFSContract: server.contracts.neofs,
AlphabetState: server, NetmapContract: server.contracts.netmap,
EpochState: server, AlphabetState: server,
Voter: server, EpochState: server,
MorphClient: server.morphClient, Voter: server,
MainnetClient: server.mainnetClient, MorphClient: server.morphClient,
MainnetClient: server.mainnetClient,
NotaryDisabled: server.notaryDisabled,
FeeProvider: server.feeConfig,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -489,6 +507,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
), ),
AlphabetSyncHandler: alphaSync, AlphabetSyncHandler: alphaSync,
NodeValidator: locodeValidator, NodeValidator: locodeValidator,
NotaryDisabled: server.notaryDisabled,
FeeProvider: server.feeConfig,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -506,6 +526,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
ContainerContract: server.contracts.container, ContainerContract: server.contracts.container,
MorphClient: server.morphClient, MorphClient: server.morphClient,
AlphabetState: server, AlphabetState: server,
FeeProvider: server.feeConfig,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -525,6 +546,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
MainnetClient: server.mainnetClient, MainnetClient: server.mainnetClient,
AlphabetState: server, AlphabetState: server,
Converter: &server.precision, Converter: &server.precision,
FeeProvider: server.feeConfig,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -548,6 +570,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
EpochState: server, EpochState: server,
AlphabetState: server, AlphabetState: server,
Converter: &server.precision, Converter: &server.precision,
FeeProvider: server.feeConfig,
MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"), MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"),
MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"), MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"),
MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")), MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")),
@ -585,6 +608,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
reputationProcessor, err := reputation.New(&reputation.Params{ reputationProcessor, err := reputation.New(&reputation.Params{
Log: log, Log: log,
PoolSize: cfg.GetInt("workers.reputation"), PoolSize: cfg.GetInt("workers.reputation"),
NotaryDisabled: server.notaryDisabled,
ReputationContract: server.contracts.reputation, ReputationContract: server.contracts.reputation,
EpochState: server, EpochState: server,
AlphabetState: server, AlphabetState: server,
@ -604,6 +628,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// initialize epoch timers // initialize epoch timers
server.epochTimer = newEpochTimer(&epochTimerArgs{ server.epochTimer = newEpochTimer(&epochTimerArgs{
l: server.log, l: server.log,
notaryDisabled: server.notaryDisabled,
nm: netmapProcessor, nm: netmapProcessor,
cnrWrapper: cnrClient, cnrWrapper: cnrClient,
epoch: server, epoch: server,
@ -632,18 +657,19 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
server.addBlockTimer(emissionTimer) server.addBlockTimer(emissionTimer)
// initialize notary deposit timer if !server.notaryDisabled {
server.notaryDepositAmount = fixedn.Fixed8(cfg.GetInt64("notary.deposit_amount")) // initialize notary deposit timer
server.notaryDuration = cfg.GetUint32("timers.notary") server.notaryDepositAmount = fixedn.Fixed8(cfg.GetInt64("notary.deposit_amount"))
server.notaryMainDeposit = cfg.GetBool("mainnet.notary_deposit") server.notaryDuration = cfg.GetUint32("timers.notary")
notaryTimer := newNotaryDepositTimer(&notaryDepositArgs{ notaryTimer := newNotaryDepositTimer(&notaryDepositArgs{
l: log, l: log,
depositor: server.depositNotary, depositor: server.depositNotary,
notaryDuration: server.notaryDuration, notaryDuration: server.notaryDuration,
}) })
server.addBlockTimer(notaryTimer) server.addBlockTimer(notaryTimer)
}
return server, nil return server, nil
} }
@ -834,14 +860,12 @@ func (s *Server) onlyAlphabetEventHandler(f event.Handler) event.Handler {
} }
func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) { func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
if s.notaryMainDeposit { mainTx, err = s.mainnetClient.DepositNotary(
mainTx, err = s.mainnetClient.DepositNotary( s.notaryDepositAmount,
s.notaryDepositAmount, s.notaryDuration+notaryExtraBlocks,
s.notaryDuration+notaryExtraBlocks, )
) if err != nil {
if err != nil { return
return
}
} }
sideTx, err = s.morphClient.DepositNotary( sideTx, err = s.morphClient.DepositNotary(
@ -853,11 +877,9 @@ func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
} }
func (s *Server) awaitNotaryDeposit(ctx context.Context, mainTx, sideTx util.Uint256) error { func (s *Server) awaitNotaryDeposit(ctx context.Context, mainTx, sideTx util.Uint256) error {
if s.notaryMainDeposit { err := awaitNotaryDepositInClient(ctx, s.mainnetClient, mainTx)
err := awaitNotaryDepositInClient(ctx, s.mainnetClient, mainTx) if err != nil {
if err != nil { return err
return err
}
} }
return awaitNotaryDepositInClient(ctx, s.morphClient, sideTx) return awaitNotaryDepositInClient(ctx, s.morphClient, sideTx)

View file

@ -45,6 +45,8 @@ type settlementDeps struct {
clientCache *ClientCache clientCache *ClientCache
balanceClient *balanceClient.Wrapper balanceClient *balanceClient.Wrapper
notaryDisabled bool
} }
type auditSettlementDeps struct { type auditSettlementDeps struct {
@ -205,12 +207,22 @@ func (s settlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int, d
return return
} }
if err := s.balanceClient.TransferXNotary(balanceClient.TransferPrm{ params := balanceClient.TransferPrm{
Amount: amount.Int64(), Amount: amount.Int64(),
From: sender, From: sender,
To: recipient, To: recipient,
Details: details, Details: details,
}); err != nil { }
var err error
if s.notaryDisabled {
err = s.balanceClient.TransferX(params)
} else {
err = s.balanceClient.TransferXNotary(params)
}
if err != nil {
log.Error("could not send transfer transaction for audit", log.Error("could not send transfer transaction for audit",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )

View file

@ -84,7 +84,7 @@ func (s *Server) voteForSidechainValidator(validators keys.PublicKeys) error {
epoch := s.EpochCounter() epoch := s.EpochCounter()
s.contracts.alphabet.iterate(func(letter glagoliticLetter, contract util.Uint160) { s.contracts.alphabet.iterate(func(letter glagoliticLetter, contract util.Uint160) {
err := invoke.AlphabetVote(s.morphClient, contract, epoch, validators) err := invoke.AlphabetVote(s.morphClient, contract, s.feeConfig, epoch, validators)
if err != nil { if err != nil {
s.log.Warn("can't invoke vote method in alphabet contract", s.log.Warn("can't invoke vote method in alphabet contract",
zap.Int8("alphabet_index", int8(letter)), zap.Int8("alphabet_index", int8(letter)),