Skip to content

Commit

Permalink
Add Edo protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Dec 25, 2020
1 parent 8d61c5b commit cbe6ebc
Show file tree
Hide file tree
Showing 34 changed files with 606 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Tzkt.Data/Models/Voting/VotingPeriod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public enum PeriodKind
Proposal,
Exploration,
Testing,
Promotion
Promotion,
Adoption
}

public enum PeriodStatus
Expand Down
10 changes: 5 additions & 5 deletions Tzkt.Sync/Protocols/Handlers/Proto1/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ protected virtual async Task ValidateBlockMetadata(JsonElement metadata)
if (!Cache.Accounts.DelegateExists(Baker))
throw new ValidationException($"non-existent block baker");

await ValidateBlockVoting(
metadata.Required("level").RequiredInt32("voting_period"),
metadata.RequiredString("voting_period_kind"));
await ValidateBlockVoting(metadata);

foreach (var baker in metadata.RequiredArray("deactivated").EnumerateArray())
if (!Cache.Accounts.DelegateExists(baker.GetString()))
Expand All @@ -65,14 +63,16 @@ protected virtual async Task ValidateBlockMetadata(JsonElement metadata)
ValidateCycleRewards(balanceUpdates.Skip(Cycle < Protocol.NoRewardCycles ? 2 : 3));
}

protected virtual async Task ValidateBlockVoting(int periodIndex, string periodKind)
protected virtual async Task ValidateBlockVoting(JsonElement metadata)
{
var periodIndex = metadata.Required("level").RequiredInt32("voting_period");

if (Cache.AppState.Get().VotingPeriod != periodIndex)
throw new ValidationException("invalid voting period index");

var period = await Cache.Periods.GetAsync(periodIndex);

var kind = periodKind switch
var kind = metadata.RequiredString("voting_period_kind") switch
{
"proposal" => PeriodKind.Proposal,
"exploration" => PeriodKind.Exploration,
Expand Down
8 changes: 5 additions & 3 deletions Tzkt.Sync/Protocols/Handlers/Proto3/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ class Validator : Proto1.Validator
{
public Validator(ProtocolHandler protocol) : base(protocol) { }

// new period king enum & wtf
protected override async Task ValidateBlockVoting(int periodIndex, string periodKind)
// new period kind enum & wtf
protected override async Task ValidateBlockVoting(JsonElement metadata)
{
var periodIndex = metadata.Required("level").RequiredInt32("voting_period");

if (Cache.AppState.Get().VotingPeriod != periodIndex)
throw new ValidationException("invalid voting period index");

var period = await Cache.Periods.GetAsync(periodIndex);

var kind = periodKind switch
var kind = metadata.RequiredString("voting_period_kind") switch
{
"proposal" => PeriodKind.Proposal,
"testing_vote" => PeriodKind.Exploration,
Expand Down
4 changes: 1 addition & 3 deletions Tzkt.Sync/Protocols/Handlers/Proto6/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ protected override async Task ValidateBlockMetadata(JsonElement metadata)
if (!Cache.Accounts.DelegateExists(Baker))
throw new ValidationException($"non-existent block baker");

await ValidateBlockVoting(
metadata.Required("level").RequiredInt32("voting_period"),
metadata.RequiredString("voting_period_kind"));
await ValidateBlockVoting(metadata);

foreach (var baker in metadata.RequiredArray("deactivated").EnumerateArray())
if (!Cache.Accounts.DelegateExists(baker.GetString()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class ProtoActivator : Proto7.ProtoActivator
{
public ProtoActivator(ProtocolHandler proto) : base(proto) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class BakerCycleCommit : Proto6.BakerCycleCommit
{
public BakerCycleCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class BakingRightsCommit : Proto3.BakingRightsCommit
{
public BakingRightsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/BlockCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class BlockCommit : Proto1.BlockCommit
{
public BlockCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/CycleCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class CycleCommit : Proto1.CycleCommit
{
public CycleCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class DeactivationCommit : Proto2.DeactivationCommit
{
public DeactivationCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class DelegatorCycleCommit : Proto3.DelegatorCycleCommit
{
public DelegatorCycleCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/FreezerCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class FreezerCommit : Proto6.FreezerCommit
{
public FreezerCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class ActivationsCommit : Proto5.ActivationsCommit
{
public ActivationsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class BallotsCommit : Proto3.BallotsCommit
{
public BallotsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class DelegationsCommit : Proto1.DelegationsCommit
{
public DelegationsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class DoubleBakingCommit : Proto2.DoubleBakingCommit
{
public DoubleBakingCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class DoubleEndorsingCommit : Proto4.DoubleEndorsingCommit
{
public DoubleEndorsingCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class EndorsementsCommit : Proto1.EndorsementsCommit
{
public EndorsementsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class NonceRevelationsCommit : Proto1.NonceRevelationsCommit
{
public NonceRevelationsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class OriginationsCommit : Proto5.OriginationsCommit
{
public OriginationsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class ProposalsCommit : Proto3.ProposalsCommit
{
public ProposalsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class RevealsCommit : Proto1.RevealsCommit
{
public RevealsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class TransactionsCommit : Proto5.TransactionsCommit
{
public TransactionsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class RevelationPenaltyCommit : Proto6.RevelationPenaltyCommit
{
public RevelationPenaltyCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class SnapshotBalanceCommit : Proto4.SnapshotBalanceCommit
{
public SnapshotBalanceCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/SoftwareCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class SoftwareCommit : Proto5.SoftwareCommit
{
public SoftwareCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/StateCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class StateCommit : Proto1.StateCommit
{
public StateCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto8
{
class StatisticsCommit : Proto1.StatisticsCommit
{
public StatisticsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
44 changes: 44 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto8/Commits/VotingCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Tzkt.Data.Models;

namespace Tzkt.Sync.Protocols.Proto8
{
class VotingCommit : Proto5.VotingCommit
{
public VotingCommit(ProtocolHandler protocol) : base(protocol) { }

// new voting period
protected override ProposalStatus GetProposalStatus(Proposal proposal, VotingPeriod period)
{
if (period.Status == PeriodStatus.Success)
return period.Kind == PeriodKind.Adoption
? ProposalStatus.Accepted
: ProposalStatus.Active;

if (period.Status == PeriodStatus.NoSupermajority)
return ProposalStatus.Rejected;

return ProposalStatus.Skipped;
}

// new voting period
protected override VotingPeriod StartNextPeriod(Block block, VotingPeriod current)
{
switch (current.Kind)
{
case PeriodKind.Proposal:
return StartBallotPeriod(block, current, PeriodKind.Exploration);
case PeriodKind.Exploration:
return StartWaitingPeriod(block, current, PeriodKind.Testing);
case PeriodKind.Testing:
return StartBallotPeriod(block, current, PeriodKind.Promotion);
case PeriodKind.Promotion:
return StartWaitingPeriod(block, current, PeriodKind.Adoption);
case PeriodKind.Adoption:
return StartProposalPeriod(block, current);
default:
throw new Exception("Invalid voting period kind");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Tzkt.Data;

namespace Tzkt.Sync.Protocols.Proto8
{
class Diagnostics : Proto5.Diagnostics
{
public Diagnostics(TzktContext db, IRpc rpc) : base(db, rpc) { }
}
}

0 comments on commit cbe6ebc

Please sign in to comment.