Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_let_mutex = "warn"
implicit_clone = "warn"
imprecise_flops = "warn"
Expand Down
5 changes: 2 additions & 3 deletions cli/src/cmd/tools/gen_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ impl GiverBuilder {
.0
.expect("invalid giver state");

let address;
match &mut account.state {
let address = match &mut account.state {
AccountState::Active(state_init) => {
let mut data = CellBuilder::new();

Expand All @@ -377,7 +376,7 @@ impl GiverBuilder {
state_init.data = Some(data.build()?);

// Compute address
address = *CellBuilder::build_from(&*state_init)?.repr_hash();
*CellBuilder::build_from(&*state_init)?.repr_hash()
}
_ => unreachable!("saved state is for the active account"),
};
Expand Down
4 changes: 2 additions & 2 deletions collator/src/mempool/impls/stub_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl MempoolAdapterStubImpl {

let mut prev_anchor_id = 0;
let start_anchor_id = prev_anchor_id + 1;
for anchor_id in start_anchor_id.. {
for anchor_id in start_anchor_id..=u32::MAX {
if self.sleep_between_anchors.load(Ordering::Acquire) {
tokio::time::sleep(make_round_interval() * 4).await;
} else {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl MempoolAdapterStubImpl {
.or(now)
.unwrap_or_default();

for anchor_id in max_anchor_id + 1.. {
for anchor_id in max_anchor_id + 1..=u32::MAX {
if self.sleep_between_anchors.load(Ordering::Acquire) {
tokio::time::sleep(make_round_interval() * 4).await;
} else {
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/commit/back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl DagBack {
&self,
trigger: &PointInfo,
) -> EngineResult<VecDeque<EnqueuedAnchor>> {
let bottom_round = (self.last_committed_proof).map_or(self.bottom_round(), |proof| proof);
let bottom_round = (self.last_committed_proof).unwrap_or(self.bottom_round());

let range = RangeInclusive::new(
// exclude used or unusable proof (it may be out of range)
Expand Down
16 changes: 10 additions & 6 deletions core/src/block_strider/starter/cold_boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,9 @@ impl StarterInner {

// NOTE: Intentionally dont spawn yet
let remove_state_file = async move {
if let Err(e) = tokio::fs::remove_file(&state_file_path).await {
if let Err(e) = tokio::fs::remove_file(&state_file_path).await
&& e.kind() != std::io::ErrorKind::NotFound
{
tracing::warn!(
path = %state_file_path.display(),
"failed to remove downloaded queue state: {e:?}",
Expand Down Expand Up @@ -1302,7 +1304,9 @@ impl StarterInner {
}
}

if local_meta.as_ref() != Some(&remote_meta) {
// remove previously downloaded persistent shard state files
// if local meta doe not match the remote one
if kind == PersistentStateKind::Shard && local_meta.as_ref() != Some(&remote_meta) {
let old_prefixes = local_meta
.as_ref()
.into_iter()
Expand All @@ -1314,9 +1318,7 @@ impl StarterInner {
&old_prefixes.chain(new_prefixes).collect::<Vec<_>>(),
)
.await;
if kind == PersistentStateKind::Shard {
remote_meta.write_to_file(meta_file.path())?;
}
remote_meta.write_to_file(meta_file.path())?;
}

if is_downloaded_persistent_state_ready(state_file, &remote_meta) {
Expand Down Expand Up @@ -1414,7 +1416,9 @@ async fn remove_downloaded_persistent_state_files(
return;
}

if let Err(e) = tokio::fs::remove_file(file_path).await {
if let Err(e) = tokio::fs::remove_file(file_path).await
&& e.kind() != std::io::ErrorKind::NotFound
{
tracing::warn!(
file_path = %file_path.display(),
"failed to remove downloaded shard state: {e:?}",
Expand Down
125 changes: 120 additions & 5 deletions core/src/block_strider/starter/starter_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,45 @@ mod s3 {
block_id: &'a BlockId,
kind: PersistentStateKind,
) -> Result<FoundState<'a>> {
let Some(_) = self
let Some(info) = self
.s3_client
.get_persistent_state_info(block_id, kind)
.await?
else {
anyhow::bail!("not found");
};

let info_for_part = info.clone();

Ok(FoundState {
split_depth: 0,
parts: Vec::new(),
split_depth: info.split_depth,
parts: info
.parts
.iter()
.map(|part| FoundStatePart {
prefix: part.prefix,
})
.collect(),
download: Box::new(move |output| {
let info = info.clone();
Box::pin(async move {
let output = self
.s3_client
.download_persistent_state(block_id, kind, output)
.download_persistent_state(info, None, output)
.await?;
Ok(output)
})
}),
download_part: None,
download_part: Some(Box::new(move |part, output| {
let info = info_for_part.clone();
Box::pin(async move {
let output = self
.s3_client
.download_persistent_state(info, Some(part.prefix), output)
.await?;
Ok(output)
})
})),
})
}

Expand Down Expand Up @@ -394,4 +412,101 @@ mod s3 {
}
}
}

#[cfg(test)]
mod tests {
use bytes::Bytes;
use object_store::ObjectStoreExt;
use object_store::memory::InMemory;
use tycho_storage::StorageContext;
use tycho_types::cell::HashBytes;
use tycho_types::models::ShardIdent;
use tycho_util::fs::MappedFile;

use super::*;
use crate::storage::{CoreStorageConfig, PersistentStateMeta, PersistentStatePrefix};

#[tokio::test]
async fn s3_starter_client_returns_split_found_state_and_downloads() -> Result<()> {
let store = Arc::new(InMemory::new());
let client = S3Client::new_for_tests(store.clone());
let (ctx, _tmp_dir) = StorageContext::new_temp().await?;
let storage = CoreStorage::open(ctx, CoreStorageConfig::new_potato()).await?;
let block_id = BlockId {
shard: ShardIdent::BASECHAIN,
seqno: 42,
root_hash: HashBytes::from([1; 32]),
file_hash: HashBytes::from([2; 32]),
};

// publish the split fixture
let prefixes = vec![0x2000000000000000, 0xa000000000000000];
let main = b"split main";
let parts = [b"first part".as_slice(), b"second part".as_slice()];
let meta = PersistentStateMeta::new(2, prefixes.clone());

store
.put(
&client.make_state_meta_key(&block_id),
Bytes::from(meta.to_bytes()?).into(),
)
.await?;
store
.put(
&client.make_state_key(
&block_id,
PersistentStateKind::Shard,
PersistentStatePrefix::Split(None),
)?,
tycho_util::compression::zstd_compress_simple(main).into(),
)
.await?;
for (prefix, part) in prefixes.iter().zip(parts) {
store
.put(
&client.make_state_key(
&block_id,
PersistentStateKind::Shard,
PersistentStatePrefix::Split(Some(*prefix)),
)?,
tycho_util::compression::zstd_compress_simple(part).into(),
)
.await?;
}

let starter_client = S3StarterClient::new(client, storage.clone());

// discover the split state
let mut found = starter_client
.find_persistent_state(&block_id, PersistentStateKind::Shard)
.await?;
assert_eq!(found.split_depth, 2);
assert_eq!(
found
.parts
.iter()
.map(|part| part.prefix)
.collect::<Vec<_>>(),
prefixes,
);

// download the main state file
let main_file =
(found.download)(storage.context().temp_files().unnamed_file().open()?).await?;
let main_file = MappedFile::from_existing_file(main_file)?;
assert_eq!(main_file.as_slice(), main);

// download one declared part
let download_part = found.download_part.take().expect("split part downloader");
let part_file = download_part(
found.parts[0].clone(),
storage.context().temp_files().unnamed_file().open()?,
)
.await?;
let part_file = MappedFile::from_existing_file(part_file)?;
assert_eq!(part_file.as_slice(), parts[0]);

Ok(())
}
}
}
26 changes: 6 additions & 20 deletions core/src/blockchain_rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,6 @@ impl BlockchainRpcClient {
Ok(res)
}

pub async fn get_persistent_state_part(
&self,
neighbour: &Neighbour,
block_id: &BlockId,
offset: u64,
) -> Result<QueryResponse<Data>, Error> {
let client = &self.inner.overlay_client;
let data = client
.query_raw::<Data>(
neighbour.clone(),
Request::from_tl(rpc::GetPersistentShardStateChunk {
block_id: *block_id,
offset,
}),
None,
)
.await?;
Ok(data)
}

pub async fn find_persistent_state(
&self,
block_id: &BlockId,
Expand Down Expand Up @@ -607,6 +587,7 @@ impl BlockchainRpcClient {
.ok_or(Error::NotFound)?,
None => state.size,
};
let is_split = state.split_depth > 0;

download_and_decompress(
size,
Expand All @@ -624,6 +605,11 @@ impl BlockchainRpcClient {
prefix,
offset,
})
} else if is_split {
Request::from_tl(rpc::GetPersistentShardStateRootChunk {
block_id,
offset,
})
} else {
Request::from_tl(rpc::GetPersistentShardStateChunk { block_id, offset })
}
Expand Down
Loading
Loading