# SNS: ExecuteGenericNervousSystemFunction

**URL:** <https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475>\
**Category:** Developers\
**Tags:** sns\
**Created:** [February 14, 2023, 1:14am UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475 "2023-02-14T01:14:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 14, 2023, 1:14am UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/1 "2023-02-14T01:14:35Z")

</div>

~~(Please ignore the spaces in the title; Discourse wouldn’t let me post this because “one or more words is very long”)~~

* * *

I’m looking for some documentation or information on the `ExecuteGenericNervousSystemFunction` in the SNS.

In particular, I couldn’t find anything about the expected return type of the target method (previously specified in the `target_method_name` field of `GenericNervousSystemFunction` via `AddGenericNervousSystemFunction`)

I suspect it’s a variant isomorphic to `Result` in order to communicate to the caller whether the operation was successful or not.

Something like `variant { Ok : vec nat8; Err : vec nat8 }`?

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 14, 2023, 8:18pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/2 "2023-02-14T20:18:57Z")

</div>

Or is this effectively a `oneway` call?

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [February 15, 2023, 3:14pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/3 "2023-02-15T15:14:54Z")

</div>

You can find more details on executing generic functions in paragraph 7. of the SNS testflight [docs](https://internetcomputer.org/docs/current/developer-docs/integrations/sns/get-sns/testflight).

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 15, 2023, 5:38pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/4 "2023-02-15T17:38:14Z")

</div>

> The validation function must return a value of the Candid type `variant { Ok: text; Err: text; }`, e.g., `Result<String, String>` in Rust. If the validation function returns `Ok(rendering)`, then the proposal is submitted and the `rendering` string is included into the proposal. Otherwise, the proposal submission fails.
> 
> The execution function gets the same binary payload as passed to the validation function and its code gets executed if the proposal is accepted. It should not return any value because this return value is ignored.

I think it would be useful for the execution function to have the same return type, and for it not to be ignored so that voters can be informed that whether it executed successfully or not.

Is this forum the right place to have that discussion? Who should be involved?

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [February 16, 2023, 9:53am UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/5 "2023-02-16T09:53:19Z")

</div>

There’s already a TODO in the [code](https://github.com/dfinity/ic/blob/d14361f9939baaeb899106b874851ad4a0ce928b/rs/sns/governance/src/canister_control.rs#L281) to deserialize the reply and check if the execution was successful. I’ll follow up with the NNS team to get an estimate when this could be implemented.

Nevertheless, already now, the proposal execution would fail if the execution method explicitly traps (e.g., by calling `ic_cdk::trap("error mesage")`). In this case, the SNS proposal would have `executed_timestamp_seconds = 0 : nat64` and

```auto
        failure_reason = opt record {
          error_message = "Canister method call to execute proposal failed: (Some(5), \"IC0503: Canister s55qq-oqaaa-aaaaa-aaakq-cai trapped explicitly: error message\")";
          error_type = 11 : int32;
        };

```

Please note that `ic_cdk::trap("error message")` is different from `return Err("error message")` because the former rolls back any state changes performed before trapping.

---

<div class="post-metadata">

**Author:** ![msumme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/msumme/32/8646_2.png) [@msumme](https://forum.dfinity.org/u/msumme)\
**Post date:** [February 16, 2023, 4:42pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/6 "2023-02-16T16:42:12Z")

</div>

Yes, currently it is effectively a 1-way call, the only exception being what @mraszyk pointed out - if your function traps, it will not be marked as successful. There is the TODO item he mentioned, which would have the same return type as the validation function has, unless we find something better that can be done there.

There’s not a finalized design, and it’s also possible we would do something else, or leave it to the developers to add another way to get debug information.

One possibility might be that we just store the bytes of the response and let someone who knows the types read it back out of the executed proposal if the response is something needed, which would provide richer functionality at the cost of requiring the SNS operators to make some tooling.

If you have any suggestions, this forum post is a good place to make them. We don’t have a finalized design that I am aware of, which is why that was left as a TODO item.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 16, 2023, 6:06pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/7 "2023-02-16T18:06:47Z")

</div>

> [@msumme](#):
>
> One possibility might be that we just store the bytes of the response and let someone who knows the types read it back out of the executed proposal if the response is something needed, which would provide richer functionality at the cost of requiring the SNS operators to make some tooling.
> 
> If you have any suggestions, this forum post is a good place to make them.

I think what you described would be the most flexible.

> [@paulyoung](#):
>
> Something like `variant { Ok : vec nat8; Err : vec nat8 }`?

---

<div class="post-metadata">

**Author:** ![jamesbeadle](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jamesbeadle/32/10110_2.png) [@jamesbeadle](https://forum.dfinity.org/u/jamesbeadle)\
**Post date:** [September 20, 2023, 7:35pm UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/8 "2023-09-20T19:35:00Z")

</div>

> [@paulyoung](#):
>
> Ok(rendering)

Hi, do you know where I might find the SNS testflight docs, the link has expired.

Thanks,  
James

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [September 21, 2023, 6:30am UTC](https://forum.dfinity.org/t/sns-executegenericnervoussystemfunction/18475/9 "2023-09-21T06:30:03Z")

</div>

Here’s the up-to-date link: [Testing on mainnet (SNS testflight) | Internet Computer](https://internetcomputer.org/docs/current/developer-docs/integrations/sns/testing/testing-on-mainnet)
