finality

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBranchGoFTranslation is the default function to translate the approval weight to gof.GradeOfFinality of a branch.
	DefaultBranchGoFTranslation BranchThresholdTranslation = func(branchID utxo.TransactionID, aw float64) gof.GradeOfFinality {
		switch {
		case aw >= lowLowerBound && aw < mediumLowerBound:
			return gof.Low
		case aw >= mediumLowerBound && aw < highLowerBound:
			return gof.Medium
		case aw >= highLowerBound:
			return gof.High
		default:
			return gof.None
		}
	}

	// DefaultMessageGoFTranslation is the default function to translate the approval weight to gof.GradeOfFinality of a message.
	DefaultMessageGoFTranslation MessageThresholdTranslation = func(aw float64) gof.GradeOfFinality {
		switch {
		case aw >= lowLowerBound && aw < mediumLowerBound:
			return gof.Low
		case aw >= mediumLowerBound && aw < highLowerBound:
			return gof.Medium
		case aw >= highLowerBound:
			return gof.High
		default:
			return gof.None
		}
	}
)

Functions

This section is empty.

Types

type BranchConflictsUpdatedEvent added in v0.9.0

type BranchConflictsUpdatedEvent struct {
	// BranchID contains the identifier of the updated Branch.
	BranchID utxo.TransactionID

	// NewConflictIDs contains the set of conflicts that this Branch was added to.
	NewConflictIDs *set.AdvancedSet[utxo.OutputID]
}

BranchConflictsUpdatedEvent is a container that acts as a dictionary for the BranchConflictsUpdated event related parameters.

type BranchCreatedEvent added in v0.9.0

type BranchCreatedEvent struct {
	// BranchID contains the identifier of the newly created Branch.
	BranchID utxo.TransactionID

	// ParentBranchIDs contains the parent Branches of the newly created Branch.
	ParentBranchIDs *set.AdvancedSet[utxo.TransactionID]

	// ConflictIDs contains the set of conflicts that this Branch is involved with.
	ConflictIDs *set.AdvancedSet[utxo.OutputID]
}

BranchCreatedEvent is a container that acts as a dictionary for the BranchCreated event related parameters.

type BranchParentsUpdatedEvent added in v0.9.0

type BranchParentsUpdatedEvent struct {
	// BranchID contains the identifier of the updated Branch.
	BranchID utxo.TransactionID

	// AddedBranch contains the forked parent Branch that replaces the removed parents.
	AddedBranch utxo.TransactionID

	// RemovedBranches contains the parent BranchIDs that were replaced by the newly forked Branch.
	RemovedBranches *set.AdvancedSet[utxo.TransactionID]
}

BranchParentsUpdatedEvent is a container that acts as a dictionary for the BranchParentsUpdated event related parameters.

type BranchThresholdTranslation

type BranchThresholdTranslation func(branchID utxo.TransactionID, aw float64) gof.GradeOfFinality

BranchThresholdTranslation is a function which translates approval weight to a gof.GradeOfFinality.

type Events added in v0.9.0

type Events struct {
	// BranchCreated is an event that gets triggered whenever a new Branch is created.
	BranchCreated *event.Event[*BranchCreatedEvent]

	// BranchConflictsUpdated is an event that gets triggered whenever the ConflictIDs of a Branch are updated.
	BranchConflictsUpdated *event.Event[*BranchConflictsUpdatedEvent]

	// BranchParentsUpdated is an event that gets triggered whenever the parent BranchIDs of a Branch are updated.
	BranchParentsUpdated *event.Event[*BranchParentsUpdatedEvent]
}

Events is a container that acts as a dictionary for the existing events of a ConflictDAG.

type Gadget

type Gadget interface {
	HandleMarker(marker markers.Marker, aw float64) (err error)
	HandleBranch(branchID utxo.TransactionID, aw float64) (err error)
	tangle.ConfirmationOracle
}

Gadget is an interface that describes the finality gadget.

type MessageThresholdTranslation

type MessageThresholdTranslation func(aw float64) gof.GradeOfFinality

MessageThresholdTranslation is a function which translates approval weight to a gof.GradeOfFinality.

