blockscanner

package
v1.109.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const MockErrorBlockHeight = 1024
View Source
const (
	ScanPosKey = "blockscanpos"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Height int64
	Txs    []string
}

type BlockScanStatus

type BlockScanStatus byte

BlockScanStatus

const (
	Processing BlockScanStatus = iota
	Failed
	Finished
	NotStarted
)

type BlockScanner

type BlockScanner struct {
	// contains filtered or unexported fields
}

BlockScanner is used to discover block height

func NewBlockScanner

func NewBlockScanner(cfg config.BifrostBlockScannerConfiguration, scannerStorage ScannerStorage, m *metrics.Metrics, mayachainBridge mayaclient.MayachainBridge, chainScanner BlockScannerFetcher) (*BlockScanner, error)

NewBlockScanner create a new instance of BlockScanner

func (*BlockScanner) FetchLastHeight

func (b *BlockScanner) FetchLastHeight() (int64, error)

FetchLastHeight retrieves the last height to start scanning blocks from on startup

  1. Check if we have a height specified in config AND its higher than the block scanner storage one, use that
  2. Get the last observed height from BASEChain if available
  3. Use block scanner storage if > 0
  4. Fetch last height from the chain itself

func (*BlockScanner) GetMessages

func (b *BlockScanner) GetMessages() <-chan int64

GetMessages return the channel

func (*BlockScanner) IsHealthy

func (b *BlockScanner) IsHealthy() bool

IsHealthy return if the block scanner is healthy or not

func (*BlockScanner) PreviousHeight added in v1.109.0

func (b *BlockScanner) PreviousHeight() int64

func (*BlockScanner) Start

func (b *BlockScanner) Start(globalTxsQueue chan types.TxIn)

Start block scanner

func (*BlockScanner) Stop

func (b *BlockScanner) Stop()

type BlockScannerFetcher

type BlockScannerFetcher interface {
	// FetchMemPool scan the mempool
	FetchMemPool(height int64) (types.TxIn, error)
	// FetchTxs scan block with the given height
	FetchTxs(fetchHeight, chainHeight int64) (types.TxIn, error)
	// GetHeight return current block height
	GetHeight() (int64, error)
}

BlockScannerFetcher define the methods a block scanner need to implement

type BlockScannerStorage

type BlockScannerStorage struct {
	*LevelDBScannerStorage
	// contains filtered or unexported fields
}

BlockScannerStorage

func NewBlockScannerStorage

func NewBlockScannerStorage(levelDbFolder string) (*BlockScannerStorage, error)

func (*BlockScannerStorage) GetInternalDb

func (s *BlockScannerStorage) GetInternalDb() *leveldb.DB

type BlockStatusItem

type BlockStatusItem struct {
	Block  Block           `json:"block"`
	Status BlockScanStatus `json:"status"`
}

BlockStatusItem indicate the status of a block

type DummyFetcher

type DummyFetcher struct {
	Tx  types.TxIn
	Err error
}

func NewDummyFetcher

func NewDummyFetcher(tx types.TxIn, err error) DummyFetcher

func (DummyFetcher) FetchMemPool

func (d DummyFetcher) FetchMemPool(height int64) (types.TxIn, error)

func (DummyFetcher) FetchTxs

func (d DummyFetcher) FetchTxs(height, chainHeight int64) (types.TxIn, error)

func (DummyFetcher) GetHeight

func (d DummyFetcher) GetHeight() (int64, error)

type LevelDBScannerStorage

type LevelDBScannerStorage struct {
	// contains filtered or unexported fields
}

LevelDBScannerStorage is a scanner storage backed by level db

func NewLevelDBScannerStorage

func NewLevelDBScannerStorage(db *leveldb.DB) (*LevelDBScannerStorage, error)

NewLevelDBScannerStorage create a new instance of LevelDBScannerStorage

func (*LevelDBScannerStorage) Close

func (ldbss *LevelDBScannerStorage) Close() error

func (*LevelDBScannerStorage) GetBlocksForRetry

func (ldbss *LevelDBScannerStorage) GetBlocksForRetry(failedOnly bool) ([]Block, error)

GetFailedBlocksForRetry

func (*LevelDBScannerStorage) GetScanPos

func (ldbss *LevelDBScannerStorage) GetScanPos() (int64, error)

GetScanPos get current Scan Pos

func (*LevelDBScannerStorage) RemoveBlockStatus

func (ldbss *LevelDBScannerStorage) RemoveBlockStatus(block int64) error

func (*LevelDBScannerStorage) SetBlockScanStatus

func (ldbss *LevelDBScannerStorage) SetBlockScanStatus(block Block, status BlockScanStatus) error

func (*LevelDBScannerStorage) SetScanPos

func (ldbss *LevelDBScannerStorage) SetScanPos(block int64) error

SetScanPos save current scan pos

type MockScannerStorage

type MockScannerStorage struct {
	// contains filtered or unexported fields
}

MockScannerStorage is to mock scanner storage interface

func NewMockScannerStorage

func NewMockScannerStorage() *MockScannerStorage

NewMockScannerStorage create a new instance of MockScannerStorage

func (*MockScannerStorage) Close

func (mss *MockScannerStorage) Close() error

func (*MockScannerStorage) GetBlocksForRetry

func (mss *MockScannerStorage) GetBlocksForRetry(failedOnly bool) ([]Block, error)

func (*MockScannerStorage) GetInternalDb

func (mss *MockScannerStorage) GetInternalDb() *leveldb.DB

func (*MockScannerStorage) GetScanPos

func (mss *MockScannerStorage) GetScanPos() (int64, error)

func (*MockScannerStorage) RemoveBlockStatus

func (mss *MockScannerStorage) RemoveBlockStatus(block int64) error

func (*MockScannerStorage) SetBlockScanStatus

func (mss *MockScannerStorage) SetBlockScanStatus(block Block, status BlockScanStatus) error

func (*MockScannerStorage) SetScanPos

func (mss *MockScannerStorage) SetScanPos(block int64) error

type ScannerStorage

type ScannerStorage interface {
	GetScanPos() (int64, error)
	SetScanPos(block int64) error
	SetBlockScanStatus(block Block, status BlockScanStatus) error
	RemoveBlockStatus(block int64) error
	GetBlocksForRetry(failedOnly bool) ([]Block, error)
	GetInternalDb() *leveldb.DB
	io.Closer
}

ScannerStorage define the method need to be used by scanner

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL