Skip to content

Commit 4a3525c

Browse files
authored
Merge pull request #330 from zargarzadehm/remove-scan-dependecy
Remove scan dependency
2 parents fd70a4a + 6d64cd4 commit 4a3525c

35 files changed

+1260
-1493
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Oracle Core v2.0
22

3-
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).
3+
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).
44

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

@@ -19,7 +19,7 @@ docker run -d \
1919
-v /path/on/host:/data \
2020
-p 9010:9010 \
2121
-p 9011:9011 \
22-
-e ORACLE_NODE_API_KEY=CHANGE_ME_KEY \
22+
-e ORACLE_WALLET_MNEMONIC=CHANGE_ME \
2323
ergoplatform/oracle-core:latest
2424
```
2525

@@ -54,7 +54,7 @@ and set the required parameters:
5454
- `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;
5555
- `node_url` node URL;
5656

57-
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.
57+
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.
5858

5959
## Bootstrapping a new oracle pool
6060

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

200200
This will submit an update tx.
201-
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).
202-
Distribute the `pool_config.yaml` file to all the oracles. Be sure they delete `scanIds.json` before restart.
201+
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).
202+
Distribute the `pool_config.yaml` file to all the oracles.
203203

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

@@ -210,7 +210,7 @@ Run
210210
oracle-core import-update-pool pool_config_updated.yaml
211211
```
212212

213-
This will update the pool_config.yaml, removes `scanIds.json`. Restart the oracle afterwards.
213+
This will update the pool_config.yaml. Restart the oracle afterwards.
214214

215215
## How to run as systemd daemon
216216

core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ tokio = { version = "1", features = ["full"] }
3232
tower-http = { version = "0.3.0", features = ["cors"] }
3333
axum = "0.6"
3434
ergo-lib = { workspace = true }
35-
ergo-node-interface = { git = "https://github.com/ergoplatform/ergo-node-interface-rust", rev = "143c2a3dc8fb772d1af37f1f1e1924067c6aad14" }
36-
# ergo-node-interface = { version = "0.4" }
35+
ergo-node-interface = { version = "0.5.0" }
3736
derive_more = "0.99"
3837
clap = { version = "4.2.4", features = ["derive"] }
3938
exitcode = "1.1.2"

core/src/actions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// This file holds all the actions which can be performed
22
/// by an oracle part of the oracle pool. These actions
33
/// are implemented on the `OraclePool` struct.
4-
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;
5-
64
use derive_more::From;
5+
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;
6+
use ergo_lib::wallet::signing::TransactionContext;
77
use ergo_node_interface::node_interface::NodeError;
88
use thiserror::Error;
99

@@ -23,12 +23,12 @@ pub enum PoolAction {
2323

2424
#[derive(Debug)]
2525
pub struct RefreshAction {
26-
pub tx: UnsignedTransaction,
26+
pub transaction_context: TransactionContext<UnsignedTransaction>,
2727
}
2828

2929
#[derive(Debug)]
3030
pub struct PublishDataPointAction {
31-
pub tx: UnsignedTransaction,
31+
pub transaction_context: TransactionContext<UnsignedTransaction>,
3232
}
3333

3434
#[derive(Error, Debug)]
@@ -63,7 +63,7 @@ fn execute_refresh_action(
6363
action: RefreshAction,
6464
node_api: &NodeApi,
6565
) -> Result<(), ActionExecError> {
66-
let tx_id = node_api.sign_and_submit_transaction(&action.tx)?;
66+
let tx_id = node_api.sign_and_submit_transaction(action.transaction_context)?;
6767
let network_prefix = &ORACLE_CONFIG.oracle_address.network();
6868
log::info!(
6969
"Refresh tx published. Check status: {}",
@@ -76,7 +76,7 @@ fn execute_publish_datapoint_action(
7676
action: PublishDataPointAction,
7777
node_api: &NodeApi,
7878
) -> Result<(), ActionExecError> {
79-
let tx_id = node_api.sign_and_submit_transaction(&action.tx)?;
79+
let tx_id = node_api.sign_and_submit_transaction(action.transaction_context)?;
8080
let network_prefix = &ORACLE_CONFIG.oracle_address.network();
8181
log::info!(
8282
"Datapoint tx published. Check status: {}",

core/src/address_util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use ergo_lib::ergotree_ir::chain::address::NetworkAddress;
55
use ergo_lib::ergotree_ir::chain::address::NetworkPrefix;
66
use ergo_lib::ergotree_ir::serialization::SigmaParsingError;
77
use ergo_lib::ergotree_ir::serialization::SigmaSerializationError;
8+
use ergo_lib::ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;
89
use thiserror::Error;
910

1011
#[derive(Error, Debug)]
@@ -31,3 +32,11 @@ pub fn pks_to_network_addresses(
3132
.map(|pk| NetworkAddress::new(network_prefix, &Address::P2Pk(pk.into())))
3233
.collect()
3334
}
35+
36+
pub fn address_to_p2pk(addr: &Address) -> Result<ProveDlog, AddressUtilError> {
37+
if let Address::P2Pk(public_key) = addr {
38+
Ok(public_key.clone())
39+
} else {
40+
Err(AddressUtilError::ExpectedP2PK)
41+
}
42+
}

core/src/api.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::monitor::{
77
check_oracle_health, check_pool_health, HealthStatus, OracleHealth, PoolHealth,
88
};
99
use crate::node_interface::node_api::{NodeApi, NodeApiError};
10-
use crate::oracle_config::{ORACLE_CONFIG, ORACLE_SECRETS};
10+
use crate::oracle_config::ORACLE_CONFIG;
1111
use crate::oracle_state::{DataSourceError, LocalDatapointState, OraclePool};
1212
use crate::pool_config::POOL_CONFIG;
1313
use axum::http::StatusCode;
@@ -128,11 +128,7 @@ async fn pool_status(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Va
128128
}
129129

130130
fn pool_status_sync(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Value>, ApiError> {
131-
let node_api = NodeApi::new(
132-
ORACLE_SECRETS.node_api_key.clone(),
133-
ORACLE_SECRETS.wallet_password.clone(),
134-
&ORACLE_CONFIG.node_url,
135-
);
131+
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
136132
let current_height = node_api.node.current_block_height()? as u32;
137133
let pool_box = oracle_pool.get_pool_box_source().get_pool_box()?;
138134
let epoch_length = POOL_CONFIG
@@ -160,11 +156,7 @@ fn pool_status_sync(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Val
160156
/// Block height of the Ergo blockchain
161157
async fn block_height() -> Result<impl IntoResponse, ApiError> {
162158
let current_height = task::spawn_blocking(move || {
163-
let node_api = NodeApi::new(
164-
ORACLE_SECRETS.node_api_key.clone(),
165-
ORACLE_SECRETS.wallet_password.clone(),
166-
&ORACLE_CONFIG.node_url,
167-
);
159+
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
168160
node_api.node.current_block_height()
169161
})
170162
.await
@@ -205,11 +197,7 @@ async fn oracle_health(oracle_pool: Arc<OraclePool>) -> impl IntoResponse {
205197
}
206198

207199
fn oracle_health_sync(oracle_pool: Arc<OraclePool>) -> Result<OracleHealth, ApiError> {
208-
let node_api = NodeApi::new(
209-
ORACLE_SECRETS.node_api_key.clone(),
210-
ORACLE_SECRETS.wallet_password.clone(),
211-
&ORACLE_CONFIG.node_url,
212-
);
200+
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
213201
let current_height = (node_api.node.current_block_height()? as u32).into();
214202
let epoch_length = POOL_CONFIG
215203
.refresh_box_wrapper_inputs
@@ -251,15 +239,11 @@ async fn pool_health(oracle_pool: Arc<OraclePool>) -> impl IntoResponse {
251239
}
252240

253241
fn pool_health_sync(oracle_pool: Arc<OraclePool>) -> Result<PoolHealth, ApiError> {
254-
let node_api = NodeApi::new(
255-
ORACLE_SECRETS.node_api_key.clone(),
256-
ORACLE_SECRETS.wallet_password.clone(),
257-
&ORACLE_CONFIG.node_url,
258-
);
242+
let node_api = NodeApi::new(&ORACLE_CONFIG.node_url);
259243
let current_height = (node_api.node.current_block_height()? as u32).into();
260244
let pool_box = &oracle_pool.get_pool_box_source().get_pool_box()?;
261245
let pool_box_height = pool_box.get_box().creation_height.into();
262-
let network_prefix = node_api.get_change_address()?.network();
246+
let network_prefix = ORACLE_CONFIG.change_address.clone().unwrap().network();
263247
let pool_health = check_pool_health(
264248
current_height,
265249
pool_box_height,

0 commit comments

Comments
 (0)