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

chore: remove some unnecessary calls to unwrap/expect #6727

Merged
merged 3 commits into from Feb 22, 2024
Merged

Conversation

DaniPopes
Copy link
Member

Mostly using entry and insert* APIs to avoid double lookups in maps and unwrap/expect in options.

Also some cleanups along the way.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

pending @emhane this touches some net/transactions code ptal

@mattsse mattsse added the C-debt A section of code is hard to understand or change label Feb 21, 2024
Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

reviewed the tx pool and network crate, found one logic change which I don't think is in scope of this pr, see comment.

Comment on lines +860 to +865
// Insert a new peer into the peerset.
let peer = Peer::new(messages, version, client_version);
let peer = match self.peers.entry(peer_id) {
Entry::Occupied(mut entry) => {
entry.insert(peer);
entry.into_mut()
Copy link
Member

@emhane emhane Feb 22, 2024

Choose a reason for hiding this comment

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

this is the only logic change, to add the peer even if we are syncing, not sure what the motivation is behind this? found the call, my bad

@@ -350,7 +350,8 @@ where
transaction: Self::Transaction,
) -> PoolResult<TxHash> {
let (_, tx) = self.validate(origin, transaction).await;
self.pool.add_transactions(origin, std::iter::once(tx)).pop().expect("exists; qed")
let mut results = self.pool.add_transactions(origin, std::iter::once(tx));
results.pop().expect("result length is the same as the input")
Copy link
Member

Choose a reason for hiding this comment

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

not sure what this error message means, where are we guaranteed that transactions ins't zero? anyhow out of scope of this pr probably

Copy link
Member Author

Choose a reason for hiding this comment

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

add_transaction takes in an iterator, the output is a Vec<Result<_>> collected from the iterator so it has the same length

@emhane emhane added this pull request to the merge queue Feb 22, 2024
Merged via the queue into main with commit 9ca813a Feb 22, 2024
29 checks passed
@emhane emhane deleted the dani/remove-expects branch February 22, 2024 16:45
} else {
let jar = NippyJar::load(&self.path.join(segment.filename(block_range, tx_range)))
.map(|jar| {
let entry = match self.map.entry(key) {
Copy link
Collaborator

@joshieDo joshieDo Feb 22, 2024

Choose a reason for hiding this comment

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

i think this would acquire a lock which is not desirable

https://docs.rs/dashmap/latest/dashmap/struct.DashMap.html#method.entry

while get allows this to be returned with reduced deadlock risk

https://docs.rs/dashmap/latest/dashmap/struct.DashMap.html#method.get

Copy link
Member Author

@DaniPopes DaniPopes Feb 22, 2024

Choose a reason for hiding this comment

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

so does calling get twice no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-debt A section of code is hard to understand or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants