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

Backmerge 211 #2633

Merged
merged 22 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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.3.2-alpha.1</LibplanetVersion>
<LibplanetVersion>5.4.0</LibplanetVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 294 files
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Xunit;
using Lib9cUtils = Lib9c.DevExtensions.Utils;
using CoconaUtils = Libplanet.Extensions.Cocona.Utils;
using Libplanet.Types.Assets;
using Nekoyume.TableData;

namespace NineChronicles.Headless.Executable.Tests.Commands
{
Expand All @@ -41,6 +43,7 @@ public class ChainCommandTest : IDisposable
// Because the purpose of ChainCommandTest is to store and read blockchain data.
private readonly StringIOConsole _console;
private readonly ChainCommand _command;
private readonly Dictionary<string, string> _sheets;

private readonly string _storePath;

Expand All @@ -50,6 +53,7 @@ public ChainCommandTest()
_command = new ChainCommand(_console);

_storePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
_sheets = TableSheetsImporter.ImportSheets();
}

[Theory]
Expand Down Expand Up @@ -91,14 +95,28 @@ public void Inspect(StoreType storeType)
policyActionsRegistry: blockPolicy.PolicyActionsRegistry,
stateStore,
new NCActionLoader());
var sheets = TableSheetsImporter.ImportSheets();
Block genesisBlock = BlockChain.ProposeGenesisBlock(
transactions: new IAction[]
{
new Initialize(
validatorSet: new ValidatorSet(
new[] { new Validator(proposer.PublicKey, BigInteger.One) }.ToList()
new InitializeStates(
validatorSet: new ValidatorSet(new List<Validator>
{
new Validator(proposer.PublicKey, 10_000_000_000_000_000_000)
}),
rankingState: new RankingState0(),
shopState: new ShopState(),
gameConfigState: new GameConfigState(sheets[nameof(GameConfigSheet)]),
redeemCodeState: new RedeemCodeState(
Bencodex.Types.Dictionary.Empty
.Add("address", RedeemCodeState.Address.Serialize())
.Add("map", Bencodex.Types.Dictionary.Empty)
),
states: ImmutableDictionary.Create<Address, IValue>()
activatedAccountsState: new ActivatedAccountsState(),
goldCurrencyState: new GoldCurrencyState(Currency.Uncapped("ncg", 2, null)),
goldDistributions: new GoldDistribution[] { },
tableSheets: sheets,
pendingActivationStates: new PendingActivationState[] { }
)
}.Select((sa, nonce) => Transaction.Create(nonce, new PrivateKey(), null, new[] { sa.PlainValue }))
.ToImmutableList());
Expand Down Expand Up @@ -151,15 +169,25 @@ public void Truncate(StoreType storeType)
policyActionsRegistry: blockPolicy.PolicyActionsRegistry,
stateStore,
new NCActionLoader());
var validatorSet = new ValidatorSet(
new[] { new Validator(proposer.PublicKey, 10_000_000_000_000_000_000) }.ToList());
var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]);
var redeemCodeListSheet = new RedeemCodeListSheet();
Block genesisBlock = BlockChain.ProposeGenesisBlock(
transactions: new IAction[]
{
new Initialize(
validatorSet: new ValidatorSet(
new[] { new Validator(proposer.PublicKey, BigInteger.One) }.ToList()
),
states: ImmutableDictionary.Create<Address, IValue>()
)
new InitializeStates(
validatorSet: validatorSet,
rankingState: new RankingState0(),
shopState: new ShopState(),
tableSheets: _sheets,
gameConfigState: gameConfigState,
redeemCodeState: new RedeemCodeState(redeemCodeListSheet),
adminAddressState: null,
activatedAccountsState: new ActivatedAccountsState(ImmutableHashSet<Address>.Empty),
goldCurrencyState: new GoldCurrencyState(Currency.Uncapped("ncg", 2, null), 0),
goldDistributions: Array.Empty<GoldDistribution>(),
pendingActivationStates: Array.Empty<PendingActivationState>())
}.Select((sa, nonce) => Transaction.Create(nonce, new PrivateKey(), null, new[] { sa.PlainValue }))
.ToImmutableList());
BlockChain chain = BlockChain.Create(
Expand Down Expand Up @@ -407,18 +435,16 @@ private Block MineGenesisBlock()
AdminState adminState =
new AdminState(new Address(genesisConfig.AdminAddress), genesisConfig.AdminValidUntil);
Block genesisBlock = BlockHelper.ProposeGenesisBlock(
new ValidatorSet(new List<Validator>
{
new Validator(GenesisHelper.ValidatorKey.PublicKey, 10_000_000_000_000_000_000)
}),
tableSheets,
goldDistributions,
pendingActivationStates.ToArray(),
adminState,
authorizedMinersState,
ImmutableHashSet<Address>.Empty,
new Dictionary<PublicKey, BigInteger>
{
{
GenesisHelper.ValidatorKey.PublicKey, BigInteger.One
}
},
genesisConfig.ActivationKeyCount != 0,
null,
new PrivateKey(ByteUtil.ParseHex(genesisConfig.PrivateKey))
Expand All @@ -439,7 +465,7 @@ private Block MineGenesisBlock()
block.Hash,
DateTimeOffset.UtcNow,
validator.PublicKey,
null,
10_000_000_000_000_000_000,
VoteFlag.PreCommit).Sign(validator)))
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ public static Block MineGenesisBlock(
AdminState adminState =
new AdminState(new Address(genesisConfig.AdminAddress), genesisConfig.AdminValidUntil);
Block genesisBlock = BlockHelper.ProposeGenesisBlock(
new ValidatorSet(
genesisValidatorSet?.Select(kv => new Validator(kv.Key, kv.Value)).ToList()
?? new List<Validator>
{
new Validator(ValidatorKey.PublicKey, 10_000_000_000_000_000_000)
}),
tableSheets,
goldDistributions,
pendingActivationStates.ToArray(),
adminState,
authorizedMinersState,
ImmutableHashSet<Address>.Empty,
genesisValidatorSet ?? new Dictionary<PublicKey, BigInteger>
{
{
ValidatorKey.PublicKey,
BigInteger.One
}
},
genesisConfig.ActivationKeyCount != 0,
null,
new PrivateKey(ByteUtil.ParseHex(genesisConfig.PrivateKey))
Expand All @@ -109,7 +108,7 @@ public static void AppendEmptyBlock(BlockChain blockChain)
block.Hash,
new[]
{
new VoteMetadata(block.Index, 0, block.Hash, block.Timestamp, ValidatorKey.PublicKey, null, VoteFlag.PreCommit).Sign(ValidatorKey),
new VoteMetadata(block.Index, 0, block.Hash, block.Timestamp, ValidatorKey.PublicKey, 10_000_000_000_000_000_000, VoteFlag.PreCommit).Sign(ValidatorKey),
}.ToImmutableArray());
blockChain.Append(block, blockCommit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<PackageReference Include="MagicOnion.Client" Version="6.1.3" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Lib9c\.Lib9c.Tests\TableSheets.cs" Link="TableSheets.cs" />
<Compile Include="..\Lib9c\.Lib9c.Tests\TableSheetsImporter.cs" Link="TableSheetsImporter.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NineChronicles.Headless.Executable\NineChronicles.Headless.Executable.csproj" />
</ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions NineChronicles.Headless.Executable.Tests/TableSheetsImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.IO;

namespace NineChronicles.Headless.Executable.Tests
{
public static class TableSheetsImporter
{
public static Dictionary<string, string> ImportSheets() =>
Lib9c.Tests.TableSheetsImporter.ImportSheets(Path
.GetFullPath("../../")
.Replace(
Path.Combine("NineChronicles.Headless.Executable.Tests", "bin"),
Path.Combine("Lib9c", "Lib9c", "TableCSV")));
}
}
9 changes: 6 additions & 3 deletions NineChronicles.Headless.Executable/Commands/GenesisCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Consensus;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -266,15 +267,17 @@ public void Mine(
// Mine genesis block
_console.Out.WriteLine("\nMining genesis block...\n");
Block block = BlockHelper.ProposeGenesisBlock(
validatorSet: new ValidatorSet(
initialValidatorSet.Select(
v => new Libplanet.Types.Consensus.Validator(
new PublicKey(ByteUtil.ParseHex(v.PublicKey)),
new BigInteger(v.Power))).ToList()),
tableSheets: tableSheets,
goldDistributions: initialDepositList.ToArray(),
pendingActivationStates: Array.Empty<PendingActivationState>(),
// FIXME Should remove default value after fixing parameter type on Lib9c side.
adminState: adminState ?? new AdminState(default, 0L),
privateKey: initialMinter,
initialValidators: initialValidatorSet.ToDictionary(
item => new PublicKey(ByteUtil.ParseHex(item.PublicKey)),
item => new BigInteger(item.Power)),
actionBases: adminMeads.Concat(initialMeads).Concat(initialPledges).Concat(GetAdditionalActionBases()),
goldCurrency: currency
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Libplanet.Types.Tx;
using Serilog;
using Libplanet.Types.Evidence;
using Libplanet.Types.Blocks;
using Libplanet.Types.Assets;

namespace NineChronicles.Headless.Executable.Commands
{
Expand Down Expand Up @@ -51,6 +53,8 @@ public ActionContext(

public int BlockProtocolVersion { get; }

public BlockCommit? LastCommit { get; }

public bool Rehearsal { get; }

public IWorld PreviousState { get; }
Expand All @@ -68,9 +72,7 @@ public void UseGas(long gas)
{
}

public long GasUsed() => 0;

public long GasLimit() => 0;
public FungibleAssetValue? MaxGasPrice => null;

public IRandom GetRandom() => new Random(RandomSeed);
}
Expand Down
20 changes: 4 additions & 16 deletions NineChronicles.Headless.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,30 @@
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;

namespace NineChronicles.Headless.Tests.Action;

public class ActionContext : IActionContext
{
private long UsedGas { get; set; }

public Address Signer { get; init; }
public TxId? TxId { get; init; }
public Address Miner { get; init; }
public long BlockIndex { get; init; }
public int BlockProtocolVersion { get; init; }
public BlockCommit LastCommit { get; init; }
public IWorld PreviousState { get; init; }
public int RandomSeed { get; init; }
public bool IsPolicyAction { get; init; }
public FungibleAssetValue? MaxGasPrice { get; set; }
public IReadOnlyList<ITransaction> Txs { get; init; }
public IReadOnlyList<EvidenceBase> Evidence { get; init; }
public void UseGas(long gas)
{
UsedGas += gas;
}

public IRandom GetRandom()
{
return new Random(RandomSeed);
}

public long GasUsed()
{
return UsedGas;
}

public long GasLimit()
{
return 0L;
}
}
2 changes: 1 addition & 1 deletion NineChronicles.Headless.Tests/Common/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class Fixtures

public static readonly Address AvatarAddress = new Address("983c3Fbfe8243a0e36D55C6C1aE26A7c8Bb6CBd4");

public static readonly Address StakeStateAddress = StakeState.DeriveAddress(UserAddress);
public static readonly Address StakeStateAddress = LegacyStakeState.DeriveAddress(UserAddress);

public static readonly TableSheets TableSheetsFX = new(TableSheetsImporter.ImportSheets());

Expand Down
2 changes: 1 addition & 1 deletion NineChronicles.Headless.Tests/GraphQLTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ InitializeStates initializeStates
0,
block.Hash,
ValidatorPrivateKeys.Select(
k => new VoteMetadata(block.Index, 0, block.Hash, block.Timestamp, k.PublicKey, null, VoteFlag.PreCommit).Sign(k))
k => new VoteMetadata(block.Index, 0, block.Hash, block.Timestamp, k.PublicKey, BigInteger.One, VoteFlag.PreCommit).Sign(k))
.ToImmutableArray());

blockchain.Append(block, blockCommit);
Expand Down
2 changes: 2 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;
using Libplanet.Types.Tx;
using Nekoyume;
using Nekoyume.Action;
Expand Down Expand Up @@ -45,6 +46,7 @@ public ActionQueryTest()
new Random().NextBytes(_nonce);
(_activationKey, PendingActivationState pending) = ActivationKey.Create(_activationCodeSeed, _nonce);
var initializeStates = new InitializeStates(
validatorSet: new ValidatorSet(new List<Validator> { new Validator(MinerPrivateKey.PublicKey, 1) }),
rankingState: new RankingState0(),
shopState: new ShopState(),
gameConfigState: new GameConfigState(),
Expand Down
34 changes: 18 additions & 16 deletions NineChronicles.Headless.Tests/GraphTypes/AddressQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GraphQL.Execution;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;
using Nekoyume.Action;
using Nekoyume.Model.State;
using NineChronicles.Headless.GraphTypes;
Expand All @@ -21,24 +22,25 @@ public class AddressQueryTest
public AddressQueryTest()
{
var initializeStates = new InitializeStates(
rankingState: new RankingState0(),
shopState: new ShopState(),
gameConfigState: new GameConfigState(),
redeemCodeState: new RedeemCodeState(Bencodex.Types.Dictionary.Empty
.Add("address", RedeemCodeState.Address.Serialize())
.Add("map", Bencodex.Types.Dictionary.Empty)
),
adminAddressState: new AdminState(new PrivateKey().Address, 1500000),
activatedAccountsState: new ActivatedAccountsState(),
validatorSet: new ValidatorSet(new List<Validator> { new Validator(MinerPrivateKey.PublicKey, 1) }),
rankingState: new RankingState0(),
shopState: new ShopState(),
gameConfigState: new GameConfigState(),
redeemCodeState: new RedeemCodeState(Bencodex.Types.Dictionary.Empty
.Add("address", RedeemCodeState.Address.Serialize())
.Add("map", Bencodex.Types.Dictionary.Empty)
),
adminAddressState: new AdminState(new PrivateKey().Address, 1500000),
activatedAccountsState: new ActivatedAccountsState(),
#pragma warning disable CS0618
// Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1319
goldCurrencyState:
new GoldCurrencyState(Currency.Legacy("NCG", 2, MinerPrivateKey.Address)),
// Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1319
goldCurrencyState:
new GoldCurrencyState(Currency.Legacy("NCG", 2, MinerPrivateKey.Address)),
#pragma warning restore CS0618
goldDistributions: Array.Empty<GoldDistribution>(),
tableSheets: new Dictionary<string, string>(),
pendingActivationStates: new PendingActivationState[] { }
);
goldDistributions: Array.Empty<GoldDistribution>(),
tableSheets: new Dictionary<string, string>(),
pendingActivationStates: new PendingActivationState[] { }
);
_standaloneContext = CreateStandaloneContext(initializeStates);
}

Expand Down
Loading
Loading