Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize max transaction per block #2437

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib9c
4 changes: 4 additions & 0 deletions NineChronicles.Headless.Executable/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,6 +143,7 @@ public void Overwrite(
string? consensusPrivateKeyString,
string[]? consensusSeedStrings,
double? consensusTargetBlockIntervalMilliseconds,
int? maxTransactionPerBlock,
string? sentryDsn,
double? sentryTraceSampleRate,
int? arenaParticipantsSyncInterval
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -459,6 +470,7 @@ IActionLoader MakeSingleActionLoader()
MinerCount = headlessConfig.MinerCount,
MinerBlockInterval = minerBlockInterval,
TxQuotaPerSigner = headlessConfig.TxQuotaPerSigner,
MaxTransactionPerBlock = headlessConfig.MaxTransactionPerBlock
};
var arenaMemoryCache = new StateMemoryCache();
hostBuilder.ConfigureServices(services =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ public async Task ActivationKeyNonce(bool trim)
ConsensusPeers = ImmutableList<BoundPeer>.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;
Expand Down
7 changes: 4 additions & 3 deletions NineChronicles.Headless/NineChroniclesNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ StandaloneContext context

IBlockPolicy blockPolicy = GetBlockPolicy(
properties.Planet,
properties.ActionLoader
properties.ActionLoader,
properties.MaxTransactionPerBlock
);
var service = new NineChroniclesNodeService(
properties.MinerPrivateKey,
Expand Down Expand Up @@ -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<bool> CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading