share

package
v0.0.0-...-da72ffe Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ActorAlreadyExists = errors.New("actor already exists")
)

Functions

This section is empty.

Types

type Account

type Account interface {
	// ID returns the unique identifier of the account, typically the string representation of the peer ID.
	ID() string

	// Address returns the derived address from the MasterPublicKey.
	Address() types.Address

	// PeerID returns the associated libp2p PeerID.
	PeerID() peer.ID

	// Name returns the name of the account.
	Name() string

	// Comment returns the optional comment or description of the account.
	Comment() string

	// MasterPrivateKey returns the master private key associated with the account.
	MasterPrivateKey() libp2pCrypto.PrivKey

	// MasterPublicKey returns the master public key associated with the account.
	MasterPublicKey() libp2pCrypto.PubKey

	// Roles returns the list of roles assigned to the account.
	Roles() []types.Role

	// ExtraPermissions returns the additional permissions associated with each role.
	ExtraPermissions() map[types.Role][]types.Permission

	// AssignRole assigns a new role with specified permissions to the account.
	AssignRole(role types.Role, permissions ...types.Permission) error

	// RemoveRole removes an existing role from the account.
	RemoveRole(role types.Role) error

	// HasPermission checks if the account has the specified permission.
	HasPermission(permission types.Permission) bool

	// MarshalPublicKey marshals the account's master public key into bytes.
	MarshalPublicKey() ([]byte, error)
}

Account defines the interface for a Decentralized Identifier (DID) with associated cryptographic keys and permissions. It encapsulates functionalities required for managing cryptographic operations, roles, and permissions.

type Actor

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

Actor represents an actor in the consensus (sequencer, validator).

func NewActor

func NewActor(account Account, shareIndex int, logger logger.Logger) *Actor

NewActor creates a new Actor instance.

func (*Actor) Account

func (v *Actor) Account() Account

Account returns the associated account of the Actor.

func (*Actor) GetPublicKeyBytes

func (v *Actor) GetPublicKeyBytes() ([]byte, error)

GetPublicKeyBytes returns the public key bytes of the Actor.

func (*Actor) LagrangeIndex

func (v *Actor) LagrangeIndex() uint32

func (*Actor) PeerID

func (v *Actor) PeerID() peer.ID

PeerID returns the peer ID of the Actor.

func (*Actor) PrivateKey

func (v *Actor) PrivateKey() crypto.PrivateKey

PrivateKey returns the private key of the Actor.

func (*Actor) PublicKey

func (v *Actor) PublicKey() crypto.PublicKey

PublicKey returns the public key of the Actor.

func (*Actor) SetLagrangeIndex

func (v *Actor) SetLagrangeIndex(index uint32)

func (*Actor) SetShareIndex

func (v *Actor) SetShareIndex(index uint32)

SetShareIndex updates the share index of the Actor. This is important when the ActorSet changes dynamically.

func (*Actor) ShareIndex

func (v *Actor) ShareIndex() int

ShareIndex returns the current share index of the Actor.

type ActorCallbackFn

type ActorCallbackFn func(ctx context.Context, actor *Actor, force bool) error

type ActorSet

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

ActorSet manages the collection of Actor's participating in consensus.

func NewActorSet

func NewActorSet(logger logger.Logger) *ActorSet

NewActorSet creates a new set of Actor's.

func (*ActorSet) AddActor

func (vs *ActorSet) AddActor(ctx context.Context, account Account, shareIndex int) error

AddActor now not only adds the Actor to the set but also initiates a connection.

func (*ActorSet) AppendActorAddedCallback

func (vs *ActorSet) AppendActorAddedCallback(callback ActorCallbackFn)

AppendActorAddedCallback sets the callback to be invoked when an Actor is added.

func (*ActorSet) AppendActorRemovedCallback

func (vs *ActorSet) AppendActorRemovedCallback(callback ActorCallbackFn)

AppendActorRemovedCallback sets the callback to be invoked when an Actor is removed.

func (*ActorSet) AssignShareIndex

func (vs *ActorSet) AssignShareIndex(id peer.ID) int

AssignShareIndex helper function used to assign unique share indices to Actor's

func (*ActorSet) CurrentLeader

func (vs *ActorSet) CurrentLeader(roles ...types.Role) *Actor

