Skip to content

Commit 6d291ee

Browse files
Merge pull request #96 from Acurast/develop
Develop
2 parents 5c21484 + e7cd5df commit 6d291ee

15 files changed

+1100
-122
lines changed

README.md

Lines changed: 202 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ To use the Acurast CLI, type `acurast` followed by any of the available options
4646

4747
- `new <project-name>` - Create a new Acurast project from a template.
4848
- `deploy [options] [project]` - Deploy the current project to the Acurast platform.
49-
- `deployments <'ls' | <id>> --cleanup` - List, view and clean up deployments.
49+
- `deployments [arg] [options]` - List, view, and manage deployments.
50+
- `deployments ls` or `deployments list` - List all your deployments.
51+
- `deployments <id>` - View details of a specific deployment.
52+
- `deployments <id> --update-env-vars` - Update environment variables for a deployment.
53+
- `deployments --cleanup` - Clean up old, finished deployments.
54+
- `deployments <id> --cleanup` - Clean up a specific deployment.
55+
- `deployments update script <deployment-id> <script-ipfs> [options]` - Update the script of a mutable deployment.
56+
- `deployments update editor <deployment-id> <new-editor-address> [options]` - Transfer editor permissions for a mutable deployment.
5057
- `live [options] [project]` - Setup a "live-code-processor" and run your project on the processor in real time.
5158
- `init` - Create an acurast.json file and .env file.
5259
- `open` - Open the Acurast resources in your browser.
@@ -84,7 +91,9 @@ The acurast.json file is generated by running acurast init. Here is an example c
8491
"minProcessorReputation": 0,
8592
"maxCostPerExecution": 100000000000,
8693
"includeEnvironmentVariables": [],
87-
"processorWhitelist": []
94+
"processorWhitelist": [],
95+
"mutability": "Immutable",
96+
"reuseKeysFrom": null
8897
}
8998
}
9099
}
@@ -137,6 +146,14 @@ ACURAST_MNEMONIC=abandon abandon about ...
137146
- `minProcessorVersions`: The minimum processor versions that will be used for the deployment.
138147
- `android`: The minimum Android version.
139148
- `ios`: The minimum iOS version.
149+
- `mutability`: The mutability of the deployment. Controls whether the deployment can be modified after creation.
150+
- `"Immutable"`: The deployment cannot be modified after creation (default).
151+
- `"Mutable"`: The deployment can be modified after creation.
152+
- `reuseKeysFrom`: An optional array that allows reusing keys from a previous deployment, if that deployment was set to "Mutable". Format: `[MultiOrigin, string, number]` where:
153+
- First element: The origin chain (currently only `"Acurast"` is supported)
154+
- Second element: The address of the original deployer
155+
- Third element: The deployment ID
156+
- Example: `["Acurast", "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", 123456]`
140157

141158
#### .env
142159

@@ -221,6 +238,189 @@ When running `acurast deploy`, the environment variables will now automatically
221238

222239
When running interval based deployments with multiple executions, the environment variables can be updated between executions. To do that, update the `.env` file and run `acurast deployments <id> -e`. This will update the environment variables for the deployment with the given ID.
223240

