fcob

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0, BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrefixOpinion defines the Storage prefix for the opinion Storage.
	PrefixOpinion byte = iota

	// PrefixTimestampOpinion defines the Storage prefix for the timestamp opinion Storage.
	PrefixTimestampOpinion

	// PrefixMessageMetadata defines the Storage prefix for the MessageMetadata Storage.
	PrefixMessageMetadata
)
View Source
const (
	// TimestampOpinionLength defines the length of a TimestampOpinion object (1 byte of opinion, 1 byte of LoK).
	TimestampOpinionLength = tangle.MessageIDLength + 2
)

Variables

View Source
var (
	// LikedThreshold is the first time threshold of FCoB.
	LikedThreshold = 2 * time.Second

	// LocallyFinalizedThreshold is the second time threshold of FCoB.
	LocallyFinalizedThreshold = 4 * time.Second
)
View Source
var (
	// TimestampWindow defines the time window for assessing the timestamp quality.
	TimestampWindow time.Duration

	// GratuitousNetworkDelay defines the time after which we assume all messages are delivered.
	GratuitousNetworkDelay time.Duration
)

Functions

func MessageMetadataFromObjectStorage added in v0.5.1

func MessageMetadataFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

MessageMetadataFromObjectStorage restores a MessageMetadata object from the object Storage.

func OpinionFromObjectStorage

func OpinionFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

OpinionFromObjectStorage restores an Opinion from the ObjectStorage.

func TimestampOpinionFromObjectStorage

func TimestampOpinionFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

TimestampOpinionFromObjectStorage restores a TimestampOpinion from the object Storage.

Types

type CachedMessageMetadata added in v0.5.1

type CachedMessageMetadata struct {
	objectstorage.CachedObject
}

CachedMessageMetadata is a wrapper for the generic CachedObject returned by the object Storage that overrides the accessor methods with a type-casted one.

func (*CachedMessageMetadata) Consume added in v0.5.1

func (c *CachedMessageMetadata) Consume(consumer func(messageMetadata *MessageMetadata), forceRelease ...bool) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedMessageMetadata) ID added in v0.5.1

func (c *CachedMessageMetadata) ID() (messageID tangle.MessageID)

ID returns the MessageID of the requested MessageMetadata.

func (*CachedMessageMetadata) Retain added in v0.5.1

Retain marks the CachedObject to still be in use by the program.

func (*CachedMessageMetadata) String added in v0.5.1

func (c *CachedMessageMetadata) String() string

String returns a human readable version of the CachedMessageMetadata.

func (*CachedMessageMetadata) Unwrap added in v0.5.1

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type CachedOpinion

type CachedOpinion struct {
	objectstorage.CachedObject
}

CachedOpinion is a wrapper for the generic CachedObject returned by the object Storage that overrides the accessor methods with a type-casted one.

func (*CachedOpinion) Consume

func (c *CachedOpinion) Consume(consumer func(opinion *Opinion), forceRelease ...bool) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedOpinion) Retain

func (c *CachedOpinion) Retain() *CachedOpinion

Retain marks the CachedObject to still be in use by the program.

func (*CachedOpinion) String

func (c *CachedOpinion) String() string

String returns a human readable version of the CachedOpinion.

func (*CachedOpinion) Unwrap

func (c *CachedOpinion) Unwrap() *Opinion

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type CachedTimestampOpinion

type CachedTimestampOpinion struct {
	objectstorage.CachedObject
}

CachedTimestampOpinion is a wrapper for the generic CachedObject returned by the object Storage that overrides the accessor methods with a type-casted one.

func (*CachedTimestampOpinion) Consume

func (c *CachedTimestampOpinion) Consume(consumer func(timestampOpinion *TimestampOpinion), forceRelease ...bool) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedTimestampOpinion) Retain

Retain marks the CachedObject to still be in use by the program.

func (*CachedTimestampOpinion) String

func (c *CachedTimestampOpinion) String() string

