-
Notifications
You must be signed in to change notification settings - Fork 21
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
chore(mempool): add logs to mempool logic #1428
base: main
Are you sure you want to change the base?
Conversation
9faeedf
to
c09f05c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1428 +/- ##
==========================================
+ Coverage 74.18% 76.05% +1.86%
==========================================
Files 359 360 +1
Lines 36240 38365 +2125
Branches 36240 38365 +2125
==========================================
+ Hits 26886 29177 +2291
+ Misses 7220 6980 -240
- Partials 2134 2208 +74
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
c09f05c
to
9b6a196
Compare
Benchmark movements: |
9b6a196
to
6452bc5
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 4 of 5 files at r1, all commit messages.
Reviewable status: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 73 at r1 (raw file):
} tracing::info!(
Please import info directly.
Code quote:
tracing::info
crates/mempool/src/mempool.rs
line 92 at r1 (raw file):
#[tracing::instrument( skip(self, args), fields( // Log subset of (informative) fields.
I think tip
and gas price
are also needed, wdyt?
Code quote:
// Log subset of (informative) fields.
6452bc5
to
f417624
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: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 73 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Please import info directly.
I'd rather not, it's not clear where it comes from (ours? an external crate?).
crates/mempool/src/mempool.rs
line 92 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
I think
tip
andgas price
are also needed, wdyt?
Will add to fee esc. flow, next PR (I don't want to log this for the first transaction of this address and nonce).
I'd rather not to add a TODO, since CI is flaky.
f417624
to
9b0916a
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 1 of 5 files at r1.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 132 at r1 (raw file):
self.align_to_account_state(account_state); } tracing::info!("Aligned mempool to committed nonces.");
Is it critical information?
Can it be for debug mode?
The same goes for the below info!
Code quote:
tracing::info!("Aligned mempool to committed nonces.");
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
} impl std::fmt::Display for AccountState {
please import it instead
Code quote:
std::fmt::Display
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
} impl std::fmt::Display for AccountState {
Can you please explain why this code is needed? and why deriving Display is not sufficient.
Code quote:
impl std::fmt::Display for AccountState {
crates/starknet_api/src/core.rs
line 9 at r1 (raw file):
use std::sync::LazyLock; use derive_more::Display;
Why are there two imports here?
Which one is used for the nonce?
Code quote:
use core::fmt::Display;
use std::fmt::Debug;
use std::sync::LazyLock;
use derive_more::Display;
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, 7 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
a discussion (no related file):
General question: How do we check that the logs work as expected?
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: all files reviewed, 7 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
a discussion (no related file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
General question: How do we check that the logs work as expected?
I checked manually.
We don't, we trust tracing
and our log configuration, which should be separately checked.
crates/mempool/src/mempool.rs
line 132 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Is it critical information?
Can it be for debug mode?The same goes for the below
info!
I want for this long operation to have midway logs; otherwise, debugging is hard.
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
please import it instead
I'd rather not to, same reason for tracing
(a general answer for std
/short named crates).
crates/starknet_api/src/core.rs
line 9 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Why are there two imports here?
Which one is used for the nonce?
An excellent example why fully-qualified names should be used. The last one, first one is only a trait, as you can see from my implementation above...
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, 7 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Can you please explain why this code is needed? and why deriving Display is not sufficient.
Directly deriving isn't possible, wherever we have it it's actually derive_more::Display
, which is only possible for newtypes (struct A(B)
).
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, 5 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 73 at r1 (raw file):
Previously, elintul (Elin) wrote…
I'd rather not, it's not clear where it comes from (ours? an external crate?).
I'm not sure I get it. Do we have two info
s?
crates/mempool/src/mempool.rs
line 132 at r1 (raw file):
Previously, elintul (Elin) wrote…
I want for this long operation to have midway logs; otherwise, debugging is hard.
Can it be for debug mode?
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, 5 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 73 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
I'm not sure I get it. Do we have two
info
s?
No, it's not only for disambiguation; it's also for generic names - what's "info"? Super unclear. tracing::info
is much better.
crates/mempool/src/mempool.rs
line 132 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Can it be for debug mode?
Will change the level next PR, I want to keep as-is for Nadin to debug this CI.
Note the rest aren't (I'd rather us having logs when bugs happen, and not retrospectively; not always easily reproducible).
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, 4 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
Previously, elintul (Elin) wrote…
Directly deriving isn't possible, wherever we have it it's actually
derive_more::Display
, which is only possible for newtypes (struct A(B)
).
Thanks, and can you please explain why you had to add the trait for Nonce
struct (below) without the implementation?
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, 4 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/starknet_api/src/core.rs
line 9 at r1 (raw file):
Previously, elintul (Elin) wrote…
An excellent example why fully-qualified names should be used. The last one, first one is only a trait, as you can see from my implementation above...
Is it not confusing to have two imports with the same name?
(if you agree, it can be changed in a separate PR)
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, 4 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Thanks, and can you please explain why you had to add the trait for
Nonce
struct (below) without the implementation?
Again, it's not the trait; it's derive_more::Display
.
Don't like it (it's longer compilation and linking), but that's the way it is in the rest of the file and I'd rather keep consistent.
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, 4 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/starknet_api/src/core.rs
line 9 at r1 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Is it not confusing to have two imports with the same name?
(if you agree, it can be changed in a separate PR)
Yes, but I don't want to fix in this PR.
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, 4 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool_types/src/mempool_types.rs
line 17 at r1 (raw file):
Previously, elintul (Elin) wrote…
Again, it's not the trait; it's
derive_more::Display
.
Don't like it (it's longer compilation and linking), but that's the way it is in the rest of the file and I'd rather keep consistent.
(Did you read my answer below? Note I already answered it.)
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, 2 unresolved discussions (waiting on @ayeletstarkware and @giladchase)
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 @ayeletstarkware and @giladchase)
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 @ayeletstarkware and @giladchase)
9b0916a
to
a4190aa
Compare
Benchmark movements: |
a4190aa
to
0659f62
Compare
Benchmark movements: |
c3ee901
to
bd470d4
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 5 of 6 files at r2, all commit messages.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 14 at r2 (raw file):
MempoolResult, }; use tracing;
Can remove, crates are always in the namespace
Code quote:
use tracing;
crates/mempool/src/mempool.rs
line 97 at r2 (raw file):
account_state = %args.account_state ), ret,
Just to be sure i understand, this returns ()
in case of success, that is the intended behavior? Note that this also prints the instrument fields
Code quote:
ret,
crates/mempool/src/mempool.rs
line 255 at r2 (raw file):
} tracing::info!("{existing_tx_ref} will be replaced by {incoming_tx_ref}.");
Do we want to instrument this function?
Without it prints look like:
2024-10-20T07:08:27.780747Z INFO add_tx: TransactionReference {...} will be replaced by ...
And with it:
2024-10-20T07:08:27.780747Z INFO add_tx::handle_fee_escalation TransactionReference {...} will be replaced by ...
Code quote:
fn handle_fee_escalation(&mut self, incoming_tx: &Transaction) -> MempoolResult<()> {
let incoming_tx_ref = TransactionReference::new(incoming_tx);
let TransactionReference { address, nonce, .. } = incoming_tx_ref;
let Some(existing_tx_ref) = self.tx_pool.get_by_address_and_nonce(address, nonce) else {
// Replacement irrelevant: no existing transaction with the same nonce for address.
return Ok(());
};
if !self.should_replace_tx(existing_tx_ref, &incoming_tx_ref) {
tracing::info!(
"{existing_tx_ref} was not replaced by {incoming_tx_ref} due to insufficient
fee escalation."
);
// TODO(Elin): consider adding a more specific error type / message.
return Err(MempoolError::DuplicateNonce { address, nonce });
}
tracing::info!("{existing_tx_ref} will be replaced by {incoming_tx_ref}.");
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: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @elintul, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 317 at r2 (raw file):
) } }
Plz move to after the impl
of the struct
Code quote:
impl std::fmt::Display for TransactionReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let TransactionReference { address, nonce, tx_hash, tip, max_l2_gas_price } = self;
write!(
f,
"TransactionReference {{ address: {address}, nonce: {nonce}, tx_hash: {tx_hash},
tip: {tip}, max_l2_gas_price: {max_l2_gas_price} }}"
)
}
}
bd470d4
to
2d23a6c
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: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 14 at r2 (raw file):
Previously, giladchase wrote…
Can remove, crates are always in the namespace
Cool!!
crates/mempool/src/mempool.rs
line 97 at r2 (raw file):
Previously, giladchase wrote…
Just to be sure i understand, this returns
()
in case of success, that is the intended behavior? Note that this also prints the instrument fields
Removed; I'll configure the node tracing subscriber to log exit (and enter) to the span, instead.
crates/mempool/src/mempool.rs
line 255 at r2 (raw file):
Previously, giladchase wrote…
Do we want to instrument this function?
Without it prints look like:2024-10-20T07:08:27.780747Z INFO add_tx: TransactionReference {...} will be replaced by ...
And with it:
2024-10-20T07:08:27.780747Z INFO add_tx::handle_fee_escalation TransactionReference {...} will be replaced by ...
Good idea, done!
(Converted all those to debug
, so we don't spam logs.)
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: 5 of 7 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 255 at r2 (raw file):
Previously, elintul (Elin) wrote…
Good idea, done!
(Converted all those todebug
, so we don't spam logs.)
Also, added tip
and max_l2_gas_price
logging to add_tx
under info
, so they always appear.
327df13
to
cdce6fd
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.
Reviewed 1 of 2 files at r3, 4 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 124 at r4 (raw file):
pub fn commit_block(&mut self, args: CommitBlockArgs) -> MempoolResult<()> { let CommitBlockArgs { nonces, tx_hashes } = args; tracing::debug!("Committing block with {} transactions to mempool.", tx_hashes.len());
Please elaborate on why this one is debug
and not info
level?
I see for get_txs
and add_tx
you've used info
Code quote:
debug!
crates/mempool/src/mempool.rs
line 167 at r4 (raw file):
// TODO(Mohammad): Rename this method once consensus API is added. fn _update_gas_price_threshold(&mut self, threshold: GasPrice) {
Do you need to add this API as well?
Code quote:
fn _update_gas_price_threshold(
crates/mempool/src/mempool.rs
line 298 at r4 (raw file):
// TODO(Elin): move to a shared location with other next-gen node crates. fn tip(tx: &Transaction) -> Tip { tx.tip().expect("Expected a valid tip value.")
I don't think the error message adds any additional information.
You can add unwrap
here.
Code quote:
"Expected a valid tip value."
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, 4 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 124 at r4 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Please elaborate on why this one is
debug
and notinfo
level?
I see forget_txs
andadd_tx
you've usedinfo
WDYM? Default level of instrument
spans is info
.
handle_fee_escalation
is an inner function, so I think it should log in debug
level, so we don't get spammed on every add_tx
call.
crates/mempool/src/mempool.rs
line 167 at r4 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
Do you need to add this API as well?
Maybe later, as we integrate it to our flow.
crates/mempool/src/mempool.rs
line 298 at r4 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
I don't think the error message adds any additional information.
You can addunwrap
here.
I'd rather production code to not use unwrap
s.
This is temporary code anyways. What's the status of moving to a >=V3
enum? Please answer offline.
cdce6fd
to
753bb70
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: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @elintul, and @giladchase)
crates/mempool/src/mempool.rs
line 124 at r4 (raw file):
Previously, elintul (Elin) wrote…
WDYM? Default level of
instrument
spans isinfo
.
handle_fee_escalation
is an inner function, so I think it should log indebug
level, so we don't get spammed on everyadd_tx
call.
exactly, I see that get_txs and add_tx use info while commit_block
uses debug. Is there a reason for that?
btw, I agree regarding handle_fee_escalation
, but I'm asking about commit_block
.
crates/mempool/src/mempool.rs
line 298 at r4 (raw file):
Previously, elintul (Elin) wrote…
I'd rather production code to not use
unwrap
s.
This is temporary code anyways. What's the status of moving to a>=V3
enum? Please answer offline.
Answered offline
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, 2 unresolved discussions (waiting on @ayeletstarkware, @giladchase, and @MohammadNassar1)
crates/mempool/src/mempool.rs
line 124 at r4 (raw file):
Previously, MohammadNassar1 (mohammad-starkware) wrote…
exactly, I see that get_txs and add_tx use info while
commit_block
uses debug. Is there a reason for that?btw, I agree regarding
handle_fee_escalation
, but I'm asking aboutcommit_block
.
Note only inside logs in commit are debug...
753bb70
to
05fb7a1
Compare
Benchmark movements: |
cebe77d
to
b9eab5c
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.
Reviewed 1 of 2 files at r3, 4 of 4 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)
b9eab5c
to
1be40e5
Compare
This change is