Consumers
Create, Deploy, and Invoke a Weight Adjustment Function

How to Create and Deploy a Weight-Adjustment Function

Blockless nodes run this function to determine how credible workers are

What Is a Weight-Adjustment Function?

The weight-adjustment function is used to score workers based on their revealed accuracy. It does this by altering the distribution of confidence other actors have placed in their peers. This update will typically occur by calculating the loss of a worker's inferences and then setting the new weights as a running average of those losses and the current weights.

In this page, we'll create a weight-adjustment function for our running example of building a topic for index levels. Each index level represents the relative performance of NFT collections part of the Yuga Labs brand over time.

How to Create and Deploy a Weight-Adjustment Function

To create a weight-adjustment function for your topic, follow the steps outlined in the tutorial below to create your first function on Blockless:

Blockless Quick Start Guide (opens in a new tab)

Once you have installed the Blockless CLI and created your initial sample function, you must modify it to implement the logic for assigning weights to the inferences made by registered workers on your topic.

You can see the weight adjustment function we used for the nft appraisals here (opens in a new tab).

To test your function locally you can run the following command:

bls function invoke

The output of your function needs to follow the same output as the example function above, which looks like this:

{
	"type":"weights",
	"weights": {
		"upt16ar7k93c6razqcuvxdauzdlaz352sfjp2rpj30": "0.3176470588235294",
		"upt16ar7k93c6razqcuvxdauzdlaz352sfjp2rpj31": "0.47647058823529417",
		"upt16ar7k93c6razqcuvxdauzdlaz352sfjp2rpj32": "0.029411764705882357"
	}
}

Note that the keys of the weights property are cosmos addresses of workers, and the values are the new weight values to be set.

After testing, you can deploy your function using:

bls function deploy

After deploying your function, save the function_id and the method (the name of the WASM file) to use when creating your topic.