github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/model/chunks/executionDataFaults.go (about)

     1  package chunks
     2  
     3  // This file contains the ChunkFaultErrors returned during chunk verification of ExecutionData.
     4  
     5  import (
     6  	"fmt"
     7  
     8  	"github.com/ipfs/go-cid"
     9  
    10  	"github.com/onflow/flow-go/model/flow"
    11  )
    12  
    13  // CFExecutionDataBlockIDMismatch is returned when the block ID contained in the execution data
    14  // root is different from chunk's block ID
    15  type CFExecutionDataBlockIDMismatch struct {
    16  	chunkIndex               uint64          // chunk's index
    17  	execResID                flow.Identifier // chunk's ExecutionResult identifier
    18  	executionDataRootBlockID flow.Identifier // blockID from chunk's ExecutionDataRoot
    19  	chunkBlockID             flow.Identifier // chunk's blockID
    20  }
    21  
    22  var _ ChunkFaultError = (*CFExecutionDataBlockIDMismatch)(nil)
    23  
    24  func (cf CFExecutionDataBlockIDMismatch) String() string {
    25  	return fmt.Sprintf("execution data root's block ID (%s) is different than chunk's block ID (%s) for chunk %d with result ID %s",
    26  		cf.executionDataRootBlockID, cf.chunkBlockID, cf.chunkIndex, cf.execResID.String())
    27  }
    28  
    29  func (cf CFExecutionDataBlockIDMismatch) Error() string {
    30  	return cf.String()
    31  }
    32  
    33  // ChunkIndex returns chunk index of the faulty chunk
    34  func (cf CFExecutionDataBlockIDMismatch) ChunkIndex() uint64 {
    35  	return cf.chunkIndex
    36  }
    37  
    38  // ExecutionResultID returns the execution result identifier including the faulty chunk
    39  func (cf CFExecutionDataBlockIDMismatch) ExecutionResultID() flow.Identifier {
    40  	return cf.execResID
    41  }
    42  
    43  // NewCFExecutionDataBlockIDMismatch creates a new instance of Chunk Fault (ExecutionDataBlockIDMismatch)
    44  func NewCFExecutionDataBlockIDMismatch(
    45  	executionDataRootBlockID flow.Identifier,
    46  	chunkBlockID flow.Identifier,
    47  	chInx uint64,
    48  	execResID flow.Identifier,
    49  ) *CFExecutionDataBlockIDMismatch {
    50  	return &CFExecutionDataBlockIDMismatch{
    51  		chunkIndex:               chInx,
    52  		execResID:                execResID,
    53  		executionDataRootBlockID: executionDataRootBlockID,
    54  		chunkBlockID:             chunkBlockID,
    55  	}
    56  }
    57  
    58  // CFExecutionDataChunksLengthMismatch is returned when execution data chunks list has different length than number of chunks for a block
    59  type CFExecutionDataChunksLengthMismatch struct {
    60  	chunkIndex                     uint64          // chunk's index
    61  	execResID                      flow.Identifier // chunk's ExecutionResult identifier
    62  	executionDataRootChunkLength   int             // number of ChunkExecutionDataIDs in ExecutionDataRoot
    63  	executionResultChunkListLength int             // number of chunks in ExecutionResult
    64  }
    65  
    66  var _ ChunkFaultError = (*CFExecutionDataChunksLengthMismatch)(nil)
    67  
    68  func (cf CFExecutionDataChunksLengthMismatch) String() string {
    69  	return fmt.Sprintf("execution data root chunk length (%d) is different than execution result chunk list length (%d) for chunk %d with result ID %s",
    70  		cf.executionDataRootChunkLength, cf.executionResultChunkListLength, cf.chunkIndex, cf.execResID.String())
    71  }
    72  
    73  func (cf CFExecutionDataChunksLengthMismatch) Error() string {
    74  	return cf.String()
    75  }
    76  
    77  // ChunkIndex returns chunk index of the faulty chunk
    78  func (cf CFExecutionDataChunksLengthMismatch) ChunkIndex() uint64 {
    79  	return cf.chunkIndex
    80  }
    81  
    82  // ExecutionResultID returns the execution result identifier including the faulty chunk
    83  func (cf CFExecutionDataChunksLengthMismatch) ExecutionResultID() flow.Identifier {
    84  	return cf.execResID
    85  }
    86  
    87  // NewCFExecutionDataChunksLengthMismatch creates a new instance of Chunk Fault (ExecutionDataBlockIDMismatch)
    88  func NewCFExecutionDataChunksLengthMismatch(
    89  	executionDataRootChunkLength int,
    90  	executionResultChunkListLength int,
    91  	chInx uint64,
    92  	execResID flow.Identifier,
    93  ) *CFExecutionDataChunksLengthMismatch {
    94  	return &CFExecutionDataChunksLengthMismatch{
    95  		chunkIndex:                     chInx,
    96  		execResID:                      execResID,
    97  		executionDataRootChunkLength:   executionDataRootChunkLength,
    98  		executionResultChunkListLength: executionResultChunkListLength,
    99  	}
   100  }
   101  
   102  // CFExecutionDataInvalidChunkCID is returned when execution data chunk's CID is different from computed
   103  type CFExecutionDataInvalidChunkCID struct {
   104  	chunkIndex                uint64          // chunk's index
   105  	execResID                 flow.Identifier // chunk's ExecutionResult identifier
   106  	executionDataRootChunkCID cid.Cid         // ExecutionDataRoot's CID for the chunk
   107  	computedChunkCID          cid.Cid         // computed CID for the chunk
   108  }
   109  
   110  var _ ChunkFaultError = (*CFExecutionDataInvalidChunkCID)(nil)
   111  
   112  func (cf CFExecutionDataInvalidChunkCID) String() string {
   113  	return fmt.Sprintf("execution data chunk CID (%s) is different than computed (%s) for chunk %d with result ID %s",
   114  		cf.executionDataRootChunkCID, cf.computedChunkCID, cf.chunkIndex, cf.execResID.String())
   115  }
   116  
   117  func (cf CFExecutionDataInvalidChunkCID) Error() string {
   118  	return cf.String()
   119  }
   120  
   121  // ChunkIndex returns chunk index of the faulty chunk
   122  func (cf CFExecutionDataInvalidChunkCID) ChunkIndex() uint64 {
   123  	return cf.chunkIndex
   124  }
   125  
   126  // ExecutionResultID returns the execution result identifier including the faulty chunk
   127  func (cf CFExecutionDataInvalidChunkCID) ExecutionResultID() flow.Identifier {
   128  	return cf.execResID
   129  }
   130  
   131  // NewCFExecutionDataInvalidChunkCID creates a new instance of Chunk Fault (NewCFExecutionDataInvalidChunkCID)
   132  func NewCFExecutionDataInvalidChunkCID(
   133  	executionDataRootChunkCID cid.Cid,
   134  	computedChunkCID cid.Cid,
   135  	chInx uint64,
   136  	execResID flow.Identifier,
   137  ) *CFExecutionDataInvalidChunkCID {
   138  	return &CFExecutionDataInvalidChunkCID{
   139  		chunkIndex:                chInx,
   140  		execResID:                 execResID,
   141  		executionDataRootChunkCID: executionDataRootChunkCID,
   142  		computedChunkCID:          computedChunkCID,
   143  	}
   144  }
   145  
   146  // CFInvalidExecutionDataID is returned when ExecutionResult's ExecutionDataID is different from computed
   147  type CFInvalidExecutionDataID struct {
   148  	chunkIndex              uint64          // chunk's index
   149  	execResID               flow.Identifier // chunk's ExecutionResult identifier
   150  	erExecutionDataID       flow.Identifier // ExecutionResult's ExecutionDataID
   151  	computedExecutionDataID flow.Identifier // computed ExecutionDataID
   152  }
   153  
   154  var _ ChunkFaultError = (*CFInvalidExecutionDataID)(nil)
   155  
   156  func (cf CFInvalidExecutionDataID) String() string {
   157  	return fmt.Sprintf("execution data ID (%s) is different than computed (%s) for chunk %d with result ID %s",
   158  		cf.erExecutionDataID, cf.computedExecutionDataID, cf.chunkIndex, cf.execResID.String())
   159  }
   160  
   161  func (cf CFInvalidExecutionDataID) Error() string {
   162  	return cf.String()
   163  }
   164  
   165  // ChunkIndex returns chunk index of the faulty chunk
   166  func (cf CFInvalidExecutionDataID) ChunkIndex() uint64 {
   167  	return cf.chunkIndex
   168  }
   169  
   170  // ExecutionResultID returns the execution result identifier including the faulty chunk
   171  func (cf CFInvalidExecutionDataID) ExecutionResultID() flow.Identifier {
   172  	return cf.execResID
   173  }
   174  
   175  // NewCFInvalidExecutionDataID creates a new instance of Chunk Fault (CFInvalidExecutionDataID)
   176  func NewCFInvalidExecutionDataID(
   177  	erExecutionDataID flow.Identifier,
   178  	computedExecutionDataID flow.Identifier,
   179  	chInx uint64,
   180  	execResID flow.Identifier,
   181  ) *CFInvalidExecutionDataID {
   182  	return &CFInvalidExecutionDataID{
   183  		chunkIndex:              chInx,
   184  		execResID:               execResID,
   185  		erExecutionDataID:       erExecutionDataID,
   186  		computedExecutionDataID: computedExecutionDataID,
   187  	}
   188  }