consensus

package
v0.0.0-...-106deb1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: BSD-3-Clause-Clear Imports: 20 Imported by: 0

Documentation

Overview

Package consensus provides the main BFT consensus algorithm.

Index

Constants

View Source
const VersionBytes = sha512.Size

VersionBytes is the space used by the version when marshalled.

Variables

View Source
var ErrVersionMismatch = errors.New("the stored version does not match with required version")

ErrVersionMismatch is returned when two versions are not matching.

View Source
var NoVersion = &Version{}

NoVersion is the default version that should be returned when no version is available in one store for a specific key.

View Source
var Operation_Op_name = map[int32]string{
	0:  "SET",
	1:  "CONCAT",
	10: "ADD",
	11: "MUL",
	20: "SADD",
	21: "SREM",
}
View Source
var Operation_Op_value = map[string]int32{
	"SET":    0,
	"CONCAT": 1,
	"ADD":    10,
	"MUL":    11,
	"SADD":   20,
	"SREM":   21,
}
View Source
var ParallelMatrix = map[Operation_Op]map[Operation_Op]ParallelType{
	Operation_SET: {Operation_SET: ParallelTypeDISALLOWDIFFERENT},
	Operation_ADD: {Operation_ADD: ParallelTypeDEFAULT},
	Operation_MUL: {Operation_MUL: ParallelTypeDEFAULT},
	Operation_SADD: {
		Operation_SADD: ParallelTypeDEFAULT,
		Operation_SREM: ParallelTypeDISALLOWEQUAL,
	},
	Operation_SREM: {
		Operation_SREM: ParallelTypeDEFAULT,
		Operation_SADD: ParallelTypeDISALLOWEQUAL,
	},
}

ParallelMatrix is used to know which operation can be run in parallel on a specific object.

Functions

This section is empty.

Types

type BBCEngine

type BBCEngine interface {
	Execute(context.Context, string, bool, []*Proof) (bool, []*Proof, error)
}

BBCEngine is the interface for binary Byzantine consensus engine.

type Endorsement

type Endorsement struct {
	Uuid                 string   `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`
	Emitter              string   `protobuf:"bytes,2,opt,name=emitter,proto3" json:"emitter,omitempty"`
	Conditions           []string `protobuf:"bytes,3,rep,name=conditions,proto3" json:"conditions,omitempty"`
	Signature            []byte   `protobuf:"bytes,16,opt,name=signature,proto3" json:"signature,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Endorsement) Descriptor

func (*Endorsement) Descriptor() ([]byte, []int)

func (*Endorsement) GetConditions

func (m *Endorsement) GetConditions() []string

func (*Endorsement) GetEmitter

func (m *Endorsement) GetEmitter() string

func (*Endorsement) GetSignature

func (m *Endorsement) GetSignature() []byte

func (*Endorsement) GetUuid

func (m *Endorsement) GetUuid() string

func (Endorsement) Hash

func (e Endorsement) Hash() ([]byte, error)

Hash returns a fixed-size hash of the (unsigned) version of the endorsement. Passed by value because of internal modifications.

func (*Endorsement) ProtoMessage

func (*Endorsement) ProtoMessage()

func (*Endorsement) Reset

func (m *Endorsement) Reset()

func (*Endorsement) String

func (m *Endorsement) String() string

func (*Endorsement) XXX_DiscardUnknown

func (m *Endorsement) XXX_DiscardUnknown()

func (*Endorsement) XXX_Marshal

func (m *Endorsement) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Endorsement) XXX_Merge

func (dst *Endorsement) XXX_Merge(src proto.Message)

func (*Endorsement) XXX_Size

func (m *Endorsement) XXX_Size() int

func (*Endorsement) XXX_Unmarshal

func (m *Endorsement) XXX_Unmarshal(b []byte) error

type Engine

type Engine struct {
	Store
	Network
	BBCEngine
	*keyring.KeyRing

	ActivityProbe chan bool // will receive data when some activity requires persistence
	// contains filtered or unexported fields
}

Engine is the main consensus engine that can process queries and endorsements

func NewEngine

func NewEngine(s Store, n Network, bbc BBCEngine, k *keyring.KeyRing, q int) *Engine

NewEngine TODO

func (*Engine) Dump

func (e *Engine) Dump(w io.Writer) error

Dump stores the current state of an engine, to be later loaded with Load.

func (*Engine) Load

func (e *Engine) Load(r io.Reader) error

Load loads the state of an engine from a dump file.

func (*Engine) Recover

func (eng *Engine) Recover(key string)

Recover allows to ask the engine to recover one key from other peers. This might be useful after being disconnected from the network.

This is an asynchronous process.

func (*Engine) Run

func (eng *Engine) Run(ctx context.Context) error

Run starts the engine in a non-blocking way.

func (*Engine) Submit

func (eng *Engine) Submit(q *Query) error

Submit submits a new query to the network of processes.

type MessageAcceptor

type MessageAcceptor func(proto.Message) bool

MessageAcceptor is a filter that can be used to filter incoming proto messages.

type Network

type Network interface {
	io.Closer

	Broadcast(m proto.Message) error
	Accept(ctx context.Context, acceptor MessageAcceptor) <-chan proto.Message
}

Network is the interface network adapters must implement.

type Operation

type Operation struct {
	Key                  string       `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Op                   Operation_Op `protobuf:"varint,2,opt,name=op,proto3,enum=consensus.Operation_Op" json:"op,omitempty"`
	Data                 []byte       `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	Metadata             []byte       `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*Operation) CheckConflict