String returns a human readable version of the CachedTimestampOpinion.

func (*CachedTimestampOpinion) Unwrap

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type ConflictSet

type ConflictSet []OpinionEssence

ConflictSet is a list of Opinion.

type ConsensusMechanism

type ConsensusMechanism struct {
	Events *ConsensusMechanismEvents

	Storage *Storage
	// contains filtered or unexported fields
}

ConsensusMechanism represents the FCoB consensus that can be used as a ConsensusMechanism in the Tangle.

func NewConsensusMechanism

func NewConsensusMechanism() *ConsensusMechanism

NewConsensusMechanism is the constructor for the FCoB consensus mechanism.

func (*ConsensusMechanism) Evaluate

func (f *ConsensusMechanism) Evaluate(messageID tangle.MessageID)

Evaluate evaluates the opinion of the given messageID.

func (*ConsensusMechanism) EvaluateTimestamp

func (f *ConsensusMechanism) EvaluateTimestamp(messageID tangle.MessageID)

EvaluateTimestamp evaluates the honesty of the timestamp of the given Message.

func (*ConsensusMechanism) Init

func (f *ConsensusMechanism) Init(tangle *tangle.Tangle)

Init initializes the ConsensusMechanism by making the Tangle object available that is using it.

func (*ConsensusMechanism) OpinionFormedTime added in v0.5.3

func (f *ConsensusMechanism) OpinionFormedTime(messageID tangle.MessageID) (t time.Time)

OpinionFormedTime returns the time when the opinion for the given message was formed.

func (*ConsensusMechanism) OpinionsEssence

func (f *ConsensusMechanism) OpinionsEssence(targetID ledgerstate.TransactionID, conflictSet ledgerstate.TransactionIDs) (opinions []OpinionEssence)

OpinionsEssence returns a list of OpinionEssence (i.e., a copy of the triple{timestamp, liked, levelOfKnowledge}) of given conflictSet.

func (*ConsensusMechanism) ProcessVote

func (f *ConsensusMechanism) ProcessVote(ev *vote.OpinionEvent)

ProcessVote allows an external voter to hand in the results of the voting process.

func (*ConsensusMechanism) SetTransactionLiked added in v0.5.8

func (f *ConsensusMechanism) SetTransactionLiked(transactionID ledgerstate.TransactionID, liked bool) (modified bool)

SetTransactionLiked sets the transaction like status.

func (*ConsensusMechanism) Setup

func (f *ConsensusMechanism) Setup()

Setup sets up the behavior of the ConsensusMechanism by making it attach to the relevant events in the Tangle.

func (*ConsensusMechanism) Shutdown

func (f *ConsensusMechanism) Shutdown()

Shutdown shuts down the ConsensusMechanism and persists its state.

func (*ConsensusMechanism) TransactionLiked

func (f *ConsensusMechanism) TransactionLiked(transactionID ledgerstate.TransactionID) (liked bool)

TransactionLiked returns a boolean value indicating whether the given Transaction is liked.

func (*ConsensusMechanism) TransactionOpinionEssence

func (f *ConsensusMechanism) TransactionOpinionEssence(transactionID ledgerstate.TransactionID) (opinion OpinionEssence)

TransactionOpinionEssence returns the opinion essence of a given transactionID.

type ConsensusMechanismEvents

type ConsensusMechanismEvents struct {
	// Error gets called when FCOB faces an error.
	Error *events.Event

	// Vote gets called when FCOB needs to vote.
	Vote *events.Event
}

ConsensusMechanismEvents represents events triggered by the ConsensusMechanism.

type LevelOfKnowledge

type LevelOfKnowledge uint8

LevelOfKnowledge defines the Level Of Knowledge type.

const (
	// Pending implies that the opinion is not formed yet.
	Pending LevelOfKnowledge = iota

	// One implies that voting is required.
	One

	// Two implies that we have locally finalized our opinion but we can still reply to eventual queries.
	Two

	// Three implies that we have locally finalized our opinion and we do not reply to eventual queries.
	Three
)

