cache

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdentifierSet

type IdentifierSet map[flow.Identifier]struct{}

IdentifierSet represents a set of node IDs (operator-defined) whose communication should be blocked.

func (IdentifierSet) Contains

func (s IdentifierSet) Contains(id flow.Identifier) bool

Contains returns true iff id ∈ s

type NodeBlocklistWrapper

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

NodeBlocklistWrapper is a wrapper for an `module.IdentityProvider` instance, where the wrapper overrides the `Ejected` flag to true for all NodeIDs in a `blocklist`. To avoid modifying the source of the identities, the wrapper creates shallow copies of the identities (whenever necessary) and modifies the `Ejected` flag only in the copy. The `NodeBlocklistWrapper` internally represents the `blocklist` as a map, to enable performant lookup. However, the exported API works with `flow.IdentifierList` for blocklist, as this is a broadly supported data structure which lends itself better to config or command-line inputs.

func NewNodeBlocklistWrapper

func NewNodeBlocklistWrapper(identityProvider module.IdentityProvider, db *badger.DB) (*NodeBlocklistWrapper, error)

NewNodeBlocklistWrapper wraps the given `IdentityProvider`. The blocklist is loaded from the database (or assumed to be empty if no database entry is present).

func (*NodeBlocklistWrapper) ByNodeID

func (w *NodeBlocklistWrapper) ByNodeID(identifier flow.Identifier) (*flow.Identity, bool)

ByNodeID returns the full identity for the node with the given Identifier, where Identifier is the way the protocol refers to the node. The function has the same semantics as a map lookup, where the boolean return value is true if and only if Identity has been found, i.e. `Identity` is not nil. Caution: function returns include ejected nodes. Please check the `Ejected` flag in the identity.

func (*NodeBlocklistWrapper) ByPeerID

func (w *NodeBlocklistWrapper) ByPeerID(p peer.ID) (*flow.Identity, bool)

ByPeerID returns the full identity for the node with the given peer ID, peer.ID is the libp2p-level identifier of a Flow node. The function has the same semantics as a map lookup, where the boolean return value is true if and only if Identity has been found, i.e. `Identity` is not nil. Caution: function returns include ejected nodes. Please check the `Ejected` flag in the identity.

func (*NodeBlocklistWrapper) ClearBlocklist

func (w *NodeBlocklistWrapper) ClearBlocklist() error

ClearBlocklist purges the set of blocked node IDs. Convenience function equivalent to w.Update(nil). No errors are expected during normal operations.

func (*NodeBlocklistWrapper) GetBlocklist

func (w *NodeBlocklistWrapper) GetBlocklist() flow.IdentifierList

GetBlocklist returns the set of blocked node IDs.

func (*NodeBlocklistWrapper) Identities

Identities returns the full identities of _all_ nodes currently known to the protocol that pass the provided filter. Caution, this includes ejected nodes. Please check the `Ejected` flag in the returned identities (or provide a filter for removing ejected nodes).

func (*NodeBlocklistWrapper) Update

func (w *NodeBlocklistWrapper) Update(blocklist flow.IdentifierList) error

Update sets the wrapper's internal set of blocked nodes to `blocklist`. Empty list and `nil` (equivalent to empty list) are accepted inputs. To avoid legacy entries in the data base, this function purges the entire data base entry if `blocklist` is empty. This implementation is _eventually consistent_, where changes are written to the data base first and then (non-atomically!) the in-memory set of blocked nodes is updated. This strongly benefits performance and modularity. No errors are expected during normal operations.

type ProtocolStateIDCache

type ProtocolStateIDCache struct {
	events.Noop
	// contains filtered or unexported fields
}

ProtocolStateIDCache implements an `id.IdentityProvider` and `p2p.IDTranslator` for the set of authorized Flow network participants as according to the given `protocol.State`. the implementation assumes that the node information changes rarely, while queries are frequent. Hence, we follow an event-driven design, where the ProtocolStateIDCache subscribes to relevant protocol notifications (mainly Epoch notifications) and updates its internally cached list of authorized node identities. Note: this implementation is _eventually consistent_, where changes in the protocol state will quickly, but not atomically, propagate to the ProtocolStateIDCache. This strongly benefits performance and modularity, as we can cache identities locally here, while the marginal delay of updates is of no concern to the protocol.