func (o *Operation) CheckConflict(o2 *Operation) error

CheckConflict returns an error if two operations cannot be executed in parallel.

func (*Operation) Descriptor

func (*Operation) Descriptor() ([]byte, []int)

func (*Operation) Exec

func (o *Operation) Exec(v *operations.Value) error

Exec returns the result of the given operation against stored data.

func (*Operation) GetData

func (m *Operation) GetData() []byte

func (*Operation) GetKey

func (m *Operation) GetKey() string

func (*Operation) GetMetadata

func (m *Operation) GetMetadata() []byte

func (*Operation) GetOp

func (m *Operation) GetOp() Operation_Op

func (*Operation) ProtoMessage

func (*Operation) ProtoMessage()

func (*Operation) Reset

func (m *Operation) Reset()

func (*Operation) String

func (m *Operation) String() string

func (*Operation) XXX_DiscardUnknown

func (m *Operation) XXX_DiscardUnknown()

func (*Operation) XXX_Marshal

func (m *Operation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Operation) XXX_Merge

func (dst *Operation) XXX_Merge(src proto.Message)

func (*Operation) XXX_Size

func (m *Operation) XXX_Size() int

func (*Operation) XXX_Unmarshal

func (m *Operation) XXX_Unmarshal(b []byte) error

type Operation_Op

type Operation_Op int32
const (
	// Operations on every values
	Operation_SET    Operation_Op = 0
	Operation_CONCAT Operation_Op = 1
	// Operations on numeric values
	Operation_ADD Operation_Op = 10
	Operation_MUL Operation_Op = 11
	// Operations on set values
	Operation_SADD Operation_Op = 20
	Operation_SREM Operation_Op = 21
)

func (Operation_Op) EnumDescriptor

func (Operation_Op) EnumDescriptor() ([]byte, []int)

func (Operation_Op) String

func (x Operation_Op) String() string

type ParallelType

type ParallelType int16

ParallelType specifies the various options available when specifying a parallelizable operation.

const (
	ParallelTypeDEFAULT ParallelType = 0x01 << iota
	ParallelTypeDISALLOWDIFFERENT
	ParallelTypeDISALLOWEQUAL
)

Definition for ParallelType. Each flag may be combined using bitwise operators.

type Proof

type Proof struct {
	// Types that are valid to be assigned to Content:
	//	*Proof_Query
	//	*Proof_Endorsement
	Content              isProof_Content `protobuf_oneof:"content"`
	XXX_NoUnkeyedLiteral struct{}        `json:"-"`
	XXX_unrecognized     []byte          `json:"-"`
	XXX_sizecache        int32           `json:"-"`
}

func (*Proof) Descriptor

func (*Proof) Descriptor() ([]byte, []int)

func (*Proof) GetContent

func (m *Proof) GetContent() isProof_Content

func (*Proof) GetEndorsement

func (m *Proof) GetEndorsement() *Endorsement

func (*Proof) GetQuery

func (m *Proof) GetQuery() *Query

func (*Proof) ProtoMessage

func (*Proof) ProtoMessage()

func (*Proof) Reset

func (m *Proof) Reset()

func (*Proof) String

func (m *Proof) String() string

func (*Proof) XXX_DiscardUnknown

func (m *Proof) XXX_DiscardUnknown()

func (*Proof) XXX_Marshal

func (m *Proof) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Proof) XXX_Merge

func (dst *Proof) XXX_Merge(src proto.Message)

func (*Proof) XXX_OneofFuncs

func (*Proof) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

func (*Proof) XXX_Size

func (m *Proof) XXX_Size() int

func (*Proof) XXX_Unmarshal

func (m *Proof) XXX_Unmarshal(b []byte) error

type Proof_Endorsement

type Proof_Endorsement struct {
	Endorsement *Endorsement `protobuf:"bytes,2,opt,name=endorsement,proto3,oneof"`
}

type Proof_Query

type Proof_Query struct {
	Query *Query `protobuf:"bytes,1,opt,name=query,proto3,oneof"`
}

type Query

type Query struct {
	Uuid                 string               `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`
	Policy               string               `protobuf:"bytes,2,opt,name=policy,proto3" json:"policy,omitempty"`
	Emitter              string               `protobuf:"bytes,3,opt,name=emitter,proto3" json:"emitter,omitempty"`
	Deadline             *timestamp.Timestamp `protobuf:"bytes,4,opt,name=deadline,proto3" json:"deadline,omitempty"`
	Requirements         map[string]*Version  `` /* 165-byte string literal not displayed */
	Operations           []*Operation         `protobuf:"bytes,6,rep,name=operations,proto3" json:"operations,omitempty"`
	Signature            []byte               `protobuf:"bytes,16,opt,name=signature,proto3" json:"signature,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func NewQuery

func NewQuery() *Query

NewQuery instanciates a new empty query.

func (*Query) CheckConflict

func (q *Query) CheckConflict(q2 *Query) error

CheckConflict returns an error if two queries are conflicting.

func (*Query) DeadlineTime

func (q *Query) DeadlineTime() time.Time

DeadlineTime returns the query deadline in native time instead of ptype.

func (*Query) Descriptor

func (*Query) Descriptor() ([]byte, []int)

func (*Query) Expired

func (q *Query) Expired() bool

Expired returns true if a query deadline is reached.

func (*Query) ExpiredSince

func (q *Query) ExpiredSince(d time.Duration) bool

ExpiredSince returns true if a query deadline have been reached for at least d duration.

func (*Query) GetDeadline

func (m *Query) GetDeadline() *timestamp.Timestamp

func (*Query) GetEmitter

func (m *Query) GetEmitter() string

func (*Query) GetOperations

func (m *Query) GetOperations() []*Operation

func (*Query) GetPolicy

func (m *Query) GetPolicy() string

func (*Query) GetRequirements

func (m *Query) GetRequirements() map[string]*Version

func (*Query) GetSignature

func (m *Query) GetSignature() []byte

func (*Query) GetTimeout

func (q *Query) GetTimeout() time.Duration

GetTimeout returns the duration that is remaining for the application of this query. This may be negative.

func (*Query) GetUuid

func (m *Query) GetUuid() string

func (Query) Hash

func (q Query) Hash() ([]byte, error)

Hash returns a fixed-size hash of the (unsigned) version of the query. Passed by value because of internal modifications.

func (*Query) ProtoMessage

func (*Query) ProtoMessage()

func (*Query) Reset

func (m *Query) Reset()

func (*Query) SetTimeout

func (q *Query) SetTimeout(t time.Duration)

SetTimeout updates the deadline of the query according to current time.

func (*Query) String

func (m *Query) String() string

func (*Query) XXX_DiscardUnknown

func (m *Query) XXX_DiscardUnknown()

func (*Query) XXX_Marshal

func (m *Query) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Query) XXX_Merge

func (dst *Query) XXX_Merge(src proto.Message)

func (*Query) XXX_Size

func (m *Query) XXX_Size() int

func (*Query) XXX_Unmarshal

func (m *Query) XXX_Unmarshal(b []byte) error

type RecoveryHandler

type RecoveryHandler func(*RecoveryRequest) (*RecoveryResponse, error)

RecoveryHandler is a callback used by the RecoveryManager.

type RecoveryManager

type RecoveryManager interface {
	RequestRecovery(ctx context.Context, key string) (*RecoveryResponse, error)
	AcceptRecovery(ctx context.Context, handler RecoveryHandler)
}

RecoveryManager is a interface that can optionally be proposed by Networks for key recovery support (after a crash or network partition).

type RecoveryRequest

type RecoveryRequest struct {
	Key                  string   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RecoveryRequest) Descriptor

func (*RecoveryRequest) Descriptor() ([]byte, []int)

func (*RecoveryRequest) GetKey

func (m *RecoveryRequest) GetKey() string

func (*RecoveryRequest) ProtoMessage

func (*RecoveryRequest) ProtoMessage()

func (*RecoveryRequest) Reset

func (m *RecoveryRequest) Reset()

func (*RecoveryRequest) String

func (m *RecoveryRequest) String() string

func (*RecoveryRequest) XXX_DiscardUnknown

func (m *RecoveryRequest) XXX_DiscardUnknown()

func (*RecoveryRequest) XXX_Marshal

func (m *RecoveryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RecoveryRequest) XXX_Merge

func (dst *RecoveryRequest) XXX_Merge(src proto.Message)

func (*RecoveryRequest) XXX_Size

func (m *RecoveryRequest) XXX_Size() int

func (*RecoveryRequest) XXX_Unmarshal

func (m *RecoveryRequest) XXX_Unmarshal(b []byte) error

type RecoveryResponse

type RecoveryResponse struct {
	Key                  string   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Version              *Version `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`
	Data                 []byte   `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RecoveryResponse) Descriptor

