-
Notifications
You must be signed in to change notification settings - Fork 279
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
feat!: unify executor data model #4597
Conversation
1520c94
to
ab863c0
Compare
67af3ba
to
0979da0
Compare
0979da0
to
67b7e71
Compare
client/tests/integration/smartcontracts/executor_with_custom_parameter/src/lib.rs
Outdated
Show resolved
Hide resolved
248973e
to
07e10db
Compare
#4635 should be merged first. This PR is currently rebased on top of it. |
07e10db
to
3a09ab6
Compare
} | ||
|
||
/// A helper trait for polymorphism, implemented for various types | ||
pub trait IntoJsonString { |
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.
why is this trait necessary?
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.
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.
|
||
assert_eq!( | ||
client | ||
.request(client::parameter::all())? |
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.
this query should return core parameters as well
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.
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/tests/integration/smartcontracts/executor_with_custom_parameter/src/lib.rs
Outdated
Show resolved
Hide resolved
client/tests/integration/smartcontracts/executor_remove_permission/src/lib.rs
Outdated
Show resolved
Hide resolved
client/tests/integration/smartcontracts/executor_with_custom_permission/src/lib.rs
Outdated
Show resolved
Hide resolved
state_transaction | ||
.world | ||
.parameters | ||
.get_mut() | ||
.retain(|parameter| { | ||
state_transaction | ||
.world | ||
.executor_data_model | ||
.parameters | ||
.contains(¶meter.id) | ||
}); |
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.
this looks as if it also removes core parameters?
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.
Replied in other thread (in sum: there are no core parameters, yet)
if !world.executor_data_model.parameters.contains(¶meter.id) { | ||
return Err(FindError::Parameter(parameter.id).into()); |
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.
what if the parameter being set is a core parameter?
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.
Replied in other thread.
@@ -13,7 +13,7 @@ license.workspace = true | |||
workspace = true | |||
|
|||
[dependencies] | |||
iroha_crypto = { workspace = true } | |||
iroha_crypto = { workspace = true, features = ["rand"] } |
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.
rand
is in default-features of iroha-crypto
, looks like no need to add it here
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.
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
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.
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
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.
rand
is in default-features ofiroha-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 puttingdefault-features = true
here would also work
Not sure what is better, leaving as-is.
76f18a9
to
09995af
Compare
/// 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"), | ||
) | ||
} |
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.
what was wrong with having implemented TryFrom
and From
?
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.
🤔 good question
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.
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!()
}
}
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.
you can't make a blanket implementation, but you can derive for each type on #[derive(PermissionTrait)]
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.
Then we also need to introduce a derive macro for ParameterTrait
, and I wouldn't want it just for the sake of this conversion.
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>
61562c1
to
c1fe4ab
Compare
Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com>
Drafted due to some questions related to chain-wide config design. More on that commented here: #4028 (comment) |
Close in favor of #4658 |
Reopening #4596 due to some GitHub force-push branch-recreate issues
Description
This PR solves a few problems:
ExecutorDataModel
entity.ExecutorDataModelObject
trait, having adefinition_id
and an arbitrary JSONpayload
(possible to support SCALE too):NewParameter
into Executor #3901PermissionTokenSchemaUpdated
event. Since this action only happens during executor migration, which emits its own eventExecutorEvent::Upgraded
, I also included the updatedExecutorDataModel
in this event.Linked issue
Closes #4352
Closes #3901