Documentation
¶
Index ¶
- Constants
- type CancelSubscription
- type DialOptionFunc
- type FixedNodeRegistry
- func (f *FixedNodeRegistry) AddNode(node Node)
- func (r *FixedNodeRegistry) GetNode(nodeId uint32) (*Node, error)
- func (r *FixedNodeRegistry) GetNodes() ([]Node, error)
- func (f *FixedNodeRegistry) OnChangedNode(nodeId uint32) (<-chan Node, CancelSubscription)
- func (f *FixedNodeRegistry) OnNewNodes() (<-chan []Node, CancelSubscription)
- func (f *FixedNodeRegistry) Stop()
- type Node
- type NodeRegistry
- type NodesContract
- type SmartContractRegistry
- func (s *SmartContractRegistry) GetNode(nodeId uint32) (*Node, error)
- func (s *SmartContractRegistry) GetNodes() ([]Node, error)
- func (s *SmartContractRegistry) OnChangedNode(nodeId uint32) (<-chan Node, CancelSubscription)
- func (s *SmartContractRegistry) OnNewNodes() (<-chan []Node, CancelSubscription)
- func (s *SmartContractRegistry) SetContractForTest(contract NodesContract)
- func (s *SmartContractRegistry) Start() error
- func (f *SmartContractRegistry) Stop()
Constants ¶
const (
CONTRACT_CALL_TIMEOUT = 10 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialOptionFunc ¶ added in v0.1.1
type DialOptionFunc func(node Node) []grpc.DialOption
type FixedNodeRegistry ¶
type FixedNodeRegistry struct {
// contains filtered or unexported fields
}
TODO: Delete this or move to a test file
func NewFixedNodeRegistry ¶
func NewFixedNodeRegistry(nodes []Node) *FixedNodeRegistry
func (*FixedNodeRegistry) AddNode ¶
func (f *FixedNodeRegistry) AddNode(node Node)
func (*FixedNodeRegistry) GetNode ¶
func (r *FixedNodeRegistry) GetNode(nodeId uint32) (*Node, error)
func (*FixedNodeRegistry) GetNodes ¶
func (r *FixedNodeRegistry) GetNodes() ([]Node, error)
func (*FixedNodeRegistry) OnChangedNode ¶
func (f *FixedNodeRegistry) OnChangedNode( nodeId uint32, ) (<-chan Node, CancelSubscription)
func (*FixedNodeRegistry) OnNewNodes ¶
func (f *FixedNodeRegistry) OnNewNodes() (<-chan []Node, CancelSubscription)
func (*FixedNodeRegistry) Stop ¶ added in v0.1.1
func (f *FixedNodeRegistry) Stop()
type Node ¶
type Node struct { NodeID uint32 SigningKey *ecdsa.PublicKey HttpAddress string IsHealthy bool IsValidConfig bool }
func (*Node) BuildClient ¶ added in v0.1.1
func (node *Node) BuildClient( extraDialOpts ...grpc.DialOption, ) (*grpc.ClientConn, error)
type NodeRegistry ¶
type NodeRegistry interface { GetNodes() ([]Node, error) GetNode(uint32) (*Node, error) OnNewNodes() (<-chan []Node, CancelSubscription) OnChangedNode(uint32) (<-chan Node, CancelSubscription) Stop() }
* The NodeRegistry is responsible for fetching the list of nodes from the registry contract and notifying listeners when the list of nodes changes.
type NodesContract ¶
type NodesContract interface {
AllNodes(opts *bind.CallOpts) ([]nodes.NodesNodeWithId, error)
}
* A dumbed down interface of abis.NodesCaller for generating mocks
type SmartContractRegistry ¶
type SmartContractRegistry struct {
// contains filtered or unexported fields
}
* The SmartContractRegistry notifies listeners of changes to the nodes by polling the contract and diffing the returned node list with what is currently in memory.
This allows it to operate statelessly and not require a database, with a trade-off for latency.
Given how infrequently this list changes, that trade-off seems acceptable.
func NewSmartContractRegistry ¶
func NewSmartContractRegistry( ctx context.Context, ethclient bind.ContractCaller, logger *zap.Logger, options config.ContractsOptions, ) (*SmartContractRegistry, error)
func (*SmartContractRegistry) GetNode ¶
func (s *SmartContractRegistry) GetNode(nodeId uint32) (*Node, error)
func (*SmartContractRegistry) GetNodes ¶
func (s *SmartContractRegistry) GetNodes() ([]Node, error)
func (*SmartContractRegistry) OnChangedNode ¶
func (s *SmartContractRegistry) OnChangedNode( nodeId uint32, ) (<-chan Node, CancelSubscription)
func (*SmartContractRegistry) OnNewNodes ¶
func (s *SmartContractRegistry) OnNewNodes() (<-chan []Node, CancelSubscription)
func (*SmartContractRegistry) SetContractForTest ¶
func (s *SmartContractRegistry) SetContractForTest(contract NodesContract)
func (*SmartContractRegistry) Start ¶
func (s *SmartContractRegistry) Start() error
* Loads the initial state from the contract and starts a background refresh loop.
To stop refreshing callers should cancel the context *
func (*SmartContractRegistry) Stop ¶ added in v0.1.1
func (f *SmartContractRegistry) Stop()