CurrentLeader returns the current leader for any of the specified roles.

func (*ActorSet) ElectLeader

func (vs *ActorSet) ElectLeader(role types.Role, metricsCollector Collector)

ElectLeader selects a leader for a specific role based on utility scores. If the role is a composite role, it also sets the leader for its constituent roles.

func (*ActorSet) ElectLeaders

func (vs *ActorSet) ElectLeaders(metricsCollector Collector)

ElectLeaders elects leaders for all eligible roles.

func (*ActorSet) GetActor

func (vs *ActorSet) GetActor(id peer.ID) *Actor

GetActor retrieves an Actor by peer ID.

func (*ActorSet) GetActorByUserID

func (vs *ActorSet) GetActorByUserID(userID string) *Actor

GetActorByUserID retrieves a Actor by user ID.

func (*ActorSet) GetActorIDs

func (vs *ActorSet) GetActorIDs() []peer.ID

GetActorIDs returns a slice of all Actor peer IDs.

func (*ActorSet) GetActors

func (vs *ActorSet) GetActors() []*Actor

GetActors returns a list of all Actors.

func (*ActorSet) GetActorsCount

func (vs *ActorSet) GetActorsCount() int

GetActorsCount returns the current number of Actor's in the ActorSet.

func (*ActorSet) GetRolesForLeader

func (vs *ActorSet) GetRolesForLeader(id peer.ID) []types.Role

GetRolesForLeader returns a slice of roles for which the given Actor is the leader.

func (*ActorSet) IsLeader

func (vs *ActorSet) IsLeader(id peer.ID, roles ...types.Role) bool

IsLeader checks if a given Actor is the current leader for any of the specified roles.

func (*ActorSet) IsLeaderForAnyRole

func (vs *ActorSet) IsLeaderForAnyRole(id peer.ID) bool

IsLeaderForAnyRole checks if a given Actor is the leader for any role.

func (*ActorSet) IsSequencer

func (vs *ActorSet) IsSequencer(id peer.ID) bool

IsSequencer checks if a given peer ID is a sequencer.

func (*ActorSet) IsValidator

func (vs *ActorSet) IsValidator(id peer.ID) bool

IsValidator checks if a given peer ID is a Actor's.

func (*ActorSet) QuorumSize

func (vs *ActorSet) QuorumSize() int

QuorumSize returns the number of Actor's required for quorum.

func (*ActorSet) RemoveActor

func (vs *ActorSet) RemoveActor(ctx context.Context, id peer.ID, force bool) error

RemoveActor removes an Actor from the set.

func (*ActorSet) SetLeader

func (vs *ActorSet) SetLeader(role types.Role, id peer.ID)

SetLeader sets the leader for a specific role (useful for tests or dynamic leader changes). If the role is a composite role, it also sets the leader for its constituent roles.

func (*ActorSet) SetQuorumThreshold

func (vs *ActorSet) SetQuorumThreshold(threshold int)

SetQuorumThreshold sets the quorum threshold for block finalization.

func (*ActorSet) WaitForActor

func (vs *ActorSet) WaitForActor(pid peer.ID, timeout time.Duration) error

WaitForActor waits until the specified Actor is present in the ActorSet or times out.

type BaseSigner

type BaseSigner interface {
	Address() (types.Address, error)
	Sign(data []byte) ([]byte, error)
	Verify(data []byte, signature []byte) (bool, error)
	Pair() KeyPair
	Type() types.SignerType
}

BaseSigner defines the common interface for signing and verifying data.

type Collector

