blockdag

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0, BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewEvents = event.CreateGroupConstructor(func() (newEvents *Events) {
	return &Events{
		BlockAttached:        event.New1[*Block](),
		BlockSolid:           event.New1[*Block](),
		BlockMissing:         event.New1[*Block](),
		MissingBlockAttached: event.New1[*Block](),
		BlockInvalid:         event.New1[*BlockInvalidEvent](),
		BlockOrphaned:        event.New1[*Block](),
		BlockUnorphaned:      event.New1[*Block](),
	}
})

NewEvents contains the constructor of the Events object (it is generated by a generic factory).

Functions

func DefaultCommitmentFunc

func DefaultCommitmentFunc(index slot.Index) (cm *commitment.Commitment, err error)

func NewTestStorage

func NewTestStorage(t *testing.T, workers *workerpool.Group, opts ...options.Option[database.Manager]) *storage.Storage

func WithMissing

func WithMissing(missing bool) options.Option[Block]

WithMissing is a constructor Option for Blocks that initializes the given block with a specific missing flag.

func WithModelOptions

func WithModelOptions(opts ...options.Option[models.Block]) options.Option[Block]

func WithOrphaned

func WithOrphaned(markedOrphaned bool) options.Option[Block]

WithOrphaned is a constructor Option for Blocks that initializes the given block with a specific orphaned flag.

func WithSolid

func WithSolid(solid bool) options.Option[Block]

WithSolid is a constructor Option for Blocks that initializes the given block with a specific solid flag.

Types

type Block

type Block struct {
	*ModelsBlock
	// contains filtered or unexported fields
}

Block represents a Block annotated with Mesh related metadata.

func NewBlock

func NewBlock(data *models.Block, opts ...options.Option[Block]) (newBlock *Block)

NewBlock creates a new Block with the given options.

func NewRootBlock

func NewRootBlock(id models.BlockID, slotTimeProvider *slot.TimeProvider, opts ...options.Option[models.Block]) (rootBlock *Block)

func (*Block) AppendChild

func (b *Block) AppendChild(child *Block, childType models.ParentsType)

AppendChild adds a child of the corresponding type to the Block.

func (*Block) Children

func (b *Block) Children() (children []*Block)

Children returns the children of the Block.

func (*Block) IsFuture

func (b *Block) IsFuture() (isFuture bool)

