Documentation
¶
Index ¶
- Constants
- type DialOptionFunc
- type Node
- type NodeRegistry
- type NodeRegistryContract
- type SingleNotificationNotifier
- type SmartContractRegistry
- func (s *SmartContractRegistry) GetNode(nodeId uint32) (*Node, error)
- func (s *SmartContractRegistry) GetNodes() ([]Node, error)
- func (s *SmartContractRegistry) OnChangedNode(nodeId uint32) <-chan Node
- func (s *SmartContractRegistry) OnNewNodes() <-chan []Node
- func (s *SmartContractRegistry) SetContractForTest(contract NodeRegistryContract)
- func (s *SmartContractRegistry) Start() error
- func (s *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 Node ¶
type Node struct {
NodeID uint32
SigningKey *ecdsa.PublicKey
HttpAddress string
IsCanonical 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
OnChangedNode(uint32) <-chan Node
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 NodeRegistryContract ¶ added in v0.3.0
type NodeRegistryContract interface {
GetAllNodes(opts *bind.CallOpts) ([]noderegistry.INodeRegistryNodeWithId, error)
}
* A dumbed down interface of abis.NodesCaller for generating mocks
type SingleNotificationNotifier ¶ added in v0.5.0
type SingleNotificationNotifier[ValueType any] struct { // contains filtered or unexported fields }
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
func (*SmartContractRegistry) OnNewNodes ¶
func (s *SmartContractRegistry) OnNewNodes() <-chan []Node
func (*SmartContractRegistry) SetContractForTest ¶
func (s *SmartContractRegistry) SetContractForTest(contract NodeRegistryContract)
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 (s *SmartContractRegistry) Stop()