[#798] cmd/neofs-node: Save latest processed block number

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-09-06 16:05:45 +03:00 committed by Alex Vanin
parent cdb3b71070
commit 4874b4ae92
2 changed files with 32 additions and 6 deletions

View file

@ -179,11 +179,19 @@ func listenMorphNotifications(c *cfg) {
endpoints[i], endpoints[j] = endpoints[j], endpoints[i]
})
fromSideChainBlock, err := c.persistate.UInt32(persistateSideChainLastBlockKey)
if err != nil {
fromSideChainBlock = 0
c.log.Warn("can't get last processed side chain block number", zap.String("error", err.Error()))
}
for i := range endpoints {
subs, err = subscriber.New(c.ctx, &subscriber.Params{
Log: c.log,
Endpoint: endpoints[i],
DialTimeout: timeout,
Log: c.log,
Endpoint: endpoints[i],
DialTimeout: timeout,
RPCInitTimeout: 10 * time.Second,
StartFromBlock: fromSideChainBlock,
})
if err == nil {
c.log.Info("websocket neo event listener established",
@ -215,6 +223,14 @@ func listenMorphNotifications(c *cfg) {
registerBlockHandler(lis, func(block *block.Block) {
c.log.Debug("new block", zap.Uint32("index", block.Index))
err = c.persistate.SetUInt32(persistateSideChainLastBlockKey, block.Index)
if err != nil {
c.log.Warn("can't update persistent state",
zap.String("chain", "side"),
zap.Uint32("block_index", block.Index))
}
tickBlockTimers(c)
})
}