func NewProtocolStateIDCache

func NewProtocolStateIDCache(
	logger zerolog.Logger,
	state protocol.State,
	eventDistributor *events.Distributor,
) (*ProtocolStateIDCache, error)

func (*ProtocolStateIDCache) ByNodeID

func (p *ProtocolStateIDCache) ByNodeID(flowID flow.Identifier) (*flow.Identity, bool)

ByNodeID returns the full identity for the node with the given Identifier, where Identifier is the way the protocol refers to the node. The function has the same semantics as a map lookup, where the boolean return value is true if and only if Identity has been found, i.e. `Identity` is not nil. Caution: function returns include ejected nodes. Please check the `Ejected` flag in the identity.

func (*ProtocolStateIDCache) ByPeerID

func (p *ProtocolStateIDCache) ByPeerID(peerID peer.ID) (*flow.Identity, bool)

ByPeerID returns the full identity for the node with the given peer ID, where ID is the way the libP2P refers to the node. The function has the same semantics as a map lookup, where the boolean return value is true if and only if Identity has been found, i.e. `Identity` is not nil. Caution: function returns include ejected nodes. Please check the `Ejected` flag in the identity.

func (*ProtocolStateIDCache) EpochCommittedPhaseStarted

func (p *ProtocolStateIDCache) EpochCommittedPhaseStarted(currentEpochCounter uint64, header *flow.Header)

EpochCommittedPhaseStarted is a callback function for notifying the `ProtocolStateIDCache` that the EpochCommitted Phase has just stared. Upon such notification, the internally-cached Identity table of authorized network participants is updated.

TODO: per API contract, implementations of `EpochCommittedPhaseStarted` should be non-blocking and virtually latency free. However, we run data base queries and acquire locks here, which is undesired.

func (*ProtocolStateIDCache) EpochSetupPhaseStarted

func (p *ProtocolStateIDCache) EpochSetupPhaseStarted(currentEpochCounter uint64, header *flow.Header)

EpochSetupPhaseStarted is a callback function for notifying the `ProtocolStateIDCache` that the EpochSetup Phase has just stared. Upon such notification, the internally-cached Identity table of authorized network participants is updated.

TODO: per API contract, implementations of `EpochSetupPhaseStarted` should be non-blocking and virtually latency free. However, we run data base queries and acquire locks here, which is undesired.

func (*ProtocolStateIDCache) EpochTransition

func (p *ProtocolStateIDCache) EpochTransition(newEpochCounter uint64, header *flow.Header)

EpochTransition is a callback function for notifying the `ProtocolStateIDCache` of an Epoch transition that just occurred. Upon such notification, the internally-cached Identity table of authorized network participants is updated.

TODO: per API contract, implementations of `EpochTransition` should be non-blocking and virtually latency free. However, we run data base queries and acquire locks here, which is undesired.

func (*ProtocolStateIDCache) GetFlowID

func (p *ProtocolStateIDCache) GetFlowID(peerID peer.ID) (flow.Identifier, error)

GetFlowID returns the Flow ID for the given peer ID. During normal operations, the following error returns are expected

  • ErrUnknownId if the given Identifier is unknown

func (*ProtocolStateIDCache) GetPeerID

func (p *ProtocolStateIDCache) GetPeerID(flowID flow.Identifier) (peer.ID, error)

GetPeerID returns the peer ID for the given Flow ID. During normal operations, the following error returns are expected

  • ErrUnknownId if the given Identifier is unknown

func (*ProtocolStateIDCache) Identities

Identities returns the full identities of _all_ nodes currently known to the protocol that pass the provided filter. Caution, this includes ejected nodes. Please check the `Ejected` flag in the identities (or provide a filter for removing ejected nodes).

Jump to

Keyboard shortcuts

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