Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offchain created from offchain #5051

Merged
merged 7 commits into from
Dec 18, 2023

Conversation

leoyvens
Copy link
Collaborator

@leoyvens leoyvens commented Dec 6, 2023

This is blocking the update to the network subgraph, which now uses file data sources within file data sources.

This is more easily reviewed commit by commit. The first four commits are strictly refactors.

@leoyvens leoyvens requested a review from mangas December 6, 2023 13:30
@leoyvens leoyvens force-pushed the leo/fix-offchain-created-from-offchain branch 3 times, most recently from 7ec4598 to abf9f26 Compare December 12, 2023 22:43
@leoyvens leoyvens force-pushed the leo/fix-offchain-created-from-offchain branch from abf9f26 to d457b3b Compare December 16, 2023 11:30
Ok(())
}

async fn data_source_long_revert() -> anyhow::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal, but committing a failing test before the fix will make bisecting through this change harder

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yhea I'll squash merge

let host = this.new_host(logger.cheap_clone(), ds, module_bytes)?;
this.hosts.push(Arc::new(host));
let Some(host) = this.new_host(logger.cheap_clone(), ds)? else { continue };
this.hosts.push(host);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be cleaner as a if let Some(..) so we can avoid the continue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code changes in a further commit.

core/src/subgraph/context/instance/hosts.rs Outdated Show resolved Hide resolved
core/src/subgraph/context/instance/mod.rs Outdated Show resolved Hide resolved
Some(host)
})
// Check for duplicates and add the host.
match is_onchain {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a simple if be clearer here?

.last()
.and_then(|h| h.creation_block_number())
<= host.data_source().creation_block()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am always a bit queasy with asserts since it's not that easy to spot panics in the logs; could we return an error here? That way, the subgraph will fail and the failure can tell use what exactly is wrong.

The hosts Vec expected the hosts to be pushed in ascending order
of block number. Creating a file ds B within another file ds A violated
that assumption, because B will have the same creation block as A. This
is by design, so the cleanest way to fix this seemed to be separating
the data structures for onchain and offchain hosts. Offchain data sources
do not need to maintain insertion order, as their processing order
ultimately does not impact determinism because they each have their own
causality region. If in the future we introduce a feature that allows
two different offchain data sources to have the same causality region, we maybe
need to revisit this.
@leoyvens leoyvens force-pushed the leo/fix-offchain-created-from-offchain branch from d457b3b to 1cf8d66 Compare December 18, 2023 18:41
@leoyvens
Copy link
Collaborator Author

@lutter thanks for the review! I've addressed it and removed the stray dbg!s I forgot to remove in #5083.

@leoyvens leoyvens merged commit 72ba5e4 into master Dec 18, 2023
7 checks passed
@leoyvens leoyvens deleted the leo/fix-offchain-created-from-offchain branch December 18, 2023 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants