Documentation
¶
Index ¶
Constants ¶
const ( NotMinted BlockStatus = 0 Minted = 1 DoubleAssignment = 2 HeightBattle = 3 GHOSTED = 4 )
const ( ObserveNewLeaderLog = 0 ObserveUpdatedBlockStatus = 1 )
Variables ¶
var ( // ReadError is returned, when querying the database failed for some reason. ReadError = errors.New("read from the database failed") // WriteError is returned, when querying the database failed for some // reason. WriteError = errors.New("write to the database failed") )
Functions ¶
This section is empty.
Types ¶
type AssignedBlock ¶
type AssignedBlock struct {
// Epoch is the epoch for which the block has been scheduled.
Epoch uint
// No is the unique number of the block in an overall leader log.
No uint
// EpochSlot is the slot number for which the block has been scheduled. The
// number is counted from the start of the epoch.
EpochSlot uint
// Slot is the slot number fow which the block has been scheduled. The
// number is counted from the chain`s inception.
Slot uint
// Timestamp is the exact time for which the block has been scheduled.
Timestamp time.Time
// Status is the current status of this scheduled block.
Status BlockStatus
// RelevantBlock links a minted block to this assigned block, which can
// further explain the status of the assigned block.
RelevantBlock *MintedBlock
}
AssignedBlock is a block assigned to a pool in an epoch, which is part of an overall leader log.
type DB ¶
type DB interface {
// Observer is returning a db.Observer for this db.DB instance.
Observer() *Observer
// GetRegisteredEpochs gets a list of all registered epochs.
GetRegisteredEpochs(ctx context.Context, ordering Ordering,
limit uint) ([]uint, error)
// GetLeaderLog gets the leader log for the given epoch.
GetLeaderLog(ctx context.Context, epoch uint) (*LeaderLog, error)
// GetAssignedBlocksAfterNow gets the assigned blocks that have been planned
// after now.
GetAssignedBlocksAfterNow(ctx context.Context) ([]AssignedBlock, error)
// GetAssignedBlocksBeforeNow gets the assigned blocks that have been
// planned before now for the given epoch.
GetAssignedBlocksBeforeNow(ctx context.Context,
epoch uint) ([]AssignedBlock, error)
// GetAssignedBlocksWithStatusBeforeNow gets the assigned blocks that have
// been planned before current time and have the given BlockStatus.
GetAssignedBlocksWithStatusBeforeNow(ctx context.Context,
status BlockStatus, offset, limit uint) ([]AssignedBlock, error)
// UpdateStatusForAssignment updates the status for the block assignment of
// the given epoch with the specified unique id called "no".
UpdateStatusForAssignment(ctx context.Context, epoch, no uint,
status BlockStatus, mintedBlockID *uint) error
// WriteMintedBlock writes the given minted block to the database and
// returns the ID primary key for this entry. If the writing fails, an error
// will be returned otherwise.
WriteMintedBlock(ctx context.Context, block *MintedBlock) (*uint, error)
// WriteLeaderLog writes the given list of assigned blocks for the given
// epoch to the DB. If a leader log has already written for this epoch, then
// the old leader log will be overwritten.
WriteLeaderLog(ctx context.Context, log *LeaderLog) error
// Close closes this database and all connections.
Close() error
}
DB is an interface to store and query leader logs as well as to manage related data.
type LeaderLog ¶
type LeaderLog struct {
// PoolID is the id in hex format of the pool for which this leader log was
// created.
PoolID string
// Epoch is the epoch for which the leader log is created.
Epoch uint
// Blocks is a list of blocks that have been assigned to the pool in this
// epoch.
Blocks []AssignedBlock
// ExpectedBlockNumber
ExpectedBlockNumber float32
// MaxPerformance is the maximal possible performance in the epoch given
// this leader log.
MaxPerformance float32
}
LeaderLog is a list of blocks assigned to a certain pool and for a certain epoch.
type MintedBlock ¶
type MintedBlock struct {
// ID is an unique identifier of the minted block entry in the database.
ID *uint
// Epoch in which the block has been minted.
Epoch uint
// EpochSlot is the slot number in which the block has been minted. The
// number is counted from the start of the epoch.
EpochSlot uint
// Slot is the slot number in which the block has been minted. The number is
// counted from the chain`s inception.
Slot uint
// Hash is the hash string in hex format for the minted block.
Hash string
// Height of this minted block.
Height uint
// PoolID is the unique identifier of the pool that minted the block. It is
// represented in hex format.
PoolID string
}
MintedBlock is a block that has been persisted on the chain.
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer allows registering change listeners for a db.DB instance.
func (*Observer) Pub ¶
func (obv *Observer) Pub(msg ObserverMessage)
Pub publishes the given message, which is distributed over all subscribed channels.
func (*Observer) Sub ¶
func (obv *Observer) Sub(c chan<- ObserverMessage)
Sub subscribes the given channel to get notification, when the db.DB got updated.
type ObserverCode ¶
type ObserverCode int
ObserverCode is referring to the type of observer notification.
type ObserverMessage ¶
type ObserverMessage struct {
Code ObserverCode
Response interface{}
}
ObserverMessage is a message describing a change of a db.DB update.