From d455b25772b06c22e585f8346b15142b4f62f9bf Mon Sep 17 00:00:00 2001 From: uink45 <79078981+uink45@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:19:40 +1000 Subject: [PATCH] Add support for holesky and custom network --- src/Lantern.Beacon.Console/Program.cs | 13 ++---- src/Lantern.Beacon.Sync/Config/Config.cs | 46 +++++++++++++++++++ .../Config/ConfigSettings.cs | 42 +++++++++++++++++ .../Config/HoleskyConfig.cs | 42 +++++++++++++++++ .../Presets/AltairPreset.cs | 14 ++++++ .../Presets/Holesky/AltairPresetValues.cs | 10 ++++ .../Presets/Holesky/Phase0PresetValues.cs | 6 +++ .../Presets/Mainnet/BellatrixPresetValues.cs | 6 --- .../Presets/Minimal/AltairPresetValues.cs | 2 +- .../Presets/Minimal/Phase0PresetValues.cs | 2 +- .../Presets/Phase0Preset.cs | 12 ++++- .../Presets/PresetSettings.cs | 12 +++++ src/Lantern.Beacon.Sync/SyncProtocol.cs | 24 +++++++--- .../SyncProtocolOptions.cs | 9 ++++ src/Lantern.Beacon.Sync/Types/NetworkType.cs | 8 ++++ .../AltairSyncTests.cs | 1 + 16 files changed, 226 insertions(+), 23 deletions(-) create mode 100644 src/Lantern.Beacon.Sync/Config/ConfigSettings.cs create mode 100644 src/Lantern.Beacon.Sync/Config/HoleskyConfig.cs create mode 100644 src/Lantern.Beacon.Sync/Presets/Holesky/AltairPresetValues.cs create mode 100644 src/Lantern.Beacon.Sync/Presets/Holesky/Phase0PresetValues.cs delete mode 100644 src/Lantern.Beacon.Sync/Presets/Mainnet/BellatrixPresetValues.cs create mode 100644 src/Lantern.Beacon.Sync/Presets/PresetSettings.cs create mode 100644 src/Lantern.Beacon.Sync/Types/NetworkType.cs diff --git a/src/Lantern.Beacon.Console/Program.cs b/src/Lantern.Beacon.Console/Program.cs index e3ab4e7..2b965ae 100644 --- a/src/Lantern.Beacon.Console/Program.cs +++ b/src/Lantern.Beacon.Console/Program.cs @@ -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; @@ -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() @@ -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"]; }); @@ -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); diff --git a/src/Lantern.Beacon.Sync/Config/Config.cs b/src/Lantern.Beacon.Sync/Config/Config.cs index 2ce1b0e..44ce846 100644 --- a/src/Lantern.Beacon.Sync/Config/Config.cs +++ b/src/Lantern.Beacon.Sync/Config/Config.cs @@ -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; @@ -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; + } } \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Config/ConfigSettings.cs b/src/Lantern.Beacon.Sync/Config/ConfigSettings.cs new file mode 100644 index 0000000..22d7c36 --- /dev/null +++ b/src/Lantern.Beacon.Sync/Config/ConfigSettings.cs @@ -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; } +} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Config/HoleskyConfig.cs b/src/Lantern.Beacon.Sync/Config/HoleskyConfig.cs new file mode 100644 index 0000000..07230a8 --- /dev/null +++ b/src/Lantern.Beacon.Sync/Config/HoleskyConfig.cs @@ -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; +} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/AltairPreset.cs b/src/Lantern.Beacon.Sync/Presets/AltairPreset.cs index 9201380..ccb7ec2 100644 --- a/src/Lantern.Beacon.Sync/Presets/AltairPreset.cs +++ b/src/Lantern.Beacon.Sync/Presets/AltairPreset.cs @@ -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; + } } \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/Holesky/AltairPresetValues.cs b/src/Lantern.Beacon.Sync/Presets/Holesky/AltairPresetValues.cs new file mode 100644 index 0000000..4567764 --- /dev/null +++ b/src/Lantern.Beacon.Sync/Presets/Holesky/AltairPresetValues.cs @@ -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; +} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/Holesky/Phase0PresetValues.cs b/src/Lantern.Beacon.Sync/Presets/Holesky/Phase0PresetValues.cs new file mode 100644 index 0000000..c1ac45f --- /dev/null +++ b/src/Lantern.Beacon.Sync/Presets/Holesky/Phase0PresetValues.cs @@ -0,0 +1,6 @@ +namespace Lantern.Beacon.Sync.Presets.Holesky; + +public class Phase0PresetValues +{ + public const int SlotsPerEpoch = 32; +} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/Mainnet/BellatrixPresetValues.cs b/src/Lantern.Beacon.Sync/Presets/Mainnet/BellatrixPresetValues.cs deleted file mode 100644 index 43c3ff6..0000000 --- a/src/Lantern.Beacon.Sync/Presets/Mainnet/BellatrixPresetValues.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Lantern.Beacon.Sync.Presets.Mainnet; - -public class BellatrixPresetValues -{ - -} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/Minimal/AltairPresetValues.cs b/src/Lantern.Beacon.Sync/Presets/Minimal/AltairPresetValues.cs index 9fa1843..3ad9120 100644 --- a/src/Lantern.Beacon.Sync/Presets/Minimal/AltairPresetValues.cs +++ b/src/Lantern.Beacon.Sync/Presets/Minimal/AltairPresetValues.cs @@ -1,6 +1,6 @@ namespace Lantern.Beacon.Sync.Presets.Minimal; -public static class AltairPresetValues +public class AltairPresetValues { public const int SyncCommitteeSize = 32; diff --git a/src/Lantern.Beacon.Sync/Presets/Minimal/Phase0PresetValues.cs b/src/Lantern.Beacon.Sync/Presets/Minimal/Phase0PresetValues.cs index e0d29f8..2c7cf9a 100644 --- a/src/Lantern.Beacon.Sync/Presets/Minimal/Phase0PresetValues.cs +++ b/src/Lantern.Beacon.Sync/Presets/Minimal/Phase0PresetValues.cs @@ -1,6 +1,6 @@ namespace Lantern.Beacon.Sync.Presets.Minimal; -public static class Phase0PresetValues +public class Phase0PresetValues { public const int SlotsPerEpoch = 8; } \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/Phase0Preset.cs b/src/Lantern.Beacon.Sync/Presets/Phase0Preset.cs index d0f67bc..9704765 100644 --- a/src/Lantern.Beacon.Sync/Presets/Phase0Preset.cs +++ b/src/Lantern.Beacon.Sync/Presets/Phase0Preset.cs @@ -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; @@ -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; + } } \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Presets/PresetSettings.cs b/src/Lantern.Beacon.Sync/Presets/PresetSettings.cs new file mode 100644 index 0000000..e0eef5c --- /dev/null +++ b/src/Lantern.Beacon.Sync/Presets/PresetSettings.cs @@ -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; } +} \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/SyncProtocol.cs b/src/Lantern.Beacon.Sync/SyncProtocol.cs index 5d8c0f7..d03ba6a 100644 --- a/src/Lantern.Beacon.Sync/SyncProtocol.cs +++ b/src/Lantern.Beacon.Sync/SyncProtocol.cs @@ -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; @@ -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"); diff --git a/src/Lantern.Beacon.Sync/SyncProtocolOptions.cs b/src/Lantern.Beacon.Sync/SyncProtocolOptions.cs index c6acdd3..8674091 100644 --- a/src/Lantern.Beacon.Sync/SyncProtocolOptions.cs +++ b/src/Lantern.Beacon.Sync/SyncProtocolOptions.cs @@ -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; @@ -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; } } \ No newline at end of file diff --git a/src/Lantern.Beacon.Sync/Types/NetworkType.cs b/src/Lantern.Beacon.Sync/Types/NetworkType.cs new file mode 100644 index 0000000..e91ea12 --- /dev/null +++ b/src/Lantern.Beacon.Sync/Types/NetworkType.cs @@ -0,0 +1,8 @@ +namespace Lantern.Beacon.Sync.Types; + +public enum NetworkType +{ + Mainnet, + Holesky, + Custom +} \ No newline at end of file diff --git a/test/Lantern.Beacon.Sync.Tests/AltairSyncTests.cs b/test/Lantern.Beacon.Sync.Tests/AltairSyncTests.cs index 781d713..e88fb1c 100644 --- a/test/Lantern.Beacon.Sync.Tests/AltairSyncTests.cs +++ b/test/Lantern.Beacon.Sync.Tests/AltairSyncTests.cs @@ -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();