Skip to content

Commit

Permalink
Add support for holesky and custom network
Browse files Browse the repository at this point in the history
  • Loading branch information
uink45 committed Jul 30, 2024
1 parent 1c59d6e commit d455b25
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 23 deletions.
13 changes: 5 additions & 8 deletions src/Lantern.Beacon.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Lantern.Discv5.Enr;
using Lantern.Beacon.Sync.Types;
using Lantern.Discv5.Enr;
using Lantern.Discv5.Enr.Entries;
using Lantern.Discv5.Enr.Identity.V4;
using Lantern.Discv5.WireProtocol.Connection;
using Lantern.Discv5.WireProtocol.Session;
using Lantern.Discv5.WireProtocol.Table;
Expand All @@ -11,10 +11,6 @@

namespace Lantern.Beacon.Console;

public class NodeTableEntry {
public Guid Id { get; set; }
}

internal static class Program
{
public static async Task Main()
Expand Down Expand Up @@ -109,7 +105,7 @@ public static async Task Main()
//options.Bootnodes = ["/ip4/135.148.103.80/tcp/9000/p2p/16Uiu2HAkwvVXtZj6u3R2F7hEXpnbDUom3rDepABdDCSzyzAM2k69"];
//options.Bootnodes = ["/ip4/54.38.80.34/tcp/9000/p2p/16Uiu2HAm8t1aQArVwrJ9fwHRGXL2sXumPGTvmsne14piPaFJ5FYi"]; // Lighthouse
//options.Bootnodes = ["/ip4/37.27.63.66/tcp/9115/p2p/16Uiu2HAm8BCbnKxJnsNq6uJAhGe3wNrUiiLCTete2vP5UUT99oNL"];
options.Bootnodes = ["/ip4/135.148.103.80/tcp/9000/p2p/16Uiu2HAkwvVXtZj6u3R2F7hEXpnbDUom3rDepABdDCSzyzAM2k69"]; // Lodestar
options.Bootnodes = ["/ip4/135.148.103.80/tcp/9000/p2p/16Uiu2HAm1iCnKSNGhee2RKa1EYbazz4JJ8CDVVCPLyXS9PFYPG1A"]; // Lodestar
//options.Bootnodes = ["/ip4/0.0.0.0/tcp/9012/p2p/16Uiu2HAmQW7R658hXDAGvR9mRr56JyX4UJpcB5KiGoDv4ENyBFX1"];
//options.Bootnodes = ["/ip4/0.0.0.0/tcp/9000/p2p/16Uiu2HAm6R996q426GYUyExKSYdKxhbD5iYedbuqQovVPTJFVHPv"];
});
Expand All @@ -118,7 +114,8 @@ public static async Task Main()
syncProtocol.Preset = SizePreset.MainnetPreset;
syncProtocol.GenesisValidatorsRoot = Convert.FromHexString("4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95");
syncProtocol.GenesisTime = 1606824023;
syncProtocol.TrustedBlockRoot = Convert.FromHexString("b6ae5813712eb99c84c3e53a7e91b5cf5e82722297e03432be3de6e4da05f1a4");
syncProtocol.TrustedBlockRoot = Convert.FromHexString("9344d07abccaa481cb301e804c99d9b3102fb70c0d950354c8d22f6f0f389ef2");
syncProtocol.Network = NetworkType.Mainnet;
});
beaconClientBuilder.AddLibp2pProtocol(libp2PBuilder => libp2PBuilder);
beaconClientBuilder.WithLoggerFactory(libp2p2LoggerFactory);
Expand Down
46 changes: 46 additions & 0 deletions src/Lantern.Beacon.Sync/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ public static void InitializeWithMainnet()
GenesisForkVersion = MainnetConfig.GenesisForkVersion;
}

