Skip to content

Commit

Permalink
Add ParisC protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jun 19, 2024
1 parent d98ee5e commit ba6fb09
Show file tree
Hide file tree
Showing 59 changed files with 2,127 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto20/Activation/ProtoActivator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Tzkt.Data.Models;

namespace Tzkt.Sync.Protocols.Proto20
{
partial class ProtoActivator : Proto19.ProtoActivator
{
public ProtoActivator(ProtocolHandler proto) : base(proto) { }

protected override void UpgradeParameters(Protocol protocol, Protocol prev)
{
// nothing to upgrade
}

protected override Task MigrateContext(AppState state)
{
// nothing to migrate
return Task.CompletedTask;
}

protected override Task RevertContext(AppState state)
{
// nothing to revert
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class AutostakingCommit : Proto19.AutostakingCommit
{
public AutostakingCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class BakerCycleCommit : Proto18.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.Proto20
{
class BakingRightsCommit : Proto18.BakingRightsCommit
{
public BakingRightsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto20/Commits/BigMapCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class BigMapCommit : Proto1.BigMapCommit
{
public BigMapCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto20/Commits/BlockCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class BlockCommit : Proto19.BlockCommit
{
public BlockCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class ContractEventCommit : Proto14.ContractEventCommit
{
public ContractEventCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
76 changes: 76 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto20/Commits/CycleCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Microsoft.EntityFrameworkCore;
using Netezos.Encoding;
using Tzkt.Data.Models;

namespace Tzkt.Sync.Protocols.Proto20
{
class CycleCommit : ProtocolCommit
{
public Cycle FutureCycle { get; protected set; }
public List<SnapshotBalance> Snapshots { get; protected set; }
public Dictionary<int, long> SelectedStakes { get; protected set; }

public CycleCommit(ProtocolHandler protocol) : base(protocol) { }

public async Task Apply(Block block)
{
if (!block.Events.HasFlag(BlockEvents.CycleBegin))
return;

var index = block.Cycle + block.Protocol.ConsensusRightsDelay;

var contextTask = Proto.Rpc.GetCycleAsync(block.Level, index);
var issuanceTask = Proto.Rpc.GetExpectedIssuance(block.Level);
await Task.WhenAll(contextTask, issuanceTask);

var context = await contextTask;
var issuance = await issuanceTask;
var cycleIssuance = issuance.EnumerateArray().First(x => x.RequiredInt32("cycle") == index);

SelectedStakes = context.RequiredArray("selected_stake_distribution")
.EnumerateArray()
.ToDictionary(
x => Cache.Accounts.GetDelegate(x.RequiredString("baker")).Id,
x => x.Required("active_stake").RequiredInt64("frozen") + x.Required("active_stake").RequiredInt64("delegated"));

Snapshots = await Db.SnapshotBalances
.AsNoTracking()
.Where(x => x.Level == block.Level - 1 && x.AccountId == x.BakerId)
.ToListAsync();

FutureCycle = new Cycle
{
Index = index,
FirstLevel = block.Protocol.GetCycleStart(index),
LastLevel = block.Protocol.GetCycleEnd(index),
SnapshotLevel = block.Level - 1,
TotalBakers = SelectedStakes.Count,
TotalBakingPower = SelectedStakes.Values.Sum(),
Seed = Hex.Parse(context.RequiredString("random_seed")),
BlockReward = cycleIssuance.RequiredInt64("baking_reward_fixed_portion"),
BlockBonusPerSlot = cycleIssuance.RequiredInt64("baking_reward_bonus_per_slot"),
EndorsementRewardPerSlot = cycleIssuance.RequiredInt64("attesting_reward_per_slot"),
NonceRevelationReward = cycleIssuance.RequiredInt64("seed_nonce_revelation_tip"),
VdfRevelationReward = cycleIssuance.RequiredInt64("vdf_revelation_tip")
};

FutureCycle.MaxBlockReward = FutureCycle.BlockReward
+ FutureCycle.BlockBonusPerSlot * (block.Protocol.EndorsersPerBlock - block.Protocol.ConsensusThreshold);

Db.Cycles.Add(FutureCycle);
}

public async Task Revert(Block block)
{
if (!block.Events.HasFlag(BlockEvents.CycleBegin))
return;

block.Protocol ??= await Cache.Protocols.GetAsync(block.ProtoCode);

await Db.Database.ExecuteSqlRawAsync($"""
DELETE FROM "Cycles"
WHERE "Index" = {block.Cycle + block.Protocol.ConsensusRightsDelay}
""");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
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.Proto20
{
class DelegatorCycleCommit : Proto18.DelegatorCycleCommit
{
public DelegatorCycleCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class EndorsingRewardCommit : Proto19.EndorsingRewardCommit
{
public EndorsingRewardCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
7 changes: 7 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto20/Commits/InboxCommit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
public class InboxCommit : Proto17.InboxCommit
{
public InboxCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class ActivationsCommit : Proto12.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.Proto20
{
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.Proto20
{
class DalPublishCommitmentCommit : Proto19.DalPublishCommitmentCommit
{
public DalPublishCommitmentCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class DelegationsCommit : Proto18.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.Proto20
{
class DoubleBakingCommit : Proto19.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.Proto20
{
class DoubleEndorsingCommit : Proto19.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.Proto20
{
class DoublePreendorsingCommit : Proto19.DoublePreendorsingCommit
{
public DoublePreendorsingCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class DrainDelegateCommit : Proto15.DrainDelegateCommit
{
public DrainDelegateCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class EndorsementsCommit : Proto19.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.Proto20
{
class IncreasePaidStorageCommit : Proto14.IncreasePaidStorageCommit
{
public IncreasePaidStorageCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class NonceRevelationsCommit : Proto19.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.Proto20
{
class OriginationsCommit : Proto14.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.Proto20
{
class PreendorsementsCommit : Proto19.PreendorsementsCommit
{
public PreendorsementsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class ProposalsCommit : Proto14.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.Proto20
{
class RegisterConstantsCommit : Proto14.RegisterConstantsCommit
{
public RegisterConstantsCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class RevealsCommit : Proto14.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.Proto20
{
class SetDelegateParametersCommit : Proto18.SetDelegateParametersCommit
{
public SetDelegateParametersCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SetDepositsLimitCommit : Proto12.SetDepositsLimitCommit
{
public SetDepositsLimitCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupAddMessagesCommit : Proto16.SmartRollupAddMessagesCommit
{
public SmartRollupAddMessagesCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupCementCommit : Proto17.SmartRollupCementCommit
{
public SmartRollupCementCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupExecuteCommit : Proto16.SmartRollupExecuteCommit
{
public SmartRollupExecuteCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupOriginateCommit : Proto16.SmartRollupOriginateCommit
{
public SmartRollupOriginateCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupPublishCommit : Proto16.SmartRollupPublishCommit
{
public SmartRollupPublishCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupRecoverBondCommit : Proto16.SmartRollupRecoverBondCommit
{
public SmartRollupRecoverBondCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupRefuteCommit : Proto16.SmartRollupRefuteCommit
{
public SmartRollupRefuteCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class SmartRollupTimeoutCommit : Proto16.SmartRollupTimeoutCommit
{
public SmartRollupTimeoutCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Sync.Protocols.Proto20
{
class StakingCommit : Proto19.StakingCommit
{
public StakingCommit(ProtocolHandler protocol) : base(protocol) { }
}
}
Loading

0 comments on commit ba6fb09

Please sign in to comment.