-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Issue 4393: Correcting Unnecessary Use of Arc #6882
Changes from 18 commits
107f971
a8186fc
b6cb2c7
faa7eb5
bc7049e
7b0bfc0
56e7723
4185d4d
20ceda9
02e5608
6444e6d
008063f
207bb2a
3fcb639
ef611aa
1a4eb45
eed5535
27fd59f
d8e838f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use std::{cmp::Ordering, collections::BTreeMap, sync::Arc}; | ||
| use std::{cmp::Ordering, collections::BTreeMap}; | ||
|
|
||
| use futures::channel::oneshot; | ||
| use polkadot_node_subsystem::{messages::ChainApiMessage, overseer}; | ||
|
|
@@ -65,12 +65,12 @@ pub struct Queues { | |
| } | ||
|
|
||
| /// A dispute participation request that can be queued. | ||
| #[derive(Debug, Clone)] | ||
| #[derive(Debug)] | ||
| pub struct ParticipationRequest { | ||
| candidate_hash: CandidateHash, | ||
| candidate_receipt: CandidateReceipt, | ||
| session: SessionIndex, | ||
| _request_timer: Arc<Option<prometheus::HistogramTimer>>, // Sends metric data when request is dropped | ||
| _request_timer: Option<prometheus::HistogramTimer>, // Sends metric data when request is dropped | ||
| } | ||
|
|
||
| /// Whether a `ParticipationRequest` should be put on best-effort or the priority queue. | ||
|
|
@@ -117,7 +117,7 @@ impl ParticipationRequest { | |
| pub fn new( | ||
| candidate_receipt: CandidateReceipt, | ||
| session: SessionIndex, | ||
| request_timer: Arc<Option<prometheus::HistogramTimer>>, | ||
| request_timer: Option<prometheus::HistogramTimer>, | ||
| ) -> Self { | ||
| Self { | ||
| candidate_hash: candidate_receipt.hash(), | ||
|
|
@@ -142,8 +142,8 @@ impl ParticipationRequest { | |
| } | ||
| } | ||
|
|
||
| // We want to compare participation requests in unit tests, so we | ||
| // only implement Eq for tests. | ||
| // We want to compare and clone participation requests in unit tests, so we | ||
| // only implement Eq and Clone for tests. | ||
| #[cfg(test)] | ||
| impl PartialEq for ParticipationRequest { | ||
| fn eq(&self, other: &Self) -> bool { | ||
|
|
@@ -160,6 +160,21 @@ impl PartialEq for ParticipationRequest { | |
| } | ||
| #[cfg(test)] | ||
| impl Eq for ParticipationRequest {} | ||
| #[cfg(test)] | ||
| impl Clone for ParticipationRequest { | ||
| fn clone(&self) -> Self { | ||
| ParticipationRequest { | ||
| candidate_receipt: self.candidate_receipt.clone(), | ||
| candidate_hash: self.candidate_hash.clone(), | ||
| session: self.session, | ||
| _request_timer: None, | ||
| } | ||
| } | ||
|
|
||
| fn clone_from(&mut self, source: &Self) { | ||
| *self = source.clone(); | ||
| } | ||
|
||
| } | ||
|
|
||
| impl Queues { | ||
| /// Create new `Queues`. | ||
|
|
||
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.
I would just not have implemented
Cloneat all. This is a bit hacky. Instead of cloning, we should be able to create new instances in tests where necessary. E.g. just a newlet ... = create_test_partitipation_request... instead of cloning the previous one.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.
I went ahead and tried your suggestion. It turns out there's some non-determinism in the helper
make_participation_request()such that the candidate hashes end up different. Particularly thesignaturefield in theCandidateDescriptorwithin theCandidateReceiptis different each time it is generated.This means that calling
make_participation_request()multiple times results in requests that don't compare as equal, ruining our asserts.Know of other ways we can do this without clone?
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.
Or here's another idea which might be considered better form.
I could at least move the
clonefunctionality intotests.rsas a helper function rather than implementing it on theParticipationRequesttype.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.
yes, making it a standalone function like
test_clonecore something would also be way better. The non-determinism is interesting, I don't see where it would be coming from?