Skip to content

Commit

Permalink
feat: delay precommit option
Browse files Browse the repository at this point in the history
(cherry picked from commit 8baa875)
(cherry picked from commit d4efac7)
  • Loading branch information
limebell committed Dec 13, 2024
1 parent 948e515 commit 2d168ff
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
ConsensusPrivateKey = Properties.ConsensusPrivateKey,
ConsensusWorkers = 500,
TargetBlockInterval = TimeSpan.FromMilliseconds(Properties.ConsensusTargetBlockIntervalMilliseconds ?? 7000),
ContextTimeoutOptions = Properties.ContextTimeoutOption,
ContextOption = Properties.ContextOption,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class LibplanetNodeServiceProperties

public TimeSpan TipTimeout { get; set; } = TimeSpan.FromSeconds(60);

public ContextTimeoutOption ContextTimeoutOption { get; set; }
public ContextOption ContextOption { get; set; }

public int DemandBuffer { get; set; } = 1150;

Expand Down
9 changes: 6 additions & 3 deletions NineChronicles.Headless.Executable/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public class Configuration
public string[]? ConsensusSeedStrings { get; set; }
public ushort? ConsensusPort { get; set; }
public double? ConsensusTargetBlockIntervalMilliseconds { get; set; }
public int? ConsensusProposeSecondBase { get; set; }
public int? ConsensusProposeTimeoutBase { get; set; }
public int? ConsensusEnterPreCommitDelay { get; set; }

public int? MaxTransactionPerBlock { get; set; }

