1

I am aware that this should break consensus, as one may easily start a node with different params -> end up with a different wasm bytecode, and thus be on a different network. However, inspite of that, I would like to set a pallet configuration item, in this case a Get<u32>, such that the value instead of being hardcoded in the runtime file, is fed through, maybe a host function? If that's possible, how do I define such a host function?

In code:

Currently I have :

parameter_types! {
    pub const MyNumber: u32 = 10;
}

What I would like to have :

parameter_types! {
    pub const MyNumber: u32 = host_my_number();
}

The rationale being, for test purposes, I find it inconvenient having to recompile the entire runtime file after changing a single configuration parameter. I can easily instead pass a different argument to my node, and have my runtime configured by that way instead.

1 Answer 1

1

Just define a struct yourself.

enum MyNumber {}
impl frame_support::traits::Get<u32> for MyNumber {
  fn get() -> u32 {
    host_my_number()
  }
}

impl Config for Runtime {
  type Number = MyNumber;
}
6
  • That's neat. Where do I put my host_my_number() though? :)
    – b0zero
    Feb 21, 2023 at 14:16
  • Anywhere that this code could access. Feb 21, 2023 at 14:19
  • That's actually a part of my question. I do not know how to talk to host functions from the runtime as I assume I can't have a direct dependency on my node on my runtime crate. Am I wrong about that?
    – b0zero
    Feb 21, 2023 at 14:23
  • What's your use case? Maybe you just need to write a fn random() -> u32 { Timestamp::now() as _ } here. Feb 21, 2023 at 14:28
  • As I mentioned in my question : I want to be able to make a host function, that keeps track of a number, either fed through the CLI or maybe use randomness, and from there I want to call that function in my runtime. How can I do that? I am not asking for the entire code logic, just how do I call any outer node function from my wasm runtime?
    – b0zero
    Feb 21, 2023 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.