Skip to content

Commit 515bee5

Browse files
authored
Merge pull request #2257 from oasisprotocol/kostko/fix/rofl-scheduler-multi-accept
rofl-scheduler: Multiple fixes
2 parents 4d00d77 + 71ee5c4 commit 515bee5

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

rofl-scheduler/rofl.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: rofl-scheduler
2-
version: 0.2.2
2+
version: 0.2.3
33
repository: https://github.com/oasisprotocol/oasis-sdk
44
tee: tdx
55
kind: raw
@@ -47,7 +47,11 @@ deployments:
4747
- id: 33R8MVGCGJg3CAYKDR87Zv2kvj65lbpcAHmZLKRA5FYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
4848
version: 0.2.1
4949
- id: Sa0PyyZJsj4UpjE6IJOyqsi92iNMrwULpRbF2tq8YmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
50+
version: 0.2.2
5051
- id: zt08xPOoXhy1SWHNcBNalVDjf6EHAUu9x6Tvq7aOBrwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
52+
version: 0.2.2
53+
- id: p+wMY5zEuP5geFAkuoxI7NFiszMMTJHgdGxizuCZdwkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
54+
- id: WbUlJcnxwoy4NGyKgKIRlYF4OL7zHuvQVQ0yhbOvYcYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
5155
endorsements:
5256
- any: {}
5357
fees: endorsing_node
@@ -88,7 +92,11 @@ deployments:
8892
- id: erQlwbWIEIx3WdLCqb7C/wWsDjDQgTW5VssQb9APrKMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
8993
version: 0.2.1
9094
- id: Iq6cDWfVpHrAfgbFvaEqhnZ7YCDHfoXEWlU5n2xFnJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
95+
version: 0.2.2
9196
- id: e9QSiflGUzqJei84tKL8N81HOMKkOXLfU6X/M/p00N0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
97+
version: 0.2.2
98+
- id: XYyfBM8gNwSOBvKutXlel9xo6g4paIhq4RiQWEBRdMkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
99+
- id: Etnh0TxJ4Kng2qrVe/M78OX53r0TJlPe+Ripp0n1nnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
92100
endorsements:
93101
- any: {}
94102
fees: endorsing_node

rofl-scheduler/src/client.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ impl MarketClient {
5555
.env
5656
.client()
5757
.sign_and_submit_tx(self.env.signer(), tx)
58-
.await?;
58+
.await?
59+
.ok()?;
5960

6061
Ok(())
6162
}
@@ -74,7 +75,8 @@ impl MarketClient {
7475
.env
7576
.client()
7677
.sign_and_submit_tx(self.env.signer(), tx)
77-
.await?;
78+
.await?
79+
.ok()?;
7880

7981
Ok(())
8082
}
@@ -93,7 +95,8 @@ impl MarketClient {
9395
.env
9496
.client()
9597
.sign_and_submit_tx(self.env.signer(), tx)
96-
.await?;
98+
.await?
99+
.ok()?;
97100

98101
Ok(())
99102
}
@@ -112,7 +115,8 @@ impl MarketClient {
112115
.env
113116
.client()
114117
.sign_and_submit_tx(self.env.signer(), tx)
115-
.await?;
118+
.await?
119+
.ok()?;
116120

117121
Ok(())
118122
}
@@ -134,6 +138,22 @@ impl MarketQueryClient {
134138
self.round
135139
}
136140

141+
/// Query specific instance.
142+
pub async fn instance(&self, id: InstanceId) -> Result<Instance> {
143+
self.parent
144+
.env
145+
.client()
146+
.query(
147+
self.round,
148+
"roflmarket.Instance",
149+
InstanceQuery {
150+
provider: self.parent.provider,
151+
id,
152+
},
153+
)
154+
.await
155+
}
156+
137157
/// Query all provider's instances.
138158
pub async fn instances(&self) -> Result<Vec<Instance>> {
139159
self.parent

rofl-scheduler/src/manager.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,13 @@ impl Manager {
298298
// Discover desired instance state.
299299
let instances: Vec<Instance> = local_state.client.instances().await?;
300300
for instance in instances {
301-
// Remove known instances.
302-
running_unknown.remove(&instance.id);
303-
304301
match instance.status {
305302
InstanceStatus::Created => {
306303
// Instance has not yet been accepted, nothing to do.
307304
continue;
308305
}
309306
InstanceStatus::Cancelled => {
310-
// Instance has been cancelled, make sure it is stopped if running.
311-
if local_state.running.contains_key(&instance.id) {
312-
local_state.pending_stop.push((instance.id, true));
313-
}
307+
// Instance has been cancelled.
314308
local_state
315309
.maybe_remove
316310
.push((instance.id, instance.updated_at));
@@ -325,6 +319,9 @@ impl Manager {
325319
}
326320
}
327321

322+
// Remove known instances. Any remaining unknown instances will be stopped.
323+
running_unknown.remove(&instance.id);
324+
328325
// Check if the instance is still paid for. If not, we immediately stop it and schedule
329326
// its removal.
330327
if instance.paid_until < now {
@@ -614,13 +611,6 @@ impl Manager {
614611
.or_default()
615612
.node_id = Some(local_node_id);
616613
}
617-
618-
// Queue a job to deploy when a deployment exists.
619-
if let Some(deployment) = instance.deployment.clone() {
620-
local_state
621-
.pending_start
622-
.push((instance, deployment.clone(), true));
623-
}
624614
}
625615

626616
Ok(())
@@ -824,6 +814,17 @@ impl Manager {
824814
return Ok(());
825815
}
826816

817+
// XXX: Temporarily skip instances that cannot be removed due to a claim bug.
818+
let info = self
819+
.client
820+
.queries_at_latest()
821+
.await?
822+
.instance(instance)
823+
.await?;
824+
if info.paid_until == info.paid_from {
825+
return Ok(());
826+
}
827+
827828
self.client.remove_instance(instance).await?;
828829

829830
let mut instances = self.instances.write().unwrap();

runtime-sdk/modules/rofl-market/src/payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl PaymentMethod for Payment {
273273
.checked_mul(total_amount)
274274
.ok_or(Error::InvalidArgument)?
275275
.checked_div(paid_time.into())
276-
.ok_or(Error::InvalidArgument)?;
276+
.unwrap_or(0);
277277

278278
<C::Runtime as Runtime>::Accounts::transfer(
279279
instance_address,

runtime-sdk/modules/rofl-market/src/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ fn test_instance_management() {
816816
assert_eq!(module, "roflmarket");
817817
assert_eq!(code, 4); // Forbidden.
818818

819+
// Ensure we are after paid_until to test the claim case.
820+
mock.runtime_header.timestamp = instance.paid_until + 10;
821+
let ctx = mock.create_ctx_for_runtime::<TestRuntime>(true);
822+
819823
// Scheduler app from the correct node should be allowed to remove instances.
820824
let dispatch_result = signer_dave.call(&ctx, "roflmarket.InstanceRemove", remove.clone());
821825
assert!(dispatch_result.result.is_success(), "call should succeed");

runtime-sdk/src/modules/rofl/app/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct SubmitTxOpts {
6363
impl Default for SubmitTxOpts {
6464
fn default() -> Self {
6565
Self {
66-
timeout: Some(Duration::from_millis(15_000)), // 15 seconds.
66+
timeout: Some(Duration::from_millis(60_000)), // 60 seconds.
6767
encrypt: true,
6868
verify: true,
6969
}

0 commit comments

Comments
 (0)