From a6c297df1fdf36b0819a2facd5faccd64a112812 Mon Sep 17 00:00:00 2001 From: area363 Date: Thu, 21 Mar 2024 17:34:11 +0900 Subject: [PATCH 1/2] bump lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 0c8ec469b..0a369cbcc 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 0c8ec469b9806f2036d1435f4e67f6e09645bb29 +Subproject commit 0a369cbcc5d4d185723b101b336043a4fc2d1ff1 From 4156fd80cafb8be64b69913ef99e3a2e26de9a26 Mon Sep 17 00:00:00 2001 From: area363 Date: Thu, 21 Mar 2024 17:34:41 +0900 Subject: [PATCH 2/2] customize maxtransactionperblock --- .../Configuration.cs | 4 ++++ NineChronicles.Headless.Executable/Program.cs | 14 +++++++++++++- .../GraphTypes/StandaloneQueryTest.cs | 2 +- .../NineChroniclesNodeService.cs | 7 ++++--- .../NineChroniclesNodeServiceProperties.cs | 2 ++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/NineChronicles.Headless.Executable/Configuration.cs b/NineChronicles.Headless.Executable/Configuration.cs index edf895785..29470f69d 100644 --- a/NineChronicles.Headless.Executable/Configuration.cs +++ b/NineChronicles.Headless.Executable/Configuration.cs @@ -85,6 +85,8 @@ public class Configuration public ushort? ConsensusPort { get; set; } public double? ConsensusTargetBlockIntervalMilliseconds { get; set; } + public int? MaxTransactionPerBlock { get; set; } + public string SentryDsn { get; set; } = ""; public double SentryTraceSampleRate { get; set; } = 0.01; @@ -141,6 +143,7 @@ public void Overwrite( string? consensusPrivateKeyString, string[]? consensusSeedStrings, double? consensusTargetBlockIntervalMilliseconds, + int? maxTransactionPerBlock, string? sentryDsn, double? sentryTraceSampleRate, int? arenaParticipantsSyncInterval @@ -192,6 +195,7 @@ public void Overwrite( ConsensusSeedStrings = consensusSeedStrings ?? ConsensusSeedStrings; ConsensusPrivateKeyString = consensusPrivateKeyString ?? ConsensusPrivateKeyString; ConsensusTargetBlockIntervalMilliseconds = consensusTargetBlockIntervalMilliseconds ?? ConsensusTargetBlockIntervalMilliseconds; + MaxTransactionPerBlock = maxTransactionPerBlock ?? MaxTransactionPerBlock; SentryDsn = sentryDsn ?? SentryDsn; SentryTraceSampleRate = sentryTraceSampleRate ?? SentryTraceSampleRate; ArenaParticipantsSyncInterval = arenaParticipantsSyncInterval ?? ArenaParticipantsSyncInterval; diff --git a/NineChronicles.Headless.Executable/Program.cs b/NineChronicles.Headless.Executable/Program.cs index ee45f18fb..43871c2ad 100644 --- a/NineChronicles.Headless.Executable/Program.cs +++ b/NineChronicles.Headless.Executable/Program.cs @@ -205,6 +205,9 @@ public async Task Run( [Option("consensus-target-block-interval", Description = "A target block interval used in consensus context. The unit is millisecond.")] double? consensusTargetBlockIntervalMilliseconds = null, + [Option("maximum-transaction-per-block", + Description = "Maximum transactions allowed in a block. null by default.")] + int? maxTransactionPerBlock = null, [Option("config", new[] { 'C' }, Description = "Absolute path of \"appsettings.json\" file to provide headless configurations.")] string? configPath = "appsettings.json", @@ -302,7 +305,7 @@ public async Task Run( txLifeTime, messageTimeout, tipTimeout, demandBuffer, skipPreload, minimumBroadcastTarget, bucketSize, chainTipStaleBehaviorType, txQuotaPerSigner, maximumPollPeers, consensusPort, consensusPrivateKeyString, consensusSeedStrings, consensusTargetBlockIntervalMilliseconds, - sentryDsn, sentryTraceSampleRate, arenaParticipantsSyncInterval + maxTransactionPerBlock, sentryDsn, sentryTraceSampleRate, arenaParticipantsSyncInterval ); #if SENTRY || ! DEBUG @@ -352,6 +355,14 @@ public async Task Run( ); } + if (headlessConfig.ConsensusPrivateKeyString is null && headlessConfig.MaxTransactionPerBlock is not null) + { + throw new CommandExitedException( + "--maximum-transaction-per-block can only be used when --consensus-private-key is provided.", + -1 + ); + } + if (headlessConfig.StateServiceManagerService is { } stateServiceManagerServiceOptions) { await DownloadStateServices(stateServiceManagerServiceOptions); @@ -459,6 +470,7 @@ IActionLoader MakeSingleActionLoader() MinerCount = headlessConfig.MinerCount, MinerBlockInterval = minerBlockInterval, TxQuotaPerSigner = headlessConfig.TxQuotaPerSigner, + MaxTransactionPerBlock = headlessConfig.MaxTransactionPerBlock }; var arenaMemoryCache = new StateMemoryCache(); hostBuilder.ConfigureServices(services => diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs index 4b36b5309..4de25b8f3 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs @@ -897,7 +897,7 @@ public async Task ActivationKeyNonce(bool trim) ConsensusPeers = ImmutableList.Empty }; - var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(Planet.Odin, StaticActionLoaderSingleton.Instance); + var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(Planet.Odin, StaticActionLoaderSingleton.Instance, null); var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance); StandaloneContextFx.NineChroniclesNodeService = service; StandaloneContextFx.BlockChain = service.Swarm?.BlockChain; diff --git a/NineChronicles.Headless/NineChroniclesNodeService.cs b/NineChronicles.Headless/NineChroniclesNodeService.cs index 24956e28e..18f784cdf 100644 --- a/NineChronicles.Headless/NineChroniclesNodeService.cs +++ b/NineChronicles.Headless/NineChroniclesNodeService.cs @@ -203,7 +203,8 @@ StandaloneContext context IBlockPolicy blockPolicy = GetBlockPolicy( properties.Planet, - properties.ActionLoader + properties.ActionLoader, + properties.MaxTransactionPerBlock ); var service = new NineChroniclesNodeService( properties.MinerPrivateKey, @@ -256,8 +257,8 @@ StandaloneContext context return service; } - internal static IBlockPolicy GetBlockPolicy(Planet planet, IActionLoader actionLoader) - => new BlockPolicySource(actionLoader).GetPolicy(planet); + internal static IBlockPolicy GetBlockPolicy(Planet planet, IActionLoader actionLoader, int? maxTransactionPerBlock) + => new BlockPolicySource(actionLoader, maxTransactionPerBlock).GetPolicy(planet); public Task CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException(); diff --git a/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs b/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs index 5121e961b..0480142e5 100644 --- a/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs +++ b/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs @@ -53,6 +53,8 @@ public NineChroniclesNodeServiceProperties( public int TxQuotaPerSigner { get; set; } + public int? MaxTransactionPerBlock { get; set; } + public IActionLoader ActionLoader { get; init; } public StateServiceManagerServiceOptions? StateServiceManagerService { get; }