Skip to content

Add support for custom action #483

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

Merged
merged 6 commits into from
Jul 26, 2018
Merged

Conversation

remagpie
Copy link
Contributor

No description provided.

@remagpie remagpie requested review from sgkim126 and kseo July 25, 2018 08:34
impl CacheableItem for Bytes {
type Address = H256;
fn is_null(&self) -> bool {
self.len() == 0

This comment was marked as resolved.

@@ -66,17 +68,17 @@ impl fmt::Display for ChainType {
}

impl ChainType {
pub fn spec<'a>(&self) -> Result<Spec, String> {
pub fn spec<'a>(&self, handlers: &[Arc<ActionHandler>]) -> Result<Spec, String> {

This comment was marked as resolved.

@@ -350,7 +373,7 @@ impl Spec {
}

/// Load from JSON object.
fn load_from(s: cjson::spec::Spec) -> Result<Spec, Error> {
fn load_from(s: cjson::spec::Spec, handlers: &[Arc<ActionHandler>]) -> Result<Spec, Error> {

This comment was marked as resolved.

Ok(())
}

fn is_target(&self, bytes: &Bytes) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about remove this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need some sort of function that only checks if provided byte array is valid one that this handler can decode, without execution. It's used for blocking invalid parcels in sync and rpc.
Since execute requires TopLevelState as argument, I think it's not a good idea to merge these.

}

/// `bytes` must be valid encoding of HitAction
fn execute(&self, bytes: &Bytes, state: &mut TopLevelState) -> StateResult<Outcome> {
Copy link
Contributor

Choose a reason for hiding this comment

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

and make this function return Option<StateResult<Outcome>>?

@@ -410,6 +410,15 @@ impl TopLevelState {
error: None,
})
}
Action::Custom(bytes) => {
let handlers = self.db.custom_handlers().to_vec();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you convert it do Vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

custom_handlers returns reference, so handlers borrows self.
self is used as mutable reference in later code, so lifetime conflicts there.
So I wanted to clone handlers, and I thought to_vec would be a good solution.

@@ -449,6 +452,10 @@ impl BlockChainClient for Client {
})
})
}

fn custom_handlers(&self) -> Vec<Arc<ActionHandler>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why noy fn custom_handlers(&self) -> &[Arc<ActionHandler>>] {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we return reference, then lock over state_db won't be released while holding that reference.
I thought it would be simpler to return a fresh copy of the vector and release the lock earlier instead of holding the lock.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. I see.

@remagpie remagpie force-pushed the custom-action branch 2 times, most recently from 952e821 to 33008a3 Compare July 26, 2018 07:51
@remagpie remagpie merged commit 47f0014 into CodeChain-io:master Jul 26, 2018
@remagpie remagpie deleted the custom-action branch July 30, 2018 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants