Navigation Menu

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

Do not stage already mined transactions #719

Merged
merged 1 commit into from Dec 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -86,6 +86,7 @@ To be released.
- Fixed a bug where `Swarm<T>` hadn't stopped properly. [[#709]]
- Fixed a bug where `BlockChain<T>.GetNextTxNonce()` had returned invalid tx
nonce. [[#718]]
- Fixed a bug where mined transactions were staged again. [[#719]]

[#662]: https://github.com/planetarium/libplanet/pull/662
[#665]: https://github.com/planetarium/libplanet/pull/665
Expand All @@ -103,6 +104,7 @@ To be released.
[#706]: https://github.com/planetarium/libplanet/pull/706
[#709]: https://github.com/planetarium/libplanet/pull/709
[#718]: https://github.com/planetarium/libplanet/pull/718
[#719]: https://github.com/planetarium/libplanet/pull/719


Version 0.7.0
Expand Down
51 changes: 51 additions & 0 deletions Libplanet.Tests/Net/SwarmTest.cs
Expand Up @@ -769,6 +769,57 @@ public async Task BroadcastTx()
}
}

[Fact(Timeout = Timeout)]
public async Task BroadcastTxWhileMining()
{
Swarm<DumbAction> swarmA = _swarms[0];
Swarm<DumbAction> swarmC = _swarms[2];

BlockChain<DumbAction> chainA = _blockchains[0];
BlockChain<DumbAction> chainC = _blockchains[2];

var privateKey = new PrivateKey();
var address = privateKey.PublicKey.ToAddress();

var txs = Enumerable.Range(0, 10).Select(_ =>
chainA.MakeTransaction(new PrivateKey(), new[] { new DumbAction(address, "foo") }))
.ToArray();

try
{
await StartAsync(swarmA);
await StartAsync(swarmC);

await swarmC.AddPeersAsync(new[] { swarmA.AsPeer }, null);

for (var i = 0; i < 100; i++)
{
swarmA.BroadcastTxs(txs);
}

var t = Task.Run(async () =>
{
for (var i = 0; i < 10; i++)
{
await chainC.MineBlock(_fx1.Address1);
}
});

await swarmC.TxReceived.WaitAsync();
await t;

for (var i = 0; i < 10; i++)
{
Assert.True(chainC.Store.ContainsTransaction(txs[i].Id));
}
}
finally
{
await StopAsync(swarmA);
await StopAsync(swarmC);
}
}

[Fact(Timeout = Timeout)]
public async Task BroadcastTxAsync()
{
Expand Down
5 changes: 5 additions & 0 deletions Libplanet/Blockchain/BlockChain.cs
Expand Up @@ -499,6 +499,11 @@ public void StageTransactions(IImmutableSet<Transaction<T>> transactions)

try
{
// FIXME: We need to create a separate pool to handle transactions.
transactions = transactions
.Where(tx => !_transactions.ContainsKey(tx.Id))
.ToImmutableHashSet();

foreach (Transaction<T> tx in transactions)
{
_transactions[tx.Id] = tx;
Expand Down
2 changes: 1 addition & 1 deletion Menees.Analyzers.Settings.xml
Expand Up @@ -2,5 +2,5 @@
<Menees.Analyzers.Settings>
<MaxLineColumns>100</MaxLineColumns>
<MaxMethodLines>200</MaxMethodLines>
<MaxFileLines>2600</MaxFileLines>
<MaxFileLines>2700</MaxFileLines>
</Menees.Analyzers.Settings>