Implementation Instructions

Authors: BlockScience and SDF, July 2023

The implementation of NG relies on two main premises - refactoring existing Neurons and creating new ones.

A PoC implementation in Rust for Soroban by Alejo Mendoza, Karol Bisztyga and Mateusz Kowalski is located in the voting-poc GitHub repository. It implements the Neural Governance, Quorum Delegation and the Trust Graph Bonus governance modules.

A technical summary for learnings when implementing an MVP version of Neural Quorum Governance on SCF can be found on a post by Karol Bisztyga: SCF Voting Mechanism Implementation.

1) Decide on Neurons to be included

pub fn add_neuron( &mut self, layer_id: u32, // specifies the layer neuron: NeuronType // specifies the neuron )

  • The example implementations provide various Neurons as examples, among them:

    • Reputation through badges

    • Past Voting History

    • Trust Bonus

    • Additionally, new Neurons can be created (expanded on below).

2) Decide on aggregators to be included

pub fn set_layer_aggregator( &mut self, layer_id: u32, // specifies a layer ID aggregator: LayerAggregator, // specifies the aggregator to use )

  • Each layer of Neurons has their own aggregator and can be arbitrarly set per layer. Standard aggregators include Sum, Product and Mean.

3) Decide on the Neural Layering (CHECK ordering)

pub fn add_layer( &mut self, env: Env )

pub fn remove_layer( &mut self, layer_id: u32 )

  • Adding and removing layers allows to set aggregators and neurons correctly.

  • While Neurons within a layer are independent of ordering, deciding the order of layers changes the input a layer starts with, with it changing the outputs.

4) Decide on the Neuron weights & parameters (if applicable)

pub fn set_neuron_weight( &mut self, layer_id: u32, // specifies the layer neuron: NeuronType, // specifies the Neuron weight: DecimalNumber, // sets the weight )

  • Each Neuron can be weighted independently through their respective weight function. Some Neurons might also include parameters to adjust, such as Quorum Sizes and tresholds for Quorum Delegation.

5) Implement oracle functions if needed

  • Some Neurons require as input outside data, such as badges collected or past voting history.

6) Implement base module

  • Neural Governance requires structure around the layering and Neurons. Receiving the votes, feeding them through the mechanism and then tallying the votes needs to be set up correctly. An example for instructions to set this up can be found here.

7) Implement new neurons

Additionally, any new Neurons can be developed and included (example instructions from here):

  • Add a new file to the neurons folder - the new Neuron has to have oracle_function, the easiest way to go is to just copy the contents of the dummy neuron

  • fill the oracle_function of the new neuron with your custom logic

  • add your Neuron module to the mod file

  • in types

    • add a field of your Neuron to the NeuronType enum

    • add a case of your Neuron to the neuron_type_from_str function

  • add a case for your Neuron in the execute_layer function in the layer file

8) Execute Neural Governance:

pub fn execute_neural_governance( &self, env: Env, voter_id: String, // specifies the voter_id for which NG is executed submission_id: String, // specifies the project for which NG is executed )

Last updated