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

Conversation

limebell
Copy link
Member

@limebell limebell commented Sep 18, 2019

This patch implements and closes #460. Some XML descriptions and test cases are included in this PR.

@limebell limebell requested a review from a team September 18, 2019 11:35
@limebell limebell self-assigned this Sep 18, 2019
@limebell limebell changed the title Cancel mining if blockchain's tip index in changed Cancel mining if blockchain's tip index is changed Sep 18, 2019
@dahlia
Copy link
Contributor

dahlia commented Sep 18, 2019

Tests in several environments failed due to timeout.

@limebell limebell force-pushed the mine-cancel branch 3 times, most recently from 54d44a1 to 512f5bf Compare September 19, 2019 11:16
@codecov
Copy link

codecov bot commented Sep 19, 2019

Codecov Report

Merging #517 into master will increase coverage by 0.02%.
The diff coverage is 96.57%.

@@            Coverage Diff             @@
##           master     #517      +/-   ##
==========================================
+ Coverage    90.3%   90.32%   +0.02%     
==========================================
  Files         201      201              
  Lines       14928    15013      +85     
==========================================
+ Hits        13481    13561      +80     
- Misses       1170     1174       +4     
- Partials      277      278       +1
Impacted Files Coverage Δ
Libplanet/Blocks/Block.cs 90.68% <100%> (+0.03%) ⬆️
Libplanet.Tests/Blockchain/BlockChainTest.cs 98.66% <100%> (+0.13%) ⬆️
Libplanet.Tests/Blockchain/NullPolicy.cs 100% <100%> (ø) ⬆️
Libplanet/Hashcash.cs 100% <100%> (ø) ⬆️
Libplanet/Blockchain/BlockChain.cs 93.95% <91.42%> (-0.24%) ⬇️
Libplanet.Tests/Net/SwarmTest.cs 98.87% <92.85%> (-0.23%) ⬇️

Libplanet.Tests/Net/SwarmTest.cs Outdated Show resolved Hide resolved
Libplanet.Tests/Net/SwarmTest.cs Outdated Show resolved Hide resolved
Libplanet/Hashcash.cs Outdated Show resolved Hide resolved
Libplanet/Blocks/Block.cs Outdated Show resolved Hide resolved
Assert.Throws<InvalidBlockIndexException>(() => _blockChain.Append(block));
Assert.False(called);

// TODO: Add test cases for swap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have an issue for this.

CHANGES.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
@limebell limebell requested review from libplanet and a team and removed request for libplanet September 23, 2019 06:01
@limebell limebell force-pushed the mine-cancel branch 3 times, most recently from c48869d to 5184241 Compare September 23, 2019 06:09
CHANGES.md Outdated Show resolved Hide resolved
Libplanet/Blockchain/BlockChain.cs Outdated Show resolved Hide resolved
Libplanet/Hashcash.cs Outdated Show resolved Hide resolved
Libplanet/Blockchain/BlockChain.cs Outdated Show resolved Hide resolved
Libplanet/Hashcash.cs Outdated Show resolved Hide resolved
throw new OperationCanceledException(
"Mining canceled due to change of tip index");
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just re-throw it?

Suggested change
else
throw;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used TaskCanceledException here because other tasks used in Swarm<T> throw TaskCanceledException when cancel is requested.

@limebell limebell requested review from dahlia and moreal September 23, 2019 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mining should stopped when the chain's tip is changed
4 participants