Skip to content

Commit

Permalink
Restore accused baking right if it was pruned
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Feb 13, 2024
1 parent f1353e2 commit befb3c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public async Task UpgradeProtocol(AppState state)
LBToggleThreshold = prev.LBToggleThreshold,
ConsensusThreshold = prev.ConsensusThreshold,
MaxDelegatedOverFrozenRatio = prev.MaxDelegatedOverFrozenRatio,
MaxExternalOverOwnStakeRatio = prev.MaxExternalOverOwnStakeRatio,
DoubleBakingSlashedPercentage = prev.DoubleBakingSlashedPercentage,
DoubleEndorsingSlashedPercentage = prev.DoubleEndorsingSlashedPercentage,
MinimalFrozenStake = prev.MinimalFrozenStake,
StakePowerMultiplier = prev.StakePowerMultiplier,
BaseIssuedPerMinute = prev.BaseIssuedPerMinute,
BlockBonusWeight = prev.BlockBonusWeight,
BlockRewardWeight = prev.BlockRewardWeight,
EndorsingRewardWeight = prev.EndorsingRewardWeight,
LBSubsidyWeight = prev.LBSubsidyWeight,
NonceRevelationRewardWeight = prev.NonceRevelationRewardWeight,
VdfRevelationRewardWeight = prev.VdfRevelationRewardWeight,
MaxBakingReward = prev.MaxBakingReward,
MaxEndorsingReward = prev.MaxEndorsingReward,
MaxSlashingPeriod = prev.MaxSlashingPeriod,
Expand Down
3 changes: 3 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto12/Rpc/Rpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ public override Task<JsonElement> GetStakeDistribution(int block, int cycle)

public override Task<JsonElement> GetDelegateParticipationAsync(int level, string address)
=> Node.GetAsync($"chains/main/blocks/{level}/context/delegates/{address}/participation");

public override Task<JsonElement> GetLevelBakingRightsAsync(int block, int level, int maxRound)
=> Node.GetAsync($"chains/main/blocks/{block}/helpers/baking_rights?level={level}&max_round={maxRound}&all=true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ public async Task Apply(Block block, JsonElement op, JsonElement content)
#region init
var accusedLevel = content.Required("bh1").RequiredInt32("level");
var accusedRound = Hex.Parse(content.Required("bh1").RequiredArray("fitness", 5)[4].RequiredString()).ToInt32();
var accusedRight = await Db.BakingRights.FirstAsync(x => x.Level == accusedLevel && x.Round == accusedRound);
var accusedBakerId = (await Db.BakingRights.AsNoTracking().FirstOrDefaultAsync(x => x.Level == accusedLevel && x.Round == accusedRound))?.BakerId;
if (accusedBakerId == null)
{
var rpcRights = await Proto.Rpc.GetLevelBakingRightsAsync(block.Level, accusedLevel, accusedRound);
var accusedBaker = rpcRights
.EnumerateArray()
.First(x => x.RequiredInt32("level") == accusedLevel && x.RequiredInt32("round") == accusedRound)
.RequiredString("delegate");
accusedBakerId = Cache.Accounts.GetDelegate(accusedBaker).Id;
}

var accuser = block.Proposer;
var offender = Cache.Accounts.GetDelegate(accusedRight.BakerId);
var offender = Cache.Accounts.GetDelegate(accusedBakerId);

var operation = new DoubleBakingOperation
{
Expand Down

0 comments on commit befb3c9

Please sign in to comment.