Documentation
¶
Index ¶
- Variables
- type Account
- type Actor
- func (v *Actor) Account() Account
- func (v *Actor) GetPublicKeyBytes() ([]byte, error)
- func (v *Actor) LagrangeIndex() uint32
- func (v *Actor) PeerID() peer.ID
- func (v *Actor) PrivateKey() crypto.PrivateKey
- func (v *Actor) PublicKey() crypto.PublicKey
- func (v *Actor) SetLagrangeIndex(index uint32)
- func (v *Actor) SetShareIndex(index uint32)
- func (v *Actor) ShareIndex() int
- type ActorCallbackFn
- type ActorSet
- func (vs *ActorSet) AddActor(ctx context.Context, account Account, shareIndex int) error
- func (vs *ActorSet) AppendActorAddedCallback(callback ActorCallbackFn)
- func (vs *ActorSet) AppendActorRemovedCallback(callback ActorCallbackFn)
- func (vs *ActorSet) AssignShareIndex(id peer.ID) int
- func (vs *ActorSet) CurrentLeader(roles ...types.Role) *Actor
- func (vs *ActorSet) ElectLeader(role types.Role, metricsCollector Collector)
- func (vs *ActorSet) ElectLeaders(metricsCollector Collector)
- func (vs *ActorSet) GetActor(id peer.ID) *Actor
- func (vs *ActorSet) GetActorByUserID(userID string) *Actor
- func (vs *ActorSet) GetActorIDs() []peer.ID
- func (vs *ActorSet) GetActors() []*Actor
- func (vs *ActorSet) GetActorsCount() int
- func (vs *ActorSet) GetRolesForLeader(id peer.ID) []types.Role
- func (vs *ActorSet) IsLeader(id peer.ID, roles ...types.Role) bool
- func (vs *ActorSet) IsLeaderForAnyRole(id peer.ID) bool
- func (vs *ActorSet) IsSequencer(id peer.ID) bool
- func (vs *ActorSet) IsValidator(id peer.ID) bool
- func (vs *ActorSet) QuorumSize() int
- func (vs *ActorSet) RemoveActor(ctx context.Context, id peer.ID, force bool) error
- func (vs *ActorSet) SetLeader(role types.Role, id peer.ID)
- func (vs *ActorSet) SetQuorumThreshold(threshold int)
- func (vs *ActorSet) WaitForActor(pid peer.ID, timeout time.Duration) error
- type BaseSigner
- type Collector
- type Epoch
- type KeyPair
- type Metrics
- type PartialSignature
- type Signer
- type ThresholdSigner
Constants ¶
This section is empty.
Variables ¶
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 (*Actor) GetPublicKeyBytes ¶
GetPublicKeyBytes returns the public key bytes of the Actor.
func (*Actor) LagrangeIndex ¶
func (*Actor) PrivateKey ¶
func (v *Actor) PrivateKey() crypto.PrivateKey
PrivateKey returns the private key of the Actor.
func (*Actor) SetLagrangeIndex ¶
func (*Actor) SetShareIndex ¶
SetShareIndex updates the share index of the Actor. This is important when the ActorSet changes dynamically.
func (*Actor) ShareIndex ¶
ShareIndex returns the current share index of the Actor.
type ActorCallbackFn ¶
type ActorSet ¶
type ActorSet struct {
// contains filtered or unexported fields
}
ActorSet manages the collection of Actor's participating in consensus.
func NewActorSet ¶
NewActorSet creates a new set of Actor's.
func (*ActorSet) AddActor ¶
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 ¶
AssignShareIndex helper function used to assign unique share indices to Actor's
func (*ActorSet) CurrentLeader ¶
CurrentLeader returns the current leader for any of the specified roles.
func (*ActorSet) ElectLeader ¶
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 ¶
ElectLeaders elects leaders for all eligible roles.
func (*ActorSet) GetActorByUserID ¶
GetActorByUserID retrieves a Actor by user ID.
func (*ActorSet) GetActorIDs ¶
GetActorIDs returns a slice of all Actor peer IDs.
func (*ActorSet) GetActorsCount ¶
GetActorsCount returns the current number of Actor's in the ActorSet.
func (*ActorSet) GetRolesForLeader ¶
GetRolesForLeader returns a slice of roles for which the given Actor is the leader.
func (*ActorSet) IsLeader ¶
IsLeader checks if a given Actor is the current leader for any of the specified roles.
func (*ActorSet) IsLeaderForAnyRole ¶
IsLeaderForAnyRole checks if a given Actor is the leader for any role.
func (*ActorSet) IsSequencer ¶
IsSequencer checks if a given peer ID is a sequencer.
func (*ActorSet) IsValidator ¶
IsValidator checks if a given peer ID is a Actor's.
func (*ActorSet) QuorumSize ¶
QuorumSize returns the number of Actor's required for quorum.
func (*ActorSet) RemoveActor ¶
RemoveActor removes an Actor from the set.
func (*ActorSet) SetLeader ¶
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 ¶
SetQuorumThreshold sets the quorum threshold for block finalization.
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 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
}
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)
}