Skip to content

Commit

Permalink
Merge pull request #2353 from planetarium/release/80
Browse files Browse the repository at this point in the history
Release/80
  • Loading branch information
sonohoshi authored Dec 11, 2023
2 parents 5e98a1e + d8f5f48 commit d5c4b97
Show file tree
Hide file tree
Showing 59 changed files with 651 additions and 354 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ RUN dotnet publish NineChronicles.Headless.Executable/NineChronicles.Headless.Ex
# Build runtime image
FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
WORKDIR /app
RUN apt-get update && apt-get install -y libc6-dev
RUN apt-get update && apt-get install -y libc6-dev liblz4-dev zlib1g-dev libsnappy-dev libzstd-dev
COPY --from=build-env /app/out .

# Install native deps & utilities for production
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev jq curl \
libc6-dev liblz4-dev zlib1g-dev libsnappy-dev libzstd-dev jq curl \
&& rm -rf /var/lib/apt/lists/*

VOLUME /data
Expand Down
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 375 files
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Bencodex.Types;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Action.State;
using Libplanet.Types.Blocks;
using Libplanet.Common;
using Libplanet.Crypto;
Expand All @@ -19,7 +20,7 @@ public void ForkEvaluation()
{
((0L, 100L), new PreActionEvaluator()),
((101L, long.MaxValue), new PostActionEvaluator()),
});
}, new SingleActionLoader(typeof(MockAction)));

Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(0), null)).Action);
Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(99), null)).Action);
Expand All @@ -36,25 +37,25 @@ public void CheckPairs()
{
((0L, 100L), new PreActionEvaluator()),
((99L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((0L, 100L), new PreActionEvaluator()),
((100L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((50L, 100L), new PreActionEvaluator()),
((101L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((0L, 100L), new PreActionEvaluator()),
((101L, long.MaxValue - 1), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
}
}

Expand All @@ -73,7 +74,6 @@ public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock bl
default,
0,
0,
false,
default,
0,
false),
Expand All @@ -97,7 +97,6 @@ public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock bl
default,
0,
0,
false,
default,
0,
false),
Expand All @@ -106,6 +105,17 @@ public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock bl
}
}

class MockAction : IAction
{
public IValue PlainValue => default(Null);

public void LoadPlainValue(IValue plainValue)
{
}

public IAccount Execute(IActionContext context) => context.PreviousState;
}

class MockBlock : IPreEvaluationBlock
{
public MockBlock(long blockIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ public class ForkableActionEvaluator : IActionEvaluator
{
private readonly HardForkRouter _router;

public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Range, IActionEvaluator ActionEvaluator)> pairs)
public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Range, IActionEvaluator ActionEvaluator)> pairs, IActionLoader actionLoader)
{
_router = new HardForkRouter(pairs);
ActionLoader = actionLoader;
}

public IActionLoader ActionLoader => throw new NotSupportedException();
public IActionLoader ActionLoader
{
get;
}

public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public class PluggedActionEvaluator : IActionEvaluator
{
private readonly IPluginActionEvaluator _pluginActionEvaluator;

public IActionLoader ActionLoader => throw new NotImplementedException();
public IActionLoader ActionLoader
{
get;
}

public PluggedActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore)
public PluggedActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore, IActionLoader actionLoader)
{
_pluginActionEvaluator = CreateActionEvaluator(pluginPath, typeName, keyValueStore);
ActionLoader = actionLoader;
}

public static Assembly LoadPlugin(string absolutePath)
Expand Down
1 change: 0 additions & 1 deletion Libplanet.Headless/Hosting/ActionEvaluatorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public enum ActionEvaluatorType
{
Default, // ActionEvaluator
ForkableActionEvaluator,
RemoteActionEvaluator,
PluggedActionEvaluator,
}
15 changes: 7 additions & 8 deletions Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Libplanet.Crypto;
using Libplanet.Extensions.ForkableActionEvaluator;
using Libplanet.Extensions.PluggedActionEvaluator;
using Libplanet.Extensions.RemoteActionEvaluator;
using Libplanet.Net;
using Libplanet.Net.Consensus;
using Libplanet.Net.Options;
Expand Down Expand Up @@ -82,8 +81,7 @@ public LibplanetNodeService(
Action<bool> preloadStatusHandlerAction,
IActionLoader actionLoader,
bool ignoreBootstrapFailure = false,
bool ignorePreloadFailure = false,
bool useRemoteActionEvaluator = false
bool ignorePreloadFailure = false
)
{
if (blockPolicy is null)
Expand Down Expand Up @@ -127,10 +125,8 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
new PluggedActionEvaluator(
ResolvePluginPath(pluginActionEvaluatorConfiguration.PluginPath),
pluginActionEvaluatorConfiguration.TypeName,
keyValueStore),
RemoteActionEvaluatorConfiguration remoteActionEvaluatorConfiguration =>
new RemoteActionEvaluator(
new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint)),
keyValueStore,
actionLoader),
DefaultActionEvaluatorConfiguration _ =>
new ActionEvaluator(
_ => blockPolicy.BlockAction,
Expand All @@ -139,7 +135,10 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
ForkableActionEvaluatorConfiguration forkableActionEvaluatorConfiguration =>
new ForkableActionEvaluator(
forkableActionEvaluatorConfiguration.Pairs.Select(
pair => ((pair.Item1.Start, pair.Item1.End), BuildActionEvaluator(pair.Item2)))),
pair => (
(pair.Item1.Start, pair.Item1.End),
BuildActionEvaluator(pair.Item2))),
actionLoader),
_ => throw new InvalidOperationException("Unexpected type."),
};
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion Libplanet.Headless/Libplanet.Headless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<ProjectReference Include="..\Lib9c\.Libplanet\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\Lib9c\.Libplanet\Libplanet.Net\Libplanet.Net.csproj" />
<ProjectReference Include="..\NineChronicles.RPC.Shared\NineChronicles.RPC.Shared\NineChronicles.RPC.Shared.csproj" />
<ProjectReference Include="..\Lib9c\.Libplanet.Extensions.RemoteActionEvaluator\Libplanet.Extensions.RemoteActionEvaluator.csproj" />
<ProjectReference Include="..\Libplanet.Extensions.ForkableActionEvaluator\Libplanet.Extensions.ForkableActionEvaluator.csproj" />
<ProjectReference Include="..\Libplanet.Extensions.PluggedActionEvaluator\Libplanet.Extensions.PluggedActionEvaluator.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace NineChronicles.Headless.AccessControlCenter.Controllers
[ApiController]
public class AccessControlServiceController : ControllerBase
{
public class BulkAddTxQuotaInput
{
public List<string> Addresses { get; set; } = new List<string>();

public int Quota { get; set; }
}

private readonly IMutableAccessControlService _accessControlService;

public AccessControlServiceController(IMutableAccessControlService accessControlService)
Expand All @@ -20,11 +27,13 @@ public AccessControlServiceController(IMutableAccessControlService accessControl
[HttpGet("entries/{address}")]
public ActionResult<int?> GetTxQuota(string address)
{
return _accessControlService.GetTxQuota(new Address(address));
var result = _accessControlService.GetTxQuota(new Address(address));

return result != null ? result : NotFound();
}

[HttpPost("entries/add-tx-quota/{address}/{quota:int}")]
public ActionResult AddTxQuota(string address, int quota)
[HttpPost("entries/add-tx-quota/{address}")]
public ActionResult AddTxQuota(string address, [FromBody] int quota)
{
var maxQuota = 10;
if (quota > maxQuota)
Expand All @@ -36,6 +45,27 @@ public ActionResult AddTxQuota(string address, int quota)
return Ok();
}

[HttpPost("entries/bulk-add-tx-quota")]
public ActionResult BulkAddTxQuota([FromBody] BulkAddTxQuotaInput bulkAddTxQuotaInput)
{
var maxQuota = 10;
var maxAddressCount = 100;
if (bulkAddTxQuotaInput.Quota > maxQuota)
{
return BadRequest($"The quota cannot exceed {maxQuota}.");
}
if (bulkAddTxQuotaInput.Addresses.Count > maxAddressCount)
{
return BadRequest($"The addresses cannot exceed {maxAddressCount}.");
}

foreach (string address in bulkAddTxQuotaInput.Addresses)
{
_accessControlService.AddTxQuota(new Address(address), bulkAddTxQuotaInput.Quota);
}
return Ok();
}

[HttpPost("entries/remove-tx-quota/{address}")]
public ActionResult RemoveTxQuota(string address)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Balance(StoreType storeType)
{
IStore store = storeType.CreateStore(_storePath);
var statesPath = Path.Combine(_storePath, "states");
Address targetAddress = new PrivateKey().ToAddress();
Address targetAddress = new PrivateKey().Address;
int targetCurrency = 10000; // 100 NCG
Block genesisBlock = GenesisHelper.MineGenesisBlock(targetAddress, targetCurrency);
var stateKeyValueStore = new RocksDBKeyValueStore(statesPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void TransferAsset(
var recipientPrivateKey = new PrivateKey();
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.TransferAsset(
senderPrivateKey.ToAddress().ToHex(),
recipientPrivateKey.ToAddress().ToHex(),
senderPrivateKey.Address.ToHex(),
recipientPrivateKey.Address.ToHex(),
Convert.ToString(amount),
filePath,
memo);
Expand All @@ -134,8 +134,8 @@ public void TransferAsset(
action.LoadPlainValue(plainValue);
Assert.Equal(memo, action.Memo);
Assert.Equal(amount, action.Amount.MajorUnit);
Assert.Equal(senderPrivateKey.ToAddress(), action.Sender);
Assert.Equal(recipientPrivateKey.ToAddress(), action.Recipient);
Assert.Equal(senderPrivateKey.Address, action.Sender);
Assert.Equal(recipientPrivateKey.Address, action.Recipient);
}
else
{
Expand Down Expand Up @@ -205,7 +205,7 @@ public void ClaimStakeReward(string addressString, int expectedCode)
public void ClaimStakeRewardWithBlockIndex(long blockIndex, Type expectedActionType)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().ToAddress();
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
Expand Down Expand Up @@ -236,7 +236,7 @@ public void ClaimStakeRewardWithActionVersion(
for (var i = actionVersionMin; i < actionVersionMax + 1; i++)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().ToAddress();
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
Expand Down
23 changes: 10 additions & 13 deletions NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void Sign_TransferAsset(int amount, bool gas)
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
actionCommand.TransferAsset(
_privateKey.ToAddress().ToHex(),
new PrivateKey().ToAddress().ToHex(),
_privateKey.Address.ToHex(),
new PrivateKey().Address.ToHex(),
Convert.ToString(amount),
filePath);
Assert_Tx(1, filePath, gas);
Expand Down Expand Up @@ -131,26 +131,23 @@ private void Assert_Tx(long txNonce, string filePath, bool gas)
{
var timeStamp = DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
var hashHex = ByteUtil.Hex(_blockHash.ByteArray);
long? maxGasPrice = null;
if (gas)
{
maxGasPrice = 1L;
}
long? maxGasPrice = gas ? (long?)1L : null;
_command.Sign(ByteUtil.Hex(_privateKey.ByteArray), txNonce, hashHex, timeStamp.ToString(),
new[] { filePath }, maxGasPrice: maxGasPrice);
var output = _console.Out.ToString();
var rawTx = Convert.FromBase64String(output!);
var tx = Transaction.Deserialize(rawTx);
Assert.Equal(txNonce, tx.Nonce);
Assert.Equal(_blockHash, tx.GenesisHash);
Assert.Equal(_privateKey.ToAddress(), tx.Signer);
Assert.Equal(_privateKey.Address, tx.Signer);
Assert.Equal(timeStamp, tx.Timestamp);
ActionBase action = (ActionBase)new NCActionLoader().LoadAction(1L, tx.Actions.Single());
long expectedGasLimit = 1L;
if (action is ITransferAsset || action is ITransferAssets)
{
expectedGasLimit = 4L;
}
long? expectedGasLimit = gas
? action is ITransferAsset || action is ITransferAssets
? (long?)4L
: (long?)1L
: null;

Assert.Equal(expectedGasLimit, tx.GasLimit);
if (gas)
{
Expand Down
Loading

0 comments on commit d5c4b97

Please sign in to comment.