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

Bump libplanet to 5.1.2 #2696

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .Lib9c.Benchmarks/Lib9c.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.Policy\Lib9c.Policy.csproj" />
<ProjectReference Include="..\Libplanet.Crypto.Secp256k1\Libplanet.Crypto.Secp256k1.csproj" />
Expand Down
9 changes: 9 additions & 0 deletions .Lib9c.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;

public class ActionContext : IActionContext
Expand All @@ -18,6 +19,8 @@ public class ActionContext : IActionContext

private IReadOnlyList<ITransaction> _txs = null;

private IReadOnlyList<EvidenceBase> _evs = null;

public BlockHash? GenesisHash { get; set; }

public Address Signer { get; set; }
Expand Down Expand Up @@ -46,6 +49,12 @@ public IReadOnlyList<ITransaction> Txs
set => _txs = value;
}

public IReadOnlyList<EvidenceBase> Evidence
{
get => _evs ?? ImmutableList<EvidenceBase>.Empty;
set => _evs = value;
}

public void UseGas(long gas)
{
_gasUsed += gas;
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Lib9c.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.Utils\Lib9c.Utils.csproj" />
<ProjectReference Include="..\Lib9c.MessagePack\Lib9c.MessagePack.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet.Mocks\Libplanet.Mocks.csproj" />
<ProjectReference Include="..\.Libplanet\test\Libplanet.Mocks\Libplanet.Mocks.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' != 'DevEx' ">
Expand Down
64 changes: 41 additions & 23 deletions .Lib9c.Tests/Policy/BlockPolicyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Lib9c.Tests
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Consensus;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;
using Nekoyume;
using Nekoyume.Action;
Expand Down Expand Up @@ -362,16 +363,20 @@ List<Transaction> GenerateTransactions(int count)

Assert.Equal(1, blockChain.Count);
var txs = GenerateTransactions(5).OrderBy(tx => tx.Id).ToList();
var evs = new List<EvidenceBase>();
var preEvalBlock1 = new BlockContent(
new BlockMetadata(
index: 1,
timestamp: DateTimeOffset.MinValue,
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: null),
transactions: txs).Propose();
Block block1 = EvaluateAndSign(store, actionEvaluator, preEvalBlock1, adminPrivateKey);
lastCommit: null,
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
var stateRootHash = blockChain.DetermineNextBlockStateRootHash(blockChain.Tip, out _);
Block block1 = EvaluateAndSign(stateRootHash, preEvalBlock1, adminPrivateKey);
blockChain.Append(block1, GenerateBlockCommit(block1, adminPrivateKey));
Assert.Equal(2, blockChain.Count);
Assert.True(blockChain.ContainsBlock(block1.Hash));
Expand All @@ -383,9 +388,12 @@ List<Transaction> GenerateTransactions(int count)
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey)),
transactions: txs).Propose();
Block block2 = EvaluateAndSign(store, actionEvaluator, preEvalBlock2, adminPrivateKey);
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey),
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
stateRootHash = blockChain.DetermineNextBlockStateRootHash(blockChain.Tip, out _);
Block block2 = EvaluateAndSign(stateRootHash, preEvalBlock2, adminPrivateKey);
blockChain.Append(block2, GenerateBlockCommit(block2, adminPrivateKey));
Assert.Equal(3, blockChain.Count);
Assert.True(blockChain.ContainsBlock(block2.Hash));
Expand All @@ -397,9 +405,12 @@ List<Transaction> GenerateTransactions(int count)
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey)),
transactions: txs).Propose();
Block block3 = EvaluateAndSign(store, actionEvaluator, preEvalBlock3, adminPrivateKey);
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey),
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
stateRootHash = blockChain.DetermineNextBlockStateRootHash(blockChain.Tip, out _);
Block block3 = EvaluateAndSign(stateRootHash, preEvalBlock3, adminPrivateKey);
Assert.Throws<InvalidBlockTxCountException>(
() => blockChain.Append(block3, GenerateBlockCommit(block3, adminPrivateKey)));
Assert.Equal(3, blockChain.Count);
Expand Down Expand Up @@ -466,16 +477,20 @@ List<Transaction> GenerateTransactions(int count)

Assert.Equal(1, blockChain.Count);
var txs = GenerateTransactions(10).OrderBy(tx => tx.Id).ToList();
var evs = new List<EvidenceBase>();
PreEvaluationBlock preEvalBlock1 = new BlockContent(
new BlockMetadata(
index: 1,
timestamp: DateTimeOffset.MinValue,
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: null),
transactions: txs).Propose();
Block block1 = EvaluateAndSign(store, actionEvaluator, preEvalBlock1, adminPrivateKey);
lastCommit: null,
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
var stateRootHash = blockChain.DetermineNextBlockStateRootHash(blockChain.Tip, out _);
Block block1 = EvaluateAndSign(stateRootHash, preEvalBlock1, adminPrivateKey);

// Should be fine since policy hasn't kicked in yet.
blockChain.Append(block1, GenerateBlockCommit(block1, adminPrivateKey));
Expand All @@ -490,9 +505,12 @@ List<Transaction> GenerateTransactions(int count)
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey)),
transactions: txs).Propose();
Block block2 = EvaluateAndSign(store, actionEvaluator, preEvalBlock2, adminPrivateKey);
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey),
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
stateRootHash = blockChain.DetermineNextBlockStateRootHash(blockChain.Tip, out _);
Block block2 = EvaluateAndSign(stateRootHash, preEvalBlock2, adminPrivateKey);

