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

Release/230 to development #2667

Merged
merged 18 commits into from
Dec 19, 2024
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 Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<LibplanetVersion>5.4.1</LibplanetVersion>
<LibplanetVersion>5.4.2</LibplanetVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 43 files
+29 −0 .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
+78 −1 .Lib9c.Tests/Action/StakeTest.cs
+8 −0 .Lib9c.Tests/Action/SynthesizeTest.cs
+1 −1 .Lib9c.Tests/Action/ValidatorDelegation/AllocateGuildRewardTest.cs
+59 −11 .Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs
+6 −3 .Lib9c.Tests/Action/ValidatorDelegation/ValidatorDelegationTestBase.cs
+6 −0 .Lib9c.Tests/Delegation/DelegationFixture.cs
+45 −20 .Lib9c.Tests/Delegation/DelegatorTest.cs
+2 −1 .Lib9c.Tests/Delegation/DummyRepository.cs
+0 −221 .Lib9c.Tests/Delegation/Migration/LegacyDelegateeMetadata.cs
+0 −138 .Lib9c.Tests/Delegation/Migration/LegacyLumpSumRewardsRecord.cs
+471 −0 .Lib9c.Tests/Delegation/Migration/LegacyTestDelegatee.cs
+228 −0 .Lib9c.Tests/Delegation/Migration/LegacyTestDelegator.cs
+0 −81 .Lib9c.Tests/Delegation/Migration/MigrateLegacyStateTest.cs
+138 −0 .Lib9c.Tests/Delegation/Migration/RewardBaseMigrationTest.cs
+2 −1 .Lib9c.Tests/Delegation/TestRepository.cs
+1 −1 Directory.Build.props
+12 −0 Lib9c/Action/ClaimStakeReward.cs
+36 −0 Lib9c/Action/InvalidItemIdException.cs
+8 −1 Lib9c/Action/Stake.cs
+14 −0 Lib9c/Action/Synthesize.cs
+6 −6 Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs
+7 −9 Lib9c/Action/ValidatorDelegation/SetValidatorCommission.cs
+12 −0 Lib9c/Addresses.cs
+202 −51 Lib9c/Delegation/Delegatee.cs
+95 −8 Lib9c/Delegation/DelegateeMetadata.cs
+93 −9 Lib9c/Delegation/DelegationAddress.cs
+87 −13 Lib9c/Delegation/DelegationRepository.cs
+1 −0 Lib9c/Delegation/Delegator.cs
+19 −0 Lib9c/Delegation/IDelegatee.cs
+46 −1 Lib9c/Delegation/IDelegationRepository.cs
+406 −0 Lib9c/Delegation/RewardBase.cs
+7 −7 Lib9c/Helper/SynthesizeSimulator.cs
+1 −0 Lib9c/Model/Guild/GuildRepository.cs
+7 −6 Lib9c/TableCSV/Item/SynthesizeWeightSheet.csv
+5 −27 Lib9c/TableData/Item/SynthesizeWeightSheet.cs
+4 −1 Lib9c/ValidatorDelegation/AbstainHistory.cs
+6 −0 Lib9c/ValidatorDelegation/ValidatorDelegatee.cs
+1 −0 Lib9c/ValidatorDelegation/ValidatorRepository.cs
+1 −0 integrations/javascript/@planetarium/.npmrc
+7 −7 integrations/javascript/@planetarium/9c-headless-provider/package.json
+1 −1 integrations/javascript/@planetarium/9c-headless-provider/src/index.ts
+17 −3 integrations/javascript/@planetarium/pnpm-lock.yaml
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
6 changes: 6 additions & 0 deletions NineChronicles.Headless.Executable/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
"Endpoint": "*:/graphql/stagetransaction",
"Period": "60s",
"Limit": 12
},
{
"Endpoint": "*:/graphql/transactionresults",
"Period": "60s",
"Limit": 60
}
],
"QuotaExceededResponse": {
Expand All @@ -117,6 +122,7 @@
"StatusCode": 429
},
"IpBanThresholdCount": 5,
"TransactionResultsBanThresholdCount": 100,
"IpBanMinute" : 60,
"IpBanResponse": {
"Content": "{ \"message\": \"Your Ip has been banned.\" }",
Expand Down
2 changes: 1 addition & 1 deletion NineChronicles.Headless/BlockChainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public UnaryResult<Dictionary<byte[], byte[]>> GetSheets(
sw.Restart();
if (addresses.Any())
{
var stateRootHash = new BlockHash(stateRootHashBytes);
var stateRootHash = new HashDigest<SHA256>(stateRootHashBytes);
IReadOnlyList<IValue> values = _blockChain.GetWorldState(stateRootHash).GetLegacyStates(addresses);
sw.Stop();
Log.Information("[GetSheets]Get sheet from state: {Count}, Elapsed: {Elapsed}", addresses.Count, sw.Elapsed);
Expand Down
34 changes: 19 additions & 15 deletions NineChronicles.Headless/GraphQLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ public void ConfigureServices(IServiceCollection services)
"Admin"));

// FIXME: Use ConfigurationException after bumping to .NET 8 or later.
options.AddPolicy(
JwtPolicyKey,
p =>
p.RequireClaim("iss",
jwtOptions["Issuer"] ?? throw new ArgumentException("jwtOptions[\"Issuer\"] is null.")));
if (Convert.ToBoolean(Configuration.GetSection("Jwt")["EnableJwtAuthentication"]))
{
options.AddPolicy(
JwtPolicyKey,
p =>
p.RequireClaim("iss",
jwtOptions["Issuer"] ?? throw new ArgumentException("jwtOptions[\"Issuer\"] is null.")));
}
});

services.AddGraphTypes();
Expand All @@ -220,6 +223,17 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

// Capture requests
app.UseMiddleware<HttpCaptureMiddleware>();

app.UseRouting();
app.UseAuthorization();
if (Convert.ToBoolean(Configuration.GetSection("IpRateLimiting")["EnableEndpointRateLimiting"]))
{
app.UseMiddleware<CustomRateLimitMiddleware>();
app.UseMiddleware<IpBanMiddleware>();
app.UseMvc();
}

if (Convert.ToBoolean(Configuration.GetSection("MultiAccountManaging")["EnableManaging"]))
{
ConcurrentDictionary<string, HashSet<Address>> ipSignerList = new();
Expand All @@ -229,7 +243,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Publisher);
}

app.UseMiddleware<HttpCaptureMiddleware>();

app.UseMiddleware<LocalAuthenticationMiddleware>();
if (Convert.ToBoolean(Configuration.GetSection("Jwt")["EnableJwtAuthentication"]))
Expand All @@ -246,15 +259,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseCors("AllowAllOrigins");
}

app.UseRouting();
app.UseAuthorization();
if (Convert.ToBoolean(Configuration.GetSection("IpRateLimiting")["EnableEndpointRateLimiting"]))
{
app.UseMiddleware<CustomRateLimitMiddleware>();
app.UseMiddleware<IpBanMiddleware>();
app.UseMvc();
}

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
Expand Down
Loading
Loading