2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2024-10-21 07:22:54 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/governance"
|
|
|
|
netmapEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
|
2020-07-24 13:54:03 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Process new epoch notification by setting global epoch value and resetting
|
|
|
|
// local epoch timer.
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) processNewEpoch(ctx context.Context, ev netmapEvent.NewEpoch) bool {
|
2021-11-10 11:05:51 +00:00
|
|
|
epoch := ev.EpochNumber()
|
2021-11-01 15:55:25 +00:00
|
|
|
|
2021-10-11 17:09:52 +00:00
|
|
|
epochDuration, err := np.netmapClient.EpochDuration()
|
|
|
|
if err != nil {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapCantGetEpochDuration,
|
2021-10-11 17:09:52 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
} else {
|
|
|
|
np.epochState.SetEpochDuration(epochDuration)
|
|
|
|
}
|
|
|
|
|
2021-10-14 11:04:09 +00:00
|
|
|
np.epochState.SetEpochCounter(epoch)
|
2022-04-04 07:07:33 +00:00
|
|
|
|
2023-04-27 14:57:27 +00:00
|
|
|
h, err := np.netmapClient.MorphTxHeight(ev.TxHash())
|
2022-04-04 07:07:33 +00:00
|
|
|
if err != nil {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapCantGetTransactionHeight,
|
2022-04-04 07:07:33 +00:00
|
|
|
zap.String("hash", ev.TxHash().StringLE()),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := np.epochTimer.ResetEpochTimer(h); err != nil {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapCantResetEpochTimer,
|
2021-10-14 11:04:09 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:08:36 +00:00
|
|
|
// get new netmap snapshot
|
2022-09-28 11:34:28 +00:00
|
|
|
networkMap, err := np.netmapClient.NetMap()
|
2020-10-29 16:08:36 +00:00
|
|
|
if err != nil {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapCantGetNetmapSnapshotToPerformCleanup,
|
2020-10-29 16:08:36 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
return false
|
2020-10-29 16:08:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
np.netmapSnapshot.update(*networkMap, epoch)
|
2024-10-21 09:21:01 +00:00
|
|
|
np.handleCleanupTick(ctx, netmapCleanupTick{epoch: epoch, txHash: ev.TxHash()})
|
|
|
|
np.handleAlphabetSync(ctx, governance.NewSyncEvent(ev.TxHash()))
|
|
|
|
np.handleNotaryDeposit(ctx, ev)
|
2023-05-26 10:24:41 +00:00
|
|
|
|
|
|
|
return true
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process new epoch tick by invoking new epoch method in network map contract.
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) processNewEpochTick(ctx context.Context) bool {
|
2021-03-23 15:20:44 +00:00
|
|
|
if !np.alphabetState.IsAlphabet() {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Info(ctx, logs.NetmapNonAlphabetModeIgnoreNewEpochTick)
|
2023-05-26 10:24:41 +00:00
|
|
|
return true
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextEpoch := np.epochState.EpochCounter() + 1
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Debug(ctx, logs.NetmapNextEpoch, zap.Uint64("value", nextEpoch))
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2023-11-08 09:05:03 +00:00
|
|
|
err := np.netmapClient.NewEpoch(nextEpoch)
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Error(ctx, logs.NetmapCantInvokeNetmapNewEpoch, zap.Error(err))
|
2023-05-26 10:24:41 +00:00
|
|
|
return false
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2023-05-26 10:24:41 +00:00
|
|
|
|
|
|
|
return true
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|