public static void InitializeWithHolesky()
{
MinGenesisTime = HoleskyConfig.MinGenesisTime;
GenesisDelay = HoleskyConfig.GenesisDelay;
SecondsPerSlot = HoleskyConfig.SecondsPerSlot;
TimeToFirstByteTimeout = HoleskyConfig.TimeToFirstByteTimeout;
RespTimeout = HoleskyConfig.RespTimeout;
AttestationSubnetCount = HoleskyConfig.AttestationSubnetCount;
SyncCommitteeSubnetCount = HoleskyConfig.SyncCommitteeSubnetCount;
GossipMaxSize = HoleskyConfig.GossipMaxSize;
MaxRequestLightClientUpdates = HoleskyConfig.MaxRequestLightClientUpdates;
AltairForkVersion = HoleskyConfig.AltairForkVersion;
AltairForkEpoch = HoleskyConfig.AltairForkEpoch;
BellatrixForkVersion = HoleskyConfig.BellatrixForkVersion;
BellatrixForkEpoch = HoleskyConfig.BellatrixForkEpoch;
CapellaForkVersion = HoleskyConfig.CapellaForkVersion;
CapellaForkEpoch = HoleskyConfig.CapellaForkEpoch;
DenebForkVersion = HoleskyConfig.DenebForkVersion;
DenebForkEpoch = HoleskyConfig.DenebForkEpoch;
ElectraForkVersion = HoleskyConfig.ElectraForkVersion;
GenesisForkVersion = HoleskyConfig.GenesisForkVersion;
}

public static void InitializeWithMinimal()
{
MinGenesisTime = MinimalConfig.MinGenesisTime;
Expand All @@ -85,4 +108,27 @@ public static void InitializeWithMinimal()
ElectraForkVersion = MinimalConfig.ElectraForkVersion;
GenesisForkVersion = MinimalConfig.GenesisForkVersion;
}

public static void InitializeWithCustom(ConfigSettings config)
{
MinGenesisTime = config.MinGenesisTime;
GenesisDelay = config.GenesisDelay;
SecondsPerSlot = config.SecondsPerSlot;
TimeToFirstByteTimeout = config.TimeToFirstByteTimeout;
RespTimeout = config.RespTimeout;
AttestationSubnetCount = config.AttestationSubnetCount;
SyncCommitteeSubnetCount = config.SyncCommitteeSubnetCount;
GossipMaxSize = config.GossipMaxSize;
MaxRequestLightClientUpdates = config.MaxRequestLightClientUpdates;
AltairForkVersion = config.AltairForkVersion;
AltairForkEpoch = config.AltairForkEpoch;
BellatrixForkVersion = config.BellatrixForkVersion;
BellatrixForkEpoch = config.BellatrixForkEpoch;
CapellaForkVersion = config.CapellaForkVersion;
CapellaForkEpoch = config.CapellaForkEpoch;
DenebForkVersion = config.DenebForkVersion;
DenebForkEpoch = config.DenebForkEpoch;
ElectraForkVersion = config.ElectraForkVersion;
GenesisForkVersion = config.GenesisForkVersion;
}
}
42 changes: 42 additions & 0 deletions src/Lantern.Beacon.Sync/Config/ConfigSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Lantern.Beacon.Sync.Config;

public class ConfigSettings
{
public int MinGenesisTime { get; set; }

public int GenesisDelay { get; set; }

public int SecondsPerSlot { get; set; }

public int TimeToFirstByteTimeout { get; set; }

public int RespTimeout { get; set; }

public int AttestationSubnetCount { get; set; }

public int SyncCommitteeSubnetCount { get; set; }

public int GossipMaxSize { get; set; }

public int MaxRequestLightClientUpdates { get; set; }

public uint GenesisForkVersion { get; set; }

public uint AltairForkVersion { get; set; }

public uint AltairForkEpoch { get; set; }

public uint BellatrixForkVersion { get; set; }

public uint BellatrixForkEpoch { get; set; }

public uint CapellaForkVersion { get; set; }

public uint CapellaForkEpoch { get; set; }

public uint DenebForkVersion { get; set; }

public uint DenebForkEpoch { get; set; }

public uint ElectraForkVersion { get; set; }
}
42 changes: 42 additions & 0 deletions src/Lantern.Beacon.Sync/Config/HoleskyConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Lantern.Beacon.Sync.Config;

