chainmanager

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 (
	ErrCommitmentUnknown  = errors.New("unknown commitment")
	ErrCommitmentNotSolid = errors.New("commitment not solid")
)
View Source
var NewEvents = event.CreateGroupConstructor(func() *Events {
	return &Events{
		CommitmentMissing:         event.New1[commitment.ID](),
		MissingCommitmentReceived: event.New1[commitment.ID](),
		CommitmentBelowRoot:       event.New1[commitment.ID](),
		ForkDetected:              event.New1[*Fork](),
	}
})

Functions

func WithForkDetectionMinimumDepth

func WithForkDetectionMinimumDepth(depth int64) options.Option[Manager]

Types

type Chain

type Chain struct {
	ForkingPoint *Commitment

	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

func NewChain

func NewChain(forkingPoint *Commitment) (fork *Chain)

func (*Chain) Commitment

func (c *Chain) Commitment(index slot.Index) (commitment *Commitment)

func (*Chain) IsSolid

func (c *Chain) IsSolid() (isSolid bool)

func (*Chain) LatestCommitment

func (c *Chain) LatestCommitment() *Commitment

func (*Chain) Size

func (c *Chain) Size() int

type ChainID

type ChainID = commitment.ID

type Commitment

type Commitment struct {
	model.Storable[commitment.ID, Commitment, *Commitment, commitmentModel] `serix:"0"`
	// contains filtered or unexported fields
}

func NewCommitment

func NewCommitment(id commitment.ID) (newCommitment *Commitment)

func (*Commitment) Chain

func (c *Commitment) Chain() (chain *Chain)

func (*Commitment) Children

func (c *Commitment) Children() []*Commitment

func (*Commitment) Commitment

func (c *Commitment) Commitment() (commitment *commitment.Commitment)

func (*Commitment) FromObjectStorage

func (c *Commitment) FromObjectStorage(key, data []byte) (err error)

FromObjectStorage deserializes a model from the object storage. TODO: this is just a temporary fix

func (*Commitment) IsSolid

func (c *Commitment) IsSolid() (isSolid bool)

func (*Commitment) ObjectStorageKey

func (c *Commitment) ObjectStorageKey() (key []byte)

ObjectStorageKey returns the bytes, that are used as a key to store the object in the k/v store. TODO: this is just a temporary fix

func (*Commitment) PublishCommitment

func (c *Commitment) PublishCommitment(commitment *commitment.Commitment) (published bool)

func (*Commitment) PublishRoots

func (c *Commitment) PublishRoots(roots *commitment.Roots) (published bool)

func (*Commitment) SetSolid

func (c *Commitment) SetSolid(solid bool) (updated bool)

type Events

type Events struct {
	CommitmentMissing         *event.Event1[commitment.ID]
	MissingCommitmentReceived *event.Event1[commitment.ID]
	CommitmentBelowRoot       *event.Event1[commitment.ID]
	ForkDetected              *event.Event1[*Fork]
	EvictionState             *eviction.Events

	event.Group[Events, *Events]
}

type Fork

type Fork struct {
	Source       identity.ID
	Commitment   *commitment.Commitment
	ForkingPoint *commitment.Commitment
}

type Manager

type Manager struct {
	Events              *Events
	CommitmentRequester *eventticker.EventTicker[commitment.ID]
	// contains filtered or unexported fields
}

func NewManager

func NewManager(opts ...options.Option[Manager]) (manager *Manager)

func (*Manager) Chain

func (m *Manager) Chain(ec commitment.ID) (chain *Chain)

func (*Manager) Commitments

func (m *Manager) Commitments(id commitment.ID, amount int) (commitments []*Commitment, err error)

func (*Manager) EvictUntil

func (m *Manager) EvictUntil(index slot.Index)

func (*Manager) ForkByForkingPoint

func (m *Manager) ForkByForkingPoint(forkingPoint commitment.ID) (fork *Fork, exists bool)

ForkByForkingPoint returns the fork generated by a peer for the given forking point.

func (*Manager) Initialize

func (m *Manager) Initialize(c *commitment.Commitment)

func (*Manager) ProcessCandidateCommitment

func (m *Manager) ProcessCandidateCommitment(commitment *commitment.Commitment) (isSolid bool, chain *Chain)

func (*Manager) ProcessCommitment

func (m *Manager) ProcessCommitment(commitment *commitment.Commitment) (isSolid bool, chain *Chain)

func (*Manager) ProcessCommitmentFromSource

func (m *Manager) ProcessCommitmentFromSource(commitment *commitment.Commitment, source identity.ID) (isSolid bool, chain *Chain)

func (*Manager) RootCommitment

func (m *Manager) RootCommitment() (rootCommitment *Commitment)

RootCommitment returns the root commitment of the manager.

func (*Manager) SetRootCommitment

func (m *Manager) SetRootCommitment(commitment *commitment.Commitment)

SetRootCommitment sets the root commitment of the manager.

func (*Manager) SwitchMainChain

func (m *Manager) SwitchMainChain(head commitment.ID) error

type TestFramework

type TestFramework struct {
	Instance *Manager

	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

func NewTestFramework

func NewTestFramework(test *testing.T, opts ...options.Option[TestFramework]) (testFramework *TestFramework)

func (*TestFramework) AssertChainIsAlias

func (t *TestFramework) AssertChainIsAlias(chain *Chain, alias string)

func (*TestFramework) AssertChainState

func (t *TestFramework) AssertChainState(chains map[string]string)

func (*TestFramework) AssertCommitmentBelowRootCount

func (t *TestFramework) AssertCommitmentBelowRootCount(expected int)

func (*TestFramework) AssertCommitmentMissingCount

func (t *TestFramework) AssertCommitmentMissingCount(expected int)

func (*TestFramework) AssertEqualChainCommitments

func (t *TestFramework) AssertEqualChainCommitments(commitments []*Commitment, aliases ...string)

func (*TestFramework) AssertForkDetectedCount

func (t *TestFramework) AssertForkDetectedCount(expected int)

func (*TestFramework) AssertMissingCommitmentReceivedCount

func (t *TestFramework) AssertMissingCommitmentReceivedCount(expected int)

func (*TestFramework) Chain

func (t *TestFramework) Chain(alias string) (chain *Chain)

func (*TestFramework) ChainCommitment

func (t *TestFramework) ChainCommitment(alias string) *Commitment

func (*TestFramework) CreateCommitment

func (t *TestFramework) CreateCommitment(alias string, prevAlias string)

func (*TestFramework) PrevSlotCommitment

func (t *TestFramework) PrevSlotCommitment(alias string) commitment.ID

func (*TestFramework) ProcessCommitment

func (t *TestFramework) ProcessCommitment(alias string) (isSolid bool, chain *Chain)

func (*TestFramework) ProcessCommitmentFromOtherSource

func (t *TestFramework) ProcessCommitmentFromOtherSource(alias string) (isSolid bool, chain *Chain)

func (*TestFramework) SlotCommitment

func (t *TestFramework) SlotCommitment(alias string) commitment.ID

func (*TestFramework) SlotCommitmentRoot

func (t *TestFramework) SlotCommitmentRoot(alias string) types.Identifier

func (*TestFramework) SlotIndex

func (t *TestFramework) SlotIndex(alias string) slot.Index

Jump to

Keyboard shortcuts

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