2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
|
|
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.
|
2023-05-26 10:24:41 +00:00
|
|
|
func (np *Processor) processNewEpoch(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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(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-01-31 13:34:01 +00:00
|
|
|
prm := cntClient.StartEstimationPrm{}
|
2021-11-12 15:19:05 +00:00
|
|
|
|
|
|
|
prm.SetEpoch(epoch - 1)
|
|
|
|
prm.SetHash(ev.TxHash())
|
|
|
|
|
2023-03-30 15:24:07 +00:00
|
|
|
if epoch > 0 && np.alphabetState.IsAlphabet() { // estimates are invalid in genesis epoch
|
2021-11-12 15:19:05 +00:00
|
|
|
err = np.containerWrp.StartEstimation(prm)
|
2021-01-29 07:48:47 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapCantStartContainerSizeEstimation,
|
2021-01-29 07:48:47 +00:00
|
|
|
zap.Uint64("epoch", epoch),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
np.netmapSnapshot.update(*networkMap, epoch)
|
2021-11-10 11:05:51 +00:00
|
|
|
np.handleCleanupTick(netmapCleanupTick{epoch: epoch, txHash: ev.TxHash()})
|
|
|
|
np.handleAlphabetSync(governance.NewSyncEvent(ev.TxHash()))
|
|
|
|
np.handleNotaryDeposit(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.
|
2023-05-26 10:24:41 +00:00
|
|
|
func (np *Processor) processNewEpochTick() bool {
|
2021-03-23 15:20:44 +00:00
|
|
|
if !np.alphabetState.IsAlphabet() {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Info(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
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Debug(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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Error(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
|
|
|
}
|