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 220 #2645

Merged
merged 46 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9a05060
Merge pull request #2617 from planetarium/release/210
U-lis Oct 28, 2024
ce78ed0
fix: Build fix from Lib9c bump
OnedgeLee Sep 25, 2024
a52d49e
test: Fix tests
OnedgeLee Nov 1, 2024
3357614
feat: Add Query and mutation
OnedgeLee Nov 1, 2024
dc7b585
test: Fix test code failing due to no delegation settings
s2quake Nov 1, 2024
f235ad0
feat: Add GQL queries for migration test
OnedgeLee Nov 1, 2024
0171c1b
fix: Fix promote to use GG
OnedgeLee Nov 1, 2024
5e38dd1
chore: Cast GuildAddress
OnedgeLee Nov 1, 2024
328a9c1
fix: Prevent overflow with string output
OnedgeLee Nov 1, 2024
3dbe087
bump: Bump lib9c (remove InitializeValidator)
s2quake Nov 5, 2024
68b4985
test: Change InitailizeValidator to InitializeStates
s2quake Nov 5, 2024
f242b27
Bump lib9c to release/1.20.0
U-lis Nov 13, 2024
e6cb0d0
Merge branch 'development' into release/220
U-lis Nov 13, 2024
c6e0b40
Bump lib9c: Update Thor block policy
U-lis Nov 14, 2024
99b9510
bump: Lib9c
OnedgeLee Nov 14, 2024
d01cc71
chore: Clean and add queries for migration
OnedgeLee Nov 14, 2024
a9f85d4
chore: Lint code
OnedgeLee Nov 14, 2024
b29f728
Bump lib9c: Update buff limit
U-lis Nov 14, 2024
006ef6f
chore: Temporally turn off gold related tests
OnedgeLee Nov 14, 2024
d7fc9a8
fix: Fix action query
OnedgeLee Nov 14, 2024
56c9d0a
bump: Lib9c hotfix
OnedgeLee Nov 14, 2024
54b12d7
bump: Lib9c 1.19.1
OnedgeLee Nov 15, 2024
6120a8d
Merge pull request #2629 from planetarium/pos-migration
U-lis Nov 15, 2024
2d34f22
Merge pull request #2630 from planetarium/release/211
U-lis Nov 15, 2024
4ed6ef4
Merge branch 'release/220' of github.com:planetarium/NineChronicles.H…
ipdae Nov 15, 2024
7d26a5b
Update libplanet version
ipdae Nov 15, 2024
a26f6e4
Merge pull request #2633 from planetarium/backmerge-211
ipdae Nov 15, 2024
f202b26
Update Validator power config
ipdae Nov 15, 2024
cf17a9e
bump: Lib9c 1.19.2
OnedgeLee Nov 18, 2024
95e207c
fix: Fix share query to handle non agent
OnedgeLee Nov 18, 2024
73f9d75
Merge pull request #2635 from planetarium/release/212
ipdae Nov 18, 2024
9ee0ca6
Add asset minters config for MintAssets ops
ipdae Nov 18, 2024
9399c49
Bump lib9c
U-lis Nov 18, 2024
7f01ac6
chore: Add admin action query
OnedgeLee Nov 20, 2024
a3db0de
bump: Lib9c
OnedgeLee Nov 20, 2024
94175a3
chore: Fix action query for temporal refund action
OnedgeLee Nov 20, 2024
8a6a105
Merge pull request #2638 from planetarium/release/213
OnedgeLee Nov 20, 2024
45bcec2
Merge pull request #2634 from planetarium/improve/genesis-config
U-lis Nov 21, 2024
17bf17a
Bump lib9c
U-lis Nov 21, 2024
7a33046
Bump lib9c: Bump libplanet
U-lis Nov 26, 2024
fe83b20
Bump lib9c: fix ClaimItems action
U-lis Nov 26, 2024
9674b7e
bump: Lib9c 1.19.4
OnedgeLee Nov 27, 2024
7d0e233
Merge pull request #2643 from planetarium/release/214
OnedgeLee Nov 27, 2024
7f74b05
Bump lib9c to 1.20.0
U-lis Nov 27, 2024
2cac22a
Merge branch 'main' into release/220
U-lis Nov 27, 2024
ac3229c
Merge branch 'development' into release/220
U-lis Nov 29, 2024
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.1</LibplanetVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 344 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")));
}
}
29 changes: 23 additions & 6 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 @@ -168,7 +169,8 @@ private void ProcessValidator(List<Validator>? config, PrivateKey initialValidat
initialValidatorSet.Add(new Validator
{
PublicKey = initialValidator.PublicKey.ToString(),
Power = 1,
// To act as a validator, you need at least 10 GuildGold, and since the DecimalPlaces of GuildGold are 18 digits, it is recommended to specify a value around 10^20.
Power = "10000000000000000000",
}
);
}
Expand Down Expand Up @@ -263,20 +265,33 @@ public void Mine(

ProcessInitialPledgeConfigs(genesisConfig.InitialPledgeConfigs, out var initialPledges);

ISet<Address>? assetMinters = null;
if (genesisConfig.AssetMinters is not null)
{
foreach (var address in genesisConfig.AssetMinters)
{
_console.Out.WriteLine($"Preparing asset minter address {address}...");
}
assetMinters = genesisConfig.AssetMinters.ToHashSet();
}

// 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)),
BigInteger.Parse(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
goldCurrency: currency,
assetMinters: assetMinters
);

Lib9cUtils.ExportBlock(block, "genesis-block");
Expand Down Expand Up @@ -397,7 +412,7 @@ private struct Validator
{
public string PublicKey { get; set; }

public long Power { get; set; }
public string Power { get; set; }
}

[Serializable]
Expand Down Expand Up @@ -454,6 +469,8 @@ private struct GenesisConfig
public List<MeadConfig>? InitialMeadConfigs { get; set; }

public List<PledgeConfig>? InitialPledgeConfigs { get; set; }

public List<Address>? AssetMinters { get; set; }
}
#pragma warning restore S3459
}
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
Loading
Loading