Skip to content

Commit 4148010

Browse files
authored
Merge pull request oasisprotocol#2172 from oasisprotocol/kostko/feature/rofl-market
runtime-sdk: Add ROFL compute market
2 parents 7305be1 + 8fe2947 commit 4148010

File tree

20 files changed

+3451
-18
lines changed

20 files changed

+3451
-18
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
# Runtime SDK Modules.
88
"runtime-sdk/modules/contracts",
99
"runtime-sdk/modules/evm",
10+
"runtime-sdk/modules/rofl-market",
1011

1112
# Smart Contract SDK.
1213
"contract-sdk",

runtime-sdk/modules/evm/src/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ fn test_c10l_evm_runtime() {
811811

812812
#[test]
813813
fn test_c10l_queries() {
814+
let _guard = crypto::signature::context::test_using_chain_context();
815+
crypto::signature::context::set_chain_context(Default::default(), "test");
816+
814817
let mut mock = mock::Mock::default();
815818
let ctx = mock.create_ctx_for_runtime::<EVMRuntime<ConfidentialEVMConfig>>(true);
816819
let mut signer = EvmSigner::new(0, keys::dave::sigspec());
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "oasis-runtime-sdk-rofl-market"
3+
description = "ROFL market module for the Oasis Runtime SDK."
4+
version = "0.1.0"
5+
authors = ["Oasis Protocol Foundation <info@oasisprotocol.org>"]
6+
edition = "2021"
7+
license = "Apache-2.0"
8+
9+
[dependencies]
10+
cbor = { version = "0.5.1", package = "oasis-cbor" }
11+
oasis-runtime-sdk = { path = "../.." }
12+
oasis-runtime-sdk-evm = { path = "../evm" }
13+
14+
# Third party.
15+
anyhow = "1.0"
16+
ethabi = { version = "18.0.0", default-features = false, features = ["std"] }
17+
once_cell = "1.8.0"
18+
rustc-hex = "2.0.1"
19+
thiserror = "1.0"
20+
zeroize = "1.7"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use oasis_runtime_sdk::{modules, types::token};
2+
3+
/// Module configuration.
4+
pub trait Config: 'static {
5+
/// Module implementing the ROFL API.
6+
type Rofl: modules::rofl::API;
7+
8+
/// Gas cost of roflmarket.ProviderCreate call.
9+
const GAS_COST_CALL_PROVIDER_CREATE: u64 = 100_000;
10+
/// Gas cost of roflmarket.ProviderUpdate call.
11+
const GAS_COST_CALL_PROVIDER_UPDATE: u64 = 100_000;
12+
/// Gas cost of roflmarket.ProviderUpdateOffers call.
13+
const GAS_COST_CALL_PROVIDER_UPDATE_OFFERS_BASE: u64 = 100_000;
14+
/// Gas cost of each added offer in roflmarket.ProviderUpdateOffers call.
15+
const GAS_COST_CALL_PROVIDER_UPDATE_OFFERS_ADD: u64 = 10_000;
16+
/// Gas cost of each removed offer in roflmarket.ProviderUpdateOffers call.
17+
const GAS_COST_CALL_PROVIDER_UPDATE_OFFERS_RM: u64 = 1_000;
18+
/// Gas cost of roflmarket.ProviderRemove call.
19+
const GAS_COST_CALL_PROVIDER_REMOVE: u64 = 100_000;
20+
/// Gas cost of roflmarket.InstanceCreate call.
21+
const GAS_COST_CALL_INSTANCE_CREATE: u64 = 100_000;
22+
/// Gas cost of roflmarket.InstanceAccept call.
23+
const GAS_COST_CALL_INSTANCE_ACCEPT_BASE: u64 = 10_000;
24+
/// Gas cost of each accepted instance in roflmarket.InstanceAccept call.
25+
const GAS_COST_CALL_INSTANCE_ACCEPT_INSTANCE: u64 = 10_000;
26+
/// Gas cost of roflmarket.InstanceTopUp call.
27+
const GAS_COST_CALL_INSTANCE_TOPUP: u64 = 10_000;
28+
/// Gas cost of roflmarket.InstanceUpdateMetadata call.
29+
const GAS_COST_CALL_INSTANCE_UPDATE_METADATA: u64 = 100_000;
30+
/// Gas cost of roflmarket.InstanceCancel call.
31+
const GAS_COST_CALL_INSTANCE_CANCEL: u64 = 10_000;
32+
/// Gas cost of roflmarket.InstanceRemove call.
33+
const GAS_COST_CALL_INSTANCE_REMOVE: u64 = 10_000;
34+
/// Gas cost of roflmarket.InstanceExecuteCmds call.
35+
const GAS_COST_CALL_INSTANCE_EXECUTE_CMDS_BASE: u64 = 10_000;
36+
/// Gas cost of each command in roflmarket.InstanceExecuteCmds call.
37+
const GAS_COST_CALL_INSTANCE_EXECUTE_CMDS_CMD: u64 = 10_000;
38+
/// Gas cost of roflmarket.InstanceCompleteCmds call.
39+
const GAS_COST_CALL_INSTANCE_COMPLETE_CMDS_BASE: u64 = 10_000;
40+
/// Gas cost of each command in roflmarket.InstanceCompleteCmds call.
41+
const GAS_COST_CALL_INSTANCE_COMPLETE_CMDS_CMD: u64 = 10_000;
42+
/// Gas cost of roflmarket.InstanceClaimPayment call.
43+
const GAS_COST_CALL_INSTANCE_CLAIM_PAYMENT_BASE: u64 = 10_000;
44+
/// Gas cost of each instance in roflmarket.InstanceClaimPayment call.
45+
const GAS_COST_CALL_INSTANCE_CLAIM_PAYMENT_INST: u64 = 10_000;
46+
47+
/// Maximum time for a provider to accept an instance. If not accepted within this window, the
48+
/// instance may be cancelled and will be refunded.
49+
const MAX_INSTANCE_ACCEPT_TIME_SECONDS: u64 = 300;
50+
/// Maximum number of offers a provider can have.
51+
const MAX_PROVIDER_OFFERS: u64 = 64;
52+
/// Maximum number of queued instance commands.
53+
const MAX_QUEUED_INSTANCE_COMMANDS: u64 = 8;
54+
/// Maximum size of an instance command.
55+
const MAX_INSTANCE_COMMAND_SIZE: usize = 16 * 1024;
56+
57+
/// Maximum number of metadata key-value pairs.
58+
const MAX_METADATA_PAIRS: usize = 64;
59+
/// Maximum metadata key size.
60+
const MAX_METADATA_KEY_SIZE: usize = 1024;
61+
/// Maximum metadata value size.
62+
const MAX_METADATA_VALUE_SIZE: usize = 16 * 1024;
63+
64+
/// Amount of stake required for maintaining a provider.
65+
///
66+
/// The stake is held in escrow and is returned to the provider when the entry is removed.
67+
const STAKE_PROVIDER_CREATE: token::BaseUnits =
68+
token::BaseUnits::new(0, token::Denomination::NATIVE);
69+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use oasis_runtime_sdk::{dispatcher, modules};
2+
3+
use super::MODULE_NAME;
4+
5+
/// Errors emitted by the module.
6+
#[derive(thiserror::Error, Debug, oasis_runtime_sdk::Error)]
7+
pub enum Error {
8+
#[error("invalid argument")]
9+
#[sdk_error(code = 1)]
10+
InvalidArgument,
11+
12+
#[error("provider already exists")]
13+
#[sdk_error(code = 2)]
14+
ProviderAlreadyExists,
15+
16+
#[error("provider not found")]
17+
#[sdk_error(code = 3)]
18+
ProviderNotFound,
19+
20+
#[error("forbidden")]
21+
#[sdk_error(code = 4)]
22+
Forbidden,
23+
24+
#[error("provider has instances")]
25+
#[sdk_error(code = 5)]
26+
ProviderHasInstances,
27+
28+
#[error("no more capacity")]
29+
#[sdk_error(code = 6)]
30+
OutOfCapacity,
31+
32+
#[error("offer not found")]
33+
#[sdk_error(code = 7)]
34+
OfferNotFound,
35+
36+
#[error("instance not found")]
37+
#[sdk_error(code = 8)]
38+
InstanceNotFound,
39+
40+
#[error("too many queued commands")]
41+
#[sdk_error(code = 9)]
42+
TooManyQueuedCommands,
43+
44+
#[error("payment failed: {0}")]
45+
#[sdk_error(code = 10)]
46+
PaymentFailed(String),
47+
48+
#[error("bad resource descriptor: {0}")]
49+
#[sdk_error(code = 11)]
50+
BadResourceDescriptor(String),
51+
52+
#[error("core: {0}")]
53+
#[sdk_error(transparent)]
54+
Core(#[from] modules::core::Error),
55+
56+
#[error("accounts: {0}")]
57+
#[sdk_error(transparent)]
58+
Accounts(#[from] modules::accounts::Error),
59+
60+
#[error("evm: {0}")]
61+
#[sdk_error(transparent)]
62+
Evm(#[from] oasis_runtime_sdk_evm::Error),
63+
64+
#[error("{0}")]
65+
#[sdk_error(transparent, abort)]
66+
Abort(#[source] dispatcher::Error),
67+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use oasis_runtime_sdk::types::address::Address;
2+
3+
use super::{types::InstanceId, MODULE_NAME};
4+
5+
/// Events emitted by the ROFL market module.
6+
#[derive(Debug, cbor::Encode, oasis_runtime_sdk::Event)]
7+
#[cbor(untagged)]
8+
pub enum Event {
9+
#[sdk_event(code = 1)]
10+
ProviderCreated { address: Address },
11+
12+
#[sdk_event(code = 2)]
13+
ProviderUpdated { address: Address },
14+
15+
#[sdk_event(code = 3)]
16+
ProviderRemoved { address: Address },
17+
18+
#[sdk_event(code = 4)]
19+
InstanceCreated { provider: Address, id: InstanceId },
20+
21+
#[sdk_event(code = 5)]
22+
InstanceUpdated { provider: Address, id: InstanceId },
23+
24+
#[sdk_event(code = 6)]
25+
InstanceAccepted { provider: Address, id: InstanceId },
26+
27+
#[sdk_event(code = 7)]
28+
InstanceCancelled { provider: Address, id: InstanceId },
29+
30+
#[sdk_event(code = 8)]
31+
InstanceRemoved { provider: Address, id: InstanceId },
32+
33+
#[sdk_event(code = 9)]
34+
InstanceCommandQueued { provider: Address, id: InstanceId },
35+
}

0 commit comments

Comments
 (0)