IsFuture returns true if the Block is a future Block (we haven't committed to its commitment slot yet).

func (*Block) IsInvalid

func (b *Block) IsInvalid() (isInvalid bool)

IsInvalid returns true if the Block was marked as invalid.

func (*Block) IsMissing

func (b *Block) IsMissing() (isMissing bool)

IsMissing returns a flag that indicates if the underlying Block data hasn't been stored, yet.

func (*Block) IsOrphaned

func (b *Block) IsOrphaned() (isOrphaned bool)

IsOrphaned returns true if the Block is orphaned (either due to being marked as orphaned itself or because it has orphaned Blocks in its past cone).

func (*Block) IsSolid

func (b *Block) IsSolid() (isSolid bool)

IsSolid returns true if the Block is solid (the entire causal history is known).

func (*Block) LikedInsteadChildren

func (b *Block) LikedInsteadChildren() []*Block

func (*Block) SetFuture

func (b *Block) SetFuture() (wasUpdated bool)

SetFuture marks the Block as future block.

func (*Block) SetInvalid

func (b *Block) SetInvalid() (wasUpdated bool)

SetInvalid marks the Block as invalid.

func (*Block) SetOrphaned

func (b *Block) SetOrphaned(orphaned bool) (wasUpdated bool)

SetOrphaned sets the orphaned flag of the Block.

func (*Block) SetSolid

func (b *Block) SetSolid() (wasUpdated bool)

SetSolid marks the Block as solid.

func (*Block) String

func (b *Block) String() string

func (*Block) StrongChildren

func (b *Block) StrongChildren() []*Block

func (*Block) Update

func (b *Block) Update(data *models.Block) (wasPublished bool)

Update publishes the given Block data to the underlying Block and marks it as no longer missing.

func (*Block) WeakChildren

func (b *Block) WeakChildren() []*Block

type BlockDAG

type BlockDAG interface {
	Events() *Events

	// Attach is used to attach new Blocks to the BlockDAG. It is the main function of the BlockDAG that triggers Events.
	Attach(data *models.Block) (block *Block, wasAttached bool, err error)

	// Block retrieves a Block with metadata from the in-memory storage of the BlockDAG.
	Block(id models.BlockID) (block *Block, exists bool)

	// SetOrphaned marks a Block as orphaned and propagates it to its future cone.
	SetOrphaned(block *Block, orphaned bool) (updated bool)

	// SetInvalid marks a Block as invalid and propagates the invalidity to its future cone.
	SetInvalid(block *Block, reason error) (wasUpdated bool)

	module.Interface
}

type BlockInvalidEvent

type BlockInvalidEvent struct {
	Block  *Block
	Reason error
}

type Events

type Events struct {
	// BlockAttached is triggered when a previously unknown Block is attached.
	BlockAttached *event.Event1[*Block]

	// BlockSolid is triggered when a Block becomes solid (its entire past cone is known and solid).
	BlockSolid *event.Event1[*Block]

	// BlockMissing is triggered when a referenced Block was not attached, yet.
	BlockMissing *event.Event1[*Block]

	// MissingBlockAttached is triggered when a previously missing Block was attached.
	MissingBlockAttached *event.Event1[*Block]

	// BlockInvalid is triggered when a Block is found to be invalid.
	BlockInvalid *event.Event1[*BlockInvalidEvent]

	// BlockOrphaned is triggered when a Block becomes orphaned.
	BlockOrphaned *event.Event1[*Block]

	// BlockUnorphaned is triggered when a Block is no longer orphaned.
	BlockUnorphaned *event.Event1[*Block]

	event.Group[Events, *Events]
}

Events is a collection of Mesh related Events.

type ModelsBlock

type ModelsBlock = models.Block

type ModelsTestFramework

type ModelsTestFramework = models.TestFramework

ModelsTestFramework is an alias that it is used to be able to embed a named version of the TestFramework.

type TestFramework

type TestFramework struct {
	Instance BlockDAG

	Test *testing.T

	*ModelsTestFramework
	// contains filtered or unexported fields
}

TestFramework implements a framework for conveniently issuing blocks in a BlockDAG as part of unit tests in a simplified way.

func NewTestFramework

func NewTestFramework(test *testing.T, workers *workerpool.Group, blockDAG BlockDAG, slotTimeProviderFunc func() *slot.TimeProvider) *TestFramework

NewTestFramework is the constructor of the TestFramework.

func (*TestFramework) AssertBlock

func (t *TestFramework) AssertBlock(alias string, callback func(block *Block))

func (*TestFramework) AssertInvalid

func (t *TestFramework) AssertInvalid(expectedValues map[string]bool)

func (*TestFramework) AssertInvalidCount

func (t *TestFramework) AssertInvalidCount(invalidCount int32, msgAndArgs ...interface{})

func (*TestFramework) AssertLikedInsteadChildren

func (t *TestFramework) AssertLikedInsteadChildren(m map[string][]string)

func (*TestFramework) AssertMissing

func (t *TestFramework) AssertMissing(expectedValues map[string]bool)

func (*TestFramework) AssertMissingCount

func (t *TestFramework) AssertMissingCount(missingCount int32, msgAndArgs ...interface{})

func (*TestFramework) AssertOrphanedBlocks

func (t *TestFramework) AssertOrphanedBlocks(orphanedBlocks models.BlockIDs, msgAndArgs ...interface{})

func (*TestFramework) AssertOrphanedCount

func (t *TestFramework) AssertOrphanedCount(storedCount int32, msgAndArgs ...interface{})

func (*TestFramework) AssertSolid

func (t *TestFramework) AssertSolid(expectedValues map[string]bool)

func (*TestFramework) AssertSolidCount

func (t *TestFramework) AssertSolidCount(solidCount int32, msgAndArgs ...interface{})

func (*TestFramework) AssertStoredCount

func (t *TestFramework) AssertStoredCount(storedCount int32, msgAndArgs ...interface{})

func (*TestFramework) AssertStrongChildren

func (t *TestFramework) AssertStrongChildren(m map[string][]string)

func (*TestFramework) AssertWeakChildren

func (t *TestFramework) AssertWeakChildren(m map[string][]string)

func (*TestFramework) IssueBlocks

func (t *TestFramework) IssueBlocks(blockAliases ...string) *TestFramework

IssueBlocks stores the given Blocks in the Storage and triggers the processing by the BlockDAG.

func (*TestFramework) SlotTimeProvider

func (t *TestFramework) SlotTimeProvider() *slot.TimeProvider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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