diff --git a/heromodels/src/models/grid4/specs/README.md b/heromodels/src/models/grid4/specs/README.md new file mode 100644 index 0000000..5aa351e --- /dev/null +++ b/heromodels/src/models/grid4/specs/README.md @@ -0,0 +1,194 @@ + +# Grid4 Data Model + +This module defines data models for nodes, groups, and slices in a cloud/grid infrastructure. Each root object is marked with `@[heap]` and can be indexed for efficient querying. + +## Root Objects Overview + +| Object | Description | Index Fields | +| ----------- | --------------------------------------------- | ------------------------------ | +| `Node` | Represents a single node in the grid | `id`, `nodegroupid`, `country` | +| `NodeGroup` | Represents a group of nodes owned by a farmer | `id`, `farmerid` | + +--- + +## Node + +Represents a single node in the grid with slices, devices, and capacity. + +| Field | Type | Description | Indexed | +| --------------- | ---------------- | -------------------------------------------- | ------- | +| `id` | `int` | Unique node ID | ✅ | +| `nodegroupid` | `int` | ID of the owning node group | ✅ | +| `uptime` | `int` | Uptime percentage (0-100) | ✅ | +| `computeslices` | `[]ComputeSlice` | List of compute slices | ❌ | +| `storageslices` | `[]StorageSlice` | List of storage slices | ❌ | +| `devices` | `DeviceInfo` | Hardware device info (storage, memory, etc.) | ❌ | +| `country` | `string` | 2-letter country code | ✅ | +| `capacity` | `NodeCapacity` | Aggregated hardware capacity | ❌ | +| `provisiontime` | `u32` | Provisioning time (simple/compatible format) | ✅ | + +--- + +## NodeGroup + +Represents a group of nodes owned by a farmer, with policies. + +| Field | Type | Description | Indexed | +| ------------------------------------- | --------------- | ---------------------------------------------- | ------- | +| `id` | `u32` | Unique group ID | ✅ | +| `farmerid` | `u32` | Farmer/user ID | ✅ | +| `secret` | `string` | Encrypted secret for booting nodes | ❌ | +| `description` | `string` | Group description | ❌ | +| `slapolicy` | `SLAPolicy` | SLA policy details | ❌ | +| `pricingpolicy` | `PricingPolicy` | Pricing policy details | ❌ | +| `compute_slice_normalized_pricing_cc` | `f64` | Pricing per 2GB compute slice in cloud credits | ❌ | +| `storage_slice_normalized_pricing_cc` | `f64` | Pricing per 1GB storage slice in cloud credits | ❌ | +| `reputation` | `int` | Reputation (0-100) | ✅ | +| `uptime` | `int` | Uptime (0-100) | ✅ | + +--- + +## ComputeSlice + +Represents a compute slice (e.g., 1GB memory unit). + +| Field | Type | Description | +| -------------------------- | --------------- | -------------------------------- | +| `nodeid` | `u32` | Owning node ID | +| `id` | `int` | Slice ID in node | +| `mem_gb` | `f64` | Memory in GB | +| `storage_gb` | `f64` | Storage in GB | +| `passmark` | `int` | Passmark score | +| `vcores` | `int` | Virtual cores | +| `cpu_oversubscription` | `int` | CPU oversubscription ratio | +| `storage_oversubscription` | `int` | Storage oversubscription ratio | +| `price_range` | `[]f64` | Price range [min, max] | +| `gpus` | `u8` | Number of GPUs | +| `price_cc` | `f64` | Price per slice in cloud credits | +| `pricing_policy` | `PricingPolicy` | Pricing policy | +| `sla_policy` | `SLAPolicy` | SLA policy | + +--- + +## StorageSlice + +Represents a 1GB storage slice. + +| Field | Type | Description | +| ---------------- | --------------- | -------------------------------- | +| `nodeid` | `u32` | Owning node ID | +| `id` | `int` | Slice ID in node | +| `price_cc` | `f64` | Price per slice in cloud credits | +| `pricing_policy` | `PricingPolicy` | Pricing policy | +| `sla_policy` | `SLAPolicy` | SLA policy | + +--- + +## DeviceInfo + +Hardware device information for a node. + +| Field | Type | Description | +| --------- | ----------------- | ----------------------- | +| `vendor` | `string` | Vendor of the node | +| `storage` | `[]StorageDevice` | List of storage devices | +| `memory` | `[]MemoryDevice` | List of memory devices | +| `cpu` | `[]CPUDevice` | List of CPU devices | +| `gpu` | `[]GPUDevice` | List of GPU devices | +| `network` | `[]NetworkDevice` | List of network devices | + +--- + +## StorageDevice + +| Field | Type | Description | +| ------------- | -------- | --------------------- | +| `id` | `string` | Unique ID for device | +| `size_gb` | `f64` | Size in GB | +| `description` | `string` | Description of device | + +--- + +## MemoryDevice + +| Field | Type | Description | +| ------------- | -------- | --------------------- | +| `id` | `string` | Unique ID for device | +| `size_gb` | `f64` | Size in GB | +| `description` | `string` | Description of device | + +--- + +## CPUDevice + +| Field | Type | Description | +| ------------- | -------- | ------------------------ | +| `id` | `string` | Unique ID for device | +| `cores` | `int` | Number of CPU cores | +| `passmark` | `int` | Passmark benchmark score | +| `description` | `string` | Description of device | +| `cpu_brand` | `string` | Brand of the CPU | +| `cpu_version` | `string` | Version of the CPU | + +--- + +## GPUDevice + +| Field | Type | Description | +| ------------- | -------- | --------------------- | +| `id` | `string` | Unique ID for device | +| `cores` | `int` | Number of GPU cores | +| `memory_gb` | `f64` | GPU memory in GB | +| `description` | `string` | Description of device | +| `gpu_brand` | `string` | Brand of the GPU | +| `gpu_version` | `string` | Version of the GPU | + +--- + +## NetworkDevice + +| Field | Type | Description | +| ------------- | -------- | --------------------- | +| `id` | `string` | Unique ID for device | +| `speed_mbps` | `int` | Network speed in Mbps | +| `description` | `string` | Description of device | + +--- + +## NodeCapacity + +Aggregated hardware capacity for a node. + +| Field | Type | Description | +| ------------ | ----- | ---------------------- | +| `storage_gb` | `f64` | Total storage in GB | +| `mem_gb` | `f64` | Total memory in GB | +| `mem_gb_gpu` | `f64` | Total GPU memory in GB | +| `passmark` | `int` | Total passmark score | +| `vcores` | `int` | Total virtual cores | + +--- + +## SLAPolicy + +Service Level Agreement policy for slices or node groups. + +| Field | Type | Description | +| -------------------- | ----- | --------------------------------------- | +| `sla_uptime` | `int` | Required uptime % (e.g., 90) | +| `sla_bandwidth_mbit` | `int` | Guaranteed bandwidth in Mbps (0 = none) | +| `sla_penalty` | `int` | Penalty % if SLA is breached (0-100) | + +--- + +## PricingPolicy + +Pricing policy for slices or node groups. + +| Field | Type | Description | +| ---------------------------- | ------- | --------------------------------------------------------- | +| `marketplace_year_discounts` | `[]int` | Discounts for 1Y, 2Y, 3Y prepaid usage (e.g. [30,40,50]) | +| `volume_discounts` | `[]int` | Volume discounts based on purchase size (e.g. [10,20,30]) | + + diff --git a/heromodels/src/models/grid4/specs/model_bid.v b/heromodels/src/models/grid4/specs/model_bid.v new file mode 100644 index 0000000..7bf2a75 --- /dev/null +++ b/heromodels/src/models/grid4/specs/model_bid.v @@ -0,0 +1,24 @@ +module datamodel + +// I can bid for infra, and optionally get accepted +@[heap] +pub struct Bid { +pub mut: + id u32 + customer_id u32 // links back to customer for this capacity (user on ledger) + compute_slices_nr int // nr of slices I need in 1 machine + compute_slice f64 // price per 1 GB slice I want to accept + storage_slices []u32 + status BidStatus + obligation bool // if obligation then will be charged and money needs to be in escrow, otherwise its an intent + start_date u32 // epoch + end_date u32 +} + +pub enum BidStatus { + pending + confirmed + assigned + cancelled + done +} diff --git a/heromodels/src/models/grid4/specs/model_node.v b/heromodels/src/models/grid4/specs/model_node.v new file mode 100644 index 0000000..d3eca99 --- /dev/null +++ b/heromodels/src/models/grid4/specs/model_node.v @@ -0,0 +1,111 @@ +module datamodel + +@[heap] +pub struct Node { +pub mut: + id int + nodegroupid int + uptime int // 0..100 + computeslices []ComputeSlice + storageslices []StorageSlice + devices DeviceInfo + country string // 2 letter code as specified in lib/data/countries/data/countryInfo.txt, use that library for validation + capacity NodeCapacity // Hardware capacity details + provisiontime u32 // lets keep it simple and compatible + pubkey string + signature_node string // signature done on node to validate pubkey with privkey + signature_farmer string // signature as done by farmers to validate their identity +} + +pub struct DeviceInfo { +pub mut: + vendor string + storage []StorageDevice + memory []MemoryDevice + cpu []CPUDevice + gpu []GPUDevice + network []NetworkDevice +} + +pub struct StorageDevice { +pub mut: + id string // can be used in node + size_gb f64 // Size of the storage device in gigabytes + description string // Description of the storage device +} + +pub struct MemoryDevice { +pub mut: + id string // can be used in node + size_gb f64 // Size of the memory device in gigabytes + description string // Description of the memory device +} + +pub struct CPUDevice { +pub mut: + id string // can be used in node + cores int // Number of CPU cores + passmark int + description string // Description of the CPU + cpu_brand string // Brand of the CPU + cpu_version string // Version of the CPU +} + +pub struct GPUDevice { +pub mut: + id string // can be used in node + cores int // Number of GPU cores + memory_gb f64 // Size of the GPU memory in gigabytes + description string // Description of the GPU + gpu_brand string + gpu_version string +} + +pub struct NetworkDevice { +pub mut: + id string // can be used in node + speed_mbps int // Network speed in Mbps + description string // Description of the network device +} + +// NodeCapacity represents the hardware capacity details of a node. +pub struct NodeCapacity { +pub mut: + storage_gb f64 // Total storage in gigabytes + mem_gb f64 // Total memory in gigabytes + mem_gb_gpu f64 // Total GPU memory in gigabytes + passmark int // Passmark score for the node + vcores int // Total virtual cores +} + +// typically 1GB of memory, but can be adjusted based based on size of machine +pub struct ComputeSlice { +pub mut: + nodeid u32 // the node in the grid, there is an object describing the node + id int // the id of the slice in the node + mem_gb f64 + storage_gb f64 + passmark int + vcores int + cpu_oversubscription int + storage_oversubscription int + price_range []f64 = [0.0, 0.0] + gpus u8 // nr of GPU's see node to know what GPU's are + price_cc f64 // price per slice (even if the grouped one) + pricing_policy PricingPolicy + sla_policy SLAPolicy +} + +// 1GB of storage +pub struct StorageSlice { +pub mut: + nodeid u32 // the node in the grid + id int // the id of the slice in the node, are tracked in the node itself + price_cc f64 // price per slice (even if the grouped one) + pricing_policy PricingPolicy + sla_policy SLAPolicy +} + +fn (mut n Node) check() ! { + // todo calculate NodeCapacity out of the devices on the Node +} diff --git a/heromodels/src/models/grid4/specs/model_nodegroup.v b/heromodels/src/models/grid4/specs/model_nodegroup.v new file mode 100644 index 0000000..57346f4 --- /dev/null +++ b/heromodels/src/models/grid4/specs/model_nodegroup.v @@ -0,0 +1,30 @@ +module datamodel + +// is a root object, is the only obj farmer needs to configure in the UI, this defines how slices will be created +@[heap] +pub struct NodeGroup { +pub mut: + id u32 + farmerid u32 // link back to farmer who owns the nodegroup, is a user? + secret string // only visible by farmer, in future encrypted, used to boot a node + description string + slapolicy SLAPolicy + pricingpolicy PricingPolicy + compute_slice_normalized_pricing_cc f64 // pricing in CC - cloud credit, per 2GB node slice + storage_slice_normalized_pricing_cc f64 // pricing in CC - cloud credit, per 1GB storage slice + reputation int = 50 // between 0 and 100, earned over time + uptime int // between 0 and 100, set by system, farmer has no ability to set this +} + +pub struct SLAPolicy { +pub mut: + sla_uptime int // should +90 + sla_bandwidth_mbit int // minimal mbits we can expect avg over 1h per node, 0 means we don't guarantee + sla_penalty int // 0-100, percent of money given back in relation to month if sla breached, e.g. 200 means we return 2 months worth of rev if sla missed +} + +pub struct PricingPolicy { +pub mut: + marketplace_year_discounts []int = [30, 40, 50] // e.g. 30,40,50 means if user has more CC in wallet than 1 year utilization on all his purchaes then this provider gives 30%, 2Y 40%, ... + volume_discounts []int = [10, 20, 30] // e.g. 10,20,30 +} diff --git a/heromodels/src/models/grid4/specs/model_reservation.v b/heromodels/src/models/grid4/specs/model_reservation.v new file mode 100644 index 0000000..6ba6d5e --- /dev/null +++ b/heromodels/src/models/grid4/specs/model_reservation.v @@ -0,0 +1,21 @@ +module datamodel + +@[heap] +pub struct Reservation { +pub mut: + id u32 + customer_id u32 // links back to customer for this capacity + compute_slices []u32 + storage_slices []u32 + status ReservationStatus + start_date u32 // epoch + end_date u32 +} + +pub enum ReservationStatus { + pending + confirmed + assigned + cancelled + done +}