func (*RecoveryResponse) Descriptor() ([]byte, []int)

func (*RecoveryResponse) GetData

func (m *RecoveryResponse) GetData() []byte

func (*RecoveryResponse) GetKey

func (m *RecoveryResponse) GetKey() string

func (*RecoveryResponse) GetVersion

func (m *RecoveryResponse) GetVersion() *Version

func (*RecoveryResponse) ProtoMessage

func (*RecoveryResponse) ProtoMessage()

func (*RecoveryResponse) Reset

func (m *RecoveryResponse) Reset()

func (*RecoveryResponse) String

func (m *RecoveryResponse) String() string

func (*RecoveryResponse) XXX_DiscardUnknown

func (m *RecoveryResponse) XXX_DiscardUnknown()

func (*RecoveryResponse) XXX_Marshal

func (m *RecoveryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RecoveryResponse) XXX_Merge

func (dst *RecoveryResponse) XXX_Merge(src proto.Message)

func (*RecoveryResponse) XXX_Size

func (m *RecoveryResponse) XXX_Size() int

func (*RecoveryResponse) XXX_Unmarshal

func (m *RecoveryResponse) XXX_Unmarshal(b []byte) error

type StartCheckpoint

type StartCheckpoint struct {
	Queries              []string `protobuf:"bytes,1,rep,name=queries,proto3" json:"queries,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*StartCheckpoint) Descriptor

func (*StartCheckpoint) Descriptor() ([]byte, []int)

func (*StartCheckpoint) GetQueries

func (m *StartCheckpoint) GetQueries() []string

func (*StartCheckpoint) ProtoMessage

func (*StartCheckpoint) ProtoMessage()

func (*StartCheckpoint) Reset

func (m *StartCheckpoint) Reset()

func (*StartCheckpoint) String

func (m *StartCheckpoint) String() string

func (*StartCheckpoint) XXX_DiscardUnknown

func (m *StartCheckpoint) XXX_DiscardUnknown()

func (*StartCheckpoint) XXX_Marshal

func (m *StartCheckpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StartCheckpoint) XXX_Merge

func (dst *StartCheckpoint) XXX_Merge(src proto.Message)

func (*StartCheckpoint) XXX_Size

func (m *StartCheckpoint) XXX_Size() int

func (*StartCheckpoint) XXX_Unmarshal

func (m *StartCheckpoint) XXX_Unmarshal(b []byte) error

type Store

type Store interface {
	sync.Locker
	io.Closer

	// Get returns the value and the version stored currently for the specified key.
	Get(key string) (value []byte, version *Version, err error)
	// Set sets the value and the version that must be stored for the specified key.
	Set(key string, value []byte, version *Version) error
	// SetBatch executes the given "Set" operations in a atomic way.
	SetBatch(keys []string, values [][]byte, versions []*Version) error
	// List returns the map of keys with their values.
	List() (map[string]*Version, error)
}

Store is the interface storage drivers must implement.

type Version

type Version struct {
	Hash                 []byte   `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func NewVersion

func NewVersion(data []byte) *Version

NewVersion returns a new version from some data.

func (*Version) Descriptor

func (*Version) Descriptor() ([]byte, []int)

func (*Version) GetHash

func (m *Version) GetHash() []byte

func (*Version) MarshalBinary

func (v *Version) MarshalBinary() (data []byte, err error)

MarshalBinary converts the version to a VersionBytes-sized bytes slice.

func (*Version) Matches

func (v *Version) Matches(v2 *Version) error

Matches returns an error is two versions are not matching.

func (*Version) ProtoMessage

func (*Version) ProtoMessage()

func (*Version) Reset

func (m *Version) Reset()

func (*Version) String

func (m *Version) String() string

func (*Version) UnmarshalBinary

func (v *Version) UnmarshalBinary(data []byte) error

UnmarshalBinary converts the input to a version.

func (*Version) XXX_DiscardUnknown

func (m *Version) XXX_DiscardUnknown()

func (*Version) XXX_Marshal

func (m *Version) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Version) XXX_Merge

func (dst *Version) XXX_Merge(src proto.Message)

func (*Version) XXX_Size

func (m *Version) XXX_Size() int

func (*Version) XXX_Unmarshal

func (m *Version) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis
Package bbc implements a very simple Byzantine Broadcast Consensus algorithm.
Package bbc implements a very simple Byzantine Broadcast Consensus algorithm.
Package encoding contains database types and (un)marshalling methods.
Package encoding contains database types and (un)marshalling methods.
Package operations contains database operations logic internals.
Package operations contains database operations logic internals.

Jump to

Keyboard shortcuts

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