241+
## Deployment Management
242+
243+
The Acurast CLI provides comprehensive deployment management capabilities, including the ability to update mutable deployments and transfer editor permissions.
244+
245+
### Basic Deployment Commands
246+
247+
```bash
248+
# List all deployments
249+
acurast deployments ls
250+
251+
# View a specific deployment
252+
acurast deployments "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456"
253+
254+
# Update environment variables for a deployment
255+
acurast deployments "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" --update-env-vars
256+
257+
# Clean up old deployments
258+
acurast deployments --cleanup
259+
260+
# Clean up a specific deployment
261+
acurast deployments "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" --cleanup
262+
```
263+
264+
**Note**: All deployment commands require the full deployment ID format: `"origin:address:number"`
265+
266+
### Updating Mutable Deployments
267+
268+
For deployments that were created with `"mutability": "Mutable"`, you can update the script and transfer editor permissions.
269+
270+
#### Update Deployment Script
271+
272+
**Command**: `acurast deployments update script <deployment-id> <script-ipfs> [options]`
273+
274+
**Arguments**:
275+
276+
- `<deployment-id>`: The deployment ID in format `"origin:address:number"` (e.g., `"Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456"`)
277+
- `<script-ipfs>`: IPFS hash of the new script (e.g., `"ipfs://QmNewScriptHash"`)
278+
279+
**Options**:
280+
281+
- `--dry-run`: Preview the update without applying
282+
- `--force`: Skip confirmation prompts
283+
284+
**Examples**:
285+
286+
```bash
287+
# Update script (dry run)
288+
acurast deployments update script "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" "ipfs://QmNewScriptHash" --dry-run
289+
290+
# Update script (actual)
291+
acurast deployments update script "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" "ipfs://QmNewScriptHash"
292+
```
293+
294+
**Requirements**:
295+
296+
- The deployment must have `"mutability": "Mutable"`
297+
- You must be the current editor of the deployment
298+
- The script must be uploaded to IPFS and provided as an IPFS hash
299+
300+
#### Transfer Editor Permissions
301+
302+
**Command**: `acurast deployments update editor <deployment-id> <new-editor-address> [options]`
303+
304+
**Arguments**:
305+
306+
- `<deployment-id>`: The deployment ID in format `"origin:address:number"` (e.g., `"Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456"`)
307+
- `<new-editor-address>`: The AccountId32 address of the new editor
308+
309+
**Options**:
310+
311+
- `--dry-run`: Preview the transfer without executing
312+
- `--force`: Skip confirmation prompts
313+
314+
**Examples**:
315+
316+
```bash
317+
# Transfer editor permissions (dry run)
318+
acurast deployments update editor "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" --dry-run
319+
320+
# Transfer editor permissions (actual)
321+
acurast deployments update editor "Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456" "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL"
322+
```
323+
324+
**Requirements**:
325+
326+
- The deployment must have `"mutability": "Mutable"`
327+
- You must be the current editor of the deployment
328+
- The new editor address must be a valid AccountId32 format
329+
330+
### Deployment ID Format
331+
332+
The deployment ID is a unique identifier for each deployment on the Acurast platform. It follows the format:
333+
334+
```
335+
"origin:address:number"
336+
```
337+
338+
**Components**:
339+
340+
- **`origin`**: The chain name where the deployment was created
341+
- Currently only `"Acurast"` is supported
342+
- This is case-sensitive
343+
- **`address`**: The AccountId32 address of the original deployer
344+
- Must be a valid Substrate AccountId32 format (e.g., `5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL`)
345+
- This is the address that deployed the job initially
346+
- **`number`**: The deployment number (u128)
347+
- This is a sequential number assigned by the blockchain
348+
- Must be a positive integer
349+
350+
**Examples**:
351+
352+
```bash
353+
# Valid deployment IDs
354+
"Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123456"
355+
"Acurast:5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY:1"
356+
"Acurast:5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty:999999"
357+
358+
# Invalid deployment IDs
359+
"Acurast:invalid-address:123" # Invalid address format
360+
"acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:123" # Wrong case
361+
"Acurast:5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL:-1" # Negative number
362+
```
363+
364+
**Usage**:
365+
366+
- **All deployment operations** require the full deployment ID format: `"origin:address:number"`
367+
- **Configuration** (reuseKeysFrom): You must use the full format as an array
368+
369+
**Finding your deployment ID**:
370+
371+
1. Run `acurast deployments ls` to see all your deployments
372+
2. The deployment ID will be displayed in the list
373+
3. For advanced operations, use the full format shown in the list
374+
375+
### Validation and Error Handling
376+
377+
The CLI provides comprehensive validation for all deployment management commands:
378+
379+
- **Deployment ID validation**: Ensures proper format and valid components
380+
- **Address validation**: Verifies AccountId32 format for all addresses
381+
- **IPFS hash validation**: Ensures scripts are provided as valid IPFS hashes
382+
- **Permission validation**: Checks that you have the necessary permissions
383+
- **Mutability validation**: Ensures the deployment is mutable before allowing updates
384+
385+
### Safety Features
386+
387+
- **Dry-run mode**: Preview changes before applying them
388+
- **Confirmation prompts**: Require explicit confirmation for destructive operations
389+
- **Error messages**: Clear, descriptive error messages for validation failures
390+
- **Transaction feedback**: Display transaction hashes for successful operations
391+
392+
## Deployment Features
393+
394+
### Mutability
395+
396+
The `mutability` field controls whether a deployment can be modified after it has been created:
397+
398+
- **`"Immutable"`** (default): The deployment cannot be modified after creation. This is the recommended setting for production deployments as it ensures consistency and prevents harmful changes.
399+
400+
- **`"Mutable"`**: The deployment can be modified after creation. This is an advanced feature and should only be used with careful consideration because misuse could result in harmful updates.
401+
402+
### Key Reuse
403+
404+
The `reuseKeysFrom` field allows you to reuse keys from a previous deployment. This is useful when you want to maintain the same cryptographic keys across deployments. To use this, the referenced deployment has to be "Mutable".
405+
406+
**Format**: `[MultiOrigin, string, number]`
407+
408+
- **First element**: The origin chain (currently only `"Acurast"` is supported)
409+
- **Second element**: The address of the original deployer (AccountId32 format)
410+
- **Third element**: The deployment ID (u128 number)
411+
412+
**Example**:
413+
414+
```json
415+
{
416+
"reuseKeysFrom": [
417+
"Acurast",
418+
"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL",
419+
123456
420+
]
421+
}
422+
```
423+
224424
## Development
225425

226426
To contribute to the development of Acurast CLI, follow these steps:

