Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

feat: Aleph Zero Hyperdrive support #143

Merged
merged 16 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ members = [
"pallets/acurast/common",
"pallets/marketplace/reputation",
"p256-crypto",
"ink/consumer",
"ink/core",
"ink/proxy",
"ink/state",
"ink/validator"
]
exclude = ["pallets/proxy"]

[workspace.package]
authors = [ "Papers AG" ]
repository = "https://github.com/Acurast/acurast-core"
version = "0.3.0"
version = "0.3.1"

# TODO: Temporary workaround (https://substrate.stackexchange.com/questions/9870)
[patch.crates-io]
Expand Down
11 changes: 11 additions & 0 deletions ink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[workspace]
members = [
"proxy",
"state",
"validator",
"consumer"
]
resolver ="1"

[profile.release]
overflow-checks = false # Disable integer overflow checks.
8 changes: 8 additions & 0 deletions ink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Contracts

```
State: 5Fw2pUR67Vic9ah7dCffMLx4qxQcZG8uYE32Ci31SUvXrefP
Validator: 5G6encHfCXmAhfAYcesSoBhGWraWzQ4wFXUgzFA7LxSSmKtu
Proxy: 5FN48UFaPYj2kYXGz9yLYka2FErzGCaEYGikxxCbxrAvEmvp
Consumer:
```
8 changes: 8 additions & 0 deletions ink/build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -eu

cargo +stable contract build --manifest-path validator/Cargo.toml
cargo +stable contract build --manifest-path state/Cargo.toml
cargo +stable contract build --manifest-path proxy/Cargo.toml
cargo +stable contract build --manifest-path consumer/Cargo.toml
23 changes: 23 additions & 0 deletions ink/consumer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "acurast-consumer-ink"
version = "0.1.0"
authors = ["Papers AG"]
edition = "2021"

