From 6f20fb6e6d23c5251ad3e5133f57e11c65065001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Ant=C3=B3nio?= Date: Sat, 21 Dec 2024 13:37:15 +0000 Subject: [PATCH] feat: rename stacks pricing (#299) * rename stacks pricing * resolve tests --- atoma-bin/atoma_node.rs | 2 +- atoma-service/src/tests.rs | 2 +- .../20241121103103_create_node_tables.sql | 22 +++--- atoma-state/src/state_manager.rs | 78 +++++++++---------- atoma-state/src/types.rs | 6 +- atoma-sui/src/events.rs | 12 +-- atoma-sui/src/subscriber.rs | 2 +- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/atoma-bin/atoma_node.rs b/atoma-bin/atoma_node.rs index dfd3c923..16d37a39 100644 --- a/atoma-bin/atoma_node.rs +++ b/atoma-bin/atoma_node.rs @@ -337,7 +337,7 @@ async fn main() -> Result<()> { .image_generations_service_url .context("Image generations service URL not configured")?, keystore: Arc::new(keystore), - address_index: address_index, + address_index, }; let daemon_app_state = DaemonState { diff --git a/atoma-service/src/tests.rs b/atoma-service/src/tests.rs index 564235ac..59699762 100644 --- a/atoma-service/src/tests.rs +++ b/atoma-service/src/tests.rs @@ -156,7 +156,7 @@ mod middleware { task_small_id: 1, selected_node_id: 1, num_compute_units: 600, - price: 1, + price_per_one_million_compute_units: 1, already_computed_units: 0, in_settle_period: false, total_hash: vec![], diff --git a/atoma-state/src/migrations/20241121103103_create_node_tables.sql b/atoma-state/src/migrations/20241121103103_create_node_tables.sql index 3af9ca4a..cad0b0be 100644 --- a/atoma-state/src/migrations/20241121103103_create_node_tables.sql +++ b/atoma-state/src/migrations/20241121103103_create_node_tables.sql @@ -28,17 +28,17 @@ CREATE TABLE IF NOT EXISTS node_subscriptions ( -- Create stacks table CREATE TABLE IF NOT EXISTS stacks ( - stack_small_id BIGINT PRIMARY KEY, - owner_address TEXT NOT NULL, - stack_id TEXT UNIQUE NOT NULL, - task_small_id BIGINT NOT NULL, - selected_node_id BIGINT NOT NULL, - num_compute_units BIGINT NOT NULL, - price BIGINT NOT NULL, - already_computed_units BIGINT NOT NULL, - in_settle_period BOOLEAN NOT NULL, - total_hash BYTEA NOT NULL, - num_total_messages BIGINT NOT NULL, + stack_small_id BIGINT PRIMARY KEY, + owner_address TEXT NOT NULL, + stack_id TEXT UNIQUE NOT NULL, + task_small_id BIGINT NOT NULL, + selected_node_id BIGINT NOT NULL, + num_compute_units BIGINT NOT NULL, + price_per_one_million_compute_units BIGINT NOT NULL, + already_computed_units BIGINT NOT NULL, + in_settle_period BOOLEAN NOT NULL, + total_hash BYTEA NOT NULL, + num_total_messages BIGINT NOT NULL, CONSTRAINT check_compute_units CHECK (already_computed_units <= num_compute_units), FOREIGN KEY (selected_node_id, task_small_id) REFERENCES node_subscriptions (node_small_id, task_small_id) diff --git a/atoma-state/src/state_manager.rs b/atoma-state/src/state_manager.rs index 9a2ce161..da51a812 100644 --- a/atoma-state/src/state_manager.rs +++ b/atoma-state/src/state_manager.rs @@ -1165,12 +1165,12 @@ impl AtomaState { task_small_id = %stack.task_small_id, selected_node_id = %stack.selected_node_id, num_compute_units = %stack.num_compute_units, - price = %stack.price) + price = %stack.price_per_one_million_compute_units) )] pub async fn insert_new_stack(&self, stack: Stack) -> Result<()> { sqlx::query( "INSERT INTO stacks - (owner_address, stack_small_id, stack_id, task_small_id, selected_node_id, num_compute_units, price, already_computed_units, in_settle_period, total_hash, num_total_messages) + (owner_address, stack_small_id, stack_id, task_small_id, selected_node_id, num_compute_units, price_per_one_million_compute_units, already_computed_units, in_settle_period, total_hash, num_total_messages) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) ON CONFLICT (stack_small_id) DO UPDATE SET already_computed_units = stacks.already_computed_units + $8 @@ -1182,7 +1182,7 @@ impl AtomaState { .bind(stack.task_small_id) .bind(stack.selected_node_id) .bind(stack.num_compute_units) - .bind(stack.price) + .bind(stack.price_per_one_million_compute_units) .bind(stack.already_computed_units) .bind(stack.in_settle_period) .bind(stack.total_hash) @@ -2377,7 +2377,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2423,7 +2423,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 30, in_settle_period: false, total_hash: vec![0; 32], @@ -2508,7 +2508,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2562,7 +2562,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 15, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2613,7 +2613,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2676,7 +2676,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2773,7 +2773,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -2890,7 +2890,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -3006,7 +3006,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -3190,7 +3190,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![1, 2, 3], @@ -3203,7 +3203,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 50, in_settle_period: true, total_hash: vec![4, 5, 6], @@ -3216,7 +3216,7 @@ mod tests { task_small_id: 1, selected_node_id: 2, num_compute_units: 300, - price: 3000, + price_per_one_million_compute_units: 3000, already_computed_units: 100, in_settle_period: false, total_hash: vec![7, 8, 9], @@ -3242,13 +3242,13 @@ mod tests { assert!( result .iter() - .any(|s| s.stack_small_id == 1 && s.price == 1000), + .any(|s| s.stack_small_id == 1 && s.price_per_one_million_compute_units == 1000), "Should find stack 1" ); assert!( result .iter() - .any(|s| s.stack_small_id == 2 && s.price == 2000), + .any(|s| s.stack_small_id == 2 && s.price_per_one_million_compute_units == 2000), "Should find stack 2" ); @@ -3321,7 +3321,7 @@ mod tests { assert_eq!(stack.task_small_id, 1); assert_eq!(stack.selected_node_id, 2); assert_eq!(stack.num_compute_units, 300); - assert_eq!(stack.price, 3000); + assert_eq!(stack.price_per_one_million_compute_units, 3000); assert_eq!(stack.already_computed_units, 100); assert!(!stack.in_settle_period); assert_eq!(stack.total_hash, vec![7, 8, 9]); @@ -3377,7 +3377,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![0; 32], @@ -3391,7 +3391,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 0, in_settle_period: false, total_hash: vec![0; 32], @@ -3458,7 +3458,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![0; 32], @@ -3472,7 +3472,7 @@ mod tests { task_small_id: 1, selected_node_id: 2, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 0, in_settle_period: false, total_hash: vec![0; 32], @@ -3544,7 +3544,7 @@ mod tests { selected_node_id: 1, num_compute_units: 100, already_computed_units: 90, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3558,7 +3558,7 @@ mod tests { selected_node_id: 1, num_compute_units: 100, already_computed_units: 50, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3572,7 +3572,7 @@ mod tests { selected_node_id: 2, num_compute_units: 100, already_computed_units: 95, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3586,7 +3586,7 @@ mod tests { selected_node_id: 3, num_compute_units: 100, already_computed_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3693,7 +3693,7 @@ mod tests { selected_node_id: 1, num_compute_units: 0, already_computed_units: 0, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3709,7 +3709,7 @@ mod tests { selected_node_id: 1, num_compute_units: i64::MAX, already_computed_units: i64::MAX / 2 + i64::MAX / 4, - price: 1000, + price_per_one_million_compute_units: 1000, in_settle_period: false, total_hash: vec![0; 32], num_total_messages: 0, @@ -3772,7 +3772,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -3854,7 +3854,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 10, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -3969,7 +3969,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: vec![0; 32], @@ -3982,7 +3982,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 50, in_settle_period: true, total_hash: vec![0; 32], @@ -3995,7 +3995,7 @@ mod tests { task_small_id: 1, selected_node_id: 2, num_compute_units: 300, - price: 3000, + price_per_one_million_compute_units: 3000, already_computed_units: 100, in_settle_period: false, total_hash: vec![0; 32], @@ -4118,7 +4118,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 0, in_settle_period: false, total_hash: hash1.clone(), @@ -4141,7 +4141,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 0, in_settle_period: false, total_hash: hash2.clone(), @@ -4155,7 +4155,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 300, - price: 3000, + price_per_one_million_compute_units: 3000, already_computed_units: 0, in_settle_period: false, total_hash: hash3.clone(), @@ -4244,7 +4244,7 @@ mod tests { task_small_id: 1, selected_node_id: 1, num_compute_units: 100, - price: 1000, + price_per_one_million_compute_units: 1000, already_computed_units: 50, in_settle_period: true, total_hash: vec![], @@ -4257,7 +4257,7 @@ mod tests { task_small_id: 1, selected_node_id: 2, num_compute_units: 200, - price: 2000, + price_per_one_million_compute_units: 2000, already_computed_units: 150, in_settle_period: true, total_hash: vec![], @@ -4270,7 +4270,7 @@ mod tests { task_small_id: 1, selected_node_id: 3, num_compute_units: 300, - price: 3000, + price_per_one_million_compute_units: 3000, already_computed_units: 250, in_settle_period: true, total_hash: vec![], diff --git a/atoma-state/src/types.rs b/atoma-state/src/types.rs index 593efb0c..32370bc9 100644 --- a/atoma-state/src/types.rs +++ b/atoma-state/src/types.rs @@ -63,7 +63,7 @@ pub struct Stack { /// Total number of compute units in this stack pub num_compute_units: i64, /// Price of the stack (likely in smallest currency unit) - pub price: i64, + pub price_per_one_million_compute_units: i64, /// Number of compute units already processed pub already_computed_units: i64, /// Indicates whether the stack is currently in the settle period @@ -84,7 +84,7 @@ impl From for Stack { task_small_id: event.task_small_id.inner as i64, selected_node_id: event.selected_node_id.inner as i64, num_compute_units: event.num_compute_units as i64, - price: event.price as i64, + price_per_one_million_compute_units: event.price_per_one_million_compute_units as i64, already_computed_units: 0, in_settle_period: false, total_hash: vec![], @@ -102,7 +102,7 @@ impl From for Stack { task_small_id: event.task_small_id.inner as i64, selected_node_id: event.selected_node_id.inner as i64, num_compute_units: event.num_compute_units as i64, - price: event.price as i64, + price_per_one_million_compute_units: event.price_per_one_million_compute_units as i64, already_computed_units: event.already_computed_units, in_settle_period: false, total_hash: vec![], diff --git a/atoma-sui/src/events.rs b/atoma-sui/src/events.rs index d5dc2f27..091e3d63 100644 --- a/atoma-sui/src/events.rs +++ b/atoma-sui/src/events.rs @@ -418,7 +418,7 @@ pub struct StackCreatedEvent { /// The price associated with this stack. /// This value represents the cost in the network's native currency for processing this stack. #[serde(deserialize_with = "deserialize_string_to_u64")] - pub price: u64, + pub price_per_one_million_compute_units: u64, } impl From<(StackCreatedEvent, i64)> for StackCreateAndUpdateEvent { @@ -430,7 +430,7 @@ impl From<(StackCreatedEvent, i64)> for StackCreateAndUpdateEvent { task_small_id: event.task_small_id, selected_node_id: event.selected_node_id, num_compute_units: event.num_compute_units, - price: event.price, + price_per_one_million_compute_units: event.price_per_one_million_compute_units, already_computed_units, } } @@ -462,9 +462,9 @@ pub struct StackCreateAndUpdateEvent { /// This represents the computational resources reserved for processing the stack's tasks. pub num_compute_units: u64, - /// The price associated with this stack. + /// The price per one million compute units associated with this stack. /// This value represents the cost in the network's native currency for processing this stack. - pub price: u64, + pub price_per_one_million_compute_units: u64, /// The number of compute units already computed for this stack. pub already_computed_units: i64, @@ -1103,7 +1103,7 @@ mod tests { "task_small_id": {"inner": "3"}, "selected_node_id": {"inner": "11"}, "num_compute_units": "5", - "price": "1000" + "price_per_one_million_compute_units": "1000" }); let event: StackCreatedEvent = serde_json::from_value(json).unwrap(); assert_eq!(event.owner, "0x123"); @@ -1112,7 +1112,7 @@ mod tests { assert_eq!(event.task_small_id.inner, 3); assert_eq!(event.selected_node_id.inner, 11); assert_eq!(event.num_compute_units, 5); - assert_eq!(event.price, 1000); + assert_eq!(event.price_per_one_million_compute_units, 1000); } #[test] diff --git a/atoma-sui/src/subscriber.rs b/atoma-sui/src/subscriber.rs index 41d8fdec..d8b3afc7 100644 --- a/atoma-sui/src/subscriber.rs +++ b/atoma-sui/src/subscriber.rs @@ -926,7 +926,7 @@ mod tests { stack_id: "test".to_string(), stack_small_id: StackSmallId { inner: 1 }, num_compute_units: 0, - price: 0, + price_per_one_million_compute_units: 0, }, None, ));