Expand Down Expand Up @@ -139,7 +140,8 @@ public void Overwrite(
string? consensusPrivateKeyString,
string[]? consensusSeedStrings,
double? consensusTargetBlockIntervalMilliseconds,
int? consensusProposeSecondBase,
int? consensusProposeTimeoutBase,
int? consensusEnterPreCommitDelay,
int? maxTransactionPerBlock,
bool? remoteKeyValueService
)
Expand Down Expand Up @@ -190,7 +192,8 @@ public void Overwrite(
ConsensusSeedStrings = consensusSeedStrings ?? ConsensusSeedStrings;
ConsensusPrivateKeyString = consensusPrivateKeyString ?? ConsensusPrivateKeyString;
ConsensusTargetBlockIntervalMilliseconds = consensusTargetBlockIntervalMilliseconds ?? ConsensusTargetBlockIntervalMilliseconds;
ConsensusProposeSecondBase = consensusProposeSecondBase ?? ConsensusProposeSecondBase;
ConsensusProposeTimeoutBase = consensusProposeTimeoutBase ?? ConsensusProposeTimeoutBase;
ConsensusEnterPreCommitDelay = consensusEnterPreCommitDelay ?? ConsensusEnterPreCommitDelay;
MaxTransactionPerBlock = maxTransactionPerBlock ?? MaxTransactionPerBlock;
RemoteKeyValueService = remoteKeyValueService ?? RemoteKeyValueService;
}
Expand Down
65 changes: 54 additions & 11 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public async Task Run(
[Option("consensus-propose-second-base",
Description = "A propose second base for consensus context timeout. The unit is second.")]
int? consensusProposeSecondBase = null,
[Option("consensus-enter-precommit-delay",
Description = "A precommit delay manually set. The unit is millisecond.")]
int? consensusEnterPreCommitDelay = null,
[Option("maximum-transaction-per-block",
Description = "Maximum transactions allowed in a block. null by default.")]
int? maxTransactionPerBlock = null,
Expand Down Expand Up @@ -290,16 +293,55 @@ public async Task Run(
GetActionEvaluatorConfiguration(configuration.GetSection("Headless").GetSection("ActionEvaluator"));

headlessConfig.Overwrite(
appProtocolVersionToken, trustedAppProtocolVersionSigners, genesisBlockPath, host, port,
swarmPrivateKeyString, storeType, storePath, noReduceStore, noMiner, minerCount,
minerPrivateKeyString, minerBlockIntervalMilliseconds, planet, iceServerStrings, peerStrings, rpcServer, rpcListenHost,
rpcListenPort, rpcRemoteServer, rpcHttpServer, graphQLServer, graphQLHost, graphQLPort,
graphQLSecretTokenPath, noCors, nonblockRenderer, nonblockRendererQueue, strictRendering,
logActionRenders, confirmations,
txLifeTime, messageTimeout, tipTimeout, demandBuffer, skipPreload,
minimumBroadcastTarget, bucketSize, chainTipStaleBehaviorType, txQuotaPerSigner, maximumPollPeers,
consensusPort, consensusPrivateKeyString, consensusSeedStrings, consensusTargetBlockIntervalMilliseconds, consensusProposeSecondBase,
maxTransactionPerBlock, remoteKeyValueService
appProtocolVersionToken,
trustedAppProtocolVersionSigners,
genesisBlockPath,
host,
port,
swarmPrivateKeyString,
storeType,
storePath,
noReduceStore,
noMiner,
minerCount,
minerPrivateKeyString,
minerBlockIntervalMilliseconds,
planet,
iceServerStrings,
peerStrings,
rpcServer,
rpcListenHost,
rpcListenPort,
rpcRemoteServer,
rpcHttpServer,
graphQLServer,
graphQLHost,
graphQLPort,
graphQLSecretTokenPath,
noCors,
nonblockRenderer,
nonblockRendererQueue,
strictRendering,
logActionRenders,
confirmations,
txLifeTime,
messageTimeout,
tipTimeout,
demandBuffer,
skipPreload,
minimumBroadcastTarget,
bucketSize,
chainTipStaleBehaviorType,
txQuotaPerSigner,
maximumPollPeers,
consensusPort,
consensusPrivateKeyString,
consensusSeedStrings,
consensusTargetBlockIntervalMilliseconds,
consensusProposeSecondBase * 1_000,
consensusEnterPreCommitDelay,
maxTransactionPerBlock,
remoteKeyValueService
);

// Clean-up previous temporary log files.
Expand Down Expand Up @@ -367,7 +409,8 @@ public async Task Run(
consensusPrivateKeyString: headlessConfig.ConsensusPrivateKeyString,
consensusSeedStrings: headlessConfig.ConsensusSeedStrings,
consensusTargetBlockIntervalMilliseconds: headlessConfig.ConsensusTargetBlockIntervalMilliseconds,
consensusProposeSecondBase: headlessConfig.ConsensusProposeSecondBase,
consensusProposeTimeoutBase: headlessConfig.ConsensusProposeTimeoutBase,
consensusEnterPreCommitDelay: headlessConfig.ConsensusEnterPreCommitDelay,
maximumPollPeers: headlessConfig.MaximumPollPeers,
actionEvaluatorConfiguration: actionEvaluatorConfiguration
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public static LibplanetNodeServiceProperties
string? consensusPrivateKeyString = null,
string[]? consensusSeedStrings = null,
double? consensusTargetBlockIntervalMilliseconds = null,
int? consensusProposeSecondBase = null,
int? consensusProposeTimeoutBase = null,
int? consensusEnterPreCommitDelay = null,
IActionEvaluatorConfiguration? actionEvaluatorConfiguration = null)
{
var swarmPrivateKey = string.IsNullOrEmpty(swarmPrivateKeyString)
Expand All @@ -108,9 +109,10 @@ public static LibplanetNodeServiceProperties
var peers = peerStrings.Select(PropertyParser.ParsePeer).ToImmutableArray();
var consensusSeeds = consensusSeedStrings?.Select(PropertyParser.ParsePeer).ToImmutableList();

var consensusContextTimeoutOption = consensusProposeSecondBase.HasValue
? new ContextTimeoutOption(consensusProposeSecondBase.Value)
: new ContextTimeoutOption();
var defaultContextOption = new ContextOption();
var consensusContextOption = new ContextOption(
proposeTimeoutBase: consensusProposeTimeoutBase ?? defaultContextOption.ProposeTimeoutBase,
enterPreCommitDelay: consensusEnterPreCommitDelay ?? defaultContextOption.EnterPreCommitDelay);

return new LibplanetNodeServiceProperties
{
Expand Down Expand Up @@ -147,7 +149,7 @@ public static LibplanetNodeServiceProperties
ConsensusSeeds = consensusSeeds,
ConsensusPrivateKey = consensusPrivateKey,
ConsensusTargetBlockIntervalMilliseconds = consensusTargetBlockIntervalMilliseconds,
ContextTimeoutOption = consensusContextTimeoutOption,
ContextOption = consensusContextOption,
ActionEvaluatorConfiguration = actionEvaluatorConfiguration ?? new DefaultActionEvaluatorConfiguration(),
};
}
Expand Down

0 comments on commit 2d168ff

Please sign in to comment.