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

Feature/precommit batcher #422

Merged
merged 19 commits into from
Jul 16, 2021
Merged

Feature/precommit batcher #422

merged 19 commits into from
Jul 16, 2021

Conversation

Elestrias
Copy link
Collaborator

@Elestrias Elestrias commented Jul 12, 2021

Description of the Change

A new model of a PreCommit messages sending via batch. The mechanism a collection and a storage of all the recieved messages until the deadline, when all the collected data will be sent as one message.

Benefits

This feature will reduce the growth of transaction fees on the network as the general amount of transactions will be reduced.
Sending a several messages through one transaction will reduce spendings of miner's resourses

Possible Drawbacks

Precommit sending system are generaly changed, so the thrusted previous one mechanism should not be used anymore in general cases.

Usage Examples or Tests [optional]

With usage of batching, miner wont send its Precommit messages ocasionally as they appears, but several Precommits in one transaction.

Alternate Designs [optional]

The system can be realised via hook, but in the future perspective it can take too much resourses
to support more than two threads for batching

Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
@codecov
Copy link

codecov bot commented Jul 12, 2021

Codecov Report

Merging #422 (8337845) into master (50d555f) will increase coverage by 0.12%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
+ Coverage   44.73%   44.86%   +0.12%     
==========================================
  Files         603      607       +4     
  Lines       26374    26458      +84     
  Branches    14219    14263      +44     
==========================================
+ Hits        11799    11870      +71     
- Misses      11263    11268       +5     
- Partials     3312     3320       +8     
Impacted Files Coverage Δ
core/miner/storage_fsm/types.hpp 61.70% <ø> (ø)
.../miner/storage_fsm/impl/precommit_batcher_impl.cpp 85.00% <85.00%> (ø)
.../miner/storage_fsm/impl/precommit_batcher_impl.hpp 100.00% <100.00%> (ø)
core/miner/storage_fsm/precommit_batcher.hpp 100.00% <100.00%> (ø)
core/vm/actor/builtin/v5/miner/miner_actor.hpp 100.00% <100.00%> (ø)
core/crypto/blake2/blake2b160.cpp 87.83% <0.00%> (-1.36%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50d555f...8337845. Read the comment docs.

test/testutil/mocks/libp2p/scheduler_mock.hpp Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/sealing_events.hpp Outdated Show resolved Hide resolved
core/vm/actor/builtin/v0/miner/miner_actor.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/vm/actor/builtin/v0/miner/miner_actor.hpp Outdated Show resolved Hide resolved
test/core/miner/PreCommitBatcherTest.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
test/core/miner/PreCommitBatcherTest.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/precommit_batcher.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
batcher->cutoffStart = std::chrono::system_clock::now();
batcher->closestCutoff = maxWait;
batcher->handle_ = scheduler->schedule(maxWait, [=]() {
auto maybe_send = batcher->sendBatch();
Copy link
Contributor

Choose a reason for hiding this comment

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

Signature here
using Callback = std::function<void()>; only void function is allowed. maybe_send.has_error() would be appropriate

core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
test/core/miner/PreCommitBatcherTest.cpp Outdated Show resolved Hide resolved
test/core/miner/PreCommitBatcherTest.cpp Outdated Show resolved Hide resolved
test/core/miner/PreCommitBatcherTest.cpp Outdated Show resolved Hide resolved
@ortyomka
Copy link
Contributor

Do not forget to integrate this part to Sealing

…cosmetic changes

Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
core/miner/storage_fsm/precommit_batcher.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/precommit_batcher.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/precommit_batcher.hpp Outdated Show resolved Hide resolved
core/vm/actor/builtin/v0/miner/miner_actor.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/precommit_batcher.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
Signed-off-by: elestrias <rus8-2002@mail.ru>
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
}

void PreCommitBatcherImpl::forceSend() {
auto maybe_result = sendBatch();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check maybe_result.has_error()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided not to check the error, just to add the outcome::result object to provided callbacks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And then handle error in caller proccess

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that it is a good idea.
Callbacks must consider that parameter could have an error.
@ortyomka what do you think?
Also I don't see any test with non-void callback

Copy link
Contributor

Choose a reason for hiding this comment

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

This like subscibtion, this error is important for those who signed up to send the batch.
But we can duplicate the error to the one who called Force.
I think this the best option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the caller of sendForce can check callback if he needs to it, otherwise I cant imagine a situation of usage this functional, maybe logs can be used just to inform?

core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
batcher->logger_ = common::createLogger("batcher");
batcher->logger_->info("Bather have been started");
batcher->handle_ = scheduler->schedule(max_wait, [=]() {
auto maybe_result = batcher->sendBatch();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check maybe_result.has_error()

Signed-off-by: elestrias <rus8-2002@mail.ru>
…ecks

Signed-off-by: elestrias <rus8-2002@mail.ru>
@Elestrias Elestrias requested a review from wer1st July 15, 2021 15:53
Signed-off-by: Mikhail Tagirov <dev.mikhail.tagirov@gmail.com>
core/miner/storage_fsm/impl/precommit_batcher_impl.cpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
core/miner/storage_fsm/impl/precommit_batcher_impl.hpp Outdated Show resolved Hide resolved
test/core/miner/precommit_batcher_test.cpp Outdated Show resolved Hide resolved
test/core/miner/precommit_batcher_test.cpp Outdated Show resolved Hide resolved
Signed-off-by: elestrias <rus8-2002@mail.ru>
…t/cpp-filecoin into feature/PrecommitBatcher
@Elestrias Elestrias requested a review from ortyomka July 16, 2021 11:20
@Elestrias Elestrias merged commit 94594c5 into master Jul 16, 2021
@Elestrias Elestrias deleted the feature/PrecommitBatcher branch July 16, 2021 12:26
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.

None yet

4 participants