Skip to content

Commit 7ddb5f3

Browse files
authored
Fix possible re-entrant lock bug (#22067)
Fixes #22055
1 parent 220df36 commit 7ddb5f3

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

crates/sui-types/src/messages_checkpoint.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::error::SuiResult;
1616
use crate::gas::GasCostSummary;
1717
use crate::message_envelope::{Envelope, Message, TrustedEnvelope, VerifiedEnvelope};
1818
use crate::signature::GenericSignature;
19-
use crate::storage::ReadStore;
2019
use crate::sui_serde::AsProtocolVersion;
2120
use crate::sui_serde::BigInt;
2221
use crate::sui_serde::Readable;
@@ -583,26 +582,6 @@ impl FullCheckpointContents {
583582
user_signatures: contents.into_v1().user_signatures,
584583
}
585584
}
586-
pub fn from_checkpoint_contents<S>(store: S, contents: CheckpointContents) -> Option<Self>
587-
where
588-
S: ReadStore,
589-
{
590-
let mut transactions = Vec::with_capacity(contents.size());
591-
for tx in contents.iter() {
592-
if let (Some(t), Some(e)) = (
593-
store.get_transaction(&tx.transaction),
594-
store.get_transaction_effects(&tx.transaction),
595-
) {
596-
transactions.push(ExecutionData::new((*t).clone().into_inner(), e))
597-
} else {
598-
return None;
599-
}
600-
}
601-
Some(Self {
602-
transactions,
603-
user_signatures: contents.into_v1().user_signatures,
604-
})
605-
}
606585

607586
pub fn iter(&self) -> Iter<'_, ExecutionData> {
608587
self.transactions.iter()

crates/sui-types/src/storage/shared_in_memory_store.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use super::error::Result;
55
use super::ObjectStore;
6-
use crate::base_types::{EpochId, TransactionDigest};
6+
use crate::base_types::{EpochId, ExecutionData, TransactionDigest};
77
use crate::committee::Committee;
88
use crate::digests::{CheckpointContentsDigest, CheckpointDigest};
99
use crate::effects::{TransactionEffects, TransactionEvents};
@@ -70,19 +70,8 @@ impl ReadStore for SharedInMemoryStore {
7070
sequence_number: Option<CheckpointSequenceNumber>,
7171
digest: &CheckpointContentsDigest,
7272
) -> Option<FullCheckpointContents> {
73-
// First look to see if we saved the complete contents already.
74-
let inner = self.inner();
75-
let contents = sequence_number
76-
.or_else(|| inner.get_sequence_number_by_contents_digest(digest))
77-
.and_then(|seq_num| inner.full_checkpoint_contents.get(&seq_num).cloned());
78-
if contents.is_some() {
79-
return contents;
80-
}
81-
82-
// Otherwise gather it from the individual components.
83-
inner.get_checkpoint_contents(digest).and_then(|contents| {
84-
FullCheckpointContents::from_checkpoint_contents(self, contents.to_owned())
85-
})
73+
self.inner()
74+
.get_full_checkpoint_contents(sequence_number, digest)
8675
}
8776

8877
fn get_committee(&self, epoch: EpochId) -> Option<Arc<Committee>> {
@@ -229,6 +218,39 @@ impl InMemoryStore {
229218
.and_then(|digest| self.get_checkpoint_by_digest(digest))
230219
}
231220

221+
fn get_full_checkpoint_contents(
222+
&self,
223+
sequence_number: Option<CheckpointSequenceNumber>,
224+
digest: &CheckpointContentsDigest,
225+
) -> Option<FullCheckpointContents> {
226+
let contents = sequence_number
227+
.or_else(|| self.get_sequence_number_by_contents_digest(digest))
228+
.and_then(|seq_num| self.full_checkpoint_contents.get(&seq_num).cloned());
229+
if contents.is_some() {
230+
return contents;
231+
}
232+
233+
let contents = self.get_checkpoint_contents(digest)?;
234+
235+
let mut transactions = Vec::with_capacity(contents.size());
236+
237+
for tx in contents.iter() {
238+
if let (Some(t), Some(e)) = (
239+
self.get_transaction_block(&tx.transaction),
240+
self.get_transaction_effects(&tx.transaction),
241+
) {
242+
transactions.push(ExecutionData::new((*t).clone().into_inner(), e.clone()))
243+
} else {
244+
return None;
245+
}
246+
}
247+
248+
Some(FullCheckpointContents::from_contents_and_execution_data(
249+
contents.to_owned(),
250+
transactions.into_iter(),
251+
))
252+
}
253+
232254
pub fn get_sequence_number_by_contents_digest(
233255
&self,
234256
digest: &CheckpointContentsDigest,

0 commit comments

Comments
 (0)