Documentation
¶
Overview ¶
Copyright (c) 2024 Hemi Labs, Inc. Use of this source code is governed by the MIT License, which can be found in the LICENSE file.
Index ¶
- Variables
- type Config
- type HashHeight
- type NotLinearError
- type PeerManager
- func (pm *PeerManager) All(ctx context.Context, f func(ctx context.Context, p *rawpeer.RawPeer))
- func (pm *PeerManager) AllBlock(ctx context.Context, f func(ctx context.Context, p *rawpeer.RawPeer))
- func (pm *PeerManager) Bad(ctx context.Context, address string) error
- func (pm *PeerManager) Good(address string) error
- func (pm *PeerManager) HandleAddr(peers []string)
- func (pm *PeerManager) Random() (*rawpeer.RawPeer, error)
- func (pm *PeerManager) RandomConnect(ctx context.Context) (*rawpeer.RawPeer, error)
- func (pm *PeerManager) Run(ctx context.Context) error
- func (pm *PeerManager) Stats() (int, int, int)
- func (pm *PeerManager) String() string
- type Server
- func (s *Server) AddExternalHeaders(ctx context.Context, headers *wire.MsgHeaders, upstreamStateId []byte) (tbcd.InsertType, *tbcd.BlockHeader, *tbcd.BlockHeader, int, error)
- func (s *Server) BalanceByAddress(ctx context.Context, encodedAddress string) (uint64, error)
- func (s *Server) BalanceByScriptHash(ctx context.Context, hash tbcd.ScriptHash) (uint64, error)
- func (s *Server) BlockByHash(ctx context.Context, hash chainhash.Hash) (*btcutil.Block, error)
- func (s *Server) BlockHashByTxId(ctx context.Context, txId chainhash.Hash) (*chainhash.Hash, error)
- func (s *Server) BlockHeaderBest(ctx context.Context) (uint64, *wire.BlockHeader, error)
- func (s *Server) BlockHeaderByHash(ctx context.Context, hash chainhash.Hash) (*wire.BlockHeader, uint64, error)
- func (s *Server) BlockHeaderByKeystoneIndex(ctx context.Context) (*tbcd.BlockHeader, error)
- func (s *Server) BlockHeaderByTxIndex(ctx context.Context) (*tbcd.BlockHeader, error)
- func (s *Server) BlockHeaderByUtxoIndex(ctx context.Context) (*tbcd.BlockHeader, error)
- func (s *Server) BlockHeadersByHeight(ctx context.Context, height uint64) ([]*wire.BlockHeader, error)
- func (s *Server) BlockHeadersInsert(ctx context.Context, headers *wire.MsgHeaders) (tbcd.InsertType, *tbcd.BlockHeader, *tbcd.BlockHeader, int, error)
- func (s *Server) BlockInTxIndex(ctx context.Context, blkid chainhash.Hash) (bool, error)
- func (s *Server) BlockInsert(ctx context.Context, blk *wire.MsgBlock) (int64, error)
- func (s *Server) BlockKeystoneByL2KeystoneAbrevHash(ctx context.Context, abrevhash chainhash.Hash) (*tbcd.Keystone, error)
- func (s *Server) BlocksMissing(ctx context.Context, count int) ([]tbcd.BlockIdentifier, error)
- func (s *Server) Collectors() []prometheus.Collector
- func (s *Server) DatabaseMetadataDel(ctx context.Context, key []byte) error
- func (s *Server) DatabaseMetadataGet(ctx context.Context, key []byte) ([]byte, error)
- func (s *Server) DatabaseMetadataPut(ctx context.Context, key []byte, value []byte) error
- func (s *Server) DatabaseVersion(ctx context.Context) (int, error)
- func (s *Server) DifficultyAtHash(ctx context.Context, hash chainhash.Hash) (*big.Int, error)
- func (s *Server) DownloadBlockFromRandomPeers(ctx context.Context, block chainhash.Hash, count uint) (*btcutil.Block, error)
- func (s *Server) ExternalHeaderSetup(ctx context.Context, upstreamStateId []byte) error
- func (s *Server) ExternalHeaderTearDown() error
- func (s *Server) FeesAtHeight(ctx context.Context, height, count int64) (uint64, error)
- func (s *Server) FullBlockAvailable(ctx context.Context, hash chainhash.Hash) (bool, error)
- func (s *Server) IndexIsLinear(ctx context.Context, startHash, endHash chainhash.Hash) (int, error)
- func (s *Server) KeystoneIndexHash(ctx context.Context) (*HashHeight, error)
- func (s *Server) KeystoneIndexIsLinear(ctx context.Context, endHash chainhash.Hash) (int, error)
- func (s *Server) KeystoneIndexer(ctx context.Context, endHash chainhash.Hash) error
- func (s *Server) KeystoneIndexerUnwind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) KeystoneIndexerWind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) RawBlockHeaderBest(ctx context.Context) (uint64, api.ByteSlice, error)
- func (s *Server) RawBlockHeadersByHeight(ctx context.Context, height uint64) ([]api.ByteSlice, error)
- func (s *Server) RemoveExternalHeaders(ctx context.Context, headers *wire.MsgHeaders, ...) (tbcd.RemoveType, *tbcd.BlockHeader, error)
- func (s *Server) Run(pctx context.Context) error
- func (s *Server) Running() bool
- func (s *Server) ScriptHashAvailableToSpend(ctx context.Context, txId chainhash.Hash, index uint32) (bool, error)
- func (s *Server) SetUpstreamStateId(ctx context.Context, upstreamStateId [32]byte) error
- func (s *Server) SpentOutputsByTxId(ctx context.Context, txId chainhash.Hash) ([]tbcd.SpentInfo, error)
- func (s *Server) SyncIndexersToBest(ctx context.Context) error
- func (s *Server) SyncIndexersToHash(ctx context.Context, hash chainhash.Hash) error
- func (s *Server) Synced(ctx context.Context) SyncInfo
- func (s *Server) TxBroadcast(ctx context.Context, tx *wire.MsgTx, force bool) (*chainhash.Hash, error)
- func (s *Server) TxBroadcastAllToPeer(ctx context.Context, p *rawpeer.RawPeer) error
- func (s *Server) TxById(ctx context.Context, txId chainhash.Hash) (*wire.MsgTx, error)
- func (s *Server) TxIndexHash(ctx context.Context) (*HashHeight, error)
- func (s *Server) TxIndexIsLinear(ctx context.Context, endHash chainhash.Hash) (int, error)
- func (s *Server) TxIndexer(ctx context.Context, endHash chainhash.Hash) error
- func (s *Server) TxIndexerUnwind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) TxIndexerWind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) UpstreamStateId(ctx context.Context) (*[32]byte, error)
- func (s *Server) UtxoIndexHash(ctx context.Context) (*HashHeight, error)
- func (s *Server) UtxoIndexIsLinear(ctx context.Context, endHash chainhash.Hash) (int, error)
- func (s *Server) UtxoIndexer(ctx context.Context, endHash chainhash.Hash) error
- func (s *Server) UtxoIndexerUnwind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) UtxoIndexerWind(ctx context.Context, startBH, endBH *tbcd.BlockHeader) error
- func (s *Server) UtxosByAddress(ctx context.Context, encodedAddress string, start uint64, count uint64) ([]tbcd.Utxo, error)
- func (s *Server) UtxosByScriptHash(ctx context.Context, hash tbcd.ScriptHash, start uint64, count uint64) ([]tbcd.Utxo, error)
- func (s *Server) UtxosByScriptHashCount(ctx context.Context, hash tbcd.ScriptHash) (uint64, error)
- type SyncInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrReset = errors.New("reset") ErrNoAddresses = errors.New("no addresses") ErrDNSSeed = errors.New("could not dns seed") ErrNoConnectedPeers = errors.New("no connected peers") )
var ( Welcome = true // Use global to enable/disable welcome message ErrTxAlreadyBroadcast = errors.New("tx already broadcast") ErrTxBroadcastNoPeers = errors.New("can't broadcast tx, no peers") ErrNotInDebugMode = errors.New("debug flag not set") )
var (
ErrAlreadyIndexing = errors.New("already indexing")
)
var ErrNotLinear = NotLinearError("not linear")
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
AutoIndex bool
BlockCacheSize string
BlockheaderCacheSize string
BlockSanity bool
HemiIndex bool
LevelDBHome string
ListenAddress string
LogLevel string
MaxCachedKeystones int
MaxCachedTxs int
MempoolEnabled bool
DatabaseDebug bool
Network string
PeersWanted int
PrometheusListenAddress string
PrometheusNamespace string
PprofListenAddress string
Seeds []string
// Fields used for running TBC in External Header Mode, where P2P is disabled
// and TBC is used to determine consensus based on headers fed from external
// code that manages the TBC node.
ExternalHeaderMode bool // Whether Header-Only Mode is enabled
EffectiveGenesisBlock *wire.BlockHeader // The header to use as the first block in TBC's consensus view
GenesisHeightOffset uint64 // The height of the effective genesis block
GenesisDifficultyOffset big.Int // The cumulative difficulty of the effective genesis block
}
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
type HashHeight ¶ added in v0.2.0
type HashHeight struct {
Hash chainhash.Hash `json:"hash"`
Height uint64 `json:"height"`
Timestamp int64 `json:"timestamp"` // optional
}
func HashHeightFromBlockHeader ¶ added in v0.11.5
func HashHeightFromBlockHeader(bh *tbcd.BlockHeader) *HashHeight
func (HashHeight) String ¶ added in v0.2.0
func (h HashHeight) String() string
type NotLinearError ¶ added in v0.6.0
type NotLinearError string
func (NotLinearError) Error ¶ added in v0.6.0
func (e NotLinearError) Error() string
func (NotLinearError) Is ¶ added in v0.6.0
func (e NotLinearError) Is(target error) bool
type PeerManager ¶ added in v0.3.0
type PeerManager struct {
// contains filtered or unexported fields
}
PeerManager keeps track of the available peers and their quality.
func NewPeerManager ¶ added in v0.5.0
func NewPeerManager(net wire.BitcoinNet, seeds []string, want int) (*PeerManager, error)
NewPeerManager returns a new peer manager.
func (*PeerManager) Bad ¶ added in v0.5.0
func (pm *PeerManager) Bad(ctx context.Context, address string) error
Bad marks the peer as bad.
func (*PeerManager) Good ¶ added in v0.5.0
func (pm *PeerManager) Good(address string) error
Good adds peer to good list if it does not exist in connected and good list already.
func (*PeerManager) HandleAddr ¶ added in v0.5.0
func (pm *PeerManager) HandleAddr(peers []string)
HandleAddr adds peers to good list.
func (*PeerManager) Random ¶ added in v0.5.0
func (pm *PeerManager) Random() (*rawpeer.RawPeer, error)
Random returns a random connected peer.
func (*PeerManager) RandomConnect ¶ added in v0.5.0
RandomConnect blocks until there is a peer ready to use.
func (*PeerManager) Stats ¶ added in v0.3.0
func (pm *PeerManager) Stats() (int, int, int)
Stats returns peer statistics.
func (*PeerManager) String ¶ added in v0.5.0
func (pm *PeerManager) String() string
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddExternalHeaders ¶ added in v0.7.0
func (s *Server) AddExternalHeaders(ctx context.Context, headers *wire.MsgHeaders, upstreamStateId []byte) (tbcd.InsertType, *tbcd.BlockHeader, *tbcd.BlockHeader, int, error)
AddExternalHeaders XXX if we are passing in upstreamStateId then why does the default live in tbcd?
func (*Server) BalanceByAddress ¶
func (*Server) BalanceByScriptHash ¶ added in v0.4.4
func (*Server) BlockByHash ¶ added in v0.3.8
BlockByHash returns a block with the given hash.
func (*Server) BlockHashByTxId ¶ added in v0.4.4
func (*Server) BlockHeaderBest ¶ added in v0.2.0
BlockHeaderBest returns the headers for the best known blocks.
func (*Server) BlockHeaderByHash ¶
func (s *Server) BlockHeaderByHash(ctx context.Context, hash chainhash.Hash) (*wire.BlockHeader, uint64, error)
XXX should we return a form of tbcd.BlockHeader which contains all info? and note that the return parameters here are reversed from BlockHeaderBest call.
func (*Server) BlockHeaderByKeystoneIndex ¶ added in v0.16.1
func (*Server) BlockHeaderByTxIndex ¶ added in v0.16.1
func (*Server) BlockHeaderByUtxoIndex ¶ added in v0.16.1
func (*Server) BlockHeadersByHeight ¶
func (*Server) BlockHeadersInsert ¶ added in v0.11.2
func (s *Server) BlockHeadersInsert(ctx context.Context, headers *wire.MsgHeaders) (tbcd.InsertType, *tbcd.BlockHeader, *tbcd.BlockHeader, int, error)
func (*Server) BlockInTxIndex ¶ added in v0.4.4
func (*Server) BlockInsert ¶ added in v0.6.0
func (*Server) BlockKeystoneByL2KeystoneAbrevHash ¶ added in v0.16.1
func (*Server) BlocksMissing ¶ added in v0.4.4
func (*Server) Collectors ¶ added in v0.9.0
func (s *Server) Collectors() []prometheus.Collector
Collectors returns the Prometheus collectors available for the server.
func (*Server) DatabaseMetadataDel ¶ added in v0.16.1
func (*Server) DatabaseMetadataGet ¶ added in v0.11.5
func (*Server) DatabaseMetadataPut ¶ added in v0.16.1
func (*Server) DatabaseVersion ¶ added in v0.11.5
func (*Server) DifficultyAtHash ¶ added in v0.2.0
func (*Server) DownloadBlockFromRandomPeers ¶ added in v0.6.0
func (*Server) ExternalHeaderSetup ¶ added in v0.7.0
func (*Server) ExternalHeaderTearDown ¶ added in v0.7.0
func (*Server) FeesAtHeight ¶
func (*Server) FullBlockAvailable ¶ added in v0.7.0
FullBlockAvailable returns whether TBC has the full block corresponding to the specified hash available in its database.
func (*Server) IndexIsLinear ¶ added in v0.2.8
func (*Server) KeystoneIndexHash ¶ added in v0.11.2
func (s *Server) KeystoneIndexHash(ctx context.Context) (*HashHeight, error)
KeystoneIndexHash returns the last hash that has been Keystone indexed.
func (*Server) KeystoneIndexIsLinear ¶ added in v0.11.2
func (*Server) KeystoneIndexer ¶ added in v0.11.2
func (*Server) KeystoneIndexerUnwind ¶ added in v0.11.2
func (*Server) KeystoneIndexerWind ¶ added in v0.11.2
func (*Server) RawBlockHeaderBest ¶ added in v0.2.0
RawBlockHeaderBest returns the raw header for the best known block. XXX should we return cumulative difficulty, hash?
func (*Server) RawBlockHeadersByHeight ¶
func (*Server) RemoveExternalHeaders ¶ added in v0.7.0
func (s *Server) RemoveExternalHeaders(ctx context.Context, headers *wire.MsgHeaders, tipAfterRemoval *wire.BlockHeader, upstreamStateId []byte) (tbcd.RemoveType, *tbcd.BlockHeader, error)
RemoveExternalHeaders removes the provided headers from TBC's state knowledge, setting the canonical tip to the provided tip. This method can only be used when TBC is running in External Header Mode.
The upstream state id is an optional identifier that the caller can use to track some upstream state which represents TBC's own state once this removal is performed. For example, op-geth uses this to track the hash of the EVM block which cumulatively represents TBC's entire header knowledge after the removal is processed, such that re-applying all Bitcoin Attributes Deposited transactions in the EVM from genesis to that hash would result in TBC having this state.
This upstream state id is tracked in TBC rather than upstream in the caller so that updates to the upstreamCursor are always made atomically with the corresponding TBC database state transition. Otherwise, an unexpected termination between updating TBC state and recording the updated upstreamCursor could cause state corruption.
func (*Server) ScriptHashAvailableToSpend ¶ added in v0.7.0
func (s *Server) ScriptHashAvailableToSpend(ctx context.Context, txId chainhash.Hash, index uint32) (bool, error)
ScriptHashAvailableToSpend returns a boolean which indicates whether a specific output (uniquely identified by TxId output index) is available for spending in the UTXO table. This function can return false for two reasons:
- The outpoint was already spent
- The outpoint never existed
func (*Server) SetUpstreamStateId ¶ added in v0.7.0
SetUpstreamStateId sets a new upstream state ID without making any other state changes to TBC, used when the upstream state is updated without requiring any TBC updates.
func (*Server) SpentOutputsByTxId ¶ added in v0.2.8
func (*Server) SyncIndexersToBest ¶ added in v0.4.4
func (*Server) SyncIndexersToHash ¶ added in v0.2.0
SyncIndexersToHash tries to move the various indexers to the supplied hash (inclusive). Note: on unwind it means that it WILL unwind the various indexers including the hash that was passed in. E.g. if this unwinds from 1001 to 1000 the indexes for block 1000 WILL be updated as well.
func (*Server) Synced ¶
Synced returns true if all block headers, blocks and all indexes are caught up.
func (*Server) TxBroadcast ¶ added in v0.5.0
func (*Server) TxBroadcastAllToPeer ¶ added in v0.5.0
func (*Server) TxIndexHash ¶ added in v0.2.0
func (s *Server) TxIndexHash(ctx context.Context) (*HashHeight, error)
TxIndexHash returns the last hash that has been Tx indexed.
func (*Server) TxIndexIsLinear ¶ added in v0.2.8
func (*Server) TxIndexerUnwind ¶ added in v0.2.8
func (*Server) TxIndexerWind ¶ added in v0.2.8
func (*Server) UpstreamStateId ¶ added in v0.7.0
UpstreamStateId fetches the last-stored upstream state ID. If the last header insertion/removal did not specify an upstream state ID, this will return the default upstream state ID.
func (*Server) UtxoIndexHash ¶ added in v0.2.0
func (s *Server) UtxoIndexHash(ctx context.Context) (*HashHeight, error)
UtxoIndexHash returns the last hash that has been UTxO indexed.
func (*Server) UtxoIndexIsLinear ¶ added in v0.2.8
func (*Server) UtxoIndexer ¶
func (*Server) UtxoIndexerUnwind ¶ added in v0.2.8
func (*Server) UtxoIndexerWind ¶ added in v0.2.8
func (*Server) UtxosByAddress ¶
func (*Server) UtxosByScriptHash ¶ added in v0.4.4
func (*Server) UtxosByScriptHashCount ¶ added in v0.11.2
type SyncInfo ¶
type SyncInfo struct {
Synced bool `json:"synced"` // True when all indexing is caught up
AtLeastMissing int `json:"at_least_missing"` // Blocks missing 0-63 is counted, >=64 returns -1
BlockHeader HashHeight `json:"blockheader_index_height"`
Keystone HashHeight `json:"keystone_index_height"`
Tx HashHeight `json:"tx_index_height"`
Utxo HashHeight `json:"utxo_index_height"`
}