Skip to content

Commit

Permalink
Reference Oracle Implementation (MystenLabs#12854)
Browse files Browse the repository at this point in the history
## Description 

This PR implements the off chain part of an oracle Proof of Concept. 

## Test Plan 

Tested in different networks.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
This PR implements the off chain part of an oracle Proof of Concept.

---------

Co-authored-by: jk jensen <[email protected]>
  • Loading branch information
longbowlu and after-ephemera authored Jul 6, 2023
1 parent 331fa2d commit 68b28fb
Show file tree
Hide file tree
Showing 13 changed files with 1,078 additions and 19 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ members = [
"crates/sui-node",
"crates/sui-open-rpc",
"crates/sui-open-rpc-macros",
"crates/sui-oracle",
"crates/sui-proc-macros",
"crates/sui-protocol-config",
"crates/sui-protocol-config-macros",
Expand Down
9 changes: 3 additions & 6 deletions crates/sui-json-rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use jsonrpsee::core::Error as RpcError;
use jsonrpsee::types::error::CallError;
use jsonrpsee::types::ErrorObject;
use sui_types::error::{SuiError, SuiObjectResponseError, UserInputError};
use sui_types::quorum_driver_types::QuorumDriverError;
use sui_types::quorum_driver_types::{QuorumDriverError, NON_RECOVERABLE_ERROR_MSG};
use thiserror::Error;
use tokio::task::JoinError;

Expand Down Expand Up @@ -78,11 +78,8 @@ impl Error {
},
Error::QuorumDriverError(err) => match err {
QuorumDriverError::NonRecoverableTransactionError { errors } => {
let error_object = ErrorObject::owned(
-32000,
"Transaction has non recoverable errors from at least 1/3 of validators",
Some(errors),
);
let error_object =
ErrorObject::owned(-32000, NON_RECOVERABLE_ERROR_MSG, Some(errors));
RpcError::Call(CallError::Custom(error_object))
}
_ => RpcError::Call(CallError::Failed(err.into())),
Expand Down
36 changes: 36 additions & 0 deletions crates/sui-oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "sui-oracle"
version.workspace = true
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
axum.workspace = true
anyhow = { version = "1.0.64", features = ["backtrace"] }
clap = { version = "3.2.17", features = ["derive"] }
prometheus = "0.13.3"
tokio = { workspace = true, features = ["full"] }
tracing = "0.1.36"
once_cell.workspace = true
futures = "0.3.23"
reqwest = { version = "0.11.13", default_features= false, features = ["blocking", "json", "rustls-tls"] }
serde = { version = "1.0.144", features = ["derive", "rc"] }
serde_json = { version = "1.0.1"}
jsonpath_lib = "0.3.0"
chrono.workspace = true
serde_with = "2.1.0"
tap.workspace = true
bcs.workspace = true

sui-config = { path = "../sui-config" }
sui-json = { path = "../sui-json" }
sui-json-rpc = { path = "../sui-json-rpc" }
sui-json-rpc-types = { path = "../sui-json-rpc-types" }
sui-sdk = { path = "../sui-sdk" }
sui-types = { path = "../sui-types" }
mysten-metrics = { path = "../mysten-metrics" }
move-core-types.workspace = true
telemetry-subscribers.workspace = true
workspace-hack = { version = "0.1", path = "../workspace-hack" }
7 changes: 7 additions & 0 deletions crates/sui-oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# sui-oracle

This oracle is intended to serve as general reference and informational purposes only. We make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability, or availability of the information provided by the oracle.

Any reliance on such information by a user is strictly at the user’s own risk. We do not assume any responsibility for errors, omissions, or inaccuracies in the information and shall not be liable for any loss or damage arising from or related to its use.

The information provided through this oracle does not constitute professional, investment or legal advice.
58 changes: 58 additions & 0 deletions crates/sui-oracle/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::SocketAddr;
use std::time::Duration;
use sui_config::Config;
use sui_types::base_types::ObjectID;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct DataSourceConfig {
pub url: String,
pub json_path: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct UploadFeedConfig {
pub submission_interval: Duration,
pub data_source_config: DataSourceConfig,
pub upload_parameters: UploadParameters,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct UploadParameters {
pub write_package_id: ObjectID,
pub write_module_name: String,
pub write_function_name: String,
pub write_data_provider_object_id: ObjectID,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct DownloadFeedConfigs {
pub read_interval: Option<Duration>,
pub read_feeds: HashMap<String, ObjectID>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct OracleNodeConfig {
pub gas_object_id: ObjectID,
pub upload_feeds: HashMap<String, HashMap<String, UploadFeedConfig>>,
pub download_feeds: DownloadFeedConfigs,

#[serde(default = "default_metrics_address")]
pub metrics_address: SocketAddr,
}

fn default_metrics_address() -> SocketAddr {
use std::net::{IpAddr, Ipv4Addr};
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9400)
}

impl Config for OracleNodeConfig {}
Loading

0 comments on commit 68b28fb

Please sign in to comment.