Skip to content

Commit

Permalink
Merge pull request #2438 from planetarium/release/120
Browse files Browse the repository at this point in the history
Release headless v120
  • Loading branch information
U-lis authored Mar 26, 2024
2 parents 659e10b + b7f412c commit c810b88
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 160 files
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
21 changes: 21 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,5 +1519,26 @@ public async Task RuneSummon()
Assert.Equal(groupId, action.GroupId);
Assert.Equal(summonCount, action.SummonCount);
}

[Fact]
public async Task RetrieveAvatarAssets()
{
var avatarAddress = new PrivateKey().Address;

var query = $@"{{
retrieveAvatarAssets(
avatarAddress: ""{avatarAddress}""
)
}}";

var queryResult = await ExecuteQueryAsync<ActionQuery>(query, standaloneContext: _standaloneContext);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var plainValue = _codec.Decode(ByteUtil.ParseHex((string)data["retrieveAvatarAssets"]));
Assert.IsType<Dictionary>(plainValue);
var actionBase = DeserializeNCAction(plainValue);
var action = Assert.IsType<RetrieveAvatarAssets>(actionBase);

Assert.Equal(avatarAddress, action.AvatarAddress);
}
}
}
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
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/ActionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ public ActionQuery(StandaloneContext standaloneContext)
RegisterGarages();
RegisterSummon();
RegisterClaimItems();
RegisterRetrieveAvatarAssets();

Field<NonNullGraphType<CraftQuery>>(
name: "craftQuery",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using GraphQL;
using GraphQL.Types;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;
using Nekoyume.Action;

namespace NineChronicles.Headless.GraphTypes;

public partial class ActionQuery
{
private void RegisterRetrieveAvatarAssets()
{
Field<NonNullGraphType<ByteStringType>>(
name: "retrieveAvatarAssets",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress",
Description = "Avatar address to retrieve assets"
}
),
resolve: context =>
{
var avatarAddress = context.GetArgument<Address>("avatarAddress");
ActionBase action = new RetrieveAvatarAssets()
{
AvatarAddress = avatarAddress
};
return Encode(context, action);
}
);
}
}
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

0 comments on commit c810b88

Please sign in to comment.