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

Cancel mining if blockchain's tip index is changed #517

Merged
merged 5 commits into from
Sep 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ To be released.

### Backward-incompatible interface changes

- `BlockChain<T>.MineBlock()` is now `async` and became to throw
`OperationCanceledException` if `BlockChain<T>`'s tip index is changed while
mining. [[#460], [#517]]
- Users became able to give a cancellation token to `Block<T>.Mine()` and
`Hashcash.Answer()` to cancel the operation. [[#460], [#517]]
- Replaced `UnexpectedlyTerminatedTxRehearsalException` with
`UnexpectedlyTerminatedActionException`.
`UnexpectedlyTerminatedActionException`. [[#498]]
- The following methods became to throw
`UnexpectedlyTerminatedActionException` with having its `InnerException`
during actions being evaluated if any action of them throws an exception:
Expand Down Expand Up @@ -64,6 +69,8 @@ To be released.

### Added interfaces

- Added `BlockChain<T>.TipChanged` event handler which invoked with argument
of `long` typed tip index when `BlockChain<T>.Tip` is changed. [[#517]]
- Added `Swarm<T>.PrepareAsync()` method. The method should be called before
calling `Swarm<T>.BootstrapAsync()`, `Swarm<T>.PreloadAsync()` and
`Swarm<T>.StartAsync()`. [[#353]]
Expand Down Expand Up @@ -118,6 +125,7 @@ To be released.
[#355]: https://github.com/planetarium/libplanet/pull/355
[#420]: https://github.com/planetarium/libplanet/pull/420
[#450]: https://github.com/planetarium/libplanet/pull/450
[#460]: https://github.com/planetarium/libplanet/issues/460
[#461]: https://github.com/planetarium/libplanet/issues/461
[#463]: https://github.com/planetarium/libplanet/issues/463
[#467]: https://github.com/planetarium/libplanet/pull/467
Expand All @@ -132,6 +140,7 @@ To be released.
[#509]: https://github.com/planetarium/libplanet/issues/509
[#511]: https://github.com/planetarium/libplanet/pull/511
[#512]: https://github.com/planetarium/libplanet/pull/512
[#517]: https://github.com/planetarium/libplanet/pull/517
[#519]: https://github.com/planetarium/libplanet/pull/519
[#520]: https://github.com/planetarium/libplanet/pull/520
[#521]: https://github.com/planetarium/libplanet/pull/521
Expand Down
21 changes: 11 additions & 10 deletions Libplanet.Benchmarks/MineBlock.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Libplanet.Blockchain;
using Libplanet.Blocks;
Expand All @@ -23,9 +24,9 @@ public MineBlock()
}

[Benchmark]
public Block<DumbAction> MineBlockEmpty()
public async Task<Block<DumbAction>> MineBlockEmpty()
{
return _blockChain.MineBlock(_fx.Address1);
return await _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockOneTransactionNoAction")]
Expand All @@ -35,9 +36,9 @@ public void MakeOneTransactionNoAction()
}

[Benchmark]
public Block<DumbAction> MineBlockOneTransactionNoAction()
public async Task<Block<DumbAction>> MineBlockOneTransactionNoAction()
{
return _blockChain.MineBlock(_fx.Address1);
return await _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockTenTransactionsNoAction")]
Expand All @@ -50,9 +51,9 @@ public void MakeTenTransactionsNoAction()
}

[Benchmark]
public Block<DumbAction> MineBlockTenTransactionsNoAction()
public async Task<Block<DumbAction>> MineBlockTenTransactionsNoAction()
{
return _blockChain.MineBlock(_fx.Address1);
return await _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockOneTransactionWithActions")]
Expand All @@ -71,9 +72,9 @@ public void MakeOneTransactionWithActions()
}

[Benchmark]
public Block<DumbAction> MineBlockOneTransactionWithActions()
public async Task<Block<DumbAction>> MineBlockOneTransactionWithActions()
{
return _blockChain.MineBlock(_fx.Address1);
return await _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockTenTransactionsWithActions")]
Expand All @@ -95,9 +96,9 @@ public void MakeTenTransactionsWithActions()
}

[Benchmark]
public Block<DumbAction> MineBlockTenTransactionsWithActions()
public async Task<Block<DumbAction>> MineBlockTenTransactionsWithActions()
{
return _blockChain.MineBlock(_fx.Address1);
return await _blockChain.MineBlock(_fx.Address1);
}
}
}
Loading