|
| 1 | +# Registrar package |
| 2 | + |
| 3 | +The `registrar` pkg is used to handle node registration on ThreeFold Grid. It is used by the `noded` module, which triggers the registration process by first collecting node capacity information, creating a Redis client, and then adding the `registrar` to the intercommunication process using `zbus` for remote procedure calls (RPC). |
| 4 | +re-registration occurs automatically every 24 hours or immediately after an IP address change, ensuring the node's information stays up-to-date. |
| 5 | +registration process can fail due to various reasons, such as RPC calls failure. |
| 6 | + |
| 7 | +The registration process includes: |
| 8 | + |
| 9 | +1. Collecting node information |
| 10 | +2. Creating/Ensuring a twinID exists for the node |
| 11 | +3. Registering the node on the blockchain |
| 12 | + |
| 13 | +## Error Handling |
| 14 | + |
| 15 | +`ErrInProgress`: Error raised if the node registration is still in progress. |
| 16 | + |
| 17 | +`ErrFailed`: Error raised if the node registration fails. |
| 18 | + |
| 19 | +## Constants |
| 20 | + |
| 21 | +### Node registration state constants |
| 22 | + |
| 23 | +`Failed`: Node registration failed |
| 24 | + |
| 25 | +`InProgress`: Node registration is in progress |
| 26 | + |
| 27 | +`Done`: Node registration is completed |
| 28 | + |
| 29 | +## Structs |
| 30 | + |
| 31 | +### State Struct |
| 32 | + |
| 33 | +Used to store the state of the node registration. |
| 34 | + |
| 35 | + |
| 36 | +```go |
| 37 | +type State struct { |
| 38 | + NodeID uint32 // The ID of the node. |
| 39 | + TwinID uint32 // The twin ID of the node. |
| 40 | + State RegistrationState // The state of the node registration. |
| 41 | + Msg string // The message associated with the node registration state. |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### RegistrationInfo Struct |
| 46 | + |
| 47 | +Used to store the capacity, location, and other information of the node. |
| 48 | + |
| 49 | + |
| 50 | +```go |
| 51 | +type RegistrationInfo struct { |
| 52 | + Capacity gridtypes.Capacity // The capacity of the node. |
| 53 | + Location geoip.Location // The location of the node. |
| 54 | + SecureBoot bool // State whether the node is booted via efi or not. |
| 55 | + Virtualized bool // State whether the node has hypervisor on it or not. |
| 56 | + SerialNumber string // The serial number of the node. |
| 57 | + GPUs map[string]interface{} // List of gpus short name |
| 58 | +} |
| 59 | +// Set the capacity of the node |
| 60 | +WithCapacity(v gridtypes.Capacity) RegistrationInfo |
| 61 | + |
| 62 | +// Set the GPUs of the node |
| 63 | +WithGPU(short string) RegistrationInfo |
| 64 | + |
| 65 | +// Set the location of the node |
| 66 | +WithLocation(v geoip.Location) RegistrationInfo |
| 67 | + |
| 68 | +// Set the secure boot status of the node |
| 69 | +WithSecureBoot(v bool) RegistrationInfo |
| 70 | + |
| 71 | +// Set the serial number of the node |
| 72 | +WithSerialNumber(v string) RegistrationInfo |
| 73 | + |
| 74 | +// Set the virtualized status of the node |
| 75 | +WithVirtualized(v bool) RegistrationInfo |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | +### Registrar Struct |
| 80 | + |
| 81 | +The registrar is used to register nodes on the ThreeFold Grid. |
| 82 | + |
| 83 | +```go |
| 84 | +type Registrar struct { |
| 85 | + state State // The state of the registrar. |
| 86 | + mutex sync.RWMutex // A mutex for synchronizing access to the registrar. |
| 87 | +} |
| 88 | + |
| 89 | +NodeID() (uint32, error) // Returns the node ID if the registrar is in the done state |
| 90 | +TwinID() (uint32, error) // Returns the twin ID if the registrar is in the done state |
| 91 | +``` |
| 92 | + |
| 93 | +## Functions |
| 94 | + |
| 95 | +```go |
| 96 | +// Creates a new registrar with the given context, client, environment, and registration information, starts the registration process and returns the registrar. |
| 97 | +NewRegistrar(ctx context.Context, cl Zbus.Client, env environment.Environment, info RegistrationInfo) *Registrar |
| 98 | + |
| 99 | + |
| 100 | +// Returns a failed state with the given error. |
| 101 | +FailedState(err error) State |
| 102 | + |
| 103 | +// Returns an in progress state |
| 104 | +InProgressState() State |
| 105 | + |
| 106 | +// Returns a done state with the given node ID and twin ID. |
| 107 | +DoneState(nodeID , twinID uint32) State |
| 108 | +``` |
| 109 | + |
| 110 | + |
0 commit comments