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

Offchain worker custom extension not working #1671

Closed
2 tasks done
Congyuwang opened this issue Sep 22, 2023 · 1 comment · Fixed by #1719
Closed
2 tasks done

Offchain worker custom extension not working #1671

Congyuwang opened this issue Sep 22, 2023 · 1 comment · Fixed by #1719
Labels
I2-bug The node fails to follow expected behavior. I10-unconfirmed Issue might be valid, but it's not yet known.

Comments

@Congyuwang
Copy link

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

Offchain worker configuration allows passing custom extensions in node/src/service.rs(as in substrate-template repo):

custom_extensions: Box<dyn Fn(Block::Hash) -> Vec<Box<dyn Extension>> + Send>,

which are later registered:

let custom_extensions = (*self.custom_extensions)(hash);

custom_extensions.into_iter().for_each(|ext| runtime.register_extension(ext));

However, since extensions are registered using TypeId, they would overwrite each other since they are all of the same type Box<dyn Extension>.

fn register_extension<T: Extension>(&mut self, ext: T) -> Result<(), Error> {
self.register_extension_with_type_id(TypeId::of::<T>(), Box::new(ext))
}

Moreover, I wouldn't be able to retrieve them later in host function using self.extension::<MyExtension>() since the registered TypeId is a generic Box<dyn Extension>.type_id().

Calling self.extension::<MyExtension>().expect("should be registered") just gets panic.

Steps to reproduce

No response

@Congyuwang Congyuwang added I10-unconfirmed Issue might be valid, but it's not yet known. I2-bug The node fails to follow expected behavior. labels Sep 22, 2023
@Congyuwang
Copy link
Author

I think custom extensions should perhaps pass something like:

custom_extensions: Box<dyn Fn(Block::Hash) -> Extensions>

instead, and somehow merge the Extensions to the extensions of the environment.

skunert added a commit that referenced this issue Sep 29, 2023
Closes #1671 

Adds a `type_id` function to the `Extension` trait, allowing to properly store an retrieve
boxed `Extensions`.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this issue Mar 25, 2024
…ytech#1719)

Closes paritytech#1671 

Adds a `type_id` function to the `Extension` trait, allowing to properly store an retrieve
boxed `Extensions`.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The node fails to follow expected behavior. I10-unconfirmed Issue might be valid, but it's not yet known.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant