Skip to content

Commit

Permalink
fix: Slot name
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v3us committed Dec 21, 2022
1 parent bd3b5d4 commit 249fc48
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5dc7270852b2d6381eaa6ff382da54ca3417c00291846ad6583466c4c0cfd4e2 cw_croncat.wasm
f0064d55912d6ca72a1d2fdd9b7414a6e9698a7f87728807690c93a70f0d888e cw_croncat.wasm
de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> CwCroncat<'a> {
owner_id,
// treasury_id: None,
min_tasks_per_agent: 3,
agent_active_indices: vec![(SlotType::Block, 0, 0), (SlotType::Time, 0, 0)],
agent_active_indices: vec![(SlotType::Block, 0, 0), (SlotType::Cron, 0, 0)],
agents_eject_threshold: 600, // how many slots an agent can miss before being ejected. 10 * 60 = 1hr
available_balance,
staked_balance: GenericBalance::default(),
Expand Down
6 changes: 3 additions & 3 deletions contracts/cw-croncat/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> CwCroncat<'a> {
(slot_id, kind)
}
(None, Some(slot_id)) => {
let kind = SlotType::Time;
let kind = SlotType::Cron;
(slot_id, kind)
}
(None, None) => {
Expand Down Expand Up @@ -406,7 +406,7 @@ impl<'a> CwCroncat<'a> {
self.block_map_queries
.save(storage, task_hash.as_bytes(), &next_id)?;
}
SlotType::Time => {
SlotType::Cron => {
self.time_map_queries
.save(storage, task_hash.as_bytes(), &next_id)?;
}
Expand All @@ -431,7 +431,7 @@ impl<'a> CwCroncat<'a> {
SlotType::Block => {
self.block_slots.update(storage, next_id, update_vec_data)?;
}
SlotType::Time => {
SlotType::Cron => {
self.time_slots.update(storage, next_id, update_vec_data)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a> CwCroncat<'a> {
) -> StdResult<Option<Vec<u8>>> {
let store = match kind {
SlotType::Block => &self.block_slots,
SlotType::Time => &self.time_slots,
SlotType::Cron => &self.time_slots,
};

let slot_data = store.may_load(storage, slot)?;
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw-croncat/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<'a> CwCroncat<'a> {
self.block_map_queries
.save(deps.storage, hash.as_bytes(), &next_id)?;
}
SlotType::Time => {
SlotType::Cron => {
self.time_map_queries
.save(deps.storage, hash.as_bytes(), &next_id)?;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'a> CwCroncat<'a> {
self.block_slots
.update(deps.storage, next_id, update_vec_data)?;
}
SlotType::Time => {
SlotType::Cron => {
self.time_slots
.update(deps.storage, next_id, update_vec_data)?;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn test_on_agent_unregister() {
.unwrap();

balancer.update_or_append(&mut config.agent_active_indices, (SlotType::Block, 0, 1));
balancer.update_or_append(&mut config.agent_active_indices, (SlotType::Time, 0, 1));
balancer.update_or_append(&mut config.agent_active_indices, (SlotType::Cron, 0, 1));
store.config.save(&mut deps.storage, &config).unwrap();
balancer
.on_agent_unregister(
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn configure() {
// assert_eq!(None, value.treasury_id);
assert_eq!(3, value.min_tasks_per_agent);
assert_eq!(
vec![(SlotType::Block, 0, 0), (SlotType::Time, 0, 0)],
vec![(SlotType::Block, 0, 0), (SlotType::Cron, 0, 0)],
value.agent_active_indices
);
assert_eq!(600, value.agents_eject_threshold);
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ fn proxy_callback_time_slots() -> StdResult<()> {
let attributes = vec![
("method", "proxy_callback"),
("slot_id", "1571797860000000000"),
("slot_kind", "Time"),
("slot_kind", "Cron"),
("task_hash", task_id_str.as_str().clone()),
];

Expand Down
50 changes: 25 additions & 25 deletions contracts/cw-croncat/src/tests/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_420_000_000_000, // current time in nanos is 1_571_797_419_879_305_533
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("1 * * * * *".to_string()),
Expand All @@ -287,7 +287,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_441_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("* 0 * * * *".to_string()),
Expand All @@ -297,7 +297,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_600_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -307,7 +307,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_615_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// with start
(
Expand All @@ -318,7 +318,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_615_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -328,7 +328,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_615_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -338,7 +338,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_803_215_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// cases when a boundary has end
// current slot is the end slot
Expand All @@ -350,7 +350,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_419_879_305_533,
SlotType::Time,
SlotType::Cron,
),
// the next slot is after the end, return end slot
(
Expand All @@ -361,7 +361,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_419_879_305_535,
SlotType::Time,
SlotType::Cron,
),
// next slot in boundaries
(
Expand All @@ -372,7 +372,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_420_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// the task has ended
(
Expand All @@ -383,7 +383,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
0,
SlotType::Time,
SlotType::Cron,
),
];
for (interval, boundary, outcome_time, outcome_slot_kind) in cases.iter() {
Expand All @@ -406,7 +406,7 @@ fn interval_get_next_cron_time() {
// the timestamp is in the current slot, so we take the next slot
1_571_797_420_000_000_000_u64.saturating_sub(1_571_797_420_000_000_000 % TWO_MINUTES)
+ TWO_MINUTES, // current time in nanos is 1_571_797_419_879_305_533
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("1 * * * * *".to_string()),
Expand All @@ -416,7 +416,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_440_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("* 0 * * * *".to_string()),
Expand All @@ -426,7 +426,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_600_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -436,7 +436,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_600_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// with start
(
Expand All @@ -447,7 +447,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_600_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -457,7 +457,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_799_600_000_000_000,
SlotType::Time,
SlotType::Cron,
),
(
Interval::Cron("15 0 * * * *".to_string()),
Expand All @@ -467,7 +467,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_803_200_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// cases when a boundary has end
// boundary end in the current slot
Expand All @@ -479,7 +479,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_320_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// next slot in boundaries
(
Expand All @@ -490,7 +490,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_440_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// next slot after the end, return end slot
(
Expand All @@ -501,7 +501,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
1_571_797_320_000_000_000,
SlotType::Time,
SlotType::Cron,
),
// the task has ended
(
Expand All @@ -512,7 +512,7 @@ fn interval_get_next_cron_time() {
is_block_boundary: Some(false),
},
0,
SlotType::Time,
SlotType::Cron,
),
];
for (interval, boundary, outcome_time, outcome_slot_kind) in cases.iter() {
Expand Down Expand Up @@ -611,7 +611,7 @@ fn slot_items_pop() {
.unwrap();
assert_eq!(
Ok(None),
store.pop_slot_item(&mut deps.storage, 0, SlotType::Time)
store.pop_slot_item(&mut deps.storage, 0, SlotType::Cron)
);
assert_eq!(
Ok(None),
Expand All @@ -636,7 +636,7 @@ fn slot_items_pop() {
assert_eq!(
*task,
store
.pop_slot_item(&mut deps.storage, 1, SlotType::Time)
.pop_slot_item(&mut deps.storage, 1, SlotType::Cron)
.unwrap()
.unwrap()
);
Expand All @@ -652,7 +652,7 @@ fn slot_items_pop() {
// Slot removed if no hash left
assert_eq!(
Ok(None),
store.pop_slot_item(&mut deps.storage, 1, SlotType::Time)
store.pop_slot_item(&mut deps.storage, 1, SlotType::Cron)
);
assert_eq!(
Ok(None),
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-croncat-core/schema/croncat.json
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
"type": "string",
"enum": [
"Block",
"Time"
"Cron"
]
},
"SmartQueries": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-croncat-core/schema/get_state_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@
"type": "string",
"enum": [
"Block",
"Time"
"Cron"
]
},
"SlotWithQueriesResponse": {
Expand Down
8 changes: 4 additions & 4 deletions packages/cw-croncat-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl BoundaryValidated {
)]
pub enum SlotType {
Block,
Time,
Cron,
}

// #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down Expand Up @@ -830,12 +830,12 @@ fn get_next_cron_time(
};

match boundary.end {
Some(end) if current_block_ts > end => (0, SlotType::Time),
Some(end) if current_block_ts > end => (0, SlotType::Cron),
Some(end) => {
let end_slot = end.saturating_sub(end % slot_granularity_time);
(u64::min(end_slot, next_slot), SlotType::Time)
(u64::min(end_slot, next_slot), SlotType::Cron)
}
_ => (next_slot, SlotType::Time),
_ => (next_slot, SlotType::Cron),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Addr = string;
export type Uint128 = string;
export type Timestamp = Uint64;
export type Uint64 = string;
export type SlotType = "Block" | "Time";
export type SlotType = "Block" | "Cron";
export type AgentStatus = "Active" | "Pending" | "Nominated";
export type CosmosMsgForEmpty = {
bank: BankMsg;
Expand Down

0 comments on commit 249fc48

Please sign in to comment.