Documentation ¶
Index ¶
- Constants
- func DisableLog()
- func UseLogger(logger btclog.Logger)
- type ChainMonitor
- type PoolInfoCache
- type ReorgData
- type StakeDatabase
- func (db *StakeDatabase) ConnectBlock(block *hcutil.Block) error
- func (db *StakeDatabase) ConnectBlockHash(hash *chainhash.Hash) (*hcutil.Block, error)
- func (db *StakeDatabase) DBPrevBlock() (*hcutil.Block, error)
- func (db *StakeDatabase) DBPrevBlockHeader() (*wire.BlockHeader, error)
- func (db *StakeDatabase) DBState() (uint32, *chainhash.Hash, error)
- func (db *StakeDatabase) DBTipBlock() (*hcutil.Block, error)
- func (db *StakeDatabase) DBTipBlockHeader() (*wire.BlockHeader, error)
- func (db *StakeDatabase) DisconnectBlock() error
- func (db *StakeDatabase) DisconnectBlocks(count int64) error
- func (db *StakeDatabase) ForgetBlock(ind int64)
- func (db *StakeDatabase) Height() uint32
- func (db *StakeDatabase) NewChainMonitor(quit chan struct{}, wg *sync.WaitGroup, blockChan chan *chainhash.Hash, ...) *ChainMonitor
- func (db *StakeDatabase) Open() error
- func (db *StakeDatabase) PoolInfo(hash chainhash.Hash) (*apitypes.TicketPoolInfo, bool)
- func (db *StakeDatabase) PoolInfoBest() (apitypes.TicketPoolInfo, uint32)
- func (db *StakeDatabase) PoolSize() int
Constants ¶
const (
// DefaultStakeDbName is the default database name
DefaultStakeDbName = "ffldb_stake"
)
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type ChainMonitor ¶
type ChainMonitor struct { ConnectingLock chan struct{} DoneConnecting chan struct{} // contains filtered or unexported fields }
ChainMonitor connects blocks to the stake DB as they come in.
func (*ChainMonitor) BlockConnectedHandler ¶
func (p *ChainMonitor) BlockConnectedHandler()
BlockConnectedHandler handles block connected notifications, which trigger data collection and storage.
func (*ChainMonitor) BlockConnectedSync ¶
func (p *ChainMonitor) BlockConnectedSync(hash *chainhash.Hash)
BlockConnectedSync is the synchronous (blocking call) handler for the newly connected block given by the hash.
func (*ChainMonitor) ReorgHandler ¶
func (p *ChainMonitor) ReorgHandler()
ReorgHandler receives notification of a chain reorganization and initiates a corresponding reorganization of the stakedb.StakeDatabase.
type PoolInfoCache ¶
PoolInfoCache contains a map of block hashes to ticket pool info data at that block height.
func NewPoolInfoCache ¶
func NewPoolInfoCache() *PoolInfoCache
NewPoolInfoCache constructs a new PoolInfoCache, and is needed to initialize the internal map.
func (*PoolInfoCache) Get ¶
func (c *PoolInfoCache) Get(hash chainhash.Hash) (*apitypes.TicketPoolInfo, bool)
Get attempts to fetch the ticket pool info for a given block hash, returning a *apitypes.TicketPoolInfo, and a bool indicating if the hash was found in the map.
func (*PoolInfoCache) Set ¶
func (c *PoolInfoCache) Set(hash chainhash.Hash, p *apitypes.TicketPoolInfo)
Set stores the ticket pool info for the given hash in the pool info cache.
type ReorgData ¶
type ReorgData struct { OldChainHead chainhash.Hash OldChainHeight int32 NewChainHead chainhash.Hash NewChainHeight int32 }
ReorgData contains the information from a reoranization notification
type StakeDatabase ¶
type StakeDatabase struct { NodeClient *hcrpcclient.Client StakeDB database.DB BestNode *stake.Node // contains filtered or unexported fields }
StakeDatabase models data for the stake database
func NewStakeDatabase ¶
func NewStakeDatabase(client *hcrpcclient.Client, params *chaincfg.Params) (*StakeDatabase, error)
NewStakeDatabase creates a StakeDatabase instance, opening or creating a new ffldb-backed stake database, and loads all live tickets into a cache.
func (*StakeDatabase) ConnectBlock ¶
func (db *StakeDatabase) ConnectBlock(block *hcutil.Block) error
ConnectBlock connects the input block to the tip of the stake DB and updates the best stake node. This exported function gets any revoked and spend tickets from the input block, and any maturing tickets from the past block in which those tickets would be found, and passes them to connectBlock.
func (*StakeDatabase) ConnectBlockHash ¶
ConnectBlockHash is a wrapper for ConnectBlock. For the input block hash, it gets the block from the node RPC client and calls ConnectBlock.
func (*StakeDatabase) DBPrevBlock ¶
func (db *StakeDatabase) DBPrevBlock() (*hcutil.Block, error)
DBPrevBlock gets the hcutil.Block for the previous best block in the stake database. It used DBState to get the best block hash, and the node RPC client to get the block itself.
func (*StakeDatabase) DBPrevBlockHeader ¶
func (db *StakeDatabase) DBPrevBlockHeader() (*wire.BlockHeader, error)
DBPrevBlockHeader gets the block header for the previous best block in the stake database. It used DBState to get the best block hash, and the node RPC client to get the header.
func (*StakeDatabase) DBState ¶
func (db *StakeDatabase) DBState() (uint32, *chainhash.Hash, error)
DBState queries the stake database for the best block height and hash.
func (*StakeDatabase) DBTipBlock ¶
func (db *StakeDatabase) DBTipBlock() (*hcutil.Block, error)
DBTipBlock gets the hcutil.Block for the current best block in the stake database. It used DBState to get the best block hash, and the node RPC client to get the block itself.
func (*StakeDatabase) DBTipBlockHeader ¶
func (db *StakeDatabase) DBTipBlockHeader() (*wire.BlockHeader, error)
DBTipBlockHeader gets the block header for the current best block in the stake database. It used DBState to get the best block hash, and the node RPC client to get the header.
func (*StakeDatabase) DisconnectBlock ¶
func (db *StakeDatabase) DisconnectBlock() error
DisconnectBlock attempts to disconnect the current best block from the stake DB and updates the best stake node.
func (*StakeDatabase) DisconnectBlocks ¶
func (db *StakeDatabase) DisconnectBlocks(count int64) error
DisconnectBlocks disconnects N blocks from the head of the chain.
func (*StakeDatabase) ForgetBlock ¶
func (db *StakeDatabase) ForgetBlock(ind int64)
ForgetBlock deletes the block with the input height from the block cache.
func (*StakeDatabase) Height ¶
func (db *StakeDatabase) Height() uint32
Height gets the block height of the best stake node. It is thread-safe, unlike using db.BestNode.Height(), and checks that the stake database is opened first.
func (*StakeDatabase) NewChainMonitor ¶
func (db *StakeDatabase) NewChainMonitor(quit chan struct{}, wg *sync.WaitGroup, blockChan chan *chainhash.Hash, reorgChan chan *ReorgData) *ChainMonitor
NewChainMonitor creates a new ChainMonitor
func (*StakeDatabase) Open ¶
func (db *StakeDatabase) Open() error
Open attempts to open an existing stake database, and will create a new one if one does not exist.
func (*StakeDatabase) PoolInfo ¶
func (db *StakeDatabase) PoolInfo(hash chainhash.Hash) (*apitypes.TicketPoolInfo, bool)
PoolInfo attempts to fetch the ticket pool info for the specified block hash from an internal pool info cache. If it is not found, you should attempt to use PoolInfoBest if the target block is at the tip of the chain.
func (*StakeDatabase) PoolInfoBest ¶
func (db *StakeDatabase) PoolInfoBest() (apitypes.TicketPoolInfo, uint32)
PoolInfoBest computes ticket pool value using the database and, if needed, the node RPC client to fetch ticket values that are not cached. Returned are a structure including ticket pool value, size, and average value.
func (*StakeDatabase) PoolSize ¶
func (db *StakeDatabase) PoolSize() int
PoolSize returns the ticket pool size in the best node of the stake database