From 0fa4283a70e3de5eb9f48c9f29449b722af466ed Mon Sep 17 00:00:00 2001 From: Luke Tchang Date: Wed, 7 Apr 2021 13:25:45 -0700 Subject: [PATCH] refactor: restructures agent config locations (#254) * feature: restructures configs and from_settings * fix: settings takes agent name from macro * fix: replaces toml with json * fix: removes redundant agent config info * fix: derives prefix from agent name * fix: readds kathy config and deletes optics base config * fix: fixes kebab case rename for base settings and removes extra db_path fields --- config/default/base.json | 49 +++++++++++++++++++++++++++ config/default/kathy-partial.json | 9 +++++ config/default/processor-partial.json | 3 ++ config/default/relayer-partial.json | 3 ++ config/default/updater-partial.json | 8 +++++ config/default/watcher-partial.json | 7 ++++ rust/Cargo.lock | 48 +++++++++++++------------- rust/kathy/config/default.toml | 15 -------- rust/kathy/src/settings.rs | 13 ++++--- rust/optics-base/config/default.toml | 33 ------------------ rust/optics-base/src/macros.rs | 12 ++++--- rust/optics-base/src/settings/mod.rs | 1 + rust/processor/config/default.toml | 36 -------------------- rust/processor/src/settings.rs | 11 +++--- rust/relayer/config/default.toml | 35 ------------------- rust/relayer/src/settings.rs | 10 +++--- rust/updater/Cargo.toml | 2 +- rust/updater/config/default.toml | 18 ---------- rust/updater/src/settings.rs | 15 ++++---- rust/watcher/config/default.toml | 36 -------------------- rust/watcher/src/settings.rs | 13 +++---- 21 files changed, 137 insertions(+), 240 deletions(-) create mode 100644 config/default/base.json create mode 100644 config/default/kathy-partial.json create mode 100644 config/default/processor-partial.json create mode 100644 config/default/relayer-partial.json create mode 100644 config/default/updater-partial.json create mode 100644 config/default/watcher-partial.json delete mode 100644 rust/kathy/config/default.toml delete mode 100644 rust/optics-base/config/default.toml delete mode 100644 rust/processor/config/default.toml delete mode 100644 rust/relayer/config/default.toml delete mode 100644 rust/updater/config/default.toml delete mode 100644 rust/watcher/config/default.toml diff --git a/config/default/base.json b/config/default/base.json new file mode 100644 index 000000000..6af3e77df --- /dev/null +++ b/config/default/base.json @@ -0,0 +1,49 @@ +{ + "replicas": [ + { + "address": "0x0000000000000000000000000000000000000000", + "domain": 60, + "name": "ethereum", + "rpc-style": "ethereum", + "config": { + "connection": { + "type": "ws", + "url": "ws://localhost:8545" + }, + "signer": { + "key": "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc", + "type": "hex-key" + } + } + }, + { + "address": "0x0000000000000000000000000000000000000000", + "domain": 61, + "name": "eth-classic", + "rpc-style": "ethereum", + "config": { + "connection": { + "type": "ws", + "url": "ws://localhost:8545" + } + } + } + ], + "home": { + "address": "0x0000000000000000000000000000000000000000", + "domain": 52752, + "name": "celo", + "rpc-style": "ethereum", + "config": { + "connection": { + "type": "http", + "url": "http://localhost:8545" + } + } + }, + "tracing": { + "level": "debug", + "style": "pretty" + }, + "db-path": "db_path" +} diff --git a/config/default/kathy-partial.json b/config/default/kathy-partial.json new file mode 100644 index 000000000..420490606 --- /dev/null +++ b/config/default/kathy-partial.json @@ -0,0 +1,9 @@ +{ + "message-interval": 100, + "chat-gen-config": { + "destination": 1, + "message": "static message", + "recipient": "recipient", + "type": "static" + } +} diff --git a/config/default/processor-partial.json b/config/default/processor-partial.json new file mode 100644 index 000000000..8b8d58914 --- /dev/null +++ b/config/default/processor-partial.json @@ -0,0 +1,3 @@ +{ + "polling-interval": 100 +} diff --git a/config/default/relayer-partial.json b/config/default/relayer-partial.json new file mode 100644 index 000000000..8b8d58914 --- /dev/null +++ b/config/default/relayer-partial.json @@ -0,0 +1,3 @@ +{ + "polling-interval": 100 +} diff --git a/config/default/updater-partial.json b/config/default/updater-partial.json new file mode 100644 index 000000000..827550833 --- /dev/null +++ b/config/default/updater-partial.json @@ -0,0 +1,8 @@ +{ + "polling-interval": 100, + "update-pause": 100, + "updater": { + "key": "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc", + "type": "hex-key" + } +} diff --git a/config/default/watcher-partial.json b/config/default/watcher-partial.json new file mode 100644 index 000000000..3e5dd1076 --- /dev/null +++ b/config/default/watcher-partial.json @@ -0,0 +1,7 @@ +{ + "polling-interval": 100, + "watcher": { + "key": "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc", + "type": "hex-key" + } +} diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 098bf374e..bb6e716b7 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1560,30 +1560,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "optics-updater" -version = "0.1.0" -dependencies = [ - "async-trait", - "color-eyre", - "config 0.11.0", - "ethers", - "futures-util", - "log", - "mockall", - "optics-base", - "optics-core", - "optics-test", - "rocksdb", - "serde 1.0.125", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-futures", - "tracing-subscriber", -] - [[package]] name = "owo-colors" version = "1.3.0" @@ -2709,6 +2685,30 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "updater" +version = "0.1.0" +dependencies = [ + "async-trait", + "color-eyre", + "config 0.11.0", + "ethers", + "futures-util", + "log", + "mockall", + "optics-base", + "optics-core", + "optics-test", + "rocksdb", + "serde 1.0.125", + "serde_json", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "tracing-subscriber", +] + [[package]] name = "url" version = "2.2.1" diff --git a/rust/kathy/config/default.toml b/rust/kathy/config/default.toml deleted file mode 100644 index 2d7b3c1c3..000000000 --- a/rust/kathy/config/default.toml +++ /dev/null @@ -1,15 +0,0 @@ -message-interval = 100 -chat-gen-config = { type = "static", destination = 1, recipient = "recipient", message = "static message" } - -[home] -name = "celo" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "Ethereum" - [home.config] - signer = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc" - connection = { type = "http", url = "http://localhost:8545" } - -[[replicas]] -# empty vector. -# no replicas needed for kathy \ No newline at end of file diff --git a/rust/kathy/src/settings.rs b/rust/kathy/src/settings.rs index 87eec39c8..a8e9ffb9c 100644 --- a/rust/kathy/src/settings.rs +++ b/rust/kathy/src/settings.rs @@ -52,10 +52,9 @@ impl From for ChatGenerator { } } -decl_settings!( - Settings { - "OPT_KATHY", - message_interval: u64, - #[serde(default)] chat_gen: ChatGenConfig, - } -); +decl_settings!(Settings { + agent: "kathy", + message_interval: u64, + #[serde(default)] + chat_gen: ChatGenConfig, +}); diff --git a/rust/optics-base/config/default.toml b/rust/optics-base/config/default.toml deleted file mode 100644 index 0acd76c56..000000000 --- a/rust/optics-base/config/default.toml +++ /dev/null @@ -1,33 +0,0 @@ -[tracing] -level = "debug" -style = "pretty" - -# ChainSetup -[home] -name = "celo" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" # ChainConf (flattened into ChainSetup) - [home.config] - # Missing signer. Will use EthereumSigner::default() - connection = { type = "http", url = "http://localhost:8545" } - -# Entry in Vec -[[replicas]] -name = "ethereum" -domain = 60 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - signer = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - connection = { type = "ws", url = "ws://localhost:8545"} - - -# Entry in Vec -[[replicas]] -name = "eth-classic" -domain = 61 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - connection = { type = "ws", url = "ws://localhost:8545"} diff --git a/rust/optics-base/src/macros.rs b/rust/optics-base/src/macros.rs index 7dd8f75c3..86650a80f 100644 --- a/rust/optics-base/src/macros.rs +++ b/rust/optics-base/src/macros.rs @@ -73,7 +73,7 @@ macro_rules! decl_settings { ( $(#[$outer:meta])* Settings { - $prefix:literal, + agent: $name:literal, $($(#[$tags:meta])* $prop:ident: $type:ty,)* } ) => { @@ -103,12 +103,14 @@ macro_rules! decl_settings { pub fn new() -> Result { let mut s = config::Config::new(); - s.merge(config::File::with_name("config/default"))?; + let env = std::env::var("RUN_ENV").unwrap_or_else(|_| "default".into()); - let env = std::env::var("RUN_MODE").unwrap_or_else(|_| "development".into()); - s.merge(config::File::with_name(&format!("config/{}", env)).required(false))?; + s.merge(config::File::with_name(&format!("../config/{}/base", env)))?; + s.merge(config::File::with_name(&format!("../config/{}/{}-partial", env, $name)).required(false))?; - s.merge(config::Environment::with_prefix($prefix))?; + // Derive Environment prefix from agent name + let prefix = format!("OPT_{}", $name.to_ascii_uppercase()); + s.merge(config::Environment::with_prefix(&prefix))?; s.try_into() } diff --git a/rust/optics-base/src/settings/mod.rs b/rust/optics-base/src/settings/mod.rs index 6705e30f7..2734bf408 100644 --- a/rust/optics-base/src/settings/mod.rs +++ b/rust/optics-base/src/settings/mod.rs @@ -85,6 +85,7 @@ impl ChainSetup { /// } /// ``` #[derive(Debug, Deserialize)] +#[serde(rename_all = "kebab-case")] pub struct Settings { /// The path to use for the DB file pub db_path: String, diff --git a/rust/processor/config/default.toml b/rust/processor/config/default.toml deleted file mode 100644 index 68df34ad8..000000000 --- a/rust/processor/config/default.toml +++ /dev/null @@ -1,36 +0,0 @@ -polling_interval = 100 -db_path = "db_path" - -[tracing] -level = "debug" -style = "pretty" - -# ChainSetup -[home] -name = "celo" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" # ChainConf (flattened into ChainSetup) - [home.config] - # Missing signer. Will use EthereumSigner::default() - connection = { type = "http", url = "http://localhost:8545" } - -# Entry in Vec -[[replicas]] -name = "ethereum" -domain = 60 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - signer = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - connection = { type = "ws", url = "ws://localhost:8545"} - - -# Entry in Vec -[[replicas]] -name = "eth-classic" -domain = 61 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - connection = { type = "ws", url = "ws://localhost:8545"} diff --git a/rust/processor/src/settings.rs b/rust/processor/src/settings.rs index 3b981a5b9..6094aae7e 100644 --- a/rust/processor/src/settings.rs +++ b/rust/processor/src/settings.rs @@ -1,10 +1,7 @@ //! Configuration use optics_base::decl_settings; -decl_settings!( - Settings { - "OPT_PROCESSOR", - db_path: String, - polling_interval: u64, - } -); +decl_settings!(Settings { + agent: "processor", + polling_interval: u64, +}); diff --git a/rust/relayer/config/default.toml b/rust/relayer/config/default.toml deleted file mode 100644 index 891066461..000000000 --- a/rust/relayer/config/default.toml +++ /dev/null @@ -1,35 +0,0 @@ -polling_interval = 100 - -[tracing] -level = "debug" -style = "pretty" - -# ChainSetup -[home] -name = "celo" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" # ChainConf (flattened into ChainSetup) - [home.config] - # Missing signer. Will use EthereumSigner::default() - connection = { type = "http", url = "http://localhost:8545" } - -# Entry in Vec -[[replicas]] -name = "ethereum" -domain = 60 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - signer = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - connection = { type = "ws", url = "ws://localhost:8545"} - - -# Entry in Vec -[[replicas]] -name = "eth-classic" -domain = 61 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - connection = { type = "ws", url = "ws://localhost:8545"} diff --git a/rust/relayer/src/settings.rs b/rust/relayer/src/settings.rs index 4fb338f60..f21868997 100644 --- a/rust/relayer/src/settings.rs +++ b/rust/relayer/src/settings.rs @@ -2,9 +2,7 @@ use optics_base::decl_settings; -decl_settings!( - Settings { - "OPT_UPDATER", - polling_interval: u64, - } -); +decl_settings!(Settings { + agent: "relayer", + polling_interval: u64, +}); diff --git a/rust/updater/Cargo.toml b/rust/updater/Cargo.toml index cf447b682..bdf3c8c87 100644 --- a/rust/updater/Cargo.toml +++ b/rust/updater/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "optics-updater" +name = "updater" version = "0.1.0" authors = ["James Prestwich "] edition = "2018" diff --git a/rust/updater/config/default.toml b/rust/updater/config/default.toml deleted file mode 100644 index ba28676fd..000000000 --- a/rust/updater/config/default.toml +++ /dev/null @@ -1,18 +0,0 @@ -updater = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - -db_path = "db_path" -polling_interval = 100 -update_pause = 100 - -[home] -name = "ethereum" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [home.config] - signer = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - connection = { type = "http", url = "http://localhost:8545" } - -[[replicas]] -# empty table. -# no replicas needed for updater \ No newline at end of file diff --git a/rust/updater/src/settings.rs b/rust/updater/src/settings.rs index 810af75ed..29e88eb5b 100644 --- a/rust/updater/src/settings.rs +++ b/rust/updater/src/settings.rs @@ -1,12 +1,9 @@ //! Configuration use optics_base::{decl_settings, settings::ethereum::EthereumSigner}; -decl_settings!( - Settings { - "OPT_UPDATER", - updater: EthereumSigner, - db_path: String, - polling_interval: u64, - update_pause: u64, - } -); +decl_settings!(Settings { + agent: "updater", + updater: EthereumSigner, + polling_interval: u64, + update_pause: u64, +}); diff --git a/rust/watcher/config/default.toml b/rust/watcher/config/default.toml deleted file mode 100644 index d5c531453..000000000 --- a/rust/watcher/config/default.toml +++ /dev/null @@ -1,36 +0,0 @@ -watcher = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} -polling_interval = 100 - -[tracing] -level = "debug" -style = "pretty" - -# ChainSetup -[home] -name = "celo" -domain = 52752 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" # ChainConf (flattened into ChainSetup) - [home.config] - # Missing signer. Will use EthereumSigner::default() - connection = { type = "http", url = "http://localhost:8545" } - -# Entry in Vec -[[replicas]] -name = "ethereum" -domain = 60 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - signer = {type = "hex-key", key = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc"} - connection = { type = "ws", url = "ws://localhost:8545"} - - -# Entry in Vec -[[replicas]] -name = "eth-classic" -domain = 61 -address = "0x0000000000000000000000000000000000000000" -rpc-style = "ethereum" - [replicas.config] - connection = { type = "ws", url = "ws://localhost:8545"} diff --git a/rust/watcher/src/settings.rs b/rust/watcher/src/settings.rs index 92a3ddda8..aacf284cc 100644 --- a/rust/watcher/src/settings.rs +++ b/rust/watcher/src/settings.rs @@ -2,11 +2,8 @@ use optics_base::{decl_settings, settings::ethereum::EthereumSigner}; -decl_settings!( - Settings { - "OPT_WATCHER", - watcher: EthereumSigner, - db_path: String, - polling_interval: u64, - } -); +decl_settings!(Settings { + agent: "watcher", + watcher: EthereumSigner, + polling_interval: u64, +});