Skip to content

Commit

Permalink
Add version number to the protocol model
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed May 31, 2024
1 parent 13b2e99 commit c347346
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Tzkt.Data/Migrations/20240424125408_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tzkt.Data/Migrations/20240424125408_Initial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Code = table.Column<int>(type: "integer", nullable: false),
Hash = table.Column<string>(type: "character(51)", fixedLength: true, maxLength: 51, nullable: false),
Version = table.Column<int>(type: "integer", nullable: false),
FirstLevel = table.Column<int>(type: "integer", nullable: false),
LastLevel = table.Column<int>(type: "integer", nullable: false),
FirstCycle = table.Column<int>(type: "integer", nullable: false),
Expand Down
3 changes: 3 additions & 0 deletions Tzkt.Data/Migrations/20240501115741_Triggers.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tzkt.Data/Migrations/20240501115809_TokensValue.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tzkt.Data/Migrations/TzktContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("TimeBetweenBlocks")
.HasColumnType("integer");

b.Property<int>("Version")
.HasColumnType("integer");

b.HasKey("Id");

b.ToTable("Protocols");
Expand Down
1 change: 1 addition & 0 deletions Tzkt.Data/Models/Blocks/Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Protocol
public int Id { get; set; }
public int Code { get; set; }
public string Hash { get; set; }
public int Version { get; set; }
public int FirstLevel { get; set; }
public int LastLevel { get; set; }
public int FirstCycle { get; set; }
Expand Down
11 changes: 4 additions & 7 deletions Tzkt.Sync/Protocols/Handlers/Genesis/GenesisHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using App.Metrics;

using Tzkt.Data;
using Tzkt.Data.Models;
using Tzkt.Sync.Services;
Expand All @@ -18,7 +13,8 @@ class GenesisHandler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "genesis";
public override string VersionName => "genesis";
public override int VersionNumber => -1;

public GenesisHandler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<GenesisHandler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand All @@ -37,6 +33,7 @@ public override Task Commit(JsonElement rawBlock)
{
Hash = rawBlock.RequiredString("protocol"),
Code = -1,
Version = VersionNumber,
FirstLevel = 0,
LastLevel = 0,
FirstCycle = 0,
Expand Down
11 changes: 4 additions & 7 deletions Tzkt.Sync/Protocols/Handlers/Initiator/InitiatorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using App.Metrics;

using Tzkt.Data;
using Tzkt.Data.Models;
using Tzkt.Sync.Services;
Expand All @@ -18,7 +13,8 @@ class InitiatorHandler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "genesis";
public override string VersionName => "genesis";
public override int VersionNumber => 0;

public InitiatorHandler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<InitiatorHandler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand All @@ -40,6 +36,7 @@ public override Task Commit(JsonElement rawBlock)
{
Hash = rawBlock.RequiredString("protocol"),
Code = 0,
Version = VersionNumber,
FirstLevel = 1,
LastLevel = 1,
FirstCycle = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ partial class ProtoActivator : ProtocolCommit
var protocol = new Protocol
{
Code = 1,
Version = Proto.VersionNumber,
Hash = rawBlock.Required("metadata").RequiredString("next_protocol"),
FirstLevel = 2,
LastLevel = -1,
Expand Down Expand Up @@ -74,7 +75,8 @@ public async Task UpgradeProtocol(AppState state)

var protocol = new Protocol
{
Code = await Db.Protocols.CountAsync() - 1,
Code = prev.Code + 1,
Version = Proto.VersionNumber,
Hash = state.NextProtocol,
FirstLevel = state.Level + 1,
LastLevel = -1,
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto1/Proto1Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto1Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "alpha";
public override string VersionName => "alpha";
public override int VersionNumber => 1;

public Proto1Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto1Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto10/Proto10Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto10Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "granada_010";
public override string VersionName => "granada_010";
public override int VersionNumber => 10;

public Proto10Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto10Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto11/Proto11Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto11Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "hangzhou_011";
public override string VersionName => "hangzhou_011";
public override int VersionNumber => 11;

public Proto11Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto11Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto12/Proto12Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto12Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "ithaca_012";
public override string VersionName => "ithaca_012";
public override int VersionNumber => 12;

public Proto12Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto12Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto13/Proto13Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto13Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "jakarta_013";
public override string VersionName => "jakarta_013";
public override int VersionNumber => 13;

public Proto13Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto13Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto14/Proto14Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto14Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "kathmandu_014";
public override string VersionName => "kathmandu_014";
public override int VersionNumber => 14;

public Proto14Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto14Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto15/Proto15Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto15Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "lima_015";
public override string VersionName => "lima_015";
public override int VersionNumber => 15;

public Proto15Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto15Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto16/Proto16Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto16Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "mumbai_016";
public override string VersionName => "mumbai_016";
public override int VersionNumber => 16;

public Proto16Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto16Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void WriteMigrationMessage(NpgsqlBinaryImporter writer, Block
writer.WriteNull();
writer.WriteNull();
writer.WriteNull();
writer.Write(Proto.Version, NpgsqlTypes.NpgsqlDbType.Text);
writer.Write(Proto.VersionName, NpgsqlTypes.NpgsqlDbType.Text);
}
}
}
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto17/Proto17Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto17Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "nairobi_017";
public override string VersionName => "nairobi_017";
public override int VersionNumber => 17;

public Proto17Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto17Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto18/Proto18Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto18Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "oxford_018";
public override string VersionName => "oxford_018";
public override int VersionNumber => 18;

public Proto18Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto18Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto19/Proto19Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto19Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "paris_019";
public override string VersionName => "paris_019";
public override int VersionNumber => 19;

public Proto19Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto19Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto2/Proto2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto2Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "alpha_002";
public override string VersionName => "alpha_002";
public override int VersionNumber => 2;

public Proto2Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto2Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto3/Proto3Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto3Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "alpha_003";
public override string VersionName => "alpha_003";
public override int VersionNumber => 3;

public Proto3Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto3Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto4/Proto4Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto4Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "athens_004";
public override string VersionName => "athens_004";
public override int VersionNumber => 4;

public Proto4Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto4Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto5/Proto5Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto5Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "babylon_005";
public override string VersionName => "babylon_005";
public override int VersionNumber => 5;

public Proto5Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto5Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto6/Proto6Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto6Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "carthage_006";
public override string VersionName => "carthage_006";
public override int VersionNumber => 6;

public Proto6Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto6Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto7/Proto7Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto7Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "delphi_007";
public override string VersionName => "delphi_007";
public override int VersionNumber => 7;

public Proto7Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto7Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto8/Proto8Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto8Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "edo_008";
public override string VersionName => "edo_008";
public override int VersionNumber => 8;

public Proto8Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto8Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto9/Proto9Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Proto9Handler : ProtocolHandler
public override IDiagnostics Diagnostics { get; }
public override IValidator Validator { get; }
public override IRpc Rpc { get; }
public override string Version => "florence_009";
public override string VersionName => "florence_009";
public override int VersionNumber => 9;

public Proto9Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger<Proto9Handler> logger, IMetrics metrics)
: base(node, db, cache, quotes, services, config, logger, metrics)
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Protocols/ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public abstract class ProtocolHandler
public abstract IDiagnostics Diagnostics { get; }
public abstract IValidator Validator { get; }
public abstract IRpc Rpc { get; }
public abstract string Version { get; }
public abstract string VersionName { get; }
public abstract int VersionNumber { get; }

public readonly TezosNode Node;
public readonly TzktContext Db;
Expand Down

0 comments on commit c347346

Please sign in to comment.