The different levels of knowledge.

func (LevelOfKnowledge) String

func (l LevelOfKnowledge) String() string

String returns a human readable version of LevelOfKnowledge.

type MessageMetadata added in v0.5.1

type MessageMetadata struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

MessageMetadata defines the metadata for a message.

func MessageMetadataFromBytes added in v0.5.1

func MessageMetadataFromBytes(bytes []byte) (messageMetadata *MessageMetadata, consumedBytes int, err error)

MessageMetadataFromBytes unmarshals a MessageMetadata object from a sequence of bytes.

func MessageMetadataFromMarshalUtil added in v0.5.1

func MessageMetadataFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (messageMetadata *MessageMetadata, err error)

MessageMetadataFromMarshalUtil unmarshals a MessageMetadata object using a MarshalUtil (for easier unmarshaling).

func NewMessageMetadata added in v0.5.1

func NewMessageMetadata(messageID tangle.MessageID) *MessageMetadata

NewMessageMetadata is the constructor of the MessageMetadata object.

func (*MessageMetadata) Bytes added in v0.5.1

func (m *MessageMetadata) Bytes() []byte

Bytes returns a marshaled version of the MessageMetadata.

func (*MessageMetadata) ID added in v0.5.1

ID returns the MessageID that this MessageMetadata object belongs to.

func (*MessageMetadata) MessageOpinionFormed added in v0.5.1

func (m *MessageMetadata) MessageOpinionFormed() bool

MessageOpinionFormed returns the messageOpinionFormed flag of the MessageMetadata.

func (*MessageMetadata) MessageOpinionTriggered added in v0.5.1

func (m *MessageMetadata) MessageOpinionTriggered() bool

MessageOpinionTriggered returns the messageOpinionTriggered flag of the MessageMetadata.

func (*MessageMetadata) ObjectStorageKey added in v0.5.1

func (m *MessageMetadata) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the StorableObject interface.

func (*MessageMetadata) ObjectStorageValue added in v0.5.1

func (m *MessageMetadata) ObjectStorageValue() []byte

ObjectStorageValue marshals the MessageMetadata into a sequence of bytes that are used as the value part in the object Storage.

func (*MessageMetadata) OpinionFormedTime added in v0.5.3

func (m *MessageMetadata) OpinionFormedTime() time.Time

OpinionFormedTime returns the opinionFormed time of the MessageMetadata.

func (*MessageMetadata) PayloadOpinionFormed added in v0.5.1

func (m *MessageMetadata) PayloadOpinionFormed() bool

PayloadOpinionFormed returns the payloadOpinionFormed flag of the MessageMetadata.

func (*MessageMetadata) SetMessageOpinionFormed added in v0.5.1

func (m *MessageMetadata) SetMessageOpinionFormed(messageOpinionFormed bool) (modified bool)

SetMessageOpinionFormed sets the messageOpinionFormed flag to the given value. It returns true if the value has been updated.

func (*MessageMetadata) SetMessageOpinionTriggered added in v0.5.1

func (m *MessageMetadata) SetMessageOpinionTriggered(messageOpinionTriggered bool) (modified bool)

SetMessageOpinionTriggered sets the messageOpinionTriggered flag to the given value. It returns true if the value has been updated.

func (*MessageMetadata) SetPayloadOpinionFormed added in v0.5.1

func (m *MessageMetadata) SetPayloadOpinionFormed(payloadOpinionFormed bool) (modified bool)

SetPayloadOpinionFormed sets the payloadOpinionFormed flag to the given value. It returns true if the value has been updated.

func (*MessageMetadata) SetTimestampOpinionFormed added in v0.5.1

func (m *MessageMetadata) SetTimestampOpinionFormed(timestampOpinionFormed bool) (modified bool)

