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): Enforce entities list on offchain data sources #4147

Merged
merged 2 commits into from
Nov 11, 2022

Conversation

leoyvens
Copy link
Collaborator

@leoyvens leoyvens commented Nov 7, 2022

First part of #3770.

This enforces that file data sources can only call entity.get, entity.set and entity.remove on entity types they've declared in the entities: array in the manifest.

@leoyvens leoyvens force-pushed the leo/enforce-enitites-on-offchain branch from 417fe9f to c3e1634 Compare November 10, 2022 10:32
@@ -42,6 +42,33 @@ pub enum DataSourceCreationError {
Unknown(#[from] Error),
}

/// Which entity types a data source can read and write to.
pub enum EntityTypeAccess {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a bit more here about how this interacts with causality region based isolation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've written a more detailed comment.

fn check_entity_type_access(&self, entity_type: &EntityType) -> Result<(), HostExportError> {
match self.entity_type_access.allows(entity_type) {
true => Ok(()),
false => Err(HostExportError::Deterministic(anyhow!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this error be added as a typed error? Seems quite specific to be matched on string so I think it could be useful to have an IsolationError subtype

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could, but given that for now we don't need to match on it I think it's fine to just use the Deterministic variant.

@@ -97,6 +99,20 @@ impl<C: Blockchain> HostExports<C> {
}
}

fn check_entity_type_access(&self, entity_type: &EntityType) -> Result<(), HostExportError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

even though this is not exported I think we should a bit of context here as a comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've written a short comment and linked it to the one on enum EntityTypeAccess.


let stop_block = test_ptr(5);
let err = ctx.start_and_sync_to_error(stop_block).await;
let message = "entity type `IpfsFile1` is not on the 'entities' list for data source `File2`. \
Copy link
Contributor

@mangas mangas Nov 11, 2022

Choose a reason for hiding this comment

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

would it be enough to check if this is an isolation error somehow (left a suggestion about subtype but that might be lost). Maybe we could match an important part of the match like IpfsFile1 or somnething rather than the full message which also includes a backtrace. As it is it will be potentially broken if this function changes.

Copy link
Collaborator Author

@leoyvens leoyvens Nov 11, 2022

Choose a reason for hiding this comment

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

If the test breaks when functionality changes, that's good! Gives us a chance to check that the change was intended. Even if its for the backtrace which is not directly related to what's being tested.

@leoyvens
Copy link
Collaborator Author

@mangas thanks for the review! I've addressed the comments.

@leoyvens leoyvens merged commit a8d184c into master Nov 11, 2022
@leoyvens leoyvens deleted the leo/enforce-enitites-on-offchain branch November 11, 2022 15:09
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.

2 participants