-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(batcher): mock BlockBuilder for tests #541
Conversation
69b2f08
to
74a60f1
Compare
Benchmark movements: |
3679914
to
8337ac8
Compare
Benchmark movements: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #541 +/- ##
==========================================
- Coverage 74.18% 5.51% -68.68%
==========================================
Files 359 51 -308
Lines 36240 3389 -32851
Branches 36240 3389 -32851
==========================================
- Hits 26886 187 -26699
+ Misses 7220 3187 -4033
+ Partials 2134 15 -2119
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
8337ac8
to
f9e3ec6
Compare
Benchmark movements: |
f9e3ec6
to
5833fbb
Compare
Benchmark movements: |
5833fbb
to
8c76f79
Compare
Benchmark movements: |
8c76f79
to
8ddf7a0
Compare
Benchmark movements: |
8ddf7a0
to
054509f
Compare
Benchmark movements: |
054509f
to
4ff3dea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 4 files at r2, all commit messages.
Reviewable status: 2 of 4 files reviewed, 6 unresolved discussions (waiting on @ArniStarkware and @yair-starkware)
crates/batcher/src/proposals_manager.rs
line 86 at r2 (raw file):
/// or validated). proposal_in_generation: Arc<Mutex<Option<ProposalId>>>, // To be able to mock BlockBuilder in tests.
Suggestion:
// Use a factory object, to be able to mock BlockBuilder in tests.
crates/batcher/src/proposals_manager.rs
line 177 at r2 (raw file):
pub sender: tokio::sync::mpsc::Sender<Transaction>, pub proposal_in_generation: Arc<Mutex<Option<ProposalId>>>, pub block_builder_factory: Arc<dyn BlockBuilderFactory>,
Consider holding an Arc<dyn BlockBuilderTrait>
.
Code quote:
pub block_builder_factory: Arc<dyn BlockBuilderFactory>,
crates/batcher/src/proposals_manager_test.rs
line 25 at r2 (raw file):
#[tokio::test] async fn proposal_generation_success() { let proposals_manager_config = ProposalsManagerConfig::default();
Please add fixtures to create the setup for the tests.
i.e. fixture for the proposal_manager, fixture for the factory, mempool client, etc.
Code quote:
let proposals_manager_config = ProposalsManagerConfig::default();
crates/batcher/src/proposals_manager_test.rs
line 26 at r2 (raw file):
async fn proposal_generation_success() { let proposals_manager_config = ProposalsManagerConfig::default(); let mut block_builder_factory = MockBlockBuilderFactory::new();
Why mut?
Code quote:
let mut block_builder_factory
crates/batcher/src/proposals_manager_test.rs
line 66 at r2 (raw file):
block_builder_factory.expect_create_block_builder().times(2).returning(|| { let mut mock_block_builder = MockBlockBuilderTrait::new(); mock_block_builder.expect_add_txs().once().returning(|_thin_txs| false);
Suggestion:
_txs
crates/batcher/src/proposals_manager_test.rs
line 149 at r2 (raw file):
let mut streamed_txs = vec![]; while let Some(tx) = tx_stream.next().await {
How do we know that the stream is over?
Code quote:
while let Some(tx) = tx_stream.next().await
d63909a
to
1479fff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 6 unresolved discussions (waiting on @ArniStarkware and @dafnamatsry)
crates/batcher/src/proposals_manager.rs
line 86 at r2 (raw file):
/// or validated). proposal_in_generation: Arc<Mutex<Option<ProposalId>>>, // To be able to mock BlockBuilder in tests.
Done.
crates/batcher/src/proposals_manager.rs
line 177 at r2 (raw file):
Previously, dafnamatsry wrote…
Consider holding an
Arc<dyn BlockBuilderTrait>
.
It makes it muchharder to mock consecutive calls
crates/batcher/src/proposals_manager_test.rs
line 25 at r2 (raw file):
Previously, dafnamatsry wrote…
Please add fixtures to create the setup for the tests.
i.e. fixture for the proposal_manager, fixture for the factory, mempool client, etc.
Sort of done, didn't find how to do it completely with adding expectations to the mocks
crates/batcher/src/proposals_manager_test.rs
line 26 at r2 (raw file):
Previously, dafnamatsry wrote…
Why mut?
Not relevant after the last change
crates/batcher/src/proposals_manager_test.rs
line 66 at r2 (raw file):
block_builder_factory.expect_create_block_builder().times(2).returning(|| { let mut mock_block_builder = MockBlockBuilderTrait::new(); mock_block_builder.expect_add_txs().once().returning(|_thin_txs| false);
Not relevant after the last change
crates/batcher/src/proposals_manager_test.rs
line 149 at r2 (raw file):
Previously, dafnamatsry wrote…
How do we know that the stream is over?
When it returns None
Benchmark movements: |
1479fff
to
59d905a
Compare
Benchmark movements: |
5ef19f8
to
64cfda8
Compare
2fd263e
to
ad07096
Compare
Benchmark movements: |
ad07096
to
11997ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 7 files reviewed, 12 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @Yael-Starkware)
crates/batcher/src/proposal_manager.rs
line 89 at r11 (raw file):
Previously, dafnamatsry wrote…
Please move next to
active_proposal
.
Consider even defining aActiveProposalInfo
struct.
Done.
crates/batcher/src/proposal_manager.rs
line 195 at r11 (raw file):
Previously, dafnamatsry wrote…
We can do something similar for mempool txs sender/receiver: the the receiving end will create the channel, in this case
block_builder
, and will return a sender.
But in the future we expect to receive a stream from the mempool and just pass it to the block builder, which is more like the current code.
crates/batcher/src/proposal_manager.rs
line 198 at r11 (raw file):
Previously, dafnamatsry wrote…
I still think we should wait only on the
block_builder.build_block()
future.In order to do that, the block_builder can expose an
abort
function that we can call if we fail to feed more mempool txs.With the current approach, what happens to the builder if
feed_more_mempool_txs
fails? does it continue the execution of txs it already has? Ending the process explicitly withblock_builder.abort()
orblock_builder.close_block()
is safer and more elegant.
Talked about it (added todo in #790)
crates/batcher/src/proposals_manager.rs
line 120 at r7 (raw file):
Previously, dafnamatsry wrote…
The builder limitations and requirements (execution resources, chunks size) are not the same as the mempool request limitations (network, etc).
It might be the case that they will eventually have the same values, but I think it makes sense to have different configurations for them.
Done.
crates/batcher/src/proposals_manager.rs
line 142 at r8 (raw file):
Previously, dafnamatsry wrote…
See my comment above.
talked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 6 files at r11, 3 of 3 files at r12, all commit messages.
Reviewable status: 5 of 7 files reviewed, 11 unresolved discussions (waiting on @ArniStarkware, @Yael-Starkware, and @yair-starkware)
crates/batcher/src/proposal_manager.rs
line 32 at r12 (raw file):
// TODO: Get correct default values. Self { block_builder_input_stream_bound: 100,
Suggestion:
block_next_txs_buffer_size:
crates/batcher/src/proposal_manager.rs
line 250 at r12 (raw file):
); for tx in mempool_txs { if let Err(e) = mempool_tx_sender.send(tx).await.map_err(|err| {
IIUC this can only happen if the receiving end of a channel is disconnected.
Maybe panic
would be better here...
Code quote:
if let Err(e) = mempool_tx_sender.send(tx).await.map_err(|err| {
crates/batcher/src/proposal_manager.rs
line 251 at r12 (raw file):
for tx in mempool_txs { if let Err(e) = mempool_tx_sender.send(tx).await.map_err(|err| { // TODO: should we return the rest of the txs to the mempool?
No, the mempool will be updated on decision_reached
with all the txs that were included in the accepted block.
Code quote:
// TODO: should we return the rest of the txs to the mempool?
crates/batcher/src/proposal_manager_test.rs
line 65 at r12 (raw file):
) { let n_txs = 2 * proposal_manager_config.max_txs_per_mempool_request; block_builder_factory.expect_create_block_builder().once().returning(move || {
Will the following work:
let mut mock_block_builder = Arc::new(MockBlockBuilderTraitWrapper::new());
block_builder_factory.expect_create_block_builder().once().returning(move || {
mock_block_builder
});
mock_block_builder.expect_build_block().return_once(...);
crates/batcher/src/proposal_manager_test.rs
line 77 at r12 (raw file):
.boxed() }, );
Please move to a simulate_build_block(mock_block_builder, ...)
function.
Code quote:
mock_block_builder.expect_build_block().return_once(
move |deadline, mempool_tx_stream, output_content_sender| {
simulate_block_builder(
deadline,
mempool_tx_stream,
output_content_sender,
Some(n_txs),
)
.boxed()
},
);
crates/batcher/src/proposal_manager_test.rs
line 103 at r12 (raw file):
assert_matches!(proposal_manager.await_active_proposal().await, Some(Ok(()))); let v: Vec<_> = stream.collect().await;
(same below)
Suggestion:
proposal_content
crates/batcher/src/proposal_manager_test.rs
line 211 at r12 (raw file):
); }
Please add tests for: deadline reached, mempool failures, and myabe other possible errors?
Can be done in a separate PR.
11997ba
to
b87a5be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 3 of 7 files reviewed, 11 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @Yael-Starkware)
crates/batcher/src/proposal_manager.rs
line 32 at r12 (raw file):
// TODO: Get correct default values. Self { block_builder_input_stream_bound: 100,
Done.
crates/batcher/src/proposal_manager.rs
line 250 at r12 (raw file):
Previously, dafnamatsry wrote…
IIUC this can only happen if the receiving end of a channel is disconnected.
Maybepanic
would be better here...
Don't you prefer to abort the proposal without crashing the batcher?
crates/batcher/src/proposal_manager.rs
line 251 at r12 (raw file):
Previously, dafnamatsry wrote…
No, the mempool will be updated on
decision_reached
with all the txs that were included in the accepted block.
Done.
crates/batcher/src/proposal_manager_test.rs
line 65 at r12 (raw file):
Previously, dafnamatsry wrote…
Will the following work:
let mut mock_block_builder = Arc::new(MockBlockBuilderTraitWrapper::new()); block_builder_factory.expect_create_block_builder().once().returning(move || { mock_block_builder }); mock_block_builder.expect_build_block().return_once(...);
No, because Arc doesn't work well with mutability.
I think I can find ways to get around this, but I prefer the more explicit.
crates/batcher/src/proposal_manager_test.rs
line 77 at r12 (raw file):
Previously, dafnamatsry wrote…
Please move to a
simulate_build_block(mock_block_builder, ...)
function.
Done.
crates/batcher/src/proposal_manager_test.rs
line 103 at r12 (raw file):
Previously, dafnamatsry wrote…
(same below)
Done.
crates/batcher/src/proposal_manager_test.rs
line 211 at r12 (raw file):
Previously, dafnamatsry wrote…
Please add tests for: deadline reached, mempool failures, and myabe other possible errors?
Can be done in a separate PR.
Will add in a separate PR
Benchmark movements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r13, all commit messages.
Reviewable status: 5 of 7 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @Yael-Starkware, and @yair-starkware)
crates/batcher/src/proposal_manager.rs
line 250 at r12 (raw file):
Previously, yair-starkware (Yair) wrote…
Don't you prefer to abort the proposal without crashing the batcher?
When there is a real bug in the code, I personally prefer to crash the batcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r12.
Reviewable status: 5 of 7 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @yair-starkware)
crates/batcher/src/proposal_manager_test.rs
line 98 at r13 (raw file):
#[rstest] #[tokio::test] async fn concecutive_proposal_generations_success(
Suggestion:
consecutive
23c9148
to
3207c61
Compare
b87a5be
to
81e45ff
Compare
81e45ff
to
11ee294
Compare
Benchmark movements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 7 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @Yael-Starkware)
crates/batcher/src/proposal_manager.rs
line 250 at r12 (raw file):
Previously, dafnamatsry wrote…
When there is a real bug in the code, I personally prefer to crash the batcher.
done
crates/batcher/src/proposal_manager_test.rs
line 98 at r13 (raw file):
#[rstest] #[tokio::test] async fn concecutive_proposal_generations_success(
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r14, all commit messages.
Reviewable status: 5 of 7 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 6 files at r11.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @yair-starkware)
This change is