Validate Node
The validate node function is passed to a helper function called validateAndVoteOnNodes where it will be run for each node that has made a submission. The validate node function will return true if the node is valid. The validate node function will be given the following params to validate a node:
K2 Submission data
Node Service URL (if present)
Types of Audits
Checking signed and uploaded data on IPFS using a CID submitted to K2
Checking status of API endpoints on node
Checking proof stored on nodes provided API endpoint
Example
One of the most common methods of validating other nodes is calling the other nodes "/proofs" endpoint in order to validate the data that they are providing. This is a simplified example of how an API endpoint validation would work:
// Executable File
validateNode(node) {
axios({
method: 'get',
url: `${node.url}/proofs`
}).then(async (response) => {
if (
response.data &&
response.data == "EXAMPLE CORRECT DATA"
) {
return true;
} else {
return false;
}
}).catch(err => {
return false;
})
}
// Abbreviated executable function
async function execute() {
cronArray.push(
cron.schedule(
'*/1 * * * *',
() => { namespace.validateAndVoteOnNodes(validateNode) }
));
return cronArray;
}For reference, this is what the validateAndVoteOnNodes function does
Last updated