pub async fn download_trie(
    client: &mut Client,
    url: &str,
    engine_state: &EngineState<LmdbGlobalState>,
    state_root_hash: Digest,
    progress_fn: impl Fn() + Send + Sync,
) -> Result<usize, anyhow::Error> {
    let mut outstanding_tries = vec![state_root_hash];

    let mut start = Instant::now();
    let mut tries_downloaded = 0;
    while let Some(next_trie_key) = outstanding_tries.pop() {
        let read_result = get_trie(
            client,
            url,
            GetTrieParams {
                trie_key: next_trie_key,
            },
        )
        .await?;
        if let Some(blob) = read_result.maybe_trie_bytes {
            let bytes: Vec<u8> = blob.into();
            let (trie, _): (Trie<Key, StoredValue>, _) =
                FromBytes::from_bytes(&bytes).map_err(anyhow::Error::msg)?;
            let mut missing_descendants = engine_state
                .put_trie_and_find_missing_descendant_trie_keys(CorrelationId::new(), &trie)?;
            outstanding_tries.append(&mut missing_descendants);
            tries_downloaded += 1;
            progress_fn()
        } else {
            return Err(anyhow::anyhow!(
                "unable to download trie at {:?}",
                next_trie_key
            ));
        }
        if tries_downloaded % 1000 == 0 {
            println!(
                "downloaded {} tries in {}ms",
                tries_downloaded,
                start.elapsed().as_millis()
            );
            start = Instant::now();
        }
    }
    println!("Downloaded {} tries", tries_downloaded);
    Ok(tries_downloaded)
}
/// Download the trie from a node to the provided lmdb path.
Download the trie from a node to the provided lmdb path.
Download the trie from a node to the provided lmdb path .
pub async fn download_trie(
    client: &mut Client,
    url: &str,
    engine_state: &EngineState<LmdbGlobalState>,
    state_root_hash: Digest,
    progress_fn: impl Fn() + Send + Sync,
) -> Result<usize, anyhow::Error> {
    let mut outstanding_tries = vec![state_root_hash];
    let mut start = Instant::now();
    let mut tries_downloaded = 0;
    while let Some(next_trie_key) = outstanding_tries.pop() {
        let read_result = get_trie(
            client,
            url,
            GetTrieParams {
                trie_key: next_trie_key,
            },
        )
        .await?;
        if let Some(blob) = read_result.maybe_trie_bytes {
            let bytes: Vec<u8> = blob.into();
            let (trie, _): (Trie<Key, StoredValue>, _) =
                FromBytes::from_bytes(&bytes).map_err(anyhow::Error::msg)?;
            let mut missing_descendants = engine_state
                .put_trie_and_find_missing_descendant_trie_keys(CorrelationId::new(), &trie)?;
            outstanding_tries.append(&mut missing_descendants);
            tries_downloaded += 1;
            progress_fn()
        } else {
            return Err(anyhow::anyhow!(
                "unable to download trie at {:?}",
                next_trie_key
            ));
        }
        if tries_downloaded % 1000 == 0 {
            println!(
                "downloaded {} tries in {}ms",
                tries_downloaded,
                start.elapsed().as_millis()
            );
            start = Instant::now();
        }
    }
    println!("Downloaded {} tries", tries_downloaded);
    Ok(tries_downloaded)
}
pub async fn download_trie ( client : & mut Client , url : & str , engine_state : & EngineState < LmdbGlobalState > , state_root_hash : Digest , progress_fn : impl Fn ( ) + Send + Sync , ) -> Result < usize , anyhow :: Error > { let mut outstanding_tries = vec ! [ state_root_hash ] ; let mut start = Instant :: now ( ) ; let mut tries_downloaded = 0 ; while let Some ( next_trie_key ) = outstanding_tries . pop ( ) { let read_result = get_trie ( client , url , GetTrieParams { trie_key : next_trie_key , } , ) . await ? ; if let Some ( blob ) = read_result . maybe_trie_bytes { let bytes : Vec < u8 > = blob . into ( ) ; let ( trie , _ ) : ( Trie < Key , StoredValue > , _ ) = FromBytes :: from_bytes ( & bytes ) . map_err ( anyhow :: Error :: msg ) ? ; let mut missing_descendants = engine_state . put_trie_and_find_missing_descendant_trie_keys ( CorrelationId :: new ( ) , & trie ) ? ; outstanding_tries . append ( & mut missing_descendants ) ; tries_downloaded += 1 ; progress_fn ( ) } else { return Err ( anyhow :: anyhow ! ( " " next_trie_key ) ) ; } if tries_downloaded % 1000 == 0 { println ! ( " " tries_downloaded start elapsed ( ) as_millis ( ) ) ; start = Instant :: now ( ) ; } } println ! ( " " tries_downloaded ) ; Ok ( tries_downloaded ) }
Download the trie from a node to the provided lmdb path.
Download the trie from a node to the provided lmdb path .
client
&mut Client
url
&str
engine_state
&EngineState<LmdbGlobalState>
state_root_hash
Digest
progress_fn
impl Fn() + Send + Sync
client
&mut Client
url
&str
engine_state
&EngineState<LmdbGlobalState>
state_root_hash
Digest
progress_fn
impl Fn() + Send + Sync