Documentation
¶
Overview ¶
Package model is a generated GoMock package.
Package model is a generated GoMock package.
Index ¶
- func WithEventId(id any) gomock.Matcher
- type Dag
- type Event
- func (e *Event) Creator() consensus.ValidatorId
- func (e *Event) EventId() EventId
- func (e Event) IsGenesis() bool
- func (e *Event) Parents() []*Event
- func (e *Event) Payload() payload.Payload
- func (e *Event) SelfParent() *Event
- func (e *Event) Seq() uint32
- func (e Event) Timestamp() time.Time
- func (e *Event) TraverseClosure(visitor EventVisitor)
- type EventId
- type EventMessage
- type EventVisitor
- type MockDag
- type MockDagMockRecorder
- type MockEventVisitor
- type MockEventVisitorMockRecorder
- type VisitResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dag ¶
type Dag interface {
// AddEvent adds an event to the DAG and connects it to its parents
// if they are already present in the DAG. If a parent is not yet present, the
// event is buffered, and re-evaluated as future events are added.
// The function returns a list of all events that got connected to the
// DAG through the addition of the given node.
AddEvent(eventMessage EventMessage) []*Event
// GetHeads returns a mapping of each validator to their current head of the DAG,
// which represent the most recent event for each of the validators.
GetHeads() map[consensus.ValidatorId]*Event
// Reaches returns true if the source event reaches the target event,
// i.e., if there exists a path from source to target in the DAG.
Reaches(source, target *Event) bool
// StronglyReaches returns true if the source event strongly reaches target event,
// i.e., if there exists a quorum of events reachable from source that also reach target.
StronglyReaches(source, target *Event) bool
}
Dag represents a Directed Acyclic Graph (DAG) structure for managing events.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a consensus event in the DAG. This is a local representation of an event that resides in memory. It contains the following fields: - Seq: The sequence number of the event, that orders events made by the same validator (Seq is always one greater than self-parent's Seq). Seq of a genesis event is 1. - Creator: The ID of the creator of the event, which is a validator node. - Parents: A list of parent events, which are the events that this event builds upon. Note that the first parent must be the self-parent, which is the parent created by the same validator. - Payload: The transactions included in the event.
func NewEvent ¶
func NewEvent(creator consensus.ValidatorId, parents []*Event, payload payload.Payload, timestamp time.Time) (*Event, error)
NewEvent creates a new Event instance. It performs checks to ensure that the first parent is the self-parent, and no parent is nil.
func (*Event) Creator ¶
func (e *Event) Creator() consensus.ValidatorId
Creator is the getter for the creator ID of the event.
func (*Event) SelfParent ¶
SelfParent returns the parent of the event that has the same creator. If there are no parents, it returns nil. Every non-genesis event is expected to have a parent event from the same creator, at index 0 of the Parents slice.
func (*Event) TraverseClosure ¶
func (e *Event) TraverseClosure(visitor EventVisitor)
TraverseClosure traverses the closure of the event with a simple depth-first search, calling the provided visitor method on each event. The closure of an event includes the event itself and all its parents recursively (all ancestors). The traversal is controlled by the result returned from EventVisitor.Visit. It can indicate to continue descending, prune the current branch, or abort the entire traversal. The visitor can be used to perform operations with each event while filtering out certain paths based on custom logic for the sake of performance.
type EventId ¶
EventId is a unique identifier for an Event, derived from its creator and parents. Among others, it is used by Events being transferred over the network to reference their parents.
func MakeEventId ¶
func MakeEventId( creator consensus.ValidatorId, parents []EventId, ) EventId
MakeEventId creates a new EventId based on the creator and parent EventIds.
type EventMessage ¶
type EventMessage struct {
Creator consensus.ValidatorId
Parents []EventId
Payload payload.Payload
Timestamp time.Time
}
EventMessage represents a network message containing event data, used to transmit events across the network. This structure is needed because the Event structure contains pointers to other events, which cannot be serialized directly for network transmission.
func (EventMessage) EventId ¶
func (e EventMessage) EventId() EventId
func (EventMessage) MessageSize ¶
func (e EventMessage) MessageSize() uint32
type EventVisitor ¶
type EventVisitor interface {
// Visit should be called by the traversal algorithms on each event.
// The Visit method returns a result that signals whether to continue,
// prune the current branch, or abort the entire traversal.
Visit(event *Event) VisitResult
}
EventVisitor is an interface for visiting events during DAG traversal. It allows for custom logic and filtering to be executed on each event visited.
func WrapEventVisitor ¶
func WrapEventVisitor(f func(*Event) VisitResult) EventVisitor
WrapEventVisitor wraps a function with a signature func(event *Event) VisitResult into an EventVisitor adapter that can be used in traversal methods. This is a convenience function to allow using simple functions as event handlers without having to define a new type.
type MockDag ¶
type MockDag struct {
// contains filtered or unexported fields
}
MockDag is a mock of Dag interface.
func NewMockDag ¶
func NewMockDag(ctrl *gomock.Controller) *MockDag
NewMockDag creates a new mock instance.
func (*MockDag) AddEvent ¶
func (m *MockDag) AddEvent(eventMessage EventMessage) []*Event
AddEvent mocks base method.
func (*MockDag) EXPECT ¶
func (m *MockDag) EXPECT() *MockDagMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockDag) GetHeads ¶
func (m *MockDag) GetHeads() map[consensus.ValidatorId]*Event
GetHeads mocks base method.
func (*MockDag) StronglyReaches ¶
StronglyReaches mocks base method.
type MockDagMockRecorder ¶
type MockDagMockRecorder struct {
// contains filtered or unexported fields
}
MockDagMockRecorder is the mock recorder for MockDag.
func (*MockDagMockRecorder) AddEvent ¶
func (mr *MockDagMockRecorder) AddEvent(eventMessage any) *gomock.Call
AddEvent indicates an expected call of AddEvent.
func (*MockDagMockRecorder) GetHeads ¶
func (mr *MockDagMockRecorder) GetHeads() *gomock.Call
GetHeads indicates an expected call of GetHeads.
func (*MockDagMockRecorder) Reaches ¶
func (mr *MockDagMockRecorder) Reaches(source, target any) *gomock.Call
Reaches indicates an expected call of Reaches.
func (*MockDagMockRecorder) StronglyReaches ¶
func (mr *MockDagMockRecorder) StronglyReaches(source, target any) *gomock.Call
StronglyReaches indicates an expected call of StronglyReaches.
type MockEventVisitor ¶
type MockEventVisitor struct {
// contains filtered or unexported fields
}
MockEventVisitor is a mock of EventVisitor interface.
func NewMockEventVisitor ¶
func NewMockEventVisitor(ctrl *gomock.Controller) *MockEventVisitor
NewMockEventVisitor creates a new mock instance.
func (*MockEventVisitor) EXPECT ¶
func (m *MockEventVisitor) EXPECT() *MockEventVisitorMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockEventVisitor) Visit ¶
func (m *MockEventVisitor) Visit(event *Event) VisitResult
Visit mocks base method.
type MockEventVisitorMockRecorder ¶
type MockEventVisitorMockRecorder struct {
// contains filtered or unexported fields
}
MockEventVisitorMockRecorder is the mock recorder for MockEventVisitor.
type VisitResult ¶
type VisitResult byte
const ( // Visit_Descent indicates to continue descending in the current branch. Visit_Descent VisitResult = iota // Visit_Prune indicates to prune the current branch, continue with others. Visit_Prune // Visit_Abort indicates to abort the entire visit, the visitor has found what it needed. Visit_Abort )
func (VisitResult) String ¶
func (i VisitResult) String() string