type Collector interface {
	// UpdateResponsiveness updates the responsiveness metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - latency: The latency observed in communication with the peer.
	//   - success: Indicates whether the communication attempt was successful.
	UpdateResponsiveness(p peer.ID, latency float64, success bool)

	// UpdateReliability updates the reliability metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - success: Indicates whether the communication attempt was successful.
	UpdateReliability(p peer.ID, success bool)

	// UpdateBandwidthUsage updates the bandwidth usage metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - value: The new bandwidth usage value.
	UpdateBandwidthUsage(p peer.ID, value float64)

	// UpdateComputational updates the computational metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - value: The new computational metric value.
	UpdateComputational(p peer.ID, value float64)

	// UpdateStorage updates the storage metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - value: The new storage metric value.
	UpdateStorage(p peer.ID, value float64)

	// UpdateUptime updates the uptime metric for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer being updated.
	//   - value: The new uptime metric value.
	UpdateUptime(p peer.ID, value float64)

	// CalculateUtilityScore computes the overall utility score for a peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer for which the utility score is computed.
	//
	// Returns:
	//   - The computed utility score as a float64.
	CalculateUtilityScore(p peer.ID) float64

	// GetMetrics retrieves the metrics for a given peer.
	//
	// Parameters:
	//   - p: The peer ID of the peer whose metrics are retrieved.
	//
	// Returns:
	//   - A pointer to the Metrics struct containing the peer's metrics.
	GetMetrics(p peer.ID) *Metrics

	// GetAllMetrics returns a copy of all collected metrics.
	//
	// Returns:
	//   - A map of peer IDs to their corresponding Metrics structs.
	GetAllMetrics() map[peer.ID]*Metrics

	// RemoveOldMetrics removes metrics that haven't been updated within the specified threshold.
	//
	// Parameters:
	//   - threshold: A duration specifying the age threshold for removing old metrics.
	RemoveOldMetrics(threshold time.Duration)

	// AdjustEmaAlpha dynamically adjusts the smoothing factor used in Exponential Moving Average calculations.
	//
	// Parameters:
	//   - newAlpha: The new EMA alpha value to be set.
	AdjustEmaAlpha(newAlpha float64)
}

Collector defines the interface for collecting and updating utility metrics for peers.

Implementations of this interface are responsible for managing metrics associated with peers, providing methods to update individual metrics, compute utility scores, and retrieve metrics data.

type Epoch

type Epoch int
var (
	FirstEpoch Epoch = 1
)

func (Epoch) Bytes

func (e Epoch) Bytes() []byte

func (Epoch) Cmp

func (e Epoch) Cmp(e2 Epoch) bool

func (Epoch) Int

func (e Epoch) Int() int

func (Epoch) IsFirst

func (e Epoch) IsFirst() bool

func (Epoch) Next

func (e Epoch) Next() Epoch

func (Epoch) Previous

func (e Epoch) Previous() Epoch

func (Epoch) String

func (e Epoch) String() string

type KeyPair

type KeyPair interface {
	GenerateKey() error
	SerializePrivate() ([]byte, error)
	SerializePublic() ([]byte, error)
	DeserializePrivate(data []byte) error
	DeserializePublic(data []byte) error
	GetPublic() any
	GetPrivate() any
	GetPublicKeyBytes() ([]byte, error)
}

KeyPair defines the interface for key management.

type Metrics

type Metrics struct {
	BandwidthUsage float64      // Bandwidth usage metric
	Computational  float64      // Computational power metric
	Storage        float64      // Storage capacity metric
	Uptime         float64      // Uptime percentage metric
	Responsiveness float64      // Responsiveness metric based on latency
	Reliability    float64      // Reliability metric based on successful interactions
	Stake          *uint256.Int // Stake or trust level associated with the peer
	LastUpdated    time.Time    // Timestamp of the last update
}

Metrics holds various performance metrics for a peer.

Fields: - BandwidthUsage: Represents the bandwidth usage metric for the peer. - Computational: Represents the computational power metric for the peer. - Storage: Represents the storage capacity metric for the peer. - Uptime: Represents the uptime percentage metric for the peer. - Responsiveness: Represents the responsiveness metric, typically calculated based on latency. - Reliability: Represents the reliability metric, possibly based on successful interactions. - Stake: Represents the stake or trust level associated with the peer. - LastUpdated: Timestamp of the last update to the metrics.

type PartialSignature

type PartialSignature struct {
	Signature  []byte
	ShareIndex int
}

type Signer

type Signer interface {
	BaseSigner
}

type ThresholdSigner

type ThresholdSigner interface {
	BaseSigner
	GeneratePartialSignature(data []byte) ([]byte, error)
	VerifyAggregatedSignature(data []byte, signature []byte) (bool, error)
	AggregateAndVerifySignature(blockHash types.Hash, data []byte, partialSigs [][]byte) ([]byte, error)
	AggregatePartialSignatures(blockHash types.Hash, data []byte, partialSigs [][]byte) ([]byte, error)
}

Jump to

Keyboard shortcuts

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