SetTimestampOpinionFormed sets the timestampOpinionFormed flag to the given value. It returns true if the value has been updated.

func (*MessageMetadata) String added in v0.5.1

func (m *MessageMetadata) String() string

String returns a human readable version of the MessageMetadata.

func (*MessageMetadata) TimestampOpinionFormed added in v0.5.1

func (m *MessageMetadata) TimestampOpinionFormed() bool

TimestampOpinionFormed returns the timestampOpinionFormed flag of the MessageMetadata.

func (*MessageMetadata) Update added in v0.5.1

Update is disabled and panics if it ever gets called - it is required to match the StorableObject interface.

type Opinion

type Opinion struct {

	// the essence associated to this opinion.
	OpinionEssence

	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Opinion defines the FCoB opinion about a transaction.

func OpinionFromMarshalUtil

func OpinionFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Opinion, err error)

OpinionFromMarshalUtil parses an opinion from the given marshal util.

func (*Opinion) Bytes

func (o *Opinion) Bytes() []byte

Bytes marshals the Opinion into a sequence of bytes.

func (*Opinion) FCOBTime1 added in v0.5.7

func (o *Opinion) FCOBTime1() time.Time

FCOBTime1 returns the opinion's LikedThreshold execution time.

func (*Opinion) FCOBTime2 added in v0.5.7

func (o *Opinion) FCOBTime2() time.Time

FCOBTime2 returns the opinion's LocallyFinalizedThreshold execution time.

func (*Opinion) LevelOfKnowledge

func (o *Opinion) LevelOfKnowledge() LevelOfKnowledge

LevelOfKnowledge returns the opinion's LevelOfKnowledge.

func (*Opinion) Liked

func (o *Opinion) Liked() bool

Liked returns the opinion's liked.

func (*Opinion) ObjectStorageKey

func (o *Opinion) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the StorableObject interface.

func (*Opinion) ObjectStorageValue

func (o *Opinion) ObjectStorageValue() []byte

ObjectStorageValue marshals the Opinion into a sequence of bytes. The ID is not serialized here as it is only used as a key in the ObjectStorage.

func (*Opinion) SetFCOBTime1 added in v0.5.7

func (o *Opinion) SetFCOBTime1(t time.Time)

SetFCOBTime1 sets the opinion's LikedThreshold execution time.

func (*Opinion) SetFCOBTime2 added in v0.5.7

func (o *Opinion) SetFCOBTime2(t time.Time)

SetFCOBTime2 sets the opinion's LocallyFinalizedThreshold execution time.

func (*Opinion) SetLevelOfKnowledge

func (o *Opinion) SetLevelOfKnowledge(lok LevelOfKnowledge)

SetLevelOfKnowledge sets the opinion's LevelOfKnowledge.

func (*Opinion) SetLiked

func (o *Opinion) SetLiked(l bool) (modified bool)

SetLiked sets the opinion's liked.

func (*Opinion) SetTimestamp

func (o *Opinion) SetTimestamp(t time.Time)

SetTimestamp sets the opinion's timestamp.

func (*Opinion) String

func (o *Opinion) String() string

String returns a human readable version of the Opinion.

func (*Opinion) Timestamp

func (o *Opinion) Timestamp() time.Time

Timestamp returns the opinion's timestamp.

func (*Opinion) Update

func (o *Opinion) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - it is required to match the StorableObject interface.

type OpinionEssence

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

OpinionEssence contains the essence of an opinion (timestamp, liked, level of knowledge).

func (OpinionEssence) LevelOfKnowledge

func (o OpinionEssence) LevelOfKnowledge() LevelOfKnowledge

LevelOfKnowledge returns the opinion's LevelOfKnowledge.

func (OpinionEssence) Liked

func (o OpinionEssence) Liked() bool

Liked returns the opinion's liked.

func (OpinionEssence) String added in v0.5.1

func (o OpinionEssence) String() string

func (OpinionEssence) Timestamp

