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

feat!: unify executor data model #4597

Closed

Conversation

0x009922
Copy link
Contributor

@0x009922 0x009922 commented May 16, 2024

Reopening #4596 due to some GitHub force-push branch-recreate issues


Description

This PR solves a few problems:

  • Allows executor define its config parameters through a single ExecutorDataModel entity.
  • Unifies parameters and permission tokens to ExecutorDataModelObject trait, having a definition_id and an arbitrary JSON payload (possible to support SCALE too):
  • Parameters no longer configure Sumeragi/WASM/limits. I.e. chain wide configuration could only be set through the config file. It is temporary: this PR is a preparation for a proper implementation of chain-wide configuration: [discussion] Align configuration-related instructions with the RFC #4028
  • Removes extra PermissionTokenSchemaUpdated event. Since this action only happens during executor migration, which emits its own event ExecutorEvent::Upgraded, I also included the updated ExecutorDataModel in this event.

Linked issue

Closes #4352
Closes #3901

@0x009922 0x009922 self-assigned this May 16, 2024
@github-actions github-actions bot added the api-changes Changes in the API for client libraries label May 16, 2024
@0x009922 0x009922 force-pushed the unified-executor-data-model branch 2 times, most recently from 1520c94 to ab863c0 Compare May 17, 2024 00:08
data_model/src/executor.rs Outdated Show resolved Hide resolved
data_model/src/executor.rs Outdated Show resolved Hide resolved
data_model/src/executor.rs Outdated Show resolved Hide resolved
data_model/src/permission.rs Outdated Show resolved Hide resolved
data_model/src/executor.rs Outdated Show resolved Hide resolved
data_model/src/visit.rs Show resolved Hide resolved
data_model/src/query/mod.rs Show resolved Hide resolved
data_model/src/events/data/events.rs Outdated Show resolved Hide resolved
data_model/src/permission.rs Outdated Show resolved Hide resolved
core/src/state.rs Outdated Show resolved Hide resolved
data_model/src/events/data/events.rs Outdated Show resolved Hide resolved
data_model/src/executor.rs Show resolved Hide resolved
smart_contract/executor/src/lib.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/lib.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/permission.rs Outdated Show resolved Hide resolved
data_model/src/lib.rs Outdated Show resolved Hide resolved
data_model/src/lib.rs Outdated Show resolved Hide resolved
@0x009922 0x009922 force-pushed the unified-executor-data-model branch from 0979da0 to 67b7e71 Compare May 20, 2024 21:36
@0x009922 0x009922 marked this pull request as ready for review May 20, 2024 21:37
@0x009922 0x009922 requested a review from DCNick3 May 21, 2024 03:53
client/tests/integration/multisignature_transaction.rs Outdated Show resolved Hide resolved
client/tests/integration/upgrade.rs Outdated Show resolved Hide resolved
client/tests/integration/upgrade.rs Outdated Show resolved Hide resolved
core/src/smartcontracts/wasm.rs Show resolved Hide resolved
data_model/src/events/data/filters.rs Outdated Show resolved Hide resolved
data_model/src/permission.rs Outdated Show resolved Hide resolved
@0x009922
Copy link
Contributor Author

#4635 should be merged first. This PR is currently rebased on top of it.

@0x009922 0x009922 force-pushed the unified-executor-data-model branch from 07e10db to 3a09ab6 Compare May 22, 2024 06:52
}

