[#910] innerring: Make notary deposit on notification instead of timer

Timer is not suitable for notary deposits because it can never fire
in case of desynchronization or external epoch changes. Notary deposits
must be handled on new epoch event.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-11-01 18:55:25 +03:00 committed by Alex Vanin
parent 45f244eb77
commit a437ffc3ed
6 changed files with 35 additions and 38 deletions

View file

@ -50,12 +50,6 @@ type (
depositor func() (util.Uint256, error)
awaiter func(context.Context, util.Uint256) error
notaryDepositArgs struct {
l *zap.Logger
depositor depositor
}
)
func (s *Server) addBlockTimer(t *timer.BlockTimer) {
@ -148,13 +142,3 @@ func newEmissionTimer(args *emitTimerArgs) *timer.BlockTimer {
},
)
}
func newNotaryDepositHandler(args *notaryDepositArgs) newEpochHandler {
return func() {
_, err := args.depositor()
if err != nil {
args.l.Warn("can't deposit notary contract",
zap.String("error", err.Error()))
}
}
}

View file

@ -647,6 +647,9 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
HandleAudit: server.onlyActiveEventHandler(
auditProcessor.StartAuditHandler(),
),
NotaryDepositHandler: server.onlyAlphabetEventHandler(
server.notaryHandler,
),
AuditSettlementsHandler: server.onlyAlphabetEventHandler(
settlementProcessor.HandleAuditEvent,
),
@ -777,7 +780,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// initialize epoch timers
server.epochTimer = newEpochTimer(&epochTimerArgs{
l: server.log,
newEpochHandlers: server.newEpochHandlers(log),
newEpochHandlers: server.newEpochTickHandlers(),
cnrWrapper: cnrClient,
epoch: server,
stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"),
@ -1015,30 +1018,12 @@ func (s *Server) onlyAlphabetEventHandler(f event.Handler) event.Handler {
}
}
func (s *Server) newEpochHandlers(log *zap.Logger) []newEpochHandler {
func (s *Server) newEpochTickHandlers() []newEpochHandler {
newEpochHandlers := []newEpochHandler{
func() {
s.netmapProcessor.HandleNewEpochTick(timerEvent.NewEpochTick{})
},
}
if !s.mainNotaryConfig.disabled {
newEpochHandlers = append(newEpochHandlers,
newNotaryDepositHandler(&notaryDepositArgs{
l: log,
depositor: s.depositMainNotary,
}),
)
}
if !s.sideNotaryConfig.disabled {
newEpochHandlers = append(newEpochHandlers,
newNotaryDepositHandler(&notaryDepositArgs{
l: log,
depositor: s.depositSideNotary,
}),
)
}
return newEpochHandlers
}

View file

@ -6,7 +6,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/spf13/viper"
"go.uber.org/zap"
)
type (
@ -50,6 +52,22 @@ func (s *Server) depositSideNotary() (tx util.Uint256, err error) {
)
}
func (s *Server) notaryHandler(_ event.Event) {
if !s.mainNotaryConfig.disabled {
_, err := s.depositMainNotary()
if err != nil {
s.log.Error("can't make notary deposit in main chain", zap.Error(err))
}
}
if !s.sideNotaryConfig.disabled {
_, err := s.depositSideNotary()
if err != nil {
s.log.Error("can't make notary deposit in side chain", zap.Error(err))
}
}
}
func (s *Server) awaitMainNotaryDeposit(ctx context.Context, tx util.Uint256) error {
return awaitNotaryDepositInClient(ctx, s.mainnetClient, tx)
}

View file

@ -32,7 +32,7 @@ func (np *Processor) handleNewEpoch(ev event.Event) {
// send event to the worker pool
err := np.pool.Submit(func() {
np.processNewEpoch(epochEvent.EpochNumber())
np.processNewEpoch(epochEvent)
})
if err != nil {
// there system can be moved into controlled degradation stage

View file

@ -4,12 +4,15 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/governance"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"go.uber.org/zap"
)
// Process new epoch notification by setting global epoch value and resetting
// local epoch timer.
func (np *Processor) processNewEpoch(epoch uint64) {
func (np *Processor) processNewEpoch(event netmapEvent.NewEpoch) {
epoch := event.EpochNumber()
epochDuration, err := np.netmapClient.EpochDuration()
if err != nil {
np.log.Warn("can't get epoch duration",
@ -48,6 +51,7 @@ func (np *Processor) processNewEpoch(epoch uint64) {
np.handleNewAudit(audit.NewAuditStartEvent(epoch))
np.handleAuditSettlements(settlement.NewAuditEvent(epoch))
np.handleAlphabetSync(governance.NewSyncEvent())
np.handleNotaryDeposit(event)
}
// Process new epoch tick by invoking new epoch method in network map contract.

View file

@ -65,6 +65,7 @@ type (
handleNewAudit event.Handler
handleAuditSettlements event.Handler
handleAlphabetSync event.Handler
handleNotaryDeposit event.Handler
nodeValidator NodeValidator
@ -86,6 +87,7 @@ type (
HandleAudit event.Handler
AuditSettlementsHandler event.Handler
AlphabetSyncHandler event.Handler
NotaryDepositHandler event.Handler
NodeValidator NodeValidator
@ -116,6 +118,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/netmap: audit settlement handler is not set")
case p.AlphabetSyncHandler == nil:
return nil, errors.New("ir/netmap: alphabet sync handler is not set")
case p.NotaryDepositHandler == nil:
return nil, errors.New("ir/netmap: notary deposit handler is not set")
case p.ContainerWrapper == nil:
return nil, errors.New("ir/netmap: container contract wrapper is not set")
case p.NodeValidator == nil:
@ -144,6 +148,8 @@ func New(p *Params) (*Processor, error) {
handleAlphabetSync: p.AlphabetSyncHandler,
handleNotaryDeposit: p.NotaryDepositHandler,
nodeValidator: p.NodeValidator,
notaryDisabled: p.NotaryDisabled,