func (o OpinionEssence) Timestamp() time.Time

Timestamp returns the opinion's timestamp.

type Storage

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

Storage is a component of the ConsensusMechanism that encapsulates the Storage related methods.

func NewStorage

func NewStorage(store kvstore.KVStore) (storage *Storage)

NewStorage is the constructor for a Storage.

func (*Storage) MessageMetadata added in v0.5.1

func (s *Storage) MessageMetadata(messageID tangle.MessageID) (cachedMessageMetadata *CachedMessageMetadata)

MessageMetadata returns the MessageMetadata associated with given MessageID.

func (*Storage) Opinion

func (s *Storage) Opinion(transactionID ledgerstate.TransactionID) (cachedOpinion *CachedOpinion)

Opinion returns the Opinion associated with given TransactionID.

func (*Storage) OpinionEssence

func (s *Storage) OpinionEssence(transactionID ledgerstate.TransactionID) (opinion OpinionEssence)

OpinionEssence returns the OpinionEssence (i.e., a copy of the triple{timestamp, liked, levelOfKnowledge}) of given transactionID.

func (*Storage) Shutdown

func (s *Storage) Shutdown()

Shutdown shuts down the Storage and causes its content to be persisted to the disk.

func (*Storage) StoreMessageMetadata added in v0.5.1

func (s *Storage) StoreMessageMetadata(messageMetadata *MessageMetadata) (stored bool)

StoreMessageMetadata stores the MessageMetadata in the object Storage. It returns true if it was stored or updated.

func (*Storage) StoreTimestampOpinion

func (s *Storage) StoreTimestampOpinion(timestampOpinion *TimestampOpinion) (stored bool)

StoreTimestampOpinion stores the TimestampOpinion in the object Storage. It returns true if it was stored or updated.

func (*Storage) TimestampOpinion

func (s *Storage) TimestampOpinion(messageID tangle.MessageID) (cachedTimestampOpinion *CachedTimestampOpinion)

TimestampOpinion returns the TimestampOpinion associated with given MessageID.

type TimestampOpinion

type TimestampOpinion struct {
	MessageID tangle.MessageID
	Value     opinion.Opinion
	LoK       LevelOfKnowledge

	objectstorage.StorableObjectFlags
}

TimestampOpinion contains the value of a timestamp opinion as well as its level of knowledge.

func TimestampOpinionFromBytes

func TimestampOpinionFromBytes(bytes []byte) (timestampOpinion *TimestampOpinion, consumedBytes int, err error)

TimestampOpinionFromBytes parses a TimestampOpinion from a byte slice.

func TimestampOpinionFromMarshalUtil

func TimestampOpinionFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *TimestampOpinion, err error)

TimestampOpinionFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.

func TimestampQuality

func TimestampQuality(messageID tangle.MessageID, target, current time.Time) (timestampOpinion *TimestampOpinion)

TimestampQuality returns the TimestampOpinion based on the given times (e.g., arrival and current).

func (*TimestampOpinion) Bytes

func (t *TimestampOpinion) Bytes() (bytes []byte)

Bytes returns the timestamp statement encoded as bytes.

func (*TimestampOpinion) Equals

func (t *TimestampOpinion) Equals(x *TimestampOpinion) bool

Equals returns true if the given timestampOpinion is equal to the given x.

func (*TimestampOpinion) ObjectStorageKey

func (t *TimestampOpinion) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the StorableObject interface.

func (*TimestampOpinion) ObjectStorageValue

func (t *TimestampOpinion) ObjectStorageValue() []byte

ObjectStorageValue marshals the TimestampOpinion into a sequence of bytes that are used as the value part in the object Storage.

func (*TimestampOpinion) String

func (t *TimestampOpinion) String() string

String returns a human readable version of the TimestampOpinion.

func (*TimestampOpinion) Update

Update is disabled and panics if it ever gets called - it is required to match the StorableObject interface.

Jump to

Keyboard shortcuts

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