[#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("without_mainnet", false)
cfg.SetDefault("without_notary", false)
cfg.SetDefault("morph.endpoint.client", "")
cfg.SetDefault("morph.endpoint.notification", "")
@ -58,7 +59,6 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("mainnet.endpoint.client", "")
cfg.SetDefault("mainnet.endpoint.notification", "")
cfg.SetDefault("mainnet.dial_timeout", "10s")
cfg.SetDefault("mainnet.notary_deposit", true)
cfg.SetDefault("key", "") // inner ring node key

View file

@ -26,6 +26,8 @@ type (
epochTimerArgs struct {
l *zap.Logger
notaryDisabled bool
nm *netmap.Processor // to handle new epoch tick
cnrWrapper *container.Wrapper // to invoke stop container estimation
@ -93,7 +95,14 @@ func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
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 {
args.l.Warn("can't stop epoch estimation",
zap.Uint64("epoch", epochN),

View file

@ -57,9 +57,10 @@ type (
precision precision.Fixed8Converter
auditClient *auditWrapper.ClientWrapper
notaryDisabled bool
feeConfig *config.FeeConfig
notaryDepositAmount fixedn.Fixed8
notaryDuration uint32
notaryMainDeposit bool
// internal variables
key *ecdsa.PrivateKey
@ -122,7 +123,7 @@ const (
)
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")
)
@ -139,6 +140,7 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
return err
}
if !s.notaryDisabled {
// make an initial deposit to notary contract to enable it
mainTx, sideTx, err := s.depositNotary()
if err != nil {
@ -152,6 +154,7 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
if err != nil {
return err
}
}
// vote for sidechain validator if it is prepared in config
err = s.voteForSidechainValidator(s.predefinedValidators)
@ -233,6 +236,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
var err error
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
server.key, err = crypto.LoadPrivateKey(cfg.GetString("key"))
if err != nil {
@ -271,10 +280,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
}
// enable notary support in the client
if !server.notaryDisabled {
err = server.morphClient.EnableNotarySupport(server.contracts.proxy)
if err != nil {
return nil, err
}
}
withoutMainNet := cfg.GetBool("without_mainnet")
@ -301,6 +312,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
}
// enable notary support in the client
if !server.notaryDisabled {
err = server.mainnetClient.EnableNotarySupport(
server.contracts.processing,
client.WithAlphabetSource(server.morphClient.Committee),
@ -309,6 +321,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err
}
}
}
server.pubKey = crypto.MarshalPublicKey(&server.key.PublicKey)
@ -323,27 +336,27 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
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 {
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 {
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 {
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 {
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 {
return nil, err
}
@ -387,6 +400,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
AuditContract: server.contracts.audit,
MorphClient: server.morphClient,
IRList: server,
FeeProvider: server.feeConfig,
ClientCache: clientCache,
Key: server.key,
RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"),
@ -406,6 +420,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
nmSrc: nmClient,
clientCache: clientCache,
balanceClient: balClient,
notaryDisabled: server.notaryDisabled,
}
auditCalcDeps := &auditSettlementDeps{
@ -449,11 +464,14 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
governanceProcessor, err := governance.New(&governance.Params{
Log: log,
NeoFSContract: server.contracts.neofs,
NetmapContract: server.contracts.netmap,
AlphabetState: server,
EpochState: server,
Voter: server,
MorphClient: server.morphClient,
MainnetClient: server.mainnetClient,
NotaryDisabled: server.notaryDisabled,
FeeProvider: server.feeConfig,
})
if err != nil {
return nil, err
@ -489,6 +507,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
),
AlphabetSyncHandler: alphaSync,
NodeValidator: locodeValidator,
NotaryDisabled: server.notaryDisabled,
FeeProvider: server.feeConfig,
})
if err != nil {
return nil, err
@ -506,6 +526,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
ContainerContract: server.contracts.container,
MorphClient: server.morphClient,
AlphabetState: server,
FeeProvider: server.feeConfig,
})
if err != nil {
return nil, err
@ -525,6 +546,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
MainnetClient: server.mainnetClient,
AlphabetState: server,
Converter: &server.precision,
FeeProvider: server.feeConfig,
})
if err != nil {
return nil, err
@ -548,6 +570,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
EpochState: server,
AlphabetState: server,
Converter: &server.precision,
FeeProvider: server.feeConfig,
MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"),
MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"),
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{
Log: log,
PoolSize: cfg.GetInt("workers.reputation"),
NotaryDisabled: server.notaryDisabled,
ReputationContract: server.contracts.reputation,
EpochState: server,
AlphabetState: server,
@ -604,6 +628,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// initialize epoch timers
server.epochTimer = newEpochTimer(&epochTimerArgs{
l: server.log,
notaryDisabled: server.notaryDisabled,
nm: netmapProcessor,
cnrWrapper: cnrClient,
epoch: server,
@ -632,10 +657,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
server.addBlockTimer(emissionTimer)
if !server.notaryDisabled {
// initialize notary deposit timer
server.notaryDepositAmount = fixedn.Fixed8(cfg.GetInt64("notary.deposit_amount"))
server.notaryDuration = cfg.GetUint32("timers.notary")
server.notaryMainDeposit = cfg.GetBool("mainnet.notary_deposit")
notaryTimer := newNotaryDepositTimer(&notaryDepositArgs{
l: log,
@ -644,6 +669,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
})
server.addBlockTimer(notaryTimer)
}
return server, nil
}
@ -834,7 +860,6 @@ func (s *Server) onlyAlphabetEventHandler(f event.Handler) event.Handler {
}
func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
if s.notaryMainDeposit {
mainTx, err = s.mainnetClient.DepositNotary(
s.notaryDepositAmount,
s.notaryDuration+notaryExtraBlocks,
@ -842,7 +867,6 @@ func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
if err != nil {
return
}
}
sideTx, err = s.morphClient.DepositNotary(
s.notaryDepositAmount,
@ -853,12 +877,10 @@ func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
}
func (s *Server) awaitNotaryDeposit(ctx context.Context, mainTx, sideTx util.Uint256) error {
if s.notaryMainDeposit {
err := awaitNotaryDepositInClient(ctx, s.mainnetClient, mainTx)
if err != nil {
return err
}
}
return awaitNotaryDepositInClient(ctx, s.morphClient, sideTx)
}

View file

@ -45,6 +45,8 @@ type settlementDeps struct {
clientCache *ClientCache
balanceClient *balanceClient.Wrapper
notaryDisabled bool
}
type auditSettlementDeps struct {
@ -205,12 +207,22 @@ func (s settlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int, d
return
}
if err := s.balanceClient.TransferXNotary(balanceClient.TransferPrm{
params := balanceClient.TransferPrm{
Amount: amount.Int64(),
From: sender,
To: recipient,
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",
zap.String("error", err.Error()),
)

View file

@ -84,7 +84,7 @@ func (s *Server) voteForSidechainValidator(validators keys.PublicKeys) error {
epoch := s.EpochCounter()
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 {
s.log.Warn("can't invoke vote method in alphabet contract",
zap.Int8("alphabet_index", int8(letter)),