/// A helper trait for polymorphism, implemented for various types
pub trait IntoJsonString {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this trait necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not necessary.

It allows all of that:

let id = "SomeId".parse().unwrap();

Permission::new(id, JsonString::from(&json!(null)));
Permission::new(id, &json!(null));
Permission::new(id, json!(null));

I find iroha_data_model to lack polymorphism in constructors a lot, actually.

data_model/src/lib.rs Outdated Show resolved Hide resolved
data_model/src/lib.rs Outdated Show resolved Hide resolved
data_model/src/lib.rs Outdated Show resolved Hide resolved
client/tests/integration/permissions.rs Outdated Show resolved Hide resolved

assert_eq!(
client
.request(client::parameter::all())?
Copy link
Contributor

Choose a reason for hiding this comment

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

this query should return core parameters as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR removes "core parameters" entirely from Iroha, temporarily. Parameter is now related only to executor-defined ones.

After merging of this PR, I will implement core parameters properly, according to #4028 (comment).

For now chain-wide parameters are only configured via config file.

client_cli/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +386 to +396
state_transaction
.world
.parameters
.get_mut()
.retain(|parameter| {
state_transaction
.world
.executor_data_model
.parameters
.contains(&parameter.id)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks as if it also removes core parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replied in other thread (in sum: there are no core parameters, yet)

Comment on lines +303 to +304
if !world.executor_data_model.parameters.contains(&parameter.id) {
return Err(FindError::Parameter(parameter.id).into());
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the parameter being set is a core parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replied in other thread.

default_executor/src/lib.rs Outdated Show resolved Hide resolved
smart_contract/executor/derive/src/permission.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/default/permissions.rs Outdated Show resolved Hide resolved
smart_contract/src/lib.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/parameter.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/permission.rs Outdated Show resolved Hide resolved
smart_contract/executor/src/lib.rs Outdated Show resolved Hide resolved
@@ -13,7 +13,7 @@ license.workspace = true
workspace = true

[dependencies]
iroha_crypto = { workspace = true }
iroha_crypto = { workspace = true, features = ["rand"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

rand is in default-features of iroha-crypto, looks like no need to add it here

Copy link
Contributor

@DCNick3 DCNick3 May 22, 2024

Choose a reason for hiding this comment

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

iroha_crypto is used in workspace without default-features (because it also gets used in wasm crates)

I think we have this setup because there were previously some bugs around this in cargo: rust-lang/cargo#11329

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it's actually not a bug, default-features = true in workspace crate makes the default features always enabled. The fix to that issue was to add a warning when you try to disable default features on a workspace dependency..

Bottom line: either the rand feature or default features as a whole must be enabled explicitly when using workspace dependencies like this (at least the ones which have default features disabled in the workspace). I think it's fine to have only rand enabled, though putting default-features = true here would also work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rand is in default-features of iroha-crypto, looks like no need to add it here

Doesn't compile with cargo check -p kagami

I think it's fine to have only rand enabled, though putting default-features = true here would also work

Not sure what is better, leaving as-is.

smart_contract/executor/src/default/permissions.rs Outdated Show resolved Hide resolved
@0x009922 0x009922 force-pushed the unified-executor-data-model branch 2 times, most recently from 76f18a9 to 09995af Compare May 23, 2024 07:00
@0x009922 0x009922 requested review from mversic and dima74 May 23, 2024 10:09
Comment on lines +28 to +51
/// Try to convert from [`PermissionObject`]
/// # Errors
/// See [`TryFromDataModelObjectError`]
fn try_from_object(object: &PermissionObject) -> Result<Self, TryFromDataModelObjectError> {
if *object.id() != <Self as Permission>::id() {
return Err(TryFromDataModelObjectError::Id(object.id().name().clone()));
}
object
.payload()
.deserialize()
.map_err(TryFromDataModelObjectError::Deserialize)
}

/// Convert into [`PermissionObject`]
fn to_object(&self) -> PermissionObject {
PermissionObject::new(
<Self as Permission>::id(),
JsonString::serialize(&self)
.expect("failed to serialize concrete data model entity; this is a bug"),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what was wrong with having implemented TryFrom and From?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 good question

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. Because:

impl<T: Parameter> TryFrom<&ParameterObject> for T {
//                 ^^^^^^^^^^^^^^^^^^^^^^^^^
//                 Only traits defined in the current crate can be implemented for arbitrary types
    type Error = TryFromDataModelObjectError;

    fn try_from(value: &ParameterObject) -> core::result::Result<Self, Self::Error> {
        todo!()
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

you can't make a blanket implementation, but you can derive for each type on #[derive(PermissionTrait)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we also need to introduce a derive macro for ParameterTrait, and I wouldn't want it just for the sake of this conversion.

0x009922 and others added 3 commits May 24, 2024 17:33
Co-authored-by: Marin Veršić <marin.versic101@gmail.com>
Co-authored-by: Nikita Strygin <dcnick3@users.noreply.github.com>
Co-authored-by: Shanin Roman <shanin1000@yandex.ru>
Co-authored-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com>
Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com>
Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com>
@0x009922 0x009922 force-pushed the unified-executor-data-model branch from 61562c1 to c1fe4ab Compare May 24, 2024 08:33
@0x009922 0x009922 requested a review from mversic May 24, 2024 08:35
Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com>
@0x009922
Copy link
Contributor Author

Drafted due to some questions related to chain-wide config design. More on that commented here: #4028 (comment)

@0x009922
Copy link
Contributor Author

Close in favor of #4658

@0x009922 0x009922 closed this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-changes Changes in the API for client libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dynamic parameter value [suggestion] Move NewParameter into Executor
5 participants