github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/state/services.go (about)

     1  package state
     2  
     3  import (
     4  	"github.com/badrootd/celestia-core/types"
     5  )
     6  
     7  //------------------------------------------------------
     8  // blockchain services types
     9  // NOTE: Interfaces used by RPC must be thread safe!
    10  //------------------------------------------------------
    11  
    12  //------------------------------------------------------
    13  // blockstore
    14  
    15  //go:generate ../scripts/mockery_generate.sh BlockStore
    16  
    17  // BlockStore defines the interface used by the ConsensusState.
    18  type BlockStore interface {
    19  	Base() int64
    20  	Height() int64
    21  	Size() int64
    22  
    23  	LoadBaseMeta() *types.BlockMeta
    24  	LoadBlockMeta(height int64) *types.BlockMeta
    25  	LoadBlock(height int64) *types.Block
    26  
    27  	SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
    28  
    29  	PruneBlocks(height int64) (uint64, error)
    30  
    31  	LoadBlockByHash(hash []byte) *types.Block
    32  	LoadBlockMetaByHash(hash []byte) *types.BlockMeta
    33  	LoadBlockPart(height int64, index int) *types.Part
    34  
    35  	LoadBlockCommit(height int64) *types.Commit
    36  	LoadSeenCommit(height int64) *types.Commit
    37  
    38  	DeleteLatestBlock() error
    39  }
    40  
    41  //-----------------------------------------------------------------------------
    42  // evidence pool
    43  
    44  //go:generate ../scripts/mockery_generate.sh EvidencePool
    45  
    46  // EvidencePool defines the EvidencePool interface used by State.
    47  type EvidencePool interface {
    48  	PendingEvidence(maxBytes int64) (ev []types.Evidence, size int64)
    49  	AddEvidence(types.Evidence) error
    50  	Update(State, types.EvidenceList)
    51  	CheckEvidence(types.EvidenceList) error
    52  }
    53  
    54  // EmptyEvidencePool is an empty implementation of EvidencePool, useful for testing. It also complies
    55  // to the consensus evidence pool interface
    56  type EmptyEvidencePool struct{}
    57  
    58  func (EmptyEvidencePool) PendingEvidence(maxBytes int64) (ev []types.Evidence, size int64) {
    59  	return nil, 0
    60  }
    61  func (EmptyEvidencePool) AddEvidence(types.Evidence) error                { return nil }
    62  func (EmptyEvidencePool) Update(State, types.EvidenceList)                {}
    63  func (EmptyEvidencePool) CheckEvidence(evList types.EvidenceList) error   { return nil }
    64  func (EmptyEvidencePool) ReportConflictingVotes(voteA, voteB *types.Vote) {}