type Option

type Option func(*Options)

Option is a function setting an option on an Options struct.

func WithBranchGoFReachedLevel

func WithBranchGoFReachedLevel(branchGradeOfFinality gof.GradeOfFinality) Option

WithBranchGoFReachedLevel returns an Option setting the branch reached grade of finality level.

func WithBranchThresholdTranslation

func WithBranchThresholdTranslation(f BranchThresholdTranslation) Option

WithBranchThresholdTranslation returns an Option setting the BranchThresholdTranslation.

func WithMessageGoFReachedLevel

func WithMessageGoFReachedLevel(msgGradeOfFinality gof.GradeOfFinality) Option

WithMessageGoFReachedLevel returns an Option setting the message reached grade of finality level.

func WithMessageThresholdTranslation

func WithMessageThresholdTranslation(f MessageThresholdTranslation) Option

WithMessageThresholdTranslation returns an Option setting the MessageThresholdTranslation.

type Options

type Options struct {
	BranchTransFunc        BranchThresholdTranslation
	MessageTransFunc       MessageThresholdTranslation
	BranchGoFReachedLevel  gof.GradeOfFinality
	MessageGoFReachedLevel gof.GradeOfFinality
}

Options defines the options for a SimpleFinalityGadget.

type SimpleFinalityGadget

type SimpleFinalityGadget struct {
	// contains filtered or unexported fields
}

SimpleFinalityGadget is a Gadget which simply translates approval weight down to gof.GradeOfFinality and then applies it to messages, branches, transactions and outputs.

func NewSimpleFinalityGadget

func NewSimpleFinalityGadget(t *tangle.Tangle, opts ...Option) *SimpleFinalityGadget

NewSimpleFinalityGadget creates a new SimpleFinalityGadget.

func (*SimpleFinalityGadget) Events

Events returns the events this gadget exposes.

func (*SimpleFinalityGadget) FirstUnconfirmedMarkerIndex added in v0.8.6

func (s *SimpleFinalityGadget) FirstUnconfirmedMarkerIndex(sequenceID markers.SequenceID) (index markers.Index)

FirstUnconfirmedMarkerIndex returns the first Index in the given Sequence that was not confirmed, yet.

func (*SimpleFinalityGadget) HandleBranch

func (s *SimpleFinalityGadget) HandleBranch(branchID utxo.TransactionID, aw float64) (err error)

HandleBranch receives a branchID and its approval weight. It propagates the GoF according to AW to transactions in the branch (UTXO future cone) and their outputs.

func (*SimpleFinalityGadget) HandleMarker

func (s *SimpleFinalityGadget) HandleMarker(marker markers.Marker, aw float64) (err error)

HandleMarker receives a marker and its current approval weight. It propagates the GoF according to AW to its past cone.

func (*SimpleFinalityGadget) IsBranchConfirmed

func (s *SimpleFinalityGadget) IsBranchConfirmed(branchID utxo.TransactionID) (confirmed bool)

IsBranchConfirmed returns whether the given branch is confirmed.

func (*SimpleFinalityGadget) IsMarkerConfirmed

func (s *SimpleFinalityGadget) IsMarkerConfirmed(marker markers.Marker) (confirmed bool)

IsMarkerConfirmed returns whether the given marker is confirmed.

func (*SimpleFinalityGadget) IsMessageConfirmed

func (s *SimpleFinalityGadget) IsMessageConfirmed(msgID tangle.MessageID) (confirmed bool)

IsMessageConfirmed returns whether the given message is confirmed.

func (*SimpleFinalityGadget) IsOutputConfirmed

func (s *SimpleFinalityGadget) IsOutputConfirmed(outputID utxo.OutputID) (confirmed bool)

IsOutputConfirmed returns whether the given output is confirmed.

func (*SimpleFinalityGadget) IsTransactionConfirmed

func (s *SimpleFinalityGadget) IsTransactionConfirmed(transactionID utxo.TransactionID) (confirmed bool)

IsTransactionConfirmed returns whether the given transaction is confirmed.

Jump to

Keyboard shortcuts

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