public class HoleskyConfig
{
public const int MinGenesisTime = 1695902100;

public const int GenesisDelay = 300;

public const int SecondsPerSlot = 12;

public const int TimeToFirstByteTimeout = 5;

public const int RespTimeout = 10;

public const int AttestationSubnetCount = 64;

public const int SyncCommitteeSubnetCount = 4;

public const int GossipMaxSize = 10485760;

public const int MaxRequestLightClientUpdates = 128;

public const uint GenesisForkVersion = 0x01017000;

public const uint AltairForkVersion = 0x02017000;

public const uint AltairForkEpoch = 0;

public const uint BellatrixForkVersion = 0x03017000;

public const uint BellatrixForkEpoch = 0;

public const uint CapellaForkVersion = 0x04017000;

public const uint CapellaForkEpoch = 256;

public const uint DenebForkVersion = 0x05017000;

public const uint DenebForkEpoch = 29696;

public const uint ElectraForkVersion = 0x05000000;
}
14 changes: 14 additions & 0 deletions src/Lantern.Beacon.Sync/Presets/AltairPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ public static void InitializeWithMainnet()
MinSyncCommitteeParticipants = Mainnet.AltairPresetValues.MinSyncCommitteeParticipants;
}

public static void InitializeWithHolesky()
{
SyncCommitteeSize = Holesky.AltairPresetValues.SyncCommitteeSize;
EpochsPerSyncCommitteePeriod = Holesky.AltairPresetValues.EpochsPerSyncCommitteePeriod;
MinSyncCommitteeParticipants = Holesky.AltairPresetValues.MinSyncCommitteeParticipants;
}

public static void InitializeWithMinimal()
{
SyncCommitteeSize = Minimal.AltairPresetValues.SyncCommitteeSize;
EpochsPerSyncCommitteePeriod = Minimal.AltairPresetValues.EpochsPerSyncCommitteePeriod;
MinSyncCommitteeParticipants = Minimal.AltairPresetValues.MinSyncCommitteeParticipants;
}

public static void InitializeWithCustom(PresetSettings preset)
{
SyncCommitteeSize = preset.SyncCommitteeSize;
EpochsPerSyncCommitteePeriod = preset.EpochsPerSyncCommitteePeriod;
MinSyncCommitteeParticipants = preset.MinSyncCommitteeParticipants;
}
}
10 changes: 10 additions & 0 deletions src/Lantern.Beacon.Sync/Presets/Holesky/AltairPresetValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Lantern.Beacon.Sync.Presets.Holesky;

public class AltairPresetValues
{
public const int SyncCommitteeSize = 512;

public const int EpochsPerSyncCommitteePeriod = 256;

public const int MinSyncCommitteeParticipants = 1;
}
6 changes: 6 additions & 0 deletions src/Lantern.Beacon.Sync/Presets/Holesky/Phase0PresetValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Lantern.Beacon.Sync.Presets.Holesky;

public class Phase0PresetValues
{
public const int SlotsPerEpoch = 32;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Lantern.Beacon.Sync.Presets.Minimal;

public static class AltairPresetValues
public class AltairPresetValues
{
public const int SyncCommitteeSize = 32;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Lantern.Beacon.Sync.Presets.Minimal;

public static class Phase0PresetValues
public class Phase0PresetValues
{
public const int SlotsPerEpoch = 8;
}
12 changes: 11 additions & 1 deletion src/Lantern.Beacon.Sync/Presets/Phase0Preset.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lantern.Beacon.Sync.Presets.Minimal;
using Lantern.Beacon.Sync.Presets.Holesky;
using Lantern.Beacon.Sync.Presets.Mainnet;

namespace Lantern.Beacon.Sync.Presets;
Expand All @@ -12,8 +12,18 @@ public static void InitializeWithMainnet()
SlotsPerEpoch = Mainnet.Phase0PresetValues.SlotsPerEpoch;
}

public static void InitializeWithHolesky()
{
SlotsPerEpoch = Holesky.Phase0PresetValues.SlotsPerEpoch;
}

public static void InitializeWithMinimal()
{
SlotsPerEpoch = Minimal.Phase0PresetValues.SlotsPerEpoch;
}

public static void InitializeWithCustom(PresetSettings preset)
{
SlotsPerEpoch = preset.SlotsPerEpoch;
}
}
12 changes: 12 additions & 0 deletions src/Lantern.Beacon.Sync/Presets/PresetSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Lantern.Beacon.Sync.Presets;

