-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporarily change the fetching of endorsing rights for a cycle
- Loading branch information
Showing
4 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
Tzkt.Sync/Protocols/Handlers/Proto10/Commits/BakingRightsCommit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
namespace Tzkt.Sync.Protocols.Proto10 | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Tzkt.Data.Models; | ||
|
||
namespace Tzkt.Sync.Protocols.Proto10 | ||
{ | ||
class BakingRightsCommit : Proto3.BakingRightsCommit | ||
{ | ||
public BakingRightsCommit(ProtocolHandler protocol) : base(protocol) { } | ||
|
||
// Tezos node is no longer able to return endorsing rights for the whole cycle, so we have to find another way... | ||
protected override async Task<IEnumerable<JsonElement>> GetEndorsingRights(Block block, int cycle) | ||
{ | ||
var rights = new List<JsonElement>(block.Protocol.BlocksPerCycle * block.Protocol.EndorsersPerBlock / 2); | ||
var firstLevel = block.Protocol.GetCycleStart(cycle); | ||
var lastLevel = block.Protocol.GetCycleEnd(cycle); | ||
|
||
for (int level = firstLevel; level <= lastLevel; level++) | ||
rights.AddRange((await Proto.Rpc.GetLevelEndorsingRightsAsync(block.Level, level)).RequiredArray().EnumerateArray()); | ||
|
||
if (!rights.Any() || rights.Sum(x => x.RequiredArray("slots").Count()) != block.Protocol.BlocksPerCycle * block.Protocol.EndorsersPerBlock) | ||
throw new ValidationException("Rpc returned less endorsing rights (slots) than it should be"); | ||
|
||
return rights; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters