Skip to content

Remove scan dependency #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 16, 2025
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Oracle Core v2.0

The oracle core requires that the user has access to a full node wallet in order to create txs & perform UTXO-set scanning. Furthermore, each oracle core is designed to work with only a single oracle pool. If an operator runs several oracles in several oracle pools then a single full node can be used, but several instances of oracle cores must be run (and set with different API ports).
The oracle core requires that the user has access to a public node with activated extra option to create txs. Furthermore, each oracle core is designed to work with only a single oracle pool. If an operator runs several oracles in several oracle pools then a single full node can be used, but several instances of oracle cores must be run (and set with different API ports).

The current oracle core is built to run the protocol specified in the [EIP-0023 PR](https://github.com/ergoplatform/eips/pull/41).

Expand All @@ -19,7 +19,7 @@ docker run -d \
-v /path/on/host:/data \
-p 9010:9010 \
-p 9011:9011 \
-e ORACLE_NODE_API_KEY=CHANGE_ME_KEY \
-e ORACLE_WALLET_MNEMONIC=CHANGE_ME \
ergoplatform/oracle-core:latest
```

Expand Down Expand Up @@ -54,7 +54,7 @@ and set the required parameters:
- `oracle_address` - a node's address that will be used by this oracle-core instance(pay tx fees, keep tokens, etc.). Make sure it has coins;
- `node_url` node URL;

Set the environment variable `ORACLE_NODE_API_KEY` to the node's API key. You can put it in the `.secrets` file and then run `source .secrets` to load it into the environment. This way, the key does not get stored in the shell history.
Set the environment variable `ORACLE_WALLET_MNEMONIC` to the oracle's mnemonic. You can put it in the `.secrets` file and then run `source .secrets` to load it into the environment. This way, the key does not get stored in the shell history.

## Bootstrapping a new oracle pool

Expand Down Expand Up @@ -198,8 +198,8 @@ With optional(only if minted) parameters:
<REWARD_TOKEN_AMOUNT> - reward token amount in the pool box at the time of update transaction is committed (only if minted)

This will submit an update tx.
After the update tx is confirmed, remove `scanIds.json` and use `pool_config_updated.yaml` to run the oracle (i.e., rename it to `pool_config.yaml` and restart the oracle).
Distribute the `pool_config.yaml` file to all the oracles. Be sure they delete `scanIds.json` before restart.
After the update tx is confirmed and use `pool_config_updated.yaml` to run the oracle (i.e., rename it to `pool_config.yaml` and restart the oracle).
Distribute the `pool_config.yaml` file to all the oracles.

### Import update pool config with `import-pool-update` command

Expand All @@ -210,7 +210,7 @@ Run
oracle-core import-update-pool pool_config_updated.yaml
```

This will update the pool_config.yaml, removes `scanIds.json`. Restart the oracle afterwards.
This will update the pool_config.yaml. Restart the oracle afterwards.

## How to run as systemd daemon

Expand Down
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ tokio = { version = "1", features = ["full"] }
tower-http = { version = "0.3.0", features = ["cors"] }
axum = "0.6"
ergo-lib = { workspace = true }
ergo-node-interface = { git = "https://github.com/ergoplatform/ergo-node-interface-rust", rev = "143c2a3dc8fb772d1af37f1f1e1924067c6aad14" }
# ergo-node-interface = { version = "0.4" }
ergo-node-interface = { version = "0.5.0" }
derive_more = "0.99"
clap = { version = "4.2.4", features = ["derive"] }
exitcode = "1.1.2"
Expand Down
12 changes: 6 additions & 6 deletions core/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// This file holds all the actions which can be performed
/// by an oracle part of the oracle pool. These actions
/// are implemented on the `OraclePool` struct.
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;

use derive_more::From;
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;
use ergo_lib::wallet::signing::TransactionContext;
use ergo_node_interface::node_interface::NodeError;
use thiserror::Error;

Expand All @@ -23,12 +23,12 @@ pub enum PoolAction {

#[derive(Debug)]
pub struct RefreshAction {
pub tx: UnsignedTransaction,
pub transaction_context: TransactionContext<UnsignedTransaction>,
}

#[derive(Debug)]
pub struct PublishDataPointAction {
pub tx: UnsignedTransaction,
pub transaction_context: TransactionContext<UnsignedTransaction>,
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -63,7 +63,7 @@ fn execute_refresh_action(
action: RefreshAction,
node_api: &NodeApi,
) -> Result<(), ActionExecError> {
let tx_id = node_api.sign_and_submit_transaction(&action.tx)?;
let tx_id = node_api.sign_and_submit_transaction(action.transaction_context)?;
let network_prefix = &ORACLE_CONFIG.oracle_address.network();
log::info!(
"Refresh tx published. Check status: {}",
Expand All @@ -76,7 +76,7 @@ fn execute_publish_datapoint_action(
action: PublishDataPointAction,
node_api: &NodeApi,
) -> Result<(), ActionExecError> {
let tx_id = node_api.sign_and_submit_transaction(&action.tx)?;
let tx_id = node_api.sign_and_submit_transaction(action.transaction_context)?;
let network_prefix = &ORACLE_CONFIG.oracle_address.network();
log::info!(
"Datapoint tx published. Check status: {}",
Expand Down
9 changes: 9 additions & 0 deletions core/src/address_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ergo_lib::ergotree_ir::chain::address::NetworkAddress;
use ergo_lib::ergotree_ir::chain::address::NetworkPrefix;
use ergo_lib::ergotree_ir::serialization::SigmaParsingError;
use ergo_lib::ergotree_ir::serialization::SigmaSerializationError;
use ergo_lib::ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -31,3 +32,11 @@ pub fn pks_to_network_addresses(
.map(|pk| NetworkAddress::new(network_prefix, &Address::P2Pk(pk.into())))
.collect()
}

pub fn address_to_p2pk(addr: &Address) -> Result<ProveDlog, AddressUtilError> {
if let Address::P2Pk(public_key) = addr {
Ok(public_key.clone())
} else {
Err(AddressUtilError::ExpectedP2PK)
}
}
28 changes: 6 additions & 22 deletions core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::monitor::{
check_oracle_health, check_pool_health, HealthStatus, OracleHealth, PoolHealth,
};
use crate::node_interface::node_api::{NodeApi, NodeApiError};
use crate::oracle_config::{ORACLE_CONFIG, ORACLE_SECRETS};
use crate::oracle_config::ORACLE_CONFIG;
use crate::oracle_state::{DataSourceError, LocalDatapointState, OraclePool};
use crate::pool_config::POOL_CONFIG;
use axum::http::StatusCode;
Expand Down Expand Up @@ -128,11 +128,7 @@ async fn pool_status(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Va
}

fn pool_status_sync(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Value>, ApiError> {
let node_api = NodeApi::new(
ORACLE_SECRETS.node_api_key.clone(),
ORACLE_SECRETS.wallet_password.clone(),
&ORACLE_CONFIG.node_url,
);
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
let current_height = node_api.node.current_block_height()? as u32;
let pool_box = oracle_pool.get_pool_box_source().get_pool_box()?;
let epoch_length = POOL_CONFIG
Expand Down Expand Up @@ -160,11 +156,7 @@ fn pool_status_sync(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Val
/// Block height of the Ergo blockchain
async fn block_height() -> Result<impl IntoResponse, ApiError> {
let current_height = task::spawn_blocking(move || {
let node_api = NodeApi::new(
ORACLE_SECRETS.node_api_key.clone(),
ORACLE_SECRETS.wallet_password.clone(),
&ORACLE_CONFIG.node_url,
);
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
node_api.node.current_block_height()
})
.await
Expand Down Expand Up @@ -205,11 +197,7 @@ async fn oracle_health(oracle_pool: Arc<OraclePool>) -> impl IntoResponse {
}

fn oracle_health_sync(oracle_pool: Arc<OraclePool>) -> Result<OracleHealth, ApiError> {
let node_api = NodeApi::new(
ORACLE_SECRETS.node_api_key.clone(),
ORACLE_SECRETS.wallet_password.clone(),
&ORACLE_CONFIG.node_url,
);
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
let current_height = (node_api.node.current_block_height()? as u32).into();
let epoch_length = POOL_CONFIG
.refresh_box_wrapper_inputs
Expand Down Expand Up @@ -251,15 +239,11 @@ async fn pool_health(oracle_pool: Arc<OraclePool>) -> impl IntoResponse {
}

fn pool_health_sync(oracle_pool: Arc<OraclePool>) -> Result<PoolHealth, ApiError> {
let node_api = NodeApi::new(
ORACLE_SECRETS.node_api_key.clone(),
ORACLE_SECRETS.wallet_password.clone(),
&ORACLE_CONFIG.node_url,
);
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
let current_height = (node_api.node.current_block_height()? as u32).into();
let pool_box = &oracle_pool.get_pool_box_source().get_pool_box()?;
let pool_box_height = pool_box.get_box().creation_height.into();
let network_prefix = node_api.get_change_address()?.network();
let network_prefix = ORACLE_CONFIG.change_address.clone().unwrap().network();
let pool_health = check_pool_health(
current_height,
pool_box_height,
Expand Down
Loading
Loading