pub async fn check_chain_rollback(
    header: &Header,
    workspace: &SysValidationWorkspace,
) -> SysValidationResult<()> {
    let header_hash = HeaderHash::with_data_sync(header);
    let k = ChainItemKey::AgentStatusSequence(
        header.author().clone(),
        ValidationStatus::Valid,
        header.header_seq(),
    );
    let env = workspace.meta_vault.env();
    // Check there are no conflicting chain items
    // at any valid or potentially valid stores.
    let count = fresh_reader!(env, |r| {
        let vault_count = workspace
            .meta_vault
            .get_activity(&r, k.clone())?
            .filter(|thh| Ok(thh.header_hash != header_hash))
            .count()?;
        let pending_count = workspace
            .meta_pending
            .get_activity(&r, k.clone())?
            .filter(|thh| Ok(thh.header_hash != header_hash))
            .count()?;
        DatabaseResult::Ok(vault_count + pending_count)
    })?;

    // Ok or log warning
    if count == 0 {
        return Ok(());
    } else {
        let s = tracing::warn_span!("agent_activity");
        let _g = s.enter();
        // TODO: implement real rollback detection once we know what that looks like
        tracing::error!(
            "Chain rollback detected at position {} for agent {:?} from header {:?}
            There were {} headers at this position",
            header.header_seq(),
            header.author(),
            header,
            count,
        );
    }
    Ok(())
}
// TODO: I think this can be removed now as rollbacks are detected when inserting
// metadata into the metadata buf.
/// Check if there are other headers at this
/// sequence number
I think this can be removed now as rollbacks are detected when inserting
metadata into the metadata buf.
Check if there are other headers at this
sequence number
I think this can be removed now as rollbacks are detected when inserting metadata into the metadata buf . Check if there are other headers at this sequence number
pub async fn check_chain_rollback(
    header: &Header,
    workspace: &SysValidationWorkspace,
) -> SysValidationResult<()> {
    let header_hash = HeaderHash::with_data_sync(header);
    let k = ChainItemKey::AgentStatusSequence(
        header.author().clone(),
        ValidationStatus::Valid,
        header.header_seq(),
    );
    let env = workspace.meta_vault.env();
    // Check there are no conflicting chain items
    // at any valid or potentially valid stores.
    let count = fresh_reader!(env, |r| {
        let vault_count = workspace
            .meta_vault
            .get_activity(&r, k.clone())?
            .filter(|thh| Ok(thh.header_hash != header_hash))
            .count()?;
        let pending_count = workspace
            .meta_pending
            .get_activity(&r, k.clone())?
            .filter(|thh| Ok(thh.header_hash != header_hash))
            .count()?;
        DatabaseResult::Ok(vault_count + pending_count)
    })?;
    // Ok or log warning
    if count == 0 {
        return Ok(());
    } else {
        let s = tracing::warn_span!("agent_activity");
        let _g = s.enter();
        // TODO: implement real rollback detection once we know what that looks like
        tracing::error!(
            "Chain rollback detected at position {} for agent {:?} from header {:?}
            There were {} headers at this position",
            header.header_seq(),
            header.author(),
            header,
            count,
        );
    }
    Ok(())
}
pub async fn check_chain_rollback ( header : & Header , workspace : & SysValidationWorkspace , ) -> SysValidationResult < ( ) > { let header_hash = HeaderHash :: with_data_sync ( header ) ; let k = ChainItemKey :: AgentStatusSequence ( header . author ( ) . clone ( ) , ValidationStatus :: Valid , header . header_seq ( ) , ) ; let env = workspace . meta_vault . env ( ) ; // Check there are no conflicting chain items // at any valid or potentially valid stores. let count = fresh_reader ! ( env r { let vault_count workspace meta_vault get_activity ( r k clone ( ) ) filter ( thh Ok ( thh header_hash header_hash ) ) count ( ) let pending_count workspace meta_pending get_activity ( r k clone ( ) ) filter ( thh Ok ( thh header_hash header_hash ) ) count ( ) DatabaseResult Ok ( vault_count pending_count ) } ) ? ; // Ok or log warning if count == 0 { return Ok ( ( ) ) ; } else { let s = tracing :: warn_span ! ( " " ) ; let _g = s . enter ( ) ; // TODO: implement real rollback detection once we know what that looks like tracing :: error ! ( " " header header_seq ( ) header author ( ) header count ) ; } Ok ( ( ) ) }
TODO: I think this can be removed now as rollbacks are detected when inserting
metadata into the metadata buf.
TODO : I think this can be removed now as rollbacks are detected when inserting metadata into the metadata buf .
header
&Header
workspace
&SysValidationWorkspace
header
&Header
workspace
&SysValidationWorkspace