Skip to content

Commit

Permalink
Merge pull request #2263 from planetarium/release/60
Browse files Browse the repository at this point in the history
Release/60
  • Loading branch information
ipdae authored Oct 5, 2023
2 parents 84588ef + 216930a commit 44553c3
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 168 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- qa-*
- 2022q3-worldboss
- release/*
# This branch is for testing only. Use until the next(v200080) release.
- test/action-evaluation-publisher-elapse-metric
tags:
- "*"
workflow_dispatch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Balance(StoreType storeType)
var stateKeyValueStore = new RocksDBKeyValueStore(statesPath);
var stateStore = new TrieStateStore(stateKeyValueStore);
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Inspect(StoreType storeType)
IStore store = storeType.CreateStore(_storePath);
IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states")));
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Expand Down Expand Up @@ -151,7 +151,7 @@ public void Truncate(StoreType storeType)
IStore store = storeType.CreateStore(_storePath);
IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states")));
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Expand Down Expand Up @@ -230,7 +230,7 @@ public void PruneState(StoreType storeType)
var stateKeyValueStore = new RocksDBKeyValueStore(statesPath);
var stateStore = new TrieStateStore(stateKeyValueStore);
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Expand Down Expand Up @@ -272,7 +272,7 @@ public void Snapshot(StoreType storeType)
var stateKeyValueStore = new RocksDBKeyValueStore(statesPath);
var stateStore = new TrieStateStore(stateKeyValueStore);
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void Inspect(
}

IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
IStore store = storeType.CreateStore(storePath);
var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
if (!(store.GetCanonicalChainId() is { } chainId))
Expand Down
4 changes: 2 additions & 2 deletions NineChronicles.Headless.Executable/Commands/ReplayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private static (FileStream? fs, StreamWriter? sw) GetOutputFileStream(
var genesisBlock = store.GetBlock(genesisBlockHash);

// Make BlockChain and blocks.
var policy = new BlockPolicySource(Logger.None).GetPolicy();
var policy = new BlockPolicySource().GetPolicy();
var stagePolicy = new VolatileStagePolicy();
var stateKeyValueStore = new RocksDBKeyValueStore(Path.Combine(storePath, "states"));
var stateStore = new TrieStateStore(stateKeyValueStore);
Expand Down Expand Up @@ -525,7 +525,7 @@ private Transaction LoadTx(string txPath)

private ActionEvaluator GetActionEvaluator(BlockChain blockChain)
{
var policy = new BlockPolicySource(Logger.None).GetPolicy();
var policy = new BlockPolicySource().GetPolicy();
IActionLoader actionLoader = new NCActionLoader();
return new ActionEvaluator(
_ => policy.BlockAction,
Expand Down
93 changes: 62 additions & 31 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,35 +353,6 @@ public async Task Run(
KeyStore = Web3KeyStore.DefaultKeyStore,
};

if (headlessConfig.GraphQLServer)
{
string? secretToken = null;
if (headlessConfig.GraphQLSecretTokenPath is { })
{
var buffer = new byte[40];
new SecureRandom().NextBytes(buffer);
secretToken = Convert.ToBase64String(buffer);
await File.WriteAllTextAsync(headlessConfig.GraphQLSecretTokenPath, secretToken);
}

var graphQLNodeServiceProperties = new GraphQLNodeServiceProperties
{
GraphQLServer = headlessConfig.GraphQLServer,
GraphQLListenHost = headlessConfig.GraphQLHost,
GraphQLListenPort = headlessConfig.GraphQLPort,
SecretToken = secretToken,
NoCors = headlessConfig.NoCors,
UseMagicOnion = headlessConfig.RpcServer,
HttpOptions = headlessConfig.RpcServer && headlessConfig.RpcHttpServer == true
? new GraphQLNodeServiceProperties.MagicOnionHttpOptions(
$"{headlessConfig.RpcListenHost}:{headlessConfig.RpcListenPort}")
: (GraphQLNodeServiceProperties.MagicOnionHttpOptions?)null,
};

var graphQLService = new GraphQLService(graphQLNodeServiceProperties, standaloneContext, configuration);
hostBuilder = graphQLService.Configure(hostBuilder);
}

var properties = NineChroniclesNodeServiceProperties
.GenerateLibplanetNodeServiceProperties(
headlessConfig.AppProtocolVersionString,
Expand Down Expand Up @@ -488,7 +459,10 @@ IActionLoader MakeSingleActionLoader()
.AddAspNetCoreInstrumentation()
.AddPrometheusExporter());
});
hostBuilder.UseNineChroniclesNode(nineChroniclesProperties, standaloneContext);

NineChroniclesNodeService service =
NineChroniclesNodeService.Create(nineChroniclesProperties, standaloneContext);
ActionEvaluationPublisher publisher;
if (headlessConfig.RpcServer)
{
var context = new RpcContext
Expand All @@ -501,7 +475,7 @@ IActionLoader MakeSingleActionLoader()
headlessConfig.RpcListenPort,
headlessConfig.RpcRemoteServer == true
);
var publisher = new ActionEvaluationPublisher(
publisher = new ActionEvaluationPublisher(
standaloneContext.NineChroniclesNodeService!.BlockRenderer,
standaloneContext.NineChroniclesNodeService!.ActionRenderer,
standaloneContext.NineChroniclesNodeService!.ExceptionRenderer,
Expand All @@ -512,13 +486,70 @@ IActionLoader MakeSingleActionLoader()
new ConcurrentDictionary<string, Sentry.ITransaction>()
);

hostBuilder.UseNineChroniclesNode(
nineChroniclesProperties,
standaloneContext,
publisher,
service);
hostBuilder.UseNineChroniclesRPC(
rpcProperties,
publisher,
standaloneContext,
configuration
);
}
else
{
var context = new RpcContext
{
RpcRemoteSever = false
};
publisher = new ActionEvaluationPublisher(
standaloneContext.NineChroniclesNodeService!.BlockRenderer,
standaloneContext.NineChroniclesNodeService!.ActionRenderer,
standaloneContext.NineChroniclesNodeService!.ExceptionRenderer,
standaloneContext.NineChroniclesNodeService!.NodeStatusRenderer,
IPAddress.Loopback.ToString(),
0,
context,
new ConcurrentDictionary<string, Sentry.ITransaction>()
);
hostBuilder.UseNineChroniclesNode(
nineChroniclesProperties,
standaloneContext,
publisher,
service);
}

if (headlessConfig.GraphQLServer)
{
string? secretToken = null;
if (headlessConfig.GraphQLSecretTokenPath is { })
{
var buffer = new byte[40];
new SecureRandom().NextBytes(buffer);
secretToken = Convert.ToBase64String(buffer);
await File.WriteAllTextAsync(headlessConfig.GraphQLSecretTokenPath, secretToken);
}

var graphQLNodeServiceProperties = new GraphQLNodeServiceProperties
{
GraphQLServer = headlessConfig.GraphQLServer,
GraphQLListenHost = headlessConfig.GraphQLHost,
GraphQLListenPort = headlessConfig.GraphQLPort,
SecretToken = secretToken,
NoCors = headlessConfig.NoCors,
UseMagicOnion = headlessConfig.RpcServer,
HttpOptions = headlessConfig.RpcServer && headlessConfig.RpcHttpServer == true
? new GraphQLNodeServiceProperties.MagicOnionHttpOptions(
$"{headlessConfig.RpcListenHost}:{headlessConfig.RpcListenPort}")
: (GraphQLNodeServiceProperties.MagicOnionHttpOptions?)null,
};

var graphQLService =
new GraphQLService(graphQLNodeServiceProperties, standaloneContext, configuration, publisher);
hostBuilder = graphQLService.Configure(hostBuilder);
}

await hostBuilder.RunConsoleAsync(cancellationToken ?? Context.CancellationToken);
}
Expand Down
4 changes: 2 additions & 2 deletions NineChronicles.Headless.Executable/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"ContentType": "application/json",
"StatusCode": 429
},
"IpBanThresholdCount": 10,
"IpBanThresholdCount": 5,
"IpBanMinute" : 60,
"IpBanResponse": {
"Content": "{ \"message\": \"Your Ip has been banned.\" }",
Expand All @@ -127,6 +127,6 @@
"EnableManaging": false,
"ManagementTimeMinutes": 10,
"TxIntervalMinutes": 10,
"ThresholdCount": 50
"ThresholdCount": 29
}
}
14 changes: 13 additions & 1 deletion NineChronicles.Headless.Tests/GraphQLStartupTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Concurrent;
using Lib9c.Renderers;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -16,7 +18,17 @@ public GraphQLStartupTest()
{
_configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
var standaloneContext = CreateStandaloneContext();
_startup = new GraphQLService.GraphQLStartup(_configuration, standaloneContext);
var publisher = new ActionEvaluationPublisher(
new BlockRenderer(),
new ActionRenderer(),
new ExceptionRenderer(),
new NodeStatusRenderer(),
"",
0,
new RpcContext(),
new ConcurrentDictionary<string, Sentry.ITransaction>()
);
_startup = new GraphQLService.GraphQLStartup(_configuration, standaloneContext, publisher);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ public async Task SubscribeTipChangedEvent()
lastCommit: GenerateBlockCommit(BlockChain.Tip.Index, BlockChain.Tip.Hash, GenesisValidators));
BlockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, GenesisValidators));

var result = await ExecuteSubscriptionQueryAsync("subscription { tipChanged { index hash } }");

// var data = (Dictionary<string, object>)((ExecutionNode) result.Data!).ToValue()!;

Assert.Equal(index, BlockChain.Tip.Index);
await Task.Delay(TimeSpan.FromSeconds(1));

var result = await ExecuteSubscriptionQueryAsync("subscription { tipChanged { index hash } }");
Assert.IsType<SubscriptionExecutionResult>(result);
var subscribeResult = (SubscriptionExecutionResult)result;
Assert.Equal(index, BlockChain.Tip.Index);
var stream = subscribeResult.Streams!.Values.FirstOrDefault();
var rawEvents = await stream.Take((int)index);
var rawEvents = await stream.Take(1);
Assert.NotNull(rawEvents);

var events = (Dictionary<string, object>)((ExecutionNode)rawEvents.Data!).ToValue()!;
Expand Down
Loading

0 comments on commit 44553c3

Please sign in to comment.