// Subpolicy kicks in.
Assert.Throws<InvalidBlockTxCountPerSignerException>(
Expand All @@ -511,9 +529,11 @@ List<Transaction> GenerateTransactions(int count)
publicKey: adminPublicKey,
previousHash: blockChain.Tip.Hash,
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey)),
transactions: txs).Propose();
Block block3 = EvaluateAndSign(store, actionEvaluator, preEvalBlock3, adminPrivateKey);
lastCommit: GenerateBlockCommit(blockChain.Tip, adminPrivateKey),
evidenceHash: BlockContent.DeriveEvidenceHash(evs)),
transactions: txs,
evidence: evs).Propose();
Block block3 = EvaluateAndSign(stateRootHash, preEvalBlock3, adminPrivateKey);
blockChain.Append(block3, GenerateBlockCommit(block3, adminPrivateKey));
Assert.Equal(3, blockChain.Count);
Assert.True(blockChain.ContainsBlock(block3.Hash));
Expand All @@ -533,6 +553,7 @@ private BlockCommit GenerateBlockCommit(Block block, PrivateKey key)
block.Hash,
DateTimeOffset.UtcNow,
privateKey.PublicKey,
null,
VoteFlag.PreCommit).Sign(privateKey)))
: null;
}
Expand Down Expand Up @@ -572,8 +593,7 @@ private Block MakeGenesisBlock(
}

private Block EvaluateAndSign(
IStore store,
ActionEvaluator actionEvaluator,
HashDigest<SHA256> stateRootHash,
PreEvaluationBlock preEvaluationBlock,
PrivateKey privateKey
)
Expand All @@ -592,9 +612,7 @@ PrivateKey privateKey
$"{BlockMetadata.SlothProtocolVersion} is not acceptable");
}

var stateRootHash = store.GetNextStateRootHash((BlockHash)preEvaluationBlock.PreviousHash);

return preEvaluationBlock.Sign(privateKey, (HashDigest<SHA256>)stateRootHash);
return preEvaluationBlock.Sign(privateKey, stateRootHash);
}
}
}
2 changes: 1 addition & 1 deletion .Lib9c.Tools/Lib9c.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.DevExtensions\Lib9c.DevExtensions.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tools/SubCommand/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ IStateStore stateStore
Block block =
store.GetBlock(blockHash);
var preEvalBlock = new PreEvaluationBlock(
block, block.Transactions
block, block.Transactions, block.Evidence
);
stderr.WriteLine(
"[{0}/{1}] Executing block #{2} {3}...",
Expand Down
2 changes: 1 addition & 1 deletion .Libplanet
Submodule .Libplanet updated 954 files
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static IPreEvaluationBlock Unmarshal(Dictionary dictionary)
{
return new PreEvaluationBlock(
BlockMarshaler.UnmarshalPreEvaluationBlockHeader((Dictionary)dictionary[HeaderKey]),
BlockMarshaler.UnmarshalBlockTransactions(dictionary));
BlockMarshaler.UnmarshalBlockTransactions(dictionary),
BlockMarshaler.UnmarshalBlockEvidence(dictionary));
}

public static byte[] Serialize(this IPreEvaluationBlock block)
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
run: |
set -e

sed -i -E 's|<TargetFramework>.*</TargetFramework>|<TargetFramework>netstandard2.1</TargetFramework>|' Lib9c*/*.csproj Libplanet*/*.csproj
sed -i -E 's|<TargetFramework>.*</TargetFramework>|<TargetFramework>netstandard2.1</TargetFramework>|' Lib9c*/*.csproj
sed -i -E 's|(<TargetFramework.+>).*(</TargetFramework>)|\1netstandard2.1\2|' .Libplanet/Directory.Build.props
sed -i -E 's|<ImplicitUsings>.*</ImplicitUsings>|<ImplicitUsings>disable</ImplicitUsings>|' Lib9c*/*.csproj Libplanet*/*.csproj
sed -i -E 's|\[MaybeNullWhen\(false\)] out TValue value|out TValue value|' Lib9c/TableData/Sheet.cs
sed -i -E 's|public bool TryGetValue\(TKey key, out TValue value, bool throwException\)|public bool TryGetValue\(TKey key, out TValue? value, bool throwException\)|' Lib9c/TableData/Sheet.cs
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Abstractions/Lib9c.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions Lib9c.DevExtensions/Lib9c.DevExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet.Stun\Libplanet.Stun.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.Stun\Libplanet.Stun.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.Policy\Lib9c.Policy.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Lib9c.Policy/Policy/DebugPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
public TxPolicyViolationException ValidateNextBlockTx(
BlockChain blockChain, Transaction transaction)
{
return null;

Check warning on line 21 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Possible null reference return.

Check warning on line 21 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Possible null reference return.

Check warning on line 21 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-js

Possible null reference return.
}

public BlockPolicyViolationException ValidateNextBlock(
BlockChain blockChain, Block nextBlock)
{
return null;

Check warning on line 27 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Possible null reference return.

Check warning on line 27 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Possible null reference return.

Check warning on line 27 in Lib9c.Policy/Policy/DebugPolicy.cs

View workflow job for this annotation

GitHub Actions / build-js

Possible null reference return.
}

public long GetMaxTransactionsBytes(long index) => long.MaxValue;
Expand All @@ -36,5 +36,7 @@
public int GetMaxTransactionsPerSignerPerBlock(long index) => int.MaxValue;

public int GetMinBlockProtocolVersion(long index) => 0;

public long GetMaxEvidencePendingDuration(long index) => 10L;
}
}
2 changes: 1 addition & 1 deletion Lib9c.Proposer/Lib9c.Proposer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet.Net\Libplanet.Net.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.Net\Libplanet.Net.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Lib9c.Proposer/Proposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Proposer
block.Hash,
DateTimeOffset.UtcNow,
_privateKey.PublicKey,
null,
VoteFlag.PreCommit).Sign(_privateKey)))
: null;
_chain.Append(block, commit);
Expand Down
Loading
Loading