Skip to content

Conversation

@leoyvens
Copy link
Collaborator

This fills in the sql implementation in dynds/private.rs, and sets V1 as the deployment schema version for new deployments.

This maintains compatibility with the deployment schema V0, which uses the shared table. This does not implement migrations from V0 to V1, so copies are enabled for all versions.

The new stores template references by manifest index, but the shared table stores them by name and the runtime creates the by name, so a map between template name and index had to be plumbed into various places.

This was tested manually with uniswap-v3, and the data_source_revert end-to-end test was modified to additionally test restarting a subgraph with dynamic data sources.

Part of #3405, the only remaining work being migrations which we'll want to do eventually.

@leoyvens leoyvens requested review from Theodus and lutter July 17, 2022 16:54
@leoyvens leoyvens changed the title Private data sources Private data sources table Jul 17, 2022
@leoyvens
Copy link
Collaborator Author

leoyvens commented Jul 18, 2022

Grafting from a V0 subgraph isn't working, I'll fix that.

Edit: Fixed

Copy link
Member

@Theodus Theodus left a comment

Choose a reason for hiding this comment

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

LGTM

@leoyvens leoyvens force-pushed the leo/impl-private-data-sources branch from 06b8f6d to ed0cae4 Compare July 21, 2022 13:52
@leoyvens leoyvens mentioned this pull request Jul 25, 2022
6 tasks
Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

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

LGTM! I have a few detail questions, but assuming they aren't a real issue this is good to merge.

pub(crate) fn revert(&self, conn: &PgConnection, block: BlockNumber) -> Result<(), StoreError> {
todo!()
// Use `@>` to leverage the gist index.
// This assumes all ranges are of the form [x, +inf).
Copy link
Collaborator

Choose a reason for hiding this comment

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

If block ranges are always [x, +inf), it would be better to not use a range at all, and just have a block$ that stores x since that could be supported by a normal BTree index. But if we do need the flexibility to disable data sources afte ra certain block, this is ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes this is trying to be future compatible with removing data sources by closing their range.

let query = format!(
"\
insert into {dst}(block_range, causality_region, manifest_idx, parent, id, param, context)
select int4range(lower(e.block_range), null), e.causality_region, e.manifest_idx,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not select just e.block_range instead of creating a new range?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The desired behaviour for this to be future compatible with closed ranges would be to literally copy the range [x, y] if y <= target_block, but if y > target_block then we'd open the range with [x, null). Do you know what would be the right SQL to achieve this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You will have fun with case expressions, something like

case
  when upper(e.block_range) <= $target_block then e.block_range
  else int4range(lower(e.block_range), null)
end

Copy link
Collaborator Author

@leoyvens leoyvens Aug 4, 2022

Choose a reason for hiding this comment

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

That seems to work, thanks! I've added a test to exercise this function, and put the debug_assert to use.

debug_assert!(
self.load(conn, target_block).map_err(|e| e.to_string())
== dst.load(conn, target_block).map_err(|e| e.to_string())
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@leoyvens leoyvens force-pushed the leo/impl-private-data-sources branch 4 times, most recently from fb2231d to 878f27d Compare July 29, 2022 19:18
@leoyvens leoyvens force-pushed the leo/impl-private-data-sources branch 2 times, most recently from 2263b47 to 587b8e6 Compare August 4, 2022 14:38
@leoyvens leoyvens force-pushed the leo/impl-private-data-sources branch from 587b8e6 to 2389f93 Compare August 4, 2022 14:43
@leoyvens leoyvens force-pushed the leo/impl-private-data-sources branch from 2389f93 to be98a6d Compare August 4, 2022 15:55
@leoyvens leoyvens merged commit bd97cdc into master Aug 4, 2022
@leoyvens leoyvens deleted the leo/impl-private-data-sources branch August 4, 2022 19:55
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.

4 participants