acurast.json

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,38 @@
1919
"maxStorage": 0
2020
},
2121
"numberOfReplicas": 1,
22-
"requiredModules": ["DataEncryption", "LLM"],
22+
"requiredModules": [],
2323
"minProcessorReputation": 0,
2424
"maxCostPerExecution": 100000000000,
2525
"includeEnvironmentVariables": [],
26-
"processorWhitelist": []
26+
"processorWhitelist": [],
27+
"mutability": "Immutable"
28+
},
29+
"test-single-onetime-mutable": {
30+
"projectName": "test-single-onetime-with-key-reuse",
31+
"fileUrl": "examples/test.js",
32+
"network": "canary",
33+
"onlyAttestedDevices": true,
34+
"assignmentStrategy": {
35+
"type": "Single"
36+
},
37+
"execution": {
38+
"type": "onetime",
39+
"maxExecutionTimeInMs": 60000
40+
},
41+
"maxAllowedStartDelayInMs": 10000,
42+
"usageLimit": {
43+
"maxMemory": 0,
44+
"maxNetworkRequests": 0,
45+
"maxStorage": 0
46+
},
47+
"numberOfReplicas": 1,
48+
"requiredModules": [],
49+
"minProcessorReputation": 0,
50+
"maxCostPerExecution": 100000000000,
51+
"includeEnvironmentVariables": [],
52+
"processorWhitelist": [],
53+
"mutability": "Mutable"
2754
},
2855
"test-single-onetime-with-env": {
2956
"projectName": "test-single-onetime-with-env",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@acurast/cli",
3-
"version": "0.3.4",
3+
"version": "0.4.0",
44
"description": "A cli to interact with the Acurast Cloud.",
55
"main": "dist/index.js",
66
"bin": {

src/acurast/convertConfigToJob.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AssignmentStrategyVariant,
44
DeploymentRuntime,
55
JobRegistration,
6+
ScriptMutability,
67
} from '../types.js'
78
import { deviceVersions } from './app-versions.js'
89

@@ -100,6 +101,7 @@ export const convertConfigToJob = (
100101
const minProcessorVersions = convertMinProcessorVersions(
101102
config.minProcessorVersions
102103
)
104+
const mutability = config.mutability ?? ScriptMutability.Immutable
103105

104106
const now = Date.now()
105107

@@ -162,6 +164,8 @@ export const convertConfigToJob = (
162164
networkRequests: config.usageLimit.maxNetworkRequests,
163165
storage: config.usageLimit.maxStorage,
164166
requiredModules: config.requiredModules,
167+
mutability,
168+
reuseKeysFrom: config.reuseKeysFrom,
165169
extra: {
166170
requirements: {
167171
assignmentStrategy,

src/acurast/createJob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
RestartPolicy,
88
} from '../types.js'
99
import { DeploymentStatus } from './types.js'
10-
import { registerJob } from './registerJob.js'
10+
import { deployJob } from './deployJob.js'
1111
import { getWallet } from '../util/getWallet.js'
1212
import type { EnvVar, JobId } from './env/types.js'
1313
import { setEnvVars } from '../util/setEnvVars.js'
@@ -176,7 +176,7 @@ export const createJob = async (
176176
statusCallback(status, data)
177177
}
178178

179-
const result = await registerJob(api, wallet, job, statusCallbackWrapper)
179+
const result = await deployJob(api, wallet, job, statusCallbackWrapper)
180180

181181
statusCallback(DeploymentStatus.Submit, { txHash: result })
182182
}

src/acurast/registerJob.ts renamed to src/acurast/deployJob.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../types.js'
99
import { DeploymentStatus } from './types.js'
1010

11-
export const registerJob = (
11+
export const deployJob = (
1212
api: ApiPromise,
1313
injector: KeyringPair,
1414
job: JobRegistration,
@@ -106,9 +106,25 @@ export const registerJob = (
106106
// ),
107107
}),
108108
})
109+
110+
// Create the additional parameters for the deploy extrinsic
111+
const mutability = api.createType(
112+
'AcurastCommonScriptMutability',
113+
job.mutability
114+
)
115+
const reuseKeysFrom = job.reuseKeysFrom
116+
? api.createType('Option<(AcurastCommonMultiOrigin, u128)>', [
117+
api.createType('AcurastCommonMultiOrigin', {
118+
acurast: job.reuseKeysFrom[1],
119+
}),
120+
api.createType('u128', job.reuseKeysFrom[2]),
121+
])
122+
: api.createType('Option<(AcurastCommonMultiOrigin, u128)>', undefined)
123+
const minMetrics = api.createType('Option<Vec<(u8, u128, u128)>>', [])
124+
109125
try {
110-
const unsub = await api.tx['acurast']
111-
['register'](jobRegistration)
126+
const unsub = await api.tx['acurastMarketplace']
127+
['deploy'](jobRegistration, mutability, reuseKeysFrom, minMetrics)
112128
.signAndSend(
113129
injector,
114130
async ({ status, events, txHash, dispatchError }) => {
@@ -219,8 +235,8 @@ export const registerJob = (
219235
new DeploymentError(
220236
e instanceof Error
221237
? e.message
222-
: 'Unknown error during job registration',
223-
'RegistrationError',
238+
: 'Unknown error during job deployment',
239+
'DeploymentError',
224240
{ originalError: e }
225241
)
226242
)

0 commit comments

Comments
 (0)