Skip to content

Commit

Permalink
Hotfix for inconsistent snapshot index
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Apr 4, 2022
1 parent 86627aa commit c31bc3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public virtual async Task Apply(
if (snapshot.StakingBalance >= block.Protocol.TokensPerRoll)
{
var baker = Cache.Accounts.GetDelegate(snapshot.AccountId);
var depositCap = Math.Min(baker.Balance, baker.FrozenDepositLimit ?? (long.MaxValue / 100));
var depositCap = Math.Min(snapshot.Balance, baker.FrozenDepositLimit ?? (long.MaxValue / 100));
var activeStake = Math.Min((long)snapshot.StakingBalance, depositCap * 100 / block.Protocol.FrozenDepositsPercentage);
var expectedEndorsements = (int)(new BigInteger(block.Protocol.BlocksPerCycle) * block.Protocol.EndorsersPerBlock * activeStake / futureCycle.SelectedStake);
bakerCycle.ExpectedBlocks = block.Protocol.BlocksPerCycle * activeStake / futureCycle.SelectedStake;
Expand Down
6 changes: 5 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto12/Commits/CycleCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public virtual async Task Apply(Block block)
{
var snapshotProto = await Cache.Protocols.FindByCycleAsync(block.Cycle - 1);
snapshotIndex = Seed.GetSnapshotIndex(futureSeed, true);
#region WTF?!
if (Cache.AppState.Get().Chain == "mainnet" && block.Cycle == 469)
snapshotIndex = 15;
#endregion
snapshotLevel = snapshotProto.GetCycleStart(block.Cycle - 1) - 1 + (snapshotIndex + 1) * snapshotProto.BlocksPerSnapshot;
}
}
Expand All @@ -63,7 +67,7 @@ public virtual async Task Apply(Block block)
.Select(x =>
{
var baker = Cache.Accounts.GetDelegate(x.AccountId);
var depositCap = Math.Min(baker.Balance, baker.FrozenDepositLimit ?? (long.MaxValue / 100));
var depositCap = Math.Min(x.Balance, baker.FrozenDepositLimit ?? (long.MaxValue / 100));
return Math.Min((long)x.StakingBalance, depositCap * 100 / block.Protocol.FrozenDepositsPercentage);
});

Expand Down

0 comments on commit c31bc3d

Please sign in to comment.