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/audit"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/governance"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/settlement"
|
|
|
|
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.
|
2021-11-10 11:05:51 +00:00
|
|
|
func (np *Processor) processNewEpoch(ev netmapEvent.NewEpoch) {
|
|
|
|
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
|
|
|
|
|
|
|
h, err := np.netmapClient.Morph().TxHeight(ev.TxHash())
|
|
|
|
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()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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-04-29 13:40:34 +00:00
|
|
|
|
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()})
|
2020-12-18 09:27:19 +00:00
|
|
|
np.handleNewAudit(audit.NewAuditStartEvent(epoch))
|
2021-01-28 19:51:41 +00:00
|
|
|
np.handleAuditSettlements(settlement.NewAuditEvent(epoch))
|
2021-11-10 11:05:51 +00:00
|
|
|
np.handleAlphabetSync(governance.NewSyncEvent(ev.TxHash()))
|
|
|
|
np.handleNotaryDeposit(ev)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process new epoch tick by invoking new epoch method in network map contract.
|
|
|
|
func (np *Processor) processNewEpochTick() {
|
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)
|
2020-07-24 13:54:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-05-31 11:50:11 +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))
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
}
|