Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Add check to avoid duplicate headers for entries #1980

Closed
Closed
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
38 changes: 22 additions & 16 deletions crates/core/src/agent/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,28 @@ fn reduce_commit_entry(
let action = action_wrapper.action();
let (entry, maybe_link_update_delete, provenances) = unwrap_to!(action => Action::Commit);

let result = create_new_chain_header(
&entry,
agent_state,
&StateWrapper::from(root_state.clone()),
&maybe_link_update_delete,
provenances,
)
.and_then(|chain_header| {
agent_state.chain_store.add(entry)?;
agent_state.chain_store.add(&chain_header)?;
Ok((chain_header, entry.address()))
})
.and_then(|(chain_header, address)| {
agent_state.top_chain_header = Some(chain_header);
Ok(address)
});
// Only make a new header and link it if the entry isn't already in the chain
let entry_addres = entry.address();
let result = match agent_state.chain_store().contains(&entry_addres) {
Ok(false) => create_new_chain_header(
&entry,
agent_state,
&StateWrapper::from(root_state.clone()),
&maybe_link_update_delete,
provenances,
)
.and_then(|chain_header| {
agent_state.chain_store.add(entry)?;
agent_state.chain_store.add(&chain_header)?;
Ok(chain_header)
})
.and_then(|chain_header| {
agent_state.top_chain_header = Some(chain_header);
Ok(entry_addres)
}),
Ok(true) => Ok(entry_addres),
Err(e) => Err(e),
};

agent_state.actions.insert(
action_wrapper.clone(),
Expand Down