From f1353e272a9ae164b40ae73d62b7eadc0dcd3218 Mon Sep 17 00:00:00 2001 From: Maksim Strebkov <257byte@gmail.com> Date: Tue, 13 Feb 2024 18:32:24 +0300 Subject: [PATCH] Update rewards for existing future cycles during migration --- .../Proto18/Activation/ProtoActivator.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tzkt.Sync/Protocols/Handlers/Proto18/Activation/ProtoActivator.cs b/Tzkt.Sync/Protocols/Handlers/Proto18/Activation/ProtoActivator.cs index ea6fcd2b..1d8d3b82 100644 --- a/Tzkt.Sync/Protocols/Handlers/Proto18/Activation/ProtoActivator.cs +++ b/Tzkt.Sync/Protocols/Handlers/Proto18/Activation/ProtoActivator.cs @@ -198,6 +198,7 @@ protected override async Task MigrateContext(AppState state) await RemoveDeadRefutationGames(state); await RemoveBigmapKeys(state); await MigrateBakers(state); + await MigrateCycles(state); } protected async Task RemoveDeadRefutationGames(AppState state) @@ -385,5 +386,25 @@ async Task MigrateBakers(AppState state) baker.TotalStakedBalance = stakes.GetValueOrDefault(baker.Address); } } + + async Task MigrateCycles(AppState state) + { + var issuances = await Proto.Rpc.GetExpectedIssuance(state.Level); + var protocol = await Cache.Protocols.GetAsync(state.NextProtocol); + var cycles = await Db.Cycles.Where(x => x.Index > state.Cycle).ToListAsync(); + foreach (var cycle in cycles) + { + var issuance = issuances.EnumerateArray().First(x => x.RequiredInt32("cycle") == cycle.Index); + + cycle.BlockReward = issuance.RequiredInt64("baking_reward_fixed_portion"); + cycle.BlockBonusPerSlot = issuance.RequiredInt64("baking_reward_bonus_per_slot"); + cycle.MaxBlockReward = cycle.BlockReward + cycle.BlockBonusPerSlot * (protocol.EndorsersPerBlock - protocol.ConsensusThreshold); + cycle.EndorsementRewardPerSlot = issuance.RequiredInt64("attesting_reward_per_slot"); + cycle.NonceRevelationReward = issuance.RequiredInt64("seed_nonce_revelation_tip"); + cycle.VdfRevelationReward = issuance.RequiredInt64("vdf_revelation_tip"); + cycle.LBSubsidy = issuance.RequiredInt64("liquidity_baking_subsidy"); + } + + } } }