-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add runtime support for offchain data sources & templates #3791
Merged
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
a6b33f5
Refactor manifest data sources
Theodus 48ccdd3
Refactor manifest data source templates
Theodus 55f8847
Start offchain monitors for static sources
Theodus ca94702
Run offchain handlers
Theodus c6338c6
offchain: dont expect `manifest_idx` in the manifest
leoyvens 3f51dc0
offchain: add `match_and_decode`, persist normally, require source
leoyvens 4def210
trigger processor: take block ptr from the trigger
leoyvens f237fea
offchain: Return cid to dataSource.address host fn
leoyvens d43a2fa
runner: transact modifications of offchain events
leoyvens b1b224a
ethereum: fix test build
leoyvens d5a5174
ipfs: Set a default maximum file size
leoyvens 7347307
ipfs: Add env var for max concurrent requests
leoyvens e17fd10
ipfs: Share ipfs service across subgraphs
leoyvens 516e104
offchain: move `ready_offchain_events` to `OffchainMonitor`
leoyvens 3f940c0
runner: Clarify comments
leoyvens c3a0855
core: Remove unecessary params from `add_dynamic_data_source`
leoyvens 6936376
core: Move poi_version out of the instance
leoyvens 801eb36
core: Move `mod instance` under `mod context`
leoyvens 8930c5c
core: Refactor OffchainMonitor::add_data_source
leoyvens 9338787
offchain: Better handling of duplicates
leoyvens acdc5a7
offchain: Bump max ipfs concurrent requests to 100
leoyvens ea0311e
refactor: Expose RuntimeHost data source
leoyvens a95454f
offchain: Remove dses that have been processed
leoyvens f30b210
refactor: Extract ReadStore out of WritableStore
leoyvens ad6264d
test: Add graphql queries to end-to-end tests
leoyvens f59d9c9
feat(file ds): Bump max spec version to 0.0.7
leoyvens 7e99135
test: Add basic file data sources e2e test
leoyvens d22b51f
runner: Isolate offchain data sources
leoyvens 824957b
offchain: Forbid static file data sources
leoyvens 717b1d0
store: Assign separate causality region for offchain dses
leoyvens ae8e2d7
graph: Fix release build
leoyvens 11633ef
tests: yarn upgrade, add file ds to the workspace
leoyvens 149a14d
fix: Update comments
leoyvens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
store: Assign separate causality region for offchain dses
- Loading branch information
commit 717b1d0c9d100cfbd422de9dc26daec861814761
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ pub(crate) struct DataSourcesTable { | |
table: DynTable, | ||
vid: DynColumn<Integer>, | ||
block_range: DynColumn<sql_types::Range<Integer>>, | ||
_causality_region: DynColumn<Integer>, | ||
causality_region: DynColumn<Integer>, | ||
manifest_idx: DynColumn<Integer>, | ||
param: DynColumn<Nullable<Binary>>, | ||
context: DynColumn<Nullable<Jsonb>>, | ||
|
@@ -43,7 +43,7 @@ impl DataSourcesTable { | |
namespace, | ||
vid: table.column("vid"), | ||
block_range: table.column("block_range"), | ||
_causality_region: table.column("causality_region"), | ||
causality_region: table.column("causality_region"), | ||
manifest_idx: table.column("manifest_idx"), | ||
param: table.column("param"), | ||
context: table.column("context"), | ||
|
@@ -85,6 +85,7 @@ impl DataSourcesTable { | |
i32, | ||
Option<Vec<u8>>, | ||
Option<serde_json::Value>, | ||
i32, | ||
); | ||
let tuples = self | ||
.table | ||
|
@@ -95,26 +96,34 @@ impl DataSourcesTable { | |
&self.manifest_idx, | ||
&self.param, | ||
&self.context, | ||
&self.causality_region, | ||
)) | ||
.order_by(&self.vid) | ||
.load::<Tuple>(conn)?; | ||
|
||
let mut dses: Vec<_> = tuples | ||
.into_iter() | ||
.map(|(block_range, manifest_idx, param, context)| { | ||
let creation_block = match block_range.0 { | ||
Bound::Included(block) => Some(block), | ||
|
||
// Should never happen. | ||
Bound::Excluded(_) | Bound::Unbounded => unreachable!("dds with open creation"), | ||
}; | ||
StoredDynamicDataSource { | ||
manifest_idx: manifest_idx as u32, | ||
param: param.map(|p| p.into()), | ||
context, | ||
creation_block, | ||
} | ||
}) | ||
.map( | ||
|(block_range, manifest_idx, param, context, causality_region)| { | ||
let creation_block = match block_range.0 { | ||
Bound::Included(block) => Some(block), | ||
|
||
// Should never happen. | ||
Bound::Excluded(_) | Bound::Unbounded => { | ||
unreachable!("dds with open creation") | ||
} | ||
}; | ||
|
||
let is_offchain = causality_region > 0; | ||
StoredDynamicDataSource { | ||
manifest_idx: manifest_idx as u32, | ||
param: param.map(|p| p.into()), | ||
context, | ||
creation_block, | ||
is_offchain, | ||
} | ||
}, | ||
) | ||
.collect(); | ||
|
||
// This sort is stable and `tuples` was ordered by vid, so `dses` will be ordered by `(creation_block, vid)`. | ||
|
@@ -129,9 +138,6 @@ impl DataSourcesTable { | |
data_sources: &[StoredDynamicDataSource], | ||
block: BlockNumber, | ||
) -> Result<usize, StoreError> { | ||
// Currently all data sources share the same causality region. | ||
let causality_region = 0; | ||
|
||
let mut inserted_total = 0; | ||
|
||
for ds in data_sources { | ||
|
@@ -140,6 +146,7 @@ impl DataSourcesTable { | |
param, | ||
context, | ||
creation_block, | ||
is_offchain, | ||
} = ds; | ||
|
||
if creation_block != &Some(block) { | ||
|
@@ -150,19 +157,32 @@ impl DataSourcesTable { | |
)); | ||
} | ||
|
||
let query = format!( | ||
"insert into {}(block_range, manifest_idx, causality_region, param, context) \ | ||
values (int4range($1, null), $2, $3, $4, $5)", | ||
self.qname | ||
); | ||
|
||
inserted_total += sql_query(query) | ||
// Onchain data sources have the causality region explicitly set to 0, while offchain | ||
// data sources have an unique causality region assigned from the sequence. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment would match the code better if was something like // Offchain data sources have a unique causality region assigned from a sequence in the database,
// while onchain data sources always have causality region 0 |
||
let query = match is_offchain { | ||
false => format!( | ||
"insert into {}(block_range, manifest_idx, param, context, causality_region) \ | ||
values (int4range($1, null), $2, $3, $4, $5)", | ||
self.qname | ||
), | ||
|
||
true => format!( | ||
"insert into {}(block_range, manifest_idx, param, context) \ | ||
values (int4range($1, null), $2, $3, $4)", | ||
self.qname | ||
), | ||
}; | ||
|
||
let query = sql_query(query) | ||
.bind::<Nullable<Integer>, _>(creation_block) | ||
.bind::<Integer, _>(*manifest_idx as i32) | ||
.bind::<Integer, _>(causality_region) | ||
.bind::<Nullable<Binary>, _>(param.as_ref().map(|p| &**p)) | ||
.bind::<Nullable<Jsonb>, _>(context) | ||
.execute(conn)?; | ||
.bind::<Nullable<Jsonb>, _>(context); | ||
|
||
inserted_total += match is_offchain { | ||
false => query.bind::<Integer, _>(0).execute(conn)?, | ||
true => query.execute(conn)?, | ||
}; | ||
} | ||
|
||
Ok(inserted_total) | ||
|
@@ -233,8 +253,15 @@ impl DataSourcesTable { | |
param, | ||
context, | ||
creation_block, | ||
is_offchain, | ||
} = ds; | ||
|
||
if !is_offchain { | ||
return Err(constraint_violation!( | ||
"called remove_offchain with onchain data sources" | ||
)); | ||
} | ||
|
||
let query = format!( | ||
"update {} set block_range = 'empty'::int4range \ | ||
where manifest_idx = $1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're dealing with integers, wouldn't
Bound::Excluded(block)
be the same asBound::Included(block+1)
? It probably won't happen but isn't really fatal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we don't use or plan to use excluded initial bounds, so we can't know what they would mean. And our usage of
lower(block_range)
assumes an included bound, so it's best to blow up if an excluded bound is ever found.