stakedb

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: ISC Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

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 added in v0.7.0

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 added in v0.7.0

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

PoolInfoCache contains a map of block hashes to ticket pool info data at that block height.

func NewPoolInfoCache added in v0.7.0

func NewPoolInfoCache() *PoolInfoCache

NewPoolInfoCache constructs a new PoolInfoCache, and is needed to initialize the internal map.

func (*PoolInfoCache) Get added in v0.7.0

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 added in v0.7.0

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 *dcrrpcclient.Client

	StakeDB  database.DB
	BestNode *stake.Node
	// contains filtered or unexported fields
}

StakeDatabase models data for the stake database

func NewStakeDatabase

func NewStakeDatabase(client *dcrrpcclient.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 *dcrutil.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

func (db *StakeDatabase) ConnectBlockHash(hash *chainhash.Hash) (*dcrutil.Block, error)

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() (*dcrutil.Block, error)

DBPrevBlock gets the dcrutil.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() (*dcrutil.Block, error)

DBTipBlock gets the dcrutil.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 added in v0.7.0

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

Jump to

Keyboard shortcuts

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