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

DelayedRenderer<T> & DelayedActionRenderer<T> for stable app-side state transfer #980

Merged
merged 8 commits into from
Sep 4, 2020

Conversation

dahlia
Copy link
Contributor

@dahlia dahlia commented Sep 1, 2020

This patch adds DelayedRenderer<T> & DelayedActionRenderer<T> that decorate another IRenderer<T> & IActionRenderer<T> and delay rendering events until the certain number of descendant blocks confirm a block. See also the unit tests and XML comments.

@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #980 into main will increase coverage by 0.16%.
The diff coverage is 91.51%.

@@            Coverage Diff             @@
##             main     #980      +/-   ##
==========================================
+ Coverage   88.88%   89.04%   +0.16%     
==========================================
  Files         320      324       +4     
  Lines       28132    29060     +928     
==========================================
+ Hits        25004    25876     +872     
- Misses       1598     1629      +31     
- Partials     1530     1555      +25     
Impacted Files Coverage Δ
Libplanet/Blockchain/BlockChain.cs 90.96% <75.00%> (ø)
Libplanet.Tests/LoggerExtensions.cs 76.19% <76.47%> (-3.12%) ⬇️
Libplanet/Blockchain/Renderers/DelayedRenderer.cs 84.47% <84.47%> (ø)
...anet/Blockchain/Renderers/DelayedActionRenderer.cs 88.58% <88.58%> (ø)
.../Blockchain/Renderers/DelayedActionRendererTest.cs 93.83% <93.83%> (ø)
....Tests/Blockchain/Renderers/DelayedRendererTest.cs 94.87% <94.87%> (ø)
Libplanet.Tests/Action/ActionContextTest.cs 90.65% <100.00%> (+2.28%) ⬆️
Libplanet.Tests/Blockchain/BlockChainTest.cs 98.59% <100.00%> (+0.04%) ⬆️
Libplanet/Action/ActionContext.cs 100.00% <100.00%> (ø)
... and 8 more

@dahlia dahlia force-pushed the delayed-renderer branch 3 times, most recently from 4319d95 to 7a084d8 Compare September 3, 2020 05:38
@dahlia dahlia changed the title WIP: DelayedRenderer<T> DelayedRenderer<T> & DelayedActionRenderer<T> for stable app-side state transfer Sep 4, 2020
@dahlia dahlia marked this pull request as ready for review September 4, 2020 09:38
Copy link
Member

@longfin longfin left a comment

Choose a reason for hiding this comment

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

I'll continue to review it again today.

Libplanet/Blockchain/Renderers/IActionRenderer.cs Outdated Show resolved Hide resolved
Libplanet/Blockchain/Renderers/DelayedRenderer.cs Outdated Show resolved Hide resolved
Comment on lines +749 to +754
IActionRenderer<DumbAction> renderer = new AnonymousActionRenderer<DumbAction>
{
ActionRenderer = (_, __, nextStates) =>
throw new SomeException("thrown by renderer"),
};
renderer = new LoggedActionRenderer<DumbAction>(renderer, Log.Logger);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it overwritten?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the way to use LoggedActionRenderer<T> as it uses decorator pattern. See also the example code in its docs.

Copy link
Contributor

@moreal moreal left a comment

Choose a reason for hiding this comment

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

I will review furthermore.

Libplanet/Blockchain/Renderers/IActionRenderer.cs Outdated Show resolved Hide resolved
Libplanet/Blockchain/Renderers/DelayedRenderer.cs Outdated Show resolved Hide resolved
dahlia added a commit to dahlia/libplanet that referenced this pull request Sep 4, 2020
earlbread
earlbread previously approved these changes Sep 4, 2020
@dahlia
Copy link
Contributor Author

dahlia commented Sep 4, 2020

@planetarium/libplanet I make multiple renderers guaranteed to get their own distinct action contexts (i.e., one renderer consuming its random state does not affect other one's random state): 4e62c1b. Please review this again!

Libplanet/Blockchain/Renderers/DelayedRenderer.cs Outdated Show resolved Hide resolved
{
throw new ArgumentException(
"Some previous blocks of two blocks are orphan.",
nameof(a)
Copy link
Member

Choose a reason for hiding this comment

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

ArgumentException seems designed for only one argument. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed I had thought the same question, and anyway I have no idea…

@dahlia dahlia merged commit 061db97 into planetarium:main Sep 4, 2020
dahlia added a commit to dahlia/NineChronicles.Headless that referenced this pull request Sep 4, 2020
dahlia added a commit to dahlia/NineChronicles.Headless that referenced this pull request Sep 4, 2020
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.

5 participants