github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/consensus/bor/errors.go (about)

     1  package bor
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/ethereum/go-ethereum/consensus/bor/clerk"
     8  )
     9  
    10  type MaxCheckpointLengthExceededError struct {
    11  	Start uint64
    12  	End   uint64
    13  }
    14  
    15  func (e *MaxCheckpointLengthExceededError) Error() string {
    16  	return fmt.Sprintf(
    17  		"Start: %d and end block: %d exceed max allowed checkpoint length: %d",
    18  		e.Start,
    19  		e.End,
    20  		MaxCheckpointLength,
    21  	)
    22  }
    23  
    24  // MismatchingValidatorsError is returned if a last block in sprint contains a
    25  // list of validators different from the one that local node calculated
    26  type MismatchingValidatorsError struct {
    27  	Number             uint64
    28  	ValidatorSetSnap   []byte
    29  	ValidatorSetHeader []byte
    30  }
    31  
    32  func (e *MismatchingValidatorsError) Error() string {
    33  	return fmt.Sprintf(
    34  		"Mismatching validators at block %d\nValidatorBytes from snapshot: 0x%x\nValidatorBytes in Header: 0x%x\n",
    35  		e.Number,
    36  		e.ValidatorSetSnap,
    37  		e.ValidatorSetHeader,
    38  	)
    39  }
    40  
    41  type BlockTooSoonError struct {
    42  	Number     uint64
    43  	Succession int
    44  }
    45  
    46  func (e *BlockTooSoonError) Error() string {
    47  	return fmt.Sprintf(
    48  		"Block %d was created too soon. Signer turn-ness number is %d\n",
    49  		e.Number,
    50  		e.Succession,
    51  	)
    52  }
    53  
    54  // UnauthorizedProposerError is returned if a header is [being] signed by an unauthorized entity.
    55  type UnauthorizedProposerError struct {
    56  	Number   uint64
    57  	Proposer []byte
    58  }
    59  
    60  func (e *UnauthorizedProposerError) Error() string {
    61  	return fmt.Sprintf(
    62  		"Proposer 0x%x is not a part of the producer set at block %d",
    63  		e.Proposer,
    64  		e.Number,
    65  	)
    66  }
    67  
    68  // UnauthorizedSignerError is returned if a header is [being] signed by an unauthorized entity.
    69  type UnauthorizedSignerError struct {
    70  	Number uint64
    71  	Signer []byte
    72  }
    73  
    74  func (e *UnauthorizedSignerError) Error() string {
    75  	return fmt.Sprintf(
    76  		"Signer 0x%x is not a part of the producer set at block %d",
    77  		e.Signer,
    78  		e.Number,
    79  	)
    80  }
    81  
    82  // WrongDifficultyError is returned if the difficulty of a block doesn't match the
    83  // turn of the signer.
    84  type WrongDifficultyError struct {
    85  	Number   uint64
    86  	Expected uint64
    87  	Actual   uint64
    88  	Signer   []byte
    89  }
    90  
    91  func (e *WrongDifficultyError) Error() string {
    92  	return fmt.Sprintf(
    93  		"Wrong difficulty at block %d, expected: %d, actual %d. Signer was %x\n",
    94  		e.Number,
    95  		e.Expected,
    96  		e.Actual,
    97  		e.Signer,
    98  	)
    99  }
   100  
   101  type InvalidStateReceivedError struct {
   102  	Number      uint64
   103  	LastStateID uint64
   104  	To          *time.Time
   105  	Event       *clerk.EventRecordWithTime
   106  }
   107  
   108  func (e *InvalidStateReceivedError) Error() string {
   109  	return fmt.Sprintf(
   110  		"Received invalid event %v at block %d. Requested events until %s. Last state id was %d",
   111  		e.Event,
   112  		e.Number,
   113  		e.To.Format(time.RFC3339),
   114  		e.LastStateID,
   115  	)
   116  }