Skip to content

Commit

Permalink
Update diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Sep 19, 2022
1 parent 0faf43b commit e4a67f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Tzkt.Data.Models;
using Tzkt.Sync.Utils;
Expand All @@ -23,7 +24,7 @@ protected override async Task TestDelegate(int level, Data.Models.Delegate deleg
if (remote.RequiredInt64("staking_balance") != delegat.StakingBalance)
throw new Exception($"Diagnostics failed: wrong staking balance {delegat.Address}");

if (remote.RequiredInt64("delegated_balance") != delegat.DelegatedBalance + delegat.RollupBonds)
if (!CheckDelegatedBalance(remote, delegat))
throw new Exception($"Diagnostics failed: wrong delegated balance {delegat.Address}");

if (remote.RequiredBool("deactivated") != !delegat.Staked)
Expand Down Expand Up @@ -93,5 +94,8 @@ protected override async Task TestCycle(AppState state, Cycle cycle)
if (remote.RequiredArray("selected_stake_distribution").Count() != cycle.SelectedBakers)
throw new Exception($"Invalid cycle {cycle.Index} selected bakers {cycle.SelectedBakers}");
}

protected virtual bool CheckDelegatedBalance(JsonElement remote, Data.Models.Delegate delegat) =>
remote.RequiredInt64("delegated_balance") == delegat.DelegatedBalance + delegat.RollupBonds;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace Tzkt.Sync.Protocols.Proto14
using System.Text.Json;
using Tzkt.Data.Models;

namespace Tzkt.Sync.Protocols.Proto14
{
class Diagnostics : Proto12.Diagnostics
{
public Diagnostics(ProtocolHandler handler) : base(handler) { }

protected override bool CheckDelegatedBalance(JsonElement remote, Delegate delegat) =>
remote.RequiredInt64("delegated_balance") == delegat.DelegatedBalance;
}
}

0 comments on commit e4a67f0

Please sign in to comment.