From 31ed4c18f9f16edb013dfae6619132e20f77bb6d Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sun, 23 Jan 2022 05:00:06 +0300 Subject: [PATCH] Accountsdb: support config in Json5 (#22605) * accountsdb: support config in json5 * update docs * remove not required dependencies Co-authored-by: Lijun Wang <83639177+lijunwangs@users.noreply.github.com> --- Cargo.lock | 121 ++++++++++++++++-- accountsdb-plugin-manager/Cargo.toml | 3 +- .../src/accountsdb_plugin_service.rs | 5 +- .../developing/plugins/accountsdb_plugin.md | 2 +- 4 files changed, 115 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba1affa1e6..1ed1882656 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ dependencies = [ "cfg-if 1.0.0", "cipher", "cpufeatures", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -371,13 +371,25 @@ dependencies = [ "digest 0.10.1", ] +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding 0.1.5", + "byte-tools", + "byteorder", + "generic-array 0.12.4", +] + [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", + "block-padding 0.2.1", "generic-array 0.14.5", ] @@ -390,6 +402,15 @@ dependencies = [ "generic-array 0.14.5", ] +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + [[package]] name = "block-padding" version = "0.2.1" @@ -481,6 +502,12 @@ dependencies = [ "serde", ] +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + [[package]] name = "byte-unit" version = "4.0.13" @@ -1390,6 +1417,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + [[package]] name = "fast-math" version = "0.1.1" @@ -2139,6 +2172,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "jsonrpc-client-transports" version = "18.0.0" @@ -2446,6 +2490,12 @@ dependencies = [ "hashbrown 0.11.2", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matches" version = "0.1.9" @@ -2782,6 +2832,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -2991,6 +3047,40 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.81", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1 0.8.2", +] + [[package]] name = "petgraph" version = "0.6.0" @@ -3066,7 +3156,7 @@ checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "opaque-debug", + "opaque-debug 0.3.0", "universal-hash", ] @@ -4039,6 +4129,18 @@ dependencies = [ "syn 1.0.81", ] +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + [[package]] name = "sha-1" version = "0.9.8" @@ -4049,7 +4151,7 @@ dependencies = [ "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -4068,7 +4170,7 @@ dependencies = [ "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -4091,7 +4193,7 @@ dependencies = [ "block-buffer 0.9.0", "digest 0.9.0", "keccak", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -4209,7 +4311,7 @@ dependencies = [ "httparse", "log 0.4.14", "rand 0.8.4", - "sha-1", + "sha-1 0.9.8", ] [[package]] @@ -4290,10 +4392,9 @@ version = "1.10.0" dependencies = [ "bs58 0.4.0", "crossbeam-channel", + "json5", "libloading", "log 0.4.14", - "serde", - "serde_derive", "serde_json", "solana-accountsdb-plugin-interface", "solana-measure", @@ -6991,7 +7092,7 @@ dependencies = [ "log 0.4.14", "rand 0.8.4", "rustls 0.20.0", - "sha-1", + "sha-1 0.9.8", "thiserror", "url 2.2.2", "utf-8", diff --git a/accountsdb-plugin-manager/Cargo.toml b/accountsdb-plugin-manager/Cargo.toml index a82091f6bd..5d3b35acd1 100644 --- a/accountsdb-plugin-manager/Cargo.toml +++ b/accountsdb-plugin-manager/Cargo.toml @@ -12,10 +12,9 @@ documentation = "https://docs.rs/solana-validator" [dependencies] bs58 = "0.4.0" crossbeam-channel = "0.5" +json5 = "0.4.1" libloading = "0.7.3" log = "0.4.11" -serde = "1.0.134" -serde_derive = "1.0.103" serde_json = "1.0.75" solana-accountsdb-plugin-interface = { path = "../accountsdb-plugin-interface", version = "=1.10.0" } solana-measure = { path = "../measure", version = "=1.10.0" } diff --git a/accountsdb-plugin-manager/src/accountsdb_plugin_service.rs b/accountsdb-plugin-manager/src/accountsdb_plugin_service.rs index 25c74bf262..9e274c04d0 100644 --- a/accountsdb-plugin-manager/src/accountsdb_plugin_service.rs +++ b/accountsdb-plugin-manager/src/accountsdb_plugin_service.rs @@ -9,7 +9,6 @@ use { }, crossbeam_channel::Receiver, log::*, - serde_json, solana_rpc::{ optimistically_confirmed_bank_tracker::BankNotification, transaction_notifier_interface::TransactionNotifierLock, @@ -156,12 +155,12 @@ impl AccountsDbPluginService { ))); } - let result: serde_json::Value = match serde_json::from_str(&contents) { + let result: serde_json::Value = match json5::from_str(&contents) { Ok(value) => value, Err(err) => { return Err(AccountsdbPluginServiceError::InvalidConfigFileFormat( format!( - "The config file {:?} is not in a valid Json format, error: {:?}", + "The config file {:?} is not in a valid Json5 format, error: {:?}", accountsdb_plugin_config_file, err ), )); diff --git a/docs/src/developing/plugins/accountsdb_plugin.md b/docs/src/developing/plugins/accountsdb_plugin.md index 0a5e51d36c..ba7ccce411 100644 --- a/docs/src/developing/plugins/accountsdb_plugin.md +++ b/docs/src/developing/plugins/accountsdb_plugin.md @@ -58,7 +58,7 @@ pub unsafe extern "C" fn _create_plugin() -> *mut dyn AccountsDbPlugin { A plugin implementation can implement the `on_load` method to initialize itself. This function is invoked after a plugin is dynamically loaded into the validator when it starts. The configuration of the plugin is controlled by a configuration -file in JSON format. The JSON file must have a field `libpath` that points +file in JSON5 format. The JSON5 file must have a field `libpath` that points to the full path name of the shared library implementing the plugin, and may have other configuration information, like connection parameters for the external database. The plugin configuration file is specified by the validator's CLI