Skip to content

processing/processing_validation_core.hpp

Header file of core implementation of processing task results validation. More...

Namespaces

Name
sgns
sgns::processing

Classes

Name
class sgns::processing::ProcessingValidationCore

Functions

Name
OUTCOME_HPP_DECLARE_ERROR_2(sgns::processing , ProcessingValidationCore::Error )
Macro for declaring error handling in the IBasicProof class.

Detailed Description

Header file of core implementation of processing task results validation.

Date: 2022-05-08 creativeid00

Note: This was mostly rewritten by Henrique A. Klein ([email protected]) and Justin Church ([email protected])

Functions Documentation

function OUTCOME_HPP_DECLARE_ERROR_2

OUTCOME_HPP_DECLARE_ERROR_2(
    sgns::processing ,
    ProcessingValidationCore::Error 
)

Macro for declaring error handling in the IBasicProof class.

Source code

#ifndef SUPERGENIUS_PROCESSING_VALIDATION_CORE_HPP
#define SUPERGENIUS_PROCESSING_VALIDATION_CORE_HPP

#include <map>
#include <string>
#include <set>
#include <vector>
#include <cstdint>
#include <functional>

#include "outcome/outcome.hpp"
#include "base/logger.hpp"
#include "processing/proto/SGProcessing.pb.h"
#include "Parameter.hpp"

namespace sgns::processing
{
    class ProcessingValidationCore
    {
    public:
        enum class Error
        {
            NO_RESULTS_FOR_SUBTASK = 0,     
            WRONG_RESULT_HASHES_LENGTH,     
            DUPLICATE_CHUNK_RESULT_HASH,    
            EMPTY_CHUNK_RESULT_HASH,        
            MISSING_CHUNK_RESULT,           
            INVALID_CHUNK_RESULT_HASH,      
            SUBTASK_ID_MISMATCH,            
            INVALID_RESULTS_BATCH,          
            CHUNK_HASH_MISMATCH_UNTOLERATED, 
            INVALID_PAYOUT_METADATA          
        };

        static constexpr uint64_t DEVELOPER_CUT_SCALE = 1000000;

        static constexpr size_t TOKEN_ID_BYTES = 32;

        ProcessingValidationCore() = default;

        outcome::result<void> ValidateResults(
            const SGProcessing::SubTaskCollection                    &subTasks,
            const std::map<std::string, SGProcessing::SubTaskResult> &results,
            std::set<std::string>                                    &invalidSubTaskIds,
            const std::vector<sgns::Parameter>                       *jobParameters   = nullptr,
            std::function<outcome::result<std::vector<uint8_t>>( const std::string &outputUri )> fetchOutputData =
                nullptr );

        outcome::result<void> ValidateIndividualResult( const SGProcessing::SubTask       &subTask,
                                                        const SGProcessing::SubTaskResult &result ) const;

    private:
        struct ChunkContribution
        {
            std::string hashBytes;
            int         chunkIdx               = 0;
            int         totalChunksForSubtask   = 0;
        };

        outcome::result<void> CheckSubTaskResultHashes(
            const SGProcessing::SubTask                                            &subTask,
            const std::map<std::string, std::map<std::string, ChunkContribution>>  &chunksBySubtask ) const;

        bool AttemptToleranceFallback(
            const std::map<std::string, ChunkContribution>                                  &contributions,
            const std::map<std::string, SGProcessing::SubTaskResult>                         &results,
            const std::vector<sgns::Parameter>                                               *jobParameters,
            const std::function<outcome::result<std::vector<uint8_t>>( const std::string & )> &fetchOutputData )
            const;

        base::Logger m_logger = base::createLogger( "ProcessingValidationCore" );
    };
}

OUTCOME_HPP_DECLARE_ERROR_2( sgns::processing, ProcessingValidationCore::Error );

#endif // SUPERGENIUS_PROCESSING_VALIDATION_CORE_HPP

Updated on 2026-09-17 at 06:29:16 +0000