Documentation ¶
Index ¶
- type Block
- type ForkDB
- func (f *ForkDB) AddLink(blockRef bstream.BlockRef, previousRefID string, obj interface{}) (exists bool, seenPrevious bool)
- func (f *ForkDB) BlockForID(blockID string) *Block
- func (f *ForkDB) BlockInCurrentChain(startAtBlock bstream.BlockRef, blockNum uint64) bstream.BlockRef
- func (f *ForkDB) ChainSwitchSegments(oldHeadBlockID, newHeadsPreviousID string) (truncatedUndo []string, reversedRedo []string, reorgJunctionBlock string)
- func (f *ForkDB) ClonedLinks() (out map[string]string, nums map[string]uint64)
- func (f *ForkDB) CompleteSegment(startBlock bstream.BlockRef) (blocks []*Block, reachLIB bool)
- func (f *ForkDB) DeleteLink(id string)
- func (f *ForkDB) Deserialize(data []byte, objectFactory ObjectFactory) error
- func (f *ForkDB) Exists(blockID string) bool
- func (f *ForkDB) HasLIB() bool
- func (f *ForkDB) HasNewIrreversibleSegment(newLIB bstream.BlockRef) (hasNew bool, irreversibleSegment, staleBlocks []*Block)
- func (f *ForkDB) InitLIB(ref bstream.BlockRef)
- func (f *ForkDB) IsBehindLIB(blockNum uint64) bool
- func (f *ForkDB) IterateLinks(...)
- func (f *ForkDB) LIBID() string
- func (f *ForkDB) LIBNum() uint64
- func (f *ForkDB) MoveLIB(blockRef bstream.BlockRef)
- func (f *ForkDB) PurgeBeforeLIB(keptBlocks int) (purgedBlocks []*Block)
- func (f *ForkDB) ReversibleSegment(startBlock bstream.BlockRef) (blocks []*Block, reachLIB bool)
- func (f *ForkDB) Serialize() ([]byte, error)
- func (f *ForkDB) SetLIB(headRef bstream.BlockRef, libNum uint64)
- func (f *ForkDB) SetLogger(logger *zap.Logger)
- type ForkDBOption
- type Forkable
- func (p *Forkable) AllBlocksAt(num uint64) (out []*pbbstream.Block)
- func (p *Forkable) AllIDs() (out []string)
- func (p *Forkable) CallWithBlocksFromCursor(cursor *bstream.Cursor, callback func([]*bstream.PreprocessedBlock)) error
- func (p *Forkable) CallWithBlocksFromNum(num uint64, callback func([]*bstream.PreprocessedBlock), withForks bool) (err error)
- func (p *Forkable) CallWithBlocksThroughCursor(startBlock uint64, cursor *bstream.Cursor, ...) error
- func (p *Forkable) CanonicalBlockAt(num uint64) *pbbstream.Block
- func (p *Forkable) GetBlockByHash(id string) (out *pbbstream.Block)
- func (p *Forkable) HeadInfo() (headNum uint64, headID string, headTime time.Time, libNum uint64, err error)
- func (p *Forkable) HeadNum() uint64
- func (p *Forkable) Linkable(blk *pbbstream.Block) bool
- func (p *Forkable) LowestBlockNum() uint64
- func (p *Forkable) ProcessBlock(blk *pbbstream.Block, obj interface{}) error
- type ForkableBlock
- type ForkableObject
- type IrreversibleBlockIDGate
- type IrreversibleBlockNumGate
- type ObjectBinaryMarshaler
- type ObjectFactory
- type ObjectJSONMarshallable
- type Option
- func EnsureAllBlocksTriggerLongestChain() Option
- func EnsureBlockFlows(blockRef bstream.BlockRef) Option
- func HoldBlocksUntilLIB() Option
- func WithExclusiveLIB(irreversibleBlock bstream.BlockRef) Option
- func WithFailOnUnlinkableBlocks(count int, gracePeriod time.Duration) Option
- func WithFilters(steps bstream.StepType) Option
- func WithInclusiveLIB(irreversibleBlock bstream.BlockRef) Option
- func WithKeptFinalBlocks(count int) Option
- func WithLogger(logger *zap.Logger) Option
- func WithWarnOnUnlinkableBlocks(count int) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ForkDB ¶
type ForkDB struct {
// contains filtered or unexported fields
}
ForkDB holds the graph of block headBlockID to previous block.
func NewForkDB ¶
func NewForkDB(opts ...ForkDBOption) *ForkDB
func (*ForkDB) BlockForID ¶
func (*ForkDB) BlockInCurrentChain ¶
func (f *ForkDB) BlockInCurrentChain(startAtBlock bstream.BlockRef, blockNum uint64) bstream.BlockRef
BlockInCurrentChain finds the block_id at height `blockNum` under the requested `startAtBlockID` base block. Passing the head block id as `startAtBlockID` will tell you if the block num is part of the longest chain.
func (*ForkDB) ChainSwitchSegments ¶
func (f *ForkDB) ChainSwitchSegments(oldHeadBlockID, newHeadsPreviousID string) (truncatedUndo []string, reversedRedo []string, reorgJunctionBlock string)
ChainSwitchSegments returns the list of block IDs that should be `undo`ne (in reverse chain order) and the list of blocks that should be `redo`ne (in chain order) for `blockID` (linking to `previousID`) to become the longest chain.
This assumes you are querying for something that *is* the longest chain (or the to-become longest chain).
func (*ForkDB) ClonedLinks ¶
CloneLinks retrieves a snapshot of the links in the ForkDB. Used only in ForkViewerin `eosws`.
func (*ForkDB) CompleteSegment ¶
CompleteSegment is like ReversibleSegment but keeps going passed lib and stops as soon no parent for a given block is present in ForkDB (there could be a hole however in which case this method returns up to the point where the hole is found).
No special handling is required for the genesis block as its parent will simply not be found in ForkDB as it cannot exist and it's just the "normal" case.
func (*ForkDB) DeleteLink ¶
func (*ForkDB) Deserialize ¶
func (f *ForkDB) Deserialize(data []byte, objectFactory ObjectFactory) error
Deserialize the ForkDB from a series of bytes. The ForkDB holding objects of unknown type, the `objectFactory` is used here so you can specify which type of object is hold in the ForkDB `objects` map.
The `objectFactory` is a function that returns a new empty pointer instance of the object. It is used to deserialize the object from the serialized data be if it's a JSON object or a binary object.
If you are using protobuf objects, you can pass `nil` as the `objectFactory` as Protobuf should be able to deserialize the correct message, don't forget to pull the Golang dependencies of the Protobuf bindings your type(s) are correclty registered.
func (*ForkDB) HasNewIrreversibleSegment ¶
func (f *ForkDB) HasNewIrreversibleSegment(newLIB bstream.BlockRef) (hasNew bool, irreversibleSegment, staleBlocks []*Block)
HasNewIrreversibleSegment returns segments upon passing the newDposLIBID that are irreversible and stale. If there was no new segment, `hasNew` will be false. WARN: this method can only be called when `HasLIB()` is true. Otherwise, it panics.
func (*ForkDB) IsBehindLIB ¶
func (*ForkDB) IterateLinks ¶
func (*ForkDB) PurgeBeforeLIB ¶
func (*ForkDB) ReversibleSegment ¶
ReversibleSegment returns the blocks between the previous irreversible Block ID and the given block ID. The LIB is excluded and the given block ID is included in the results.
Do not call this function if the `.HasLIB()` is false, as the result would make no sense.
WARN: if the segment is broken by some unlinkable blocks, the return value is `nil`.
type ForkDBOption ¶
type ForkDBOption func(db *ForkDB)
func ForkDBWithLogger ¶
func ForkDBWithLogger(logger *zap.Logger) ForkDBOption
type Forkable ¶
func (*Forkable) CallWithBlocksFromCursor ¶
func (*Forkable) CallWithBlocksFromNum ¶
func (*Forkable) CallWithBlocksThroughCursor ¶
func (*Forkable) CanonicalBlockAt ¶
func (*Forkable) GetBlockByHash ¶
func (*Forkable) LowestBlockNum ¶
type ForkableBlock ¶
type ForkableObject ¶
type ForkableObject struct { // The three following fields are filled when handling multi-block steps, like when passing Irreversibile segments, the whole segment is represented in here. StepCount int // Total number of steps in multi-block steps. StepIndex int // Index for the current block StepBlocks []*bstream.PreprocessedBlock // You can decide to process them when StepCount == StepIndex +1 or when StepIndex == 0 only. // Object that was returned by PreprocessBlock(). Could be nil Obj interface{} // contains filtered or unexported fields }
func (*ForkableObject) Cursor ¶
func (fobj *ForkableObject) Cursor() *bstream.Cursor
func (*ForkableObject) FinalBlockHeight ¶
func (fobj *ForkableObject) FinalBlockHeight() uint64
func (*ForkableObject) ReorgJunctionBlock ¶
func (fobj *ForkableObject) ReorgJunctionBlock() bstream.BlockRef
func (*ForkableObject) Step ¶
func (fobj *ForkableObject) Step() bstream.StepType
func (*ForkableObject) WrappedObject ¶
func (fobj *ForkableObject) WrappedObject() interface{}
type IrreversibleBlockIDGate ¶
type IrreversibleBlockIDGate struct { MaxHoldOff int // contains filtered or unexported fields }
This gate lets all blocks through once the target block ID has passed AS IRREVERSIBLE
func NewIrreversibleBlockIDGate ¶
func NewIrreversibleBlockIDGate(blockID string, gateType bstream.GateType, h bstream.Handler, opts ...bstream.GateOption) *IrreversibleBlockIDGate
func (*IrreversibleBlockIDGate) ProcessBlock ¶
func (g *IrreversibleBlockIDGate) ProcessBlock(blk *pbbstream.Block, obj interface{}) error
func (*IrreversibleBlockIDGate) SetLogger ¶
func (g *IrreversibleBlockIDGate) SetLogger(logger *zap.Logger)
type IrreversibleBlockNumGate ¶
type IrreversibleBlockNumGate struct { MaxHoldOff int // contains filtered or unexported fields }
IrreversibleBlockNumGate This gate lets all blocks through once the target blocknum has passed AS IRREVERSIBLE
func NewIrreversibleBlockNumGate ¶
func NewIrreversibleBlockNumGate(blockNum uint64, gateType bstream.GateType, h bstream.Handler, opts ...bstream.GateOption) *IrreversibleBlockNumGate
func (*IrreversibleBlockNumGate) ProcessBlock ¶
func (g *IrreversibleBlockNumGate) ProcessBlock(blk *pbbstream.Block, obj interface{}) error
func (*IrreversibleBlockNumGate) SetLogger ¶
func (g *IrreversibleBlockNumGate) SetLogger(logger *zap.Logger)
type ObjectBinaryMarshaler ¶
type ObjectBinaryMarshaler interface { MarshalBinary() ([]byte, error) UnmarshalBinary([]byte) error }
ObjectBinaryMarshaler is an interface that tells the ForkDB that the object can be serialized as binary via a call to `MarshalBinary` and deserialized the same way via `UnmarshalBinary` assuming you correctly provide the `objectFactory` when calling `ForkDB#Deserialize`.
type ObjectFactory ¶
type ObjectFactory func() any
ObjectFactory is an interface that tells the ForkDB how to create a new object for deserialization. It is used when deserializing the ForkDB's object so that the correct type is instantiated.
type ObjectJSONMarshallable ¶
type ObjectJSONMarshallable interface {
JSONMarshallable()
}
ObjectJSONMarshallable is a marker interface that tells the ForkDB that the object can be serialized as JSON via a call to `json.Marshal` and deserialized the same way via `json.Unmarshal` assuming you correctly provide the `objectFactory` when calling `ForkDB#Deserialize`.
type Option ¶
type Option func(f *Forkable)
func EnsureAllBlocksTriggerLongestChain ¶
func EnsureAllBlocksTriggerLongestChain() Option
EnsureAllBlocksTriggerLongestChain will force every block to be considered as the longest chain, therefore making it appear as New at least once. The only edge case is if there is a hole between a block and LIB when it is received, and it is forked out: in this case, that block would never appear. It is extremely unlikely to happen, because incoming blocks should be linkable, and blocks that are not forked out will eventually be processed anyway.
func EnsureBlockFlows ¶
func HoldBlocksUntilLIB ¶
func HoldBlocksUntilLIB() Option
func WithExclusiveLIB ¶
func WithFilters ¶
WithFilters choses the steps we want to pass through the sub handler. It defaults to StepsAll upon creation.