[dependencies]
ink = { version = "4.2.0", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
33 changes: 33 additions & 0 deletions ink/consumer/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

use ink::env::call::Selector;

// Method selectors

pub const FULFILL_SELECTOR: Selector = Selector::new(ink::selector_bytes!("fulfill"));

// Method types

pub type FulfillReturn = Result<(), ink::prelude::string::String>;

#[ink::contract]
mod client {
use ink::prelude::vec::Vec;

#[ink(storage)]
pub struct Client {
// Template
}

impl Client {
#[ink(constructor)]
pub fn new() -> Self {
Self {}
}

#[ink(message)]
pub fn fulfill(&mut self, _job_id: u64, _payload: Vec<u8>) -> crate::FulfillReturn {
Ok(())
}
}
}
19 changes: 19 additions & 0 deletions ink/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "acurast-core-ink"
version = "0.1.0"
authors = ["Papers AG"]
edition = "2021"

[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"] }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"scale/std",
"scale-info/std",
]
3 changes: 3 additions & 0 deletions ink/core/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub mod types;
164 changes: 164 additions & 0 deletions ink/core/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
extern crate alloc;

use alloc::format;
use alloc::vec::Vec;
use scale::{Decode, Encode};
use scale_info::prelude::cmp::Ordering;

#[derive(Clone, Eq, PartialEq)]
pub enum Version {
V1 = 1,
}

#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
pub struct IncomingAction {
pub id: u64,
pub payload: VersionedIncomingActionPayload,
}

impl Ord for IncomingAction {
fn cmp(&self, other: &Self) -> Ordering {
if self.id < other.id {
Ordering::Less
} else if self.id > other.id {
Ordering::Greater
} else {
Ordering::Equal
}
}
}

impl PartialOrd for IncomingAction {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
pub enum VersionedIncomingActionPayload {
V1(IncomingActionPayloadV1),
}

#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
pub enum IncomingActionPayloadV1 {
AssignJobProcessor(AssignProcessorPayloadV1),
FinalizeJob(FinalizeJobPayloadV1),
Noop,
}

#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
pub struct AssignProcessorPayloadV1 {
pub job_id: u128,
pub processor: [u8; 32],
}

#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
pub struct FinalizeJobPayloadV1 {
pub job_id: u128,
pub unused_reward: u128,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
pub struct RawOutgoingAction {
pub id: u64,
pub origin: [u8; 32],
pub payload_version: u16,
pub payload: Vec<u8>,
}

#[derive(Clone, Eq, PartialEq)]
pub struct OutgoingAction {
pub id: u64,
pub origin: [u8; 32], // AccountId
pub payload: VersionedOutgoingActionPayload,
}

impl OutgoingAction {
pub fn decode(payload: &Vec<u8>) -> Result<OutgoingAction, scale::Error> {
match RawOutgoingAction::decode(&mut payload.as_slice()) {
Err(err) => Err(err),
Ok(action) => Ok(OutgoingAction {
id: action.id,
origin: action.origin,
payload: VersionedOutgoingActionPayload::decode(action)?,
}),
}
}
}

#[derive(Clone, Eq, PartialEq, Decode)]
pub enum VersionedOutgoingActionPayload {
V1(OutgoingActionPayloadV1),
}

impl VersionedOutgoingActionPayload {
fn decode(action: RawOutgoingAction) -> Result<VersionedOutgoingActionPayload, scale::Error> {
match action.payload_version {
v if v == Version::V1 as u16 => {
let action = OutgoingActionPayloadV1::decode(&mut action.payload.as_slice())?;

Ok(VersionedOutgoingActionPayload::V1(action))
}
v => {
let msg: &str = format!("Unknown VersionedOutgoingActionPayload: {:?}", v).leak();
Err(scale::Error::from(msg))
}
}
}
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
pub enum OutgoingActionPayloadV1 {
RegisterJob(RegisterJobPayloadV1),
DeregisterJob(u128),
FinalizeJob(Vec<u128>),
SetJobEnvironment(SetJobEnvironmentPayloadV1),
Noop,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct RegisterJobMatchV1 {
pub source: [u8; 32], // AccountId
pub start_delay: u64,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct RegisterJobPayloadV1 {
pub job_id: u128,
pub allowed_sources: Vec<[u8; 32]>, // Vec<AccountId>
pub allow_only_verified_sources: bool,
pub destination: [u8; 32], // AccountId
pub required_modules: Vec<u16>,
pub script: Vec<u8>,
pub duration: u64,
pub start_time: u64,
pub end_time: u64,
pub interval: u64,
pub max_start_delay: u64,
pub memory: u32,
pub network_requests: u32,
pub storage: u32,
// Extra,
pub slots: u8,
pub reward: u128,
pub min_reputation: Option<u128>,
pub instant_match: Vec<RegisterJobMatchV1>,
pub expected_fulfillment_fee: u128,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct SetProcessorJobEnvironmentV1 {
pub address: [u8; 32], // AccountId
pub variables: Vec<(Vec<u8>, Vec<u8>)>,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct SetJobEnvironmentPayloadV1 {
pub job_id: u128,
pub public_key: Vec<u8>,
pub processors: Vec<SetProcessorJobEnvironmentV1>,
}
40 changes: 40 additions & 0 deletions ink/proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "acurast-proxy-ink"
version = "0.1.0"
authors = ["Papers AG"]
edition = "2021"

[profile.release]
overflow-checks = false # Disable integer overflow checks.

[dependencies]
ink = { version = "4.2.0", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"] }

derive_more = { version = "0.99.17", default-features = false }

acurast-core-ink = { path = "../core", default-features = false }
acurast-state-ink = { path = "../state", default-features = false, features = ["ink-as-dependency"] }
acurast-validator-ink = { path = "../validator", default-features = false, features = ["ink-as-dependency"] }
acurast-consumer-ink = { path = "../consumer", default-features = false, features = ["ink-as-dependency"] }

[dev-dependencies]
hex-literal = "0.4.1"

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"acurast-core-ink/std",
"acurast-state-ink/std",
"acurast-validator-ink/std",
"acurast-consumer-ink/std"
]
ink-as-dependency = []
Loading
Loading