public class PresetSettings
{
public int SlotsPerEpoch { get; set; }

public int SyncCommitteeSize { get; set; }

public int EpochsPerSyncCommitteePeriod { get; set; }

public int MinSyncCommitteeParticipants { get; set; }
}
24 changes: 18 additions & 6 deletions src/Lantern.Beacon.Sync/SyncProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Lantern.Beacon.Sync.Types.Ssz.Capella;
using Lantern.Beacon.Sync.Types.Ssz.Deneb;
using Microsoft.Extensions.Logging;
using SszSharp;

namespace Lantern.Beacon.Sync;

Expand Down Expand Up @@ -37,18 +36,31 @@ public void Init(AltairLightClientStore? altairStore,
DenebLightClientFinalityUpdate? finalityUpdate,
DenebLightClientOptimisticUpdate? optimisticUpdate)
{
if (options.Preset.Equals(SizePreset.MainnetPreset))
if (options.Network.Equals(NetworkType.Mainnet))
{
Config.Config.InitializeWithMainnet();
Phase0Preset.InitializeWithMainnet();
AltairPreset.InitializeWithMainnet();
}
else if (options.Preset.Equals(SizePreset.MinimalPreset))
else if (options.Network.Equals(NetworkType.Holesky))
{
Config.Config.InitializeWithMinimal();
Phase0Preset.InitializeWithMinimal();
AltairPreset.InitializeWithMinimal();
Config.Config.InitializeWithHolesky();
Phase0Preset.InitializeWithHolesky();
AltairPreset.InitializeWithHolesky();
}
else if (options.Network.Equals(NetworkType.Custom))
{
if(options is { ConfigSettings: not null, PresetSettings: not null })
{
Config.Config.InitializeWithCustom(options.ConfigSettings);
Phase0Preset.InitializeWithCustom(options.PresetSettings);
AltairPreset.InitializeWithCustom(options.PresetSettings);
}
else
{
throw new Exception("Custom config and preset settings not provided");
}
}
else
{
throw new Exception("Invalid preset type");
Expand Down
9 changes: 9 additions & 0 deletions src/Lantern.Beacon.Sync/SyncProtocolOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Lantern.Beacon.Sync.Config;
using Lantern.Beacon.Sync.Presets;
using Lantern.Beacon.Sync.Types;
using SszSharp;

namespace Lantern.Beacon.Sync;
Expand All @@ -11,4 +14,10 @@ public class SyncProtocolOptions
public byte[] GenesisValidatorsRoot { get; set; }

public byte[] TrustedBlockRoot { get; set; }

public NetworkType Network { get; set; }

public ConfigSettings? ConfigSettings { get; set; }

public PresetSettings? PresetSettings { get; set; }
}
8 changes: 8 additions & 0 deletions src/Lantern.Beacon.Sync/Types/NetworkType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Lantern.Beacon.Sync.Types;

public enum NetworkType
{
Mainnet,
Holesky,
Custom
}
1 change: 1 addition & 0 deletions test/Lantern.Beacon.Sync.Tests/AltairSyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void Setup()
_options = new SyncProtocolOptions();
_options.Preset = SizePreset.MinimalPreset;
_syncProtocol = new SyncProtocol(_options, LoggingOptions.Default);

Config.Config.InitializeWithMinimal();
Phase0Preset.InitializeWithMinimal();
AltairPreset.InitializeWithMinimal();
Expand Down

0 comments on commit d455b25

Please sign in to comment.