types

package
v0.0.0-...-6e5196d Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BTCHeaderHashLen = 32

Variables

View Source
var (
	ErrEmptyCache            = errors.New("empty cache")
	ErrInvalidMaxEntries     = errors.New("invalid max entries")
	ErrTooManyEntries        = errors.New("the number of blocks is more than maxEntries")
	ErrorUnsortedBlocks      = errors.New("blocks are not sorted by height")
	ErrInvalidMultiSig       = errors.New("invalid multi-sig")
	ErrInsufficientPower     = errors.New("insufficient power")
	ErrInvalidEpochNum       = errors.New("invalid epoch number")
	ErrInconsistentBlockHash = errors.New("inconsistent BlockHash")
	ErrLivenessAttack        = errors.New("liveness attack")
)

Functions

func GetValidNetParams

func GetValidNetParams() map[string]bool

Types

type BTCCache

type BTCCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBTCCache

func NewBTCCache(maxEntries uint64) (*BTCCache, error)

func (*BTCCache) Add

func (b *BTCCache) Add(ib *IndexedBlock)

Add adds a new block to the cache. Thread-safe.

func (*BTCCache) FindBlock

func (b *BTCCache) FindBlock(blockHeight uint64) *IndexedBlock

FindBlock uses binary search to find the block with the given height in cache

func (*BTCCache) First

func (b *BTCCache) First() *IndexedBlock

func (*BTCCache) GetAllBlocks

func (b *BTCCache) GetAllBlocks() []*IndexedBlock

GetAllBlocks returns list of all blocks in cache

func (*BTCCache) GetLastBlocks

func (b *BTCCache) GetLastBlocks(stopHeight uint64) ([]*IndexedBlock, error)

GetLastBlocks returns list of blocks between the given stopHeight and the tip of the chain in cache

func (*BTCCache) Init

func (b *BTCCache) Init(ibs []*IndexedBlock) error

Init initializes the cache with the given blocks. Input blocks should be sorted by height. Thread-safe.

func (*BTCCache) RemoveAll

func (b *BTCCache) RemoveAll()

RemoveAll deletes all the blocks in cache

func (*BTCCache) RemoveLast

func (b *BTCCache) RemoveLast() error

RemoveLast deletes the last block in cache

func (*BTCCache) Resize

func (b *BTCCache) Resize(maxEntries uint64) error

func (*BTCCache) Size

func (b *BTCCache) Size() uint64

Size returns the size of the cache. Thread-safe.

func (*BTCCache) Tip

func (b *BTCCache) Tip() *IndexedBlock

func (*BTCCache) Trim

func (b *BTCCache) Trim()

Trim trims BTCCache to only keep the latest `maxEntries` blocks, and set `maxEntries` to be the cache size

func (*BTCCache) TrimConfirmedBlocks

func (b *BTCCache) TrimConfirmedBlocks(k int) []*IndexedBlock

TrimConfirmedBlocks keeps the last <=k blocks in the cache and returns the rest in the same order the returned blocks are considered confirmed

type BTCHeaderHashBytes

type BTCHeaderHashBytes []byte

func NewBTCHeaderHashBytesFromBytes

func NewBTCHeaderHashBytesFromBytes(hash []byte) (BTCHeaderHashBytes, error)

func NewBTCHeaderHashBytesFromChainhash

func NewBTCHeaderHashBytesFromChainhash(chHash *chainhash.Hash) BTCHeaderHashBytes

func NewBTCHeaderHashBytesFromHex

func NewBTCHeaderHashBytesFromHex(hex string) (BTCHeaderHashBytes, error)

func (*BTCHeaderHashBytes) Eq

func (*BTCHeaderHashBytes) FromChainhash

func (m *BTCHeaderHashBytes) FromChainhash(hash *chainhash.Hash)

func (BTCHeaderHashBytes) Marshal

func (m BTCHeaderHashBytes) Marshal() ([]byte, error)

func (*BTCHeaderHashBytes) MarshalHex

func (m *BTCHeaderHashBytes) MarshalHex() string

func (BTCHeaderHashBytes) MarshalJSON

func (m BTCHeaderHashBytes) MarshalJSON() ([]byte, error)

func (BTCHeaderHashBytes) MarshalTo

func (m BTCHeaderHashBytes) MarshalTo(data []byte) (int, error)

func (BTCHeaderHashBytes) MustMarshal

func (m BTCHeaderHashBytes) MustMarshal() []byte

func (*BTCHeaderHashBytes) Size

func (m *BTCHeaderHashBytes) Size() int

func (*BTCHeaderHashBytes) String

func (m *BTCHeaderHashBytes) String() string

func (BTCHeaderHashBytes) ToChainhash

func (m BTCHeaderHashBytes) ToChainhash() *chainhash.Hash

func (*BTCHeaderHashBytes) Unmarshal

func (m *BTCHeaderHashBytes) Unmarshal(bz []byte) error

func (*BTCHeaderHashBytes) UnmarshalHex

func (m *BTCHeaderHashBytes) UnmarshalHex(hash string) error

func (*BTCHeaderHashBytes) UnmarshalJSON

func (m *BTCHeaderHashBytes) UnmarshalJSON(bz []byte) error

type IndexedBlock

type IndexedBlock struct {
	Height int32
	Header *wire.BlockHeader
	Txs    []*btcutil.Tx
}

IndexedBlock is a BTC block with some extra information compared to wire.MsgBlock, including: - block height - txHash, txHashWitness, txIndex for each Tx These are necessary for generating Merkle proof (and thus the `MsgInsertBTCSpvProof` message in babylon) of a certain tx

func NewIndexedBlock

func NewIndexedBlock(height int32, header *wire.BlockHeader, txs []*btcutil.Tx) *IndexedBlock

func NewIndexedBlockFromMsgBlock

func NewIndexedBlockFromMsgBlock(height int32, block *wire.MsgBlock) *IndexedBlock

func (*IndexedBlock) BlockHash

func (ib *IndexedBlock) BlockHash() chainhash.Hash

func (*IndexedBlock) GenSPVProof

func (ib *IndexedBlock) GenSPVProof(txIdx int) (*btcctypes.BTCSpvProof, error)

GenSPVProof generates a Merkle proof of a certain tx with index txIdx

func (*IndexedBlock) MsgBlock

func (ib *IndexedBlock) MsgBlock() *wire.MsgBlock

type RelayerConfig

type RelayerConfig struct {
	NetParams       string `mapstructure:"netparams"`          // should be mainnet|testnet|simnet|signet
	BTCCacheSize    uint64 `mapstructure:"btc_cache_size"`     // size of the BTC cache
	MaxHeadersInMsg uint32 `mapstructure:"max_headers_in_msg"` // maximum number of headers in a MsgInsertHeaders message
}

RelayerConfig defines configuration for the reporter.

func DefaultRelayerConfig

func DefaultRelayerConfig() RelayerConfig

func (*RelayerConfig) Validate

func (cfg *RelayerConfig) Validate() error

type SupportedBtcNetwork

type SupportedBtcNetwork string
const (
	BtcMainnet SupportedBtcNetwork = "mainnet"
	BtcTestnet SupportedBtcNetwork = "testnet"
	BtcSimnet  SupportedBtcNetwork = "simnet"
	BtcRegtest SupportedBtcNetwork = "regtest"
	BtcSignet  SupportedBtcNetwork = "signet"
)

func (SupportedBtcNetwork) String

func (c SupportedBtcNetwork) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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