diff --git a/Cargo.lock b/Cargo.lock index 3b04444..ff2f436 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,7 +55,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.2.14", "once_cell", "version_check", "zerocopy", @@ -131,18 +131,6 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" -[[package]] -name = "argon2" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" -dependencies = [ - "base64ct", - "blake2", - "cpufeatures", - "password-hash 0.5.0", -] - [[package]] name = "arrayref" version = "0.3.7" @@ -175,15 +163,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -295,12 +274,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64" version = "0.21.7" @@ -319,6 +292,33 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" +[[package]] +name = "bellperson" +version = "0.24.1" +source = "git+https://github.com/iron-fish/bellperson.git?branch=blstrs#37b9976bcd96986cbdc71ae09fc455015e3dfac0" +dependencies = [ + "bincode", + "blake2s_simd", + "blstrs", + "byteorder", + "crossbeam-channel", + "digest 0.10.7", + "ec-gpu", + "ec-gpu-gen", + "ff", + "group", + "log", + "memmap2", + "pairing", + "rand 0.8.5", + "rand_core 0.6.4", + "rayon", + "rustversion", + "serde", + "sha2 0.10.8", + "thiserror", +] + [[package]] name = "bincode" version = "1.3.3" @@ -330,13 +330,13 @@ dependencies = [ [[package]] name = "bip0039" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68a5a99c65851e7be249f5cf510c0a136f18c9bca32139576d59bd3f577b043" +checksum = "568b6890865156d9043af490d4c4081c385dd68ea10acd6ca15733d511e6b51c" dependencies = [ - "hmac", - "pbkdf2", - "rand", + "hmac 0.12.1", + "pbkdf2 0.12.2", + "rand 0.8.5", "sha2 0.10.8", "unicode-normalization", "zeroize", @@ -385,15 +385,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "blake2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "blake2b_simd" version = "1.0.2" @@ -469,19 +460,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3c196a77437e7cc2fb515ce413a6401291578b5afc8ecb29a3c7ab957f05941" dependencies = [ - "ff 0.12.1", - "rand_core", - "subtle", -] - -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" -dependencies = [ - "ff 0.13.0", - "rand_core", + "ff", + "rand_core 0.6.4", "subtle", ] @@ -506,10 +486,10 @@ checksum = "1ff3694b352ece02eb664a09ffb948ee69b35afa2e6ac444a6b8cb9d515deebd" dependencies = [ "blst", "byte-slice-cast", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "pairing", - "rand_core", + "rand_core 0.6.4", "serde", "subtle", ] @@ -614,10 +594,10 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", - "constants", "db_handler", "networking", "oreo_errors", + "params", "serde_json", "tokio", "tracing", @@ -684,12 +664,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" -[[package]] -name = "cobs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" - [[package]] name = "colorchoice" version = "1.0.1" @@ -710,12 +684,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "const-crc32-nostd" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808ac43170e95b11dd23d78aa9eaac5bea45776a602955552c4e833f3f0f823d" - [[package]] name = "const-oid" version = "0.9.6" @@ -728,10 +696,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" -[[package]] -name = "constants" -version = "0.1.0" - [[package]] name = "core-foundation" version = "0.9.4" @@ -781,12 +745,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "critical-section" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" - [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -843,36 +801,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array 0.14.7", - "rand_core", + "rand_core 0.6.4", "typenum", ] [[package]] -name = "crypto_box" -version = "0.9.1" +name = "crypto-mac" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16182b4f39a82ec8a6851155cc4c0cda3065bb1db33651726a29e1951de0f009" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "aead 0.5.2", - "crypto_secretbox", - "curve25519-dalek", - "salsa20", + "generic-array 0.14.7", "subtle", - "zeroize", ] [[package]] -name = "crypto_secretbox" -version = "0.1.1" +name = "crypto_box" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d6cf87adf719ddf43a805e92c6870a531aedda35ff640442cbaf8674e141e1" +checksum = "fd26c32de5307fd08aac445a75c43472b14559d5dccdfba8022dbcd075838ebc" dependencies = [ "aead 0.5.2", - "cipher 0.4.4", - "generic-array 0.14.7", - "poly1305 0.8.0", + "chacha20 0.9.1", + "chacha20poly1305 0.10.1", "salsa20", - "subtle", + "x25519-dalek", + "xsalsa20poly1305", "zeroize", ] @@ -899,40 +853,26 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.3" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ - "cfg-if", - "cpufeatures", - "curve25519-dalek-derive", - "digest 0.10.7", - "fiat-crypto", - "rustc_version", + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", "subtle", "zeroize", ] -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] - [[package]] name = "db_handler" version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "constants", "futures", "oreo_errors", + "params", "redis", "serde", "serde_json", @@ -944,12 +884,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "debugless-unwrap" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f400d0750c0c069e8493f2256cb4da6f604b6d2eeb69a0ca8863acde352f8400" - [[package]] name = "der" version = "0.7.9" @@ -961,17 +895,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "derive-getters" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] - [[package]] name = "digest" version = "0.9.0" @@ -1013,15 +936,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "document-features" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" -dependencies = [ - "litrs", -] - [[package]] name = "dotenv" version = "0.15.0" @@ -1043,13 +957,13 @@ dependencies = [ "bincode", "bytes", "clap", - "constants", "db_handler", "dotenv", "futures", "hex", "networking", "oreo_errors", + "params", "priority-queue", "rayon", "serde", @@ -1069,7 +983,6 @@ dependencies = [ "anyhow", "bytes", "clap", - "constants", "db_handler", "futures", "gethostname", @@ -1078,7 +991,7 @@ dependencies = [ "networking", "num_cpus", "oreo_errors", - "rand", + "rand 0.8.5", "rayon", "tokio", "tokio-util", @@ -1102,8 +1015,8 @@ dependencies = [ "crossbeam-channel", "ec-gpu", "execute", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "hex", "log", "num_cpus", @@ -1114,31 +1027,6 @@ dependencies = [ "yastl", ] -[[package]] -name = "ed25519" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" -dependencies = [ - "pkcs8", - "signature", -] - -[[package]] -name = "ed25519-dalek" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" -dependencies = [ - "curve25519-dalek", - "ed25519", - "rand_core", - "serde", - "sha2 0.10.8", - "subtle", - "zeroize", -] - [[package]] name = "either" version = "1.11.0" @@ -1148,23 +1036,10 @@ dependencies = [ "serde", ] -[[package]] -name = "embedded-io" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" - -[[package]] -name = "embedded-io" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" - [[package]] name = "equihash" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab579d7cf78477773b03e80bc2f89702ef02d7112c711d54ca93dcdce68533d5" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" dependencies = [ "blake2b_simd", "byteorder", @@ -1243,8 +1118,7 @@ checksum = "69dc321eb6be977f44674620ca3aa21703cb20ffbe560e1ae97da08401ffbcad" [[package]] name = "f4jumble" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a83e8d7fd0c526af4aad893b7c9fe41e2699ed8a776a6c74aecdeafe05afc75" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" dependencies = [ "blake2b_simd", ] @@ -1262,42 +1136,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" dependencies = [ "bitvec", - "rand_core", + "rand_core 0.6.4", "subtle", ] -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core", - "subtle", -] - -[[package]] -name = "fiat-crypto" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" - [[package]] name = "finl_unicode" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" -[[package]] -name = "fish_hash" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cea268879491ea825e57d07604f4080d26acfee3c603077ea3ac1e5ea034313" -dependencies = [ - "blake3", - "tiny-keccak", -] - [[package]] name = "flate2" version = "1.0.30" @@ -1372,42 +1220,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "frost-core" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5afd375261c34d31ff24dad068382f4bc3c95010c919d4fb8d483dc3d85c023" -dependencies = [ - "byteorder", - "const-crc32-nostd", - "debugless-unwrap", - "derive-getters", - "document-features", - "hex", - "itertools 0.13.0", - "postcard", - "rand_core", - "serde", - "serdect", - "thiserror", - "thiserror-nostd-notrait", - "visibility", - "zeroize", -] - -[[package]] -name = "frost-rerandomized" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9d77595060546b53543d96b83dbeacaf3907e40a89763a8bb22124812b0cb6" -dependencies = [ - "derive-getters", - "document-features", - "frost-core", - "hex", - "rand_core", -] - [[package]] name = "funty" version = "2.0.0" @@ -1522,7 +1334,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -1544,6 +1355,19 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.2.14" @@ -1553,7 +1377,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -1575,24 +1399,13 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ - "ff 0.12.1", - "rand", - "rand_core", + "ff", + "rand 0.8.5", + "rand_core 0.6.4", "rand_xorshift", "subtle", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff 0.13.0", - "rand_core", - "subtle", -] - [[package]] name = "halo2_gadgets" version = "0.2.0" @@ -1601,12 +1414,12 @@ checksum = "85e10bf9924da1754e443641c9e7f9f00483749f8fb837fde696ef6ed6e2f079" dependencies = [ "arrayvec", "bitvec", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "halo2_proofs", "lazy_static", - "pasta_curves 0.4.1", - "rand", + "pasta_curves", + "rand 0.8.5", "subtle", "uint", ] @@ -1618,23 +1431,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff771b9a2445cd2545c9ef26d863c290fbb44ae440c825a20eb7156f67a949a" dependencies = [ "blake2b_simd", - "ff 0.12.1", - "group 0.12.1", - "pasta_curves 0.4.1", - "rand_core", + "ff", + "group", + "pasta_curves", + "rand_core 0.6.4", "rayon", "tracing", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -1678,20 +1482,6 @@ dependencies = [ "http", ] -[[package]] -name = "heapless" -version = "0.7.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" -dependencies = [ - "atomic-polyfill", - "hash32", - "rustc_version", - "serde", - "spin 0.9.8", - "stable_deref_trait", -] - [[package]] name = "heck" version = "0.4.1" @@ -1734,7 +1524,17 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ - "hmac", + "hmac 0.12.1", +] + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", ] [[package]] @@ -1852,210 +1652,78 @@ dependencies = [ name = "incrementalmerkletree" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ad43a3f5795945459d577f6589cf62a476e92c79b75e70cd954364e14ce17b" -dependencies = [ - "serde", -] - -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array 0.14.7", -] - -[[package]] -name = "ironfish" -version = "0.3.0" -source = "git+https://github.com/iron-fish/ironfish.git?branch=master#6693fe5f913850867c0a3063f41ab4bff9891ab9" -dependencies = [ - "argon2", - "blake2b_simd", - "blake2s_simd", - "blake3", - "blstrs", - "byteorder", - "chacha20poly1305 0.10.1", - "crypto_box", - "ff 0.12.1", - "fish_hash", - "group 0.12.1", - "hex", - "hkdf", - "ironfish-bellperson", - "ironfish-frost", - "ironfish-jubjub", - "ironfish_zkp", - "lazy_static", - "rand", - "sha2 0.10.8", - "tiny-bip39", - "xxhash-rust", -] - -[[package]] -name = "ironfish-bellperson" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2e19b8d7c61fdbdfde5ba86cec85b9facf60b2b5ef9968618c353f8f7f6815" -dependencies = [ - "bincode", - "blake2s_simd", - "blstrs", - "byteorder", - "crossbeam-channel", - "digest 0.10.7", - "ec-gpu", - "ec-gpu-gen", - "ff 0.12.1", - "group 0.12.1", - "log", - "memmap2", - "pairing", - "rand", - "rand_core", - "rayon", - "rustversion", - "serde", - "sha2 0.10.8", - "thiserror", -] - -[[package]] -name = "ironfish-frost" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bee779ebf008aa92e1bb90993a47ab730065a8d39f5fa6630cde1ddfcf56a46" -dependencies = [ - "blake3", - "chacha20 0.9.1", - "chacha20poly1305 0.10.1", - "ed25519-dalek", - "ironfish-reddsa", - "rand_chacha", - "rand_core", - "siphasher", - "x25519-dalek", -] - -[[package]] -name = "ironfish-jubjub" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ee437e98296799ebdff1f62c14c63bbfb65df3e4e19c3913e7c46b9827b148" -dependencies = [ - "bitvec", - "blst", - "blstrs", - "ff 0.12.1", - "group 0.12.1", - "lazy_static", - "rand_core", - "subtle", -] - -[[package]] -name = "ironfish-primitives" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7b213445520fb92462bd4a79274ad9b31c1ce49248f6eaa7ca3a50e8fe413d3" -dependencies = [ - "aes", - "bip0039", - "bitvec", - "blake2b_simd", - "blake2s_simd", - "blstrs", - "byteorder", - "chacha20poly1305 0.9.1", - "equihash", - "ff 0.12.1", - "fpe", - "group 0.12.1", - "hex", - "incrementalmerkletree", - "ironfish-jubjub", - "lazy_static", - "memuse", - "nonempty", - "orchard", - "rand", - "rand_core", - "sha2 0.9.9", - "subtle", - "zcash_address", - "zcash_encoding", - "zcash_note_encryption", +checksum = "d5ad43a3f5795945459d577f6589cf62a476e92c79b75e70cd954364e14ce17b" +dependencies = [ + "serde", ] [[package]] -name = "ironfish-proofs" -version = "0.1.0" +name = "indexmap" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea51eb3565333b8c67483a16499452215326df95f92160bd567f16c35f82e29" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ - "blake2b_simd", - "blstrs", - "byteorder", - "directories", - "ff 0.12.1", - "group 0.12.1", - "ironfish-bellperson", - "ironfish-jubjub", - "ironfish-primitives", - "lazy_static", - "rand_core", - "redjubjub", - "tracing", + "equivalent", + "hashbrown", ] [[package]] -name = "ironfish-reddsa" -version = "0.1.0" +name = "inout" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb4aecfd3334f0128215ce47f57360d91d68ff9d6fd890e1faca3c79b2bfa28d" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "ironfish" +version = "0.3.0" +source = "git+https://github.com/oreoslabs/ironfish-optimize.git?branch=feature/support-wasm#94be97ec39c3be46e406ed665728e5d0f8e48d98" dependencies = [ + "bellperson", "blake2b_simd", + "blake2s_simd", + "blake3", + "blst", + "blstrs", "byteorder", - "frost-rerandomized", - "group 0.13.0", + "chacha20poly1305 0.9.1", + "crypto_box", + "ff", + "group", "hex", - "jubjub 0.10.0", - "pasta_curves 0.5.1", - "rand_core", - "serde", - "thiserror", - "zeroize", + "ironfish_zkp", + "jubjub 0.9.0 (git+https://github.com/oreoslabs/jubjub.git?branch=blstrs)", + "lazy_static", + "libc", + "log", + "rand 0.8.5", + "sha2 0.10.8", + "tiny-bip39", + "xxhash-rust", ] [[package]] name = "ironfish_zkp" version = "0.2.0" -source = "git+https://github.com/iron-fish/ironfish.git?branch=master#6693fe5f913850867c0a3063f41ab4bff9891ab9" +source = "git+https://github.com/oreoslabs/ironfish-optimize.git?branch=feature/support-wasm#94be97ec39c3be46e406ed665728e5d0f8e48d98" dependencies = [ + "bellperson", "blake2s_simd", + "blst", "blstrs", "byteorder", - "ff 0.12.1", - "group 0.12.1", - "ironfish-bellperson", - "ironfish-jubjub", - "ironfish-primitives", - "ironfish-proofs", + "ff", + "getrandom 0.2.14", + "group", + "jubjub 0.9.0 (git+https://github.com/oreoslabs/jubjub.git?branch=blstrs)", "lazy_static", - "rand", + "rand 0.8.5", + "rand_core 0.6.4", + "serde", + "zcash_primitives", + "zcash_proofs", ] [[package]] @@ -2073,15 +1741,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -2104,24 +1763,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a575df5f985fe1cd5b2b05664ff6accfc46559032b954529fd225a2168d27b0f" dependencies = [ "bitvec", - "bls12_381 0.7.1", - "ff 0.12.1", - "group 0.12.1", - "rand_core", + "bls12_381", + "ff", + "group", + "rand_core 0.6.4", "subtle", ] [[package]] name = "jubjub" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8499f7a74008aafbecb2a2e608a3e13e4dd3e84df198b604451efe93f2de6e61" +version = "0.9.0" +source = "git+https://github.com/oreoslabs/jubjub.git?branch=blstrs#3f864b418d01bf330cefdad04bfd15362971c34b" dependencies = [ "bitvec", - "bls12_381 0.8.0", - "ff 0.13.0", - "group 0.13.0", - "rand_core", + "blst", + "blstrs", + "ff", + "group", + "lazy_static", + "rand_core 0.6.4", "subtle", ] @@ -2173,12 +1833,6 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" -[[package]] -name = "litrs" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" - [[package]] name = "lock_api" version = "0.4.12" @@ -2272,7 +1926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2301,9 +1955,9 @@ dependencies = [ "anyhow", "axum", "bytes", - "constants", "db_handler", "oreo_errors", + "params", "serde", "serde_json", "tokio", @@ -2362,7 +2016,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand", + "rand 0.8.5", "smallvec", "zeroize", ] @@ -2481,9 +2135,9 @@ dependencies = [ "aes", "bitvec", "blake2b_simd", - "ff 0.12.1", + "ff", "fpe", - "group 0.12.1", + "group", "halo2_gadgets", "halo2_proofs", "hex", @@ -2491,13 +2145,13 @@ dependencies = [ "lazy_static", "memuse", "nonempty", - "pasta_curves 0.4.1", - "rand", + "pasta_curves", + "rand 0.8.5", "reddsa", "serde", "subtle", "tracing", - "zcash_note_encryption", + "zcash_note_encryption 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2522,9 +2176,13 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" dependencies = [ - "group 0.12.1", + "group", ] +[[package]] +name = "params" +version = "0.1.0" + [[package]] name = "parking_lot" version = "0.12.2" @@ -2548,17 +2206,6 @@ dependencies = [ "windows-targets 0.52.5", ] -[[package]] -name = "password-hash" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" -dependencies = [ - "base64ct", - "rand_core", - "subtle", -] - [[package]] name = "password-hash" version = "0.5.0" @@ -2566,7 +2213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -2577,23 +2224,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cc65faf8e7313b4b1fbaa9f7ca917a0eed499a9663be71477f87993604341d8" dependencies = [ "blake2b_simd", - "ff 0.12.1", - "group 0.12.1", + "ff", + "group", "lazy_static", - "rand", - "static_assertions", - "subtle", -] - -[[package]] -name = "pasta_curves" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" -dependencies = [ - "ff 0.13.0", - "group 0.13.0", - "rand", + "rand 0.8.5", "static_assertions", "subtle", ] @@ -2606,12 +2240,21 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pbkdf2" -version = "0.11.0" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd" +dependencies = [ + "crypto-mac", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest 0.10.7", - "password-hash 0.4.2", + "password-hash", ] [[package]] @@ -2710,19 +2353,6 @@ dependencies = [ "universal-hash 0.5.1", ] -[[package]] -name = "postcard" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" -dependencies = [ - "cobs", - "embedded-io 0.4.0", - "embedded-io 0.6.1", - "heapless", - "serde", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2755,19 +2385,18 @@ version = "0.1.0" dependencies = [ "anyhow", "axum", + "bellperson", "blst", "blstrs", "clap", - "constants", "db_handler", - "getrandom", + "getrandom 0.2.14", "ironfish", - "ironfish-bellperson", "ironfish_zkp", "networking", "oreo_errors", - "rand", - "rand_core", + "rand 0.8.5", + "rand_core 0.6.4", "rayon", "serde_json", "tokio", @@ -2792,6 +2421,19 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -2799,8 +2441,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -2810,7 +2462,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -2819,7 +2480,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.14", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -2828,7 +2498,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -2859,10 +2529,10 @@ checksum = "4cc8038c8b7e481bdf688d0585d4897ed0e9e0cee10aa365dde51238c20e4182" dependencies = [ "blake2b_simd", "byteorder", - "group 0.12.1", - "jubjub 0.9.0", - "pasta_curves 0.4.1", - "rand_core", + "group", + "jubjub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pasta_curves", + "rand_core 0.6.4", "serde", "thiserror", "zeroize", @@ -2900,8 +2570,8 @@ dependencies = [ "blake2b_simd", "byteorder", "digest 0.9.0", - "jubjub 0.9.0", - "rand_core", + "jubjub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.6.4", "serde", "thiserror", "zeroize", @@ -2931,7 +2601,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "getrandom", + "getrandom 0.2.14", "libredox", "thiserror", ] @@ -2988,7 +2658,7 @@ checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if", - "getrandom", + "getrandom 0.2.14", "libc", "spin 0.9.8", "untrusted", @@ -3008,7 +2678,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "spki", "subtle", @@ -3027,15 +2697,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.34" @@ -3168,12 +2829,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "serde" version = "1.0.200" @@ -3240,16 +2895,6 @@ dependencies = [ "unsafe-libyaml", ] -[[package]] -name = "serdect" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" -dependencies = [ - "base16ct", - "serde", -] - [[package]] name = "server" version = "0.1.0" @@ -3259,12 +2904,12 @@ dependencies = [ "axum-extra", "bincode", "clap", - "constants", "db_handler", "dotenv", "hex", "networking", "oreo_errors", + "params", "serde_json", "sha2 0.10.8", "tokio", @@ -3340,15 +2985,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest 0.10.7", - "rand_core", + "rand_core 0.6.4", ] -[[package]] -name = "siphasher" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" - [[package]] name = "slab" version = "0.4.9" @@ -3405,7 +3044,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools 0.12.1", + "itertools", "nom", "unicode_categories", ] @@ -3473,7 +3112,7 @@ checksum = "18ec4c9e9c434dceec904013de09c070921bab90c76ff1551cd73663836793bc" dependencies = [ "anyhow", "csv", - "itertools 0.12.1", + "itertools", "sqlx", "tokio", "uuid", @@ -3540,14 +3179,14 @@ dependencies = [ "generic-array 0.14.7", "hex", "hkdf", - "hmac", + "hmac 0.12.1", "itoa", "log", "md-5", "memchr", "once_cell", "percent-encoding", - "rand", + "rand 0.8.5", "rsa", "serde", "sha1", @@ -3579,14 +3218,14 @@ dependencies = [ "futures-util", "hex", "hkdf", - "hmac", + "hmac 0.12.1", "home", "itoa", "log", "md-5", "memchr", "once_cell", - "rand", + "rand 0.8.5", "serde", "serde_json", "sha2 0.10.8", @@ -3621,12 +3260,6 @@ dependencies = [ "urlencoding", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "static_assertions" version = "1.1.0" @@ -3737,26 +3370,6 @@ dependencies = [ "syn 2.0.60", ] -[[package]] -name = "thiserror-nostd-notrait" -version = "1.0.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8444e638022c44d2a9337031dee8acb732bcc7fbf52ac654edc236b26408b61" -dependencies = [ - "thiserror-nostd-notrait-impl", -] - -[[package]] -name = "thiserror-nostd-notrait-impl" -version = "1.0.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585e5ef40a784ce60b49c67d762110688d211d395d39e096be204535cf64590e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] - [[package]] name = "thread_local" version = "1.1.8" @@ -3778,32 +3391,23 @@ dependencies = [ [[package]] name = "tiny-bip39" -version = "1.0.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62cc94d358b5a1e84a5cb9109f559aa3c4d634d2b1b4de3d0fa4adc7c78e2861" +checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d" dependencies = [ "anyhow", - "hmac", + "hmac 0.8.1", "once_cell", - "pbkdf2", - "rand", + "pbkdf2 0.4.0", + "rand 0.7.3", "rustc-hash", - "sha2 0.10.8", + "sha2 0.9.9", "thiserror", "unicode-normalization", "wasm-bindgen", "zeroize", ] -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -4005,20 +3609,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "transfer-tool" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "constants", - "db_handler", - "networking", - "tokio", - "tracing", - "utils", -] - [[package]] name = "typenum" version = "1.17.0" @@ -4160,8 +3750,8 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ - "getrandom", - "rand", + "getrandom 0.2.14", + "rand 0.8.5", "uuid-macro-internal", ] @@ -4195,15 +3785,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "visibility" -version = "0.1.1" +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d674d135b4a8c1d7e813e2f8d1c9a58308aee4a680323066025e53132218bd91" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" @@ -4471,12 +4056,26 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "2.0.1" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" +checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" dependencies = [ "curve25519-dalek", - "rand_core", + "rand_core 0.5.1", + "zeroize", +] + +[[package]] +name = "xsalsa20poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02a6dad357567f81cd78ee75f7c61f1b30bb2fe4390be8fb7c69e2ac8dffb6c7" +dependencies = [ + "aead 0.5.2", + "poly1305 0.8.0", + "salsa20", + "subtle", + "zeroize", ] [[package]] @@ -4498,8 +4097,7 @@ dependencies = [ [[package]] name = "zcash_address" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1322a31b757f0087f110cc4a85dc5c6ccf83d0533bac04c4d3d1ce9112cc602" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" dependencies = [ "bech32", "bs58", @@ -4510,8 +4108,7 @@ dependencies = [ [[package]] name = "zcash_encoding" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb61ea88eb539bc0ac2068e5da99411dd4978595b3d7ff6a4b1562ddc8e8710" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" dependencies = [ "byteorder", "nonempty", @@ -4525,8 +4122,74 @@ checksum = "33f84ae538f05a8ac74c82527f06b77045ed9553a0871d9db036166a4c344e3a" dependencies = [ "chacha20 0.8.2", "chacha20poly1305 0.9.1", - "rand_core", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "zcash_note_encryption" +version = "0.1.0" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" +dependencies = [ + "chacha20 0.8.2", + "chacha20poly1305 0.9.1", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "zcash_primitives" +version = "0.7.0" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" +dependencies = [ + "aes", + "bip0039", + "bitvec", + "blake2b_simd", + "blake2s_simd", + "blst", + "blstrs", + "byteorder", + "chacha20poly1305 0.9.1", + "equihash", + "ff", + "fpe", + "group", + "hex", + "incrementalmerkletree", + "jubjub 0.9.0 (git+https://github.com/oreoslabs/jubjub.git?branch=blstrs)", + "lazy_static", + "memuse", + "nonempty", + "orchard", + "rand 0.8.5", + "rand_core 0.6.4", + "sha2 0.9.9", "subtle", + "zcash_address", + "zcash_encoding", + "zcash_note_encryption 0.1.0 (git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs)", +] + +[[package]] +name = "zcash_proofs" +version = "0.7.1" +source = "git+https://github.com/oreoslabs/librustzcash.git?branch=blstrs#978420602b03f4353e3df6f4916c908e1b4fc8e5" +dependencies = [ + "bellperson", + "blake2b_simd", + "blst", + "blstrs", + "byteorder", + "directories", + "ff", + "group", + "jubjub 0.9.0 (git+https://github.com/oreoslabs/jubjub.git?branch=blstrs)", + "lazy_static", + "rand_core 0.6.4", + "redjubjub", + "tracing", + "zcash_primitives", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 142d459..80fddea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ resolver = "2" members = [ "crates/networking", - "crates/constants", "crates/db_handler", "crates/oreo_errors", "crates/server", @@ -10,5 +9,6 @@ members = [ "crates/prover", "crates/dworker", "crates/dservice", - "crates/chain_loader", "crates/transfer-tool", + "crates/chain_loader", + "crates/params", ] diff --git a/crates/chain_loader/Cargo.toml b/crates/chain_loader/Cargo.toml index 62cb7c7..f74a191 100644 --- a/crates/chain_loader/Cargo.toml +++ b/crates/chain_loader/Cargo.toml @@ -12,7 +12,7 @@ tokio = { version = "1.35.1", features = ["full"] } tracing = "0.1.40" utils = { path = "../utils" } networking = { path = "../networking" } -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } -serde_json = "1.0.117" \ No newline at end of file +serde_json = "1.0.117" +params = { path = "../params" } \ No newline at end of file diff --git a/crates/chain_loader/src/lib.rs b/crates/chain_loader/src/lib.rs deleted file mode 100644 index 1b2eb96..0000000 --- a/crates/chain_loader/src/lib.rs +++ /dev/null @@ -1,58 +0,0 @@ -use std::time::Duration; - -use constants::{LOCAL_BLOCKS_CHECKPOINT, PRIMARY_BATCH}; -use db_handler::{DBHandler, DBTransaction, InnerBlock, Json, PgHandler}; -use networking::{rpc_abi::RpcBlock, rpc_handler::RpcHandler}; -use tokio::time::sleep; -use tracing::info; -use utils::blocks_range; - -pub async fn load_checkpoint(rpc_node: String, db_handler: PgHandler) -> anyhow::Result<()> { - let rpc_handler = RpcHandler::new(rpc_node); - for group in blocks_range(1..LOCAL_BLOCKS_CHECKPOINT + 1, PRIMARY_BATCH) { - if db_handler - .get_blocks(group.start as i64, group.end as i64) - .await - .is_ok() - { - continue; - } - let results = { - loop { - match rpc_handler.get_blocks(group.start, group.end) { - Ok(res) => break res, - Err(_) => {} - } - sleep(Duration::from_secs(3)).await; - } - }; - let blocks: Vec = results - .data - .blocks - .into_iter() - .map(|item| item.block) - .collect(); - let inner_blocks = blocks - .into_iter() - .map(|rpc| InnerBlock { - hash: rpc.hash.clone(), - sequence: rpc.sequence as i64, - transactions: Json( - rpc.transactions - .into_iter() - .map(|tx| DBTransaction { - hash: tx.hash, - serialized_notes: tx.notes.into_iter().map(|n| n.serialized).collect(), - }) - .collect(), - ), - }) - .collect(); - info!( - "save blocks from {} to {} in local db", - group.start, group.end - ); - let _ = db_handler.save_blocks(inner_blocks).await; - } - Ok(()) -} diff --git a/crates/chain_loader/src/main.rs b/crates/chain_loader/src/main.rs index ad7f57c..3877f34 100644 --- a/crates/chain_loader/src/main.rs +++ b/crates/chain_loader/src/main.rs @@ -1,34 +1,140 @@ +use std::{ + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + time::Duration, +}; + use anyhow::Result; -use chain_loader::load_checkpoint; use clap::Parser; -use db_handler::{DBHandler, DbConfig, PgHandler}; -use utils::{handle_signals, initialize_logger}; +use db_handler::{load_db, DBTransaction, InnerBlock, Json}; +use networking::{rpc_abi::RpcBlock, rpc_handler::RpcHandler}; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; +use tokio::{sync::oneshot, time::sleep}; +use tracing::{error, info}; +use utils::{blocks_range, initialize_logger, initialize_logger_filter, EnvFilter}; #[derive(Parser, Debug, Clone)] -struct Command { +struct ChainLoader { /// The path to db config file #[clap(long)] - pub dbconfig: String, + dbconfig: String, /// Set your logger level #[clap(short, long, default_value = "0")] - pub verbosity: u8, + verbosity: u8, /// The Ironfish rpc node to connect to #[clap(short, long, default_value = "127.0.0.1:9092")] - pub node: String, + node: String, + /// The network id, 0 for mainnet, 1 for testnet. + #[clap(long)] + network: u8, +} + +impl ChainLoader { + async fn start(&self, shut_down: Arc) -> Result<()> { + let rpc_handler = RpcHandler::new(self.node.clone()); + let genesis_block = rpc_handler + .get_latest_block() + .unwrap() + .data + .genesis_block_identifier; + if genesis_block.hash.to_lowercase() != N::GENESIS_BLOCK_HASH.to_lowercase() { + panic!("Genesis block doesn't match"); + } + + let db_handler = { load_db(self.dbconfig.clone()).unwrap() }; + + for group in blocks_range(1..N::LOCAL_BLOCKS_CHECKPOINT + 1, N::PRIMARY_BATCH) { + if shut_down.load(Ordering::Relaxed) { + info!("Chainloader should exit now"); + break; + } + if db_handler + .get_blocks(group.start as i64, group.end as i64) + .await + .is_ok() + { + continue; + } + let results = { + loop { + match rpc_handler.get_blocks(group.start, group.end) { + Ok(res) => break res, + Err(e) => { + error!("Failed to get rpc blocks {}", e); + } + } + sleep(Duration::from_secs(1)).await; + } + }; + let blocks: Vec = results + .data + .blocks + .into_iter() + .map(|item| item.block) + .collect(); + let inner_blocks = blocks + .into_iter() + .map(|rpc| InnerBlock { + hash: rpc.hash.clone(), + sequence: rpc.sequence as i64, + transactions: Json( + rpc.transactions + .into_iter() + .map(|tx| DBTransaction { + hash: tx.hash, + serialized_notes: tx + .notes + .into_iter() + .map(|n| n.serialized) + .collect(), + }) + .collect(), + ), + }) + .collect(); + if group.end % 1000 == 0 { + info!( + "save blocks from {} to {} in local db", + group.start, group.end + ); + } + let _ = db_handler.save_blocks(inner_blocks).await; + } + Ok(()) + } } #[tokio::main] async fn main() -> Result<()> { - let args = Command::parse(); - let Command { - dbconfig, - verbosity, - node, - } = args; - initialize_logger(verbosity); - handle_signals().await?; - let db_config = DbConfig::load(dbconfig).unwrap(); - let db_handler = PgHandler::from_config(&db_config); - load_checkpoint(node, db_handler).await?; + let loader = ChainLoader::parse(); + initialize_logger(loader.verbosity); + initialize_logger_filter(EnvFilter::from_default_env()); + let shut_down = Arc::new(AtomicBool::new(false)); + handle_signals(shut_down.clone()).await; + match loader.network { + Mainnet::ID => loader.start::(shut_down).await?, + Testnet::ID => loader.start::(shut_down).await?, + _ => panic!("Invalid network used"), + } Ok(()) } + +async fn handle_signals(shut_down: Arc) { + let (router, handler) = oneshot::channel(); + tokio::spawn(async move { + let _ = router.send(()); + match tokio::signal::ctrl_c().await { + Ok(()) => { + shut_down.store(true, Ordering::SeqCst); + info!("Shutdown signal received, exit after 3 seconds"); + sleep(Duration::from_secs(3)).await; + std::process::exit(0); + } + Err(error) => error!("tokio::signal::ctrl_c encountered an error: {}", error), + } + }); + let _ = handler.await; + info!("Shutdown handler installed"); +} diff --git a/crates/constants/Cargo.toml b/crates/constants/Cargo.toml deleted file mode 100644 index 06d8173..0000000 --- a/crates/constants/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "constants" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/crates/constants/src/lib.rs b/crates/constants/src/lib.rs deleted file mode 100644 index f6768d0..0000000 --- a/crates/constants/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -use std::time::Duration; - -pub const ACCOUNT_VERSION: u8 = 2; -pub const IRON_NATIVE_ASSET: &str = - "51f33a2f14f92735e562dc658a5639279ddca3d5079a6d1242b2a588a9cbf44c"; -pub const OREOS_VALUE: &str = "1"; -pub const OREOSRIPTIONS_ENDPOINT: &str = "http://localhost:20001/api"; -pub const MAINNET_GENESIS_HASH: &str = - "eac623b099b8081d2bde92d43a4a7795385c94e2c0ae4097ef488972e83ff2b3"; -pub const MAINNET_GENESIS_SEQUENCE: i64 = 1; -pub const REORG_DEPTH: i64 = 100; -pub const SECONDARY_BATCH: i64 = 10000; -pub const RESCHEDULING_DURATION: Duration = Duration::from_secs(30); -pub const PRIMARY_BATCH: u64 = 100; -pub const LOCAL_BLOCKS_CHECKPOINT: u64 = 797_000; diff --git a/crates/db_handler/Cargo.toml b/crates/db_handler/Cargo.toml index 7c1c794..7244f00 100644 --- a/crates/db_handler/Cargo.toml +++ b/crates/db_handler/Cargo.toml @@ -16,11 +16,11 @@ sqlx = { version = "0.7.0", features = ["runtime-tokio-rustls", "postgres"] } substring = "1.4.5" tracing = "0.1.40" oreo_errors = { path = "../oreo_errors" } -constants = { path = "../constants" } redis = { version = "0.25.2", features = [ "tokio-comp", "tokio-native-tls-comp", ] } +params = { path = "../params" } [dev-dependencies] sqlx-db-tester = "0.4.0" diff --git a/crates/db_handler/src/config.rs b/crates/db_handler/src/config.rs index 1ff6d82..f2267d2 100644 --- a/crates/db_handler/src/config.rs +++ b/crates/db_handler/src/config.rs @@ -5,6 +5,8 @@ use tracing::info; use std::{fs, path::Path}; +use crate::DBType; + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct DbConfig { pub host: String, @@ -44,6 +46,14 @@ impl DbConfig { pub fn url(&self) -> String { format!("{}/{}", self.server_url(), self.dbname) } + + pub fn protocol(&self) -> DBType { + match self.protocol.as_str() { + "postgres" => DBType::Postgres, + "redis" => DBType::Redis, + _ => DBType::Unknown, + } + } } impl DbConfig { diff --git a/crates/db_handler/src/lib.rs b/crates/db_handler/src/lib.rs index a2b030e..77d2f6e 100644 --- a/crates/db_handler/src/lib.rs +++ b/crates/db_handler/src/lib.rs @@ -2,7 +2,11 @@ mod config; mod pg_handler; mod redis_handler; +use std::{path::Path, str::FromStr}; + +use anyhow::anyhow; pub use config::DbConfig; +use futures::executor::block_on; pub use pg_handler::*; pub use redis_handler::*; @@ -10,13 +14,13 @@ pub use sqlx::types::Json; use oreo_errors::OreoError; use serde::{Deserialize, Serialize}; -use sqlx::FromRow; +use sqlx::{postgres::PgConnectOptions, ConnectOptions, FromRow, PgPool}; use substring::Substring; #[async_trait::async_trait] pub trait DBHandler { - /// Initialize a DB handler - fn from_config(config: &DbConfig) -> Self; + //// DB type: postgres and redis for now + fn db_type(&self) -> String; /// Save account in db and return account name async fn save_account(&self, account: Account, worker_id: u32) -> Result; /// Get account name from db @@ -75,3 +79,39 @@ pub struct BonusAddress { pub address: String, pub paid: bool, } + +pub enum DBType { + Postgres, + Redis, + Unknown, +} + +impl DbConfig { + pub fn build(&self) -> anyhow::Result> { + match self.protocol() { + DBType::Postgres => { + let url = self.server_url(); + let options = PgConnectOptions::from_str(&url) + .unwrap() + .disable_statement_logging() + .clone(); + let pool = block_on(async { PgPool::connect_with(options).await }); + match pool { + Ok(pool) => Ok(Box::new(PgHandler::new(pool))), + Err(e) => Err(anyhow!("Failed to connect pgsql {}", e)), + } + } + DBType::Redis => { + let client = RedisClient::connect(&self.server_url(), self.default_pool_size)?; + Ok(Box::new(client)) + } + DBType::Unknown => { + panic!("Invalid database used") + } + } + } +} + +pub fn load_db(filename: impl AsRef) -> anyhow::Result> { + DbConfig::load(filename)?.build() +} diff --git a/crates/db_handler/src/pg_handler.rs b/crates/db_handler/src/pg_handler.rs index 8feab84..6d6c897 100644 --- a/crates/db_handler/src/pg_handler.rs +++ b/crates/db_handler/src/pg_handler.rs @@ -1,8 +1,5 @@ -use std::str::FromStr; - -use futures::executor::block_on; use oreo_errors::OreoError; -use sqlx::{postgres::PgConnectOptions, ConnectOptions, PgPool, Row}; +use sqlx::{PgPool, Row}; use crate::{BonusAddress, DBTransaction, InnerBlock}; @@ -164,14 +161,8 @@ impl PgHandler { #[async_trait::async_trait] impl DBHandler for PgHandler { - fn from_config(config: &crate::config::DbConfig) -> Self { - let url = config.server_url(); - let options = PgConnectOptions::from_str(&url) - .unwrap() - .disable_statement_logging() - .clone(); - let pool = block_on(async { PgPool::connect_with(options).await.unwrap() }); - Self::new(pool) + fn db_type(&self) -> String { + "Postgres".to_string() } async fn save_account(&self, account: Account, _worker_id: u32) -> Result { @@ -246,11 +237,14 @@ impl DBHandler for PgHandler { } } +unsafe impl Send for PgHandler {} +unsafe impl Sync for PgHandler {} + #[cfg(test)] mod tests { use std::path::Path; - use constants::{MAINNET_GENESIS_HASH, MAINNET_GENESIS_SEQUENCE}; + use params::{mainnet::Mainnet, network::Network}; use sqlx::types::Json; use sqlx_db_tester::TestPg; @@ -275,8 +269,8 @@ mod tests { name: address_to_name(ADDRESS), create_head: None, create_hash: None, - head: MAINNET_GENESIS_SEQUENCE, - hash: MAINNET_GENESIS_HASH.to_string(), + head: Mainnet::GENESIS_BLOCK_HEIGHT as i64, + hash: Mainnet::GENESIS_BLOCK_HASH.to_string(), in_vk: IN_VK.to_string(), out_vk: OUT_VK.to_string(), vk: VK.to_string(), diff --git a/crates/db_handler/src/redis_handler.rs b/crates/db_handler/src/redis_handler.rs index 084e5bf..e0995e4 100644 --- a/crates/db_handler/src/redis_handler.rs +++ b/crates/db_handler/src/redis_handler.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use substring::Substring; use tracing::info; -use crate::{config::DbConfig, Account, DBHandler, InnerBlock}; +use crate::{Account, DBHandler, InnerBlock}; pub const REDIS_ACCOUNT_KEY: &str = "IRONACCOUNT"; pub const REDIS_ACCOUNT_KEY_V1: &str = "IRONACCOUNTV1"; @@ -69,6 +69,10 @@ impl RedisClient { #[async_trait::async_trait] impl DBHandler for RedisClient { + fn db_type(&self) -> String { + "Redis".to_string() + } + async fn save_account(&self, account: Account, _worker_id: u32) -> Result { let address = account.address.clone(); match self.hget(&self.db_name, &address).await { @@ -148,17 +152,15 @@ impl DBHandler for RedisClient { async fn get_blocks(&self, _start: i64, _end: i64) -> Result, OreoError> { unimplemented!("Redis is deprecated for such feature!") } - - fn from_config(config: &DbConfig) -> Self { - info!("Redis handler selected"); - RedisClient::connect(&config.server_url(), config.default_pool_size).unwrap() - } } pub fn address_to_name(address: &str) -> String { address.substring(0, 10).into() } +unsafe impl Send for RedisClient {} +unsafe impl Sync for RedisClient {} + #[cfg(test)] mod tests { @@ -170,15 +172,13 @@ mod tests { // Outgoing View Key cee4ff41d7d8da5eedc6493134981eaad7b26a8b0291a4eac9ba95090fa47bf7 // Address d63ba13d7c35caf942c64d5139b948b885ec931977a3f248c13e7f3c1bd0aa64 - use constants::MAINNET_GENESIS_HASH; - use constants::MAINNET_GENESIS_SEQUENCE; use oreo_errors::OreoError; use super::address_to_name; - use super::RedisClient; - use crate::config::DbConfig; + use crate::load_db; use crate::Account; use crate::DBHandler; + use params::{mainnet::Mainnet, network::Network}; const VK: &str = "4ae4eb9606ba57b3b17a444100a9ac6453cd67e6fe4c860e63a2e18b1200978ab5ecce68e8639d5016cbe73b0ea9a3c8e906fc881af2e9ccfa7a7b63fb73d555"; const IN_VK: &str = "4a08bec0ec5a471352f340d737e4b3baec2aec8d0a2e12201d92d8ad71aadd07"; @@ -190,8 +190,8 @@ mod tests { name: address_to_name(ADDRESS), create_head: None, create_hash: None, - head: MAINNET_GENESIS_SEQUENCE, - hash: MAINNET_GENESIS_HASH.to_string(), + head: Mainnet::GENESIS_BLOCK_HEIGHT as i64, + hash: Mainnet::GENESIS_BLOCK_HASH.to_string(), in_vk: IN_VK.to_string(), out_vk: OUT_VK.to_string(), vk: VK.to_string(), @@ -200,10 +200,8 @@ mod tests { } } - fn get_tdb() -> RedisClient { - let config = DbConfig::load("./fixtures/redis-config.yml").unwrap(); - let db_handler = RedisClient::from_config(&config); - db_handler + fn get_tdb() -> Box { + load_db("./fixtures/redis-config.yml").unwrap() } #[tokio::test] diff --git a/crates/dservice/Cargo.toml b/crates/dservice/Cargo.toml index 7fc862d..f575937 100644 --- a/crates/dservice/Cargo.toml +++ b/crates/dservice/Cargo.toml @@ -19,7 +19,6 @@ axum = { version = "0.7.3", features = ["macros"] } serde_json = "1.0.111" tower = { version = "0.4.13", features = ["timeout"] } tower-http = { version = "0.5.0", features = ["cors"] } -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } networking = { path = "../networking" } @@ -28,3 +27,4 @@ hex = "0.4.3" priority-queue = "2.0.2" dotenv = "0.15.0" bincode = "1.3.3" +params = { path = "../params" } diff --git a/crates/dservice/src/lib.rs b/crates/dservice/src/lib.rs index 9989bb8..7e50cd8 100644 --- a/crates/dservice/src/lib.rs +++ b/crates/dservice/src/lib.rs @@ -15,18 +15,18 @@ use axum::{ routing::post, BoxError, Json, Router, }; -use constants::{LOCAL_BLOCKS_CHECKPOINT, PRIMARY_BATCH, REORG_DEPTH, RESCHEDULING_DURATION}; -use db_handler::{DBHandler, InnerBlock, PgHandler}; +use db_handler::{DBHandler, InnerBlock}; use manager::{AccountInfo, Manager, SecpKey, ServerMessage, SharedState, TaskInfo}; use networking::{ decryption_message::{DecryptionMessage, ScanRequest, SuccessResponse}, rpc_abi::BlockInfo, socket_message::codec::DRequest, }; +use params::network::Network; use tokio::{net::TcpListener, sync::oneshot, time::sleep}; use tower::{timeout::TimeoutLayer, ServiceBuilder}; use tower_http::cors::{Any, CorsLayer}; -use tracing::{debug, error, info}; +use tracing::{debug, error, info, warn}; use utils::{blocks_range, default_secp, verify, Signature}; pub mod manager; @@ -37,13 +37,14 @@ pub async fn scheduling_tasks( accounts: &Vec, blocks: Vec, ) -> anyhow::Result<()> { - for account in accounts.iter() { - if let Some(account_info) = scheduler + for account in accounts { + let account_info_maybe = scheduler .account_mappling .read() .await .get(&account.address) - { + .cloned(); + if let Some(account_info) = account_info_maybe { debug!( "start scanning {} blocks for account {:?}", blocks.len(), @@ -102,11 +103,11 @@ pub async fn scheduling_tasks( Ok(()) } -pub async fn run_dserver( +pub async fn run_dserver( dlisten: SocketAddr, restful: SocketAddr, rpc_server: String, - db_handler: PgHandler, + db_handler: Box, server: String, sk_u8: [u8; 32], pk_u8: [u8; 33], @@ -116,39 +117,18 @@ pub async fn run_dserver( pk: pk_u8, }; let shared_resource = Arc::new(SharedState::new(db_handler, &rpc_server, &server, secp_key)); - let manager = Manager::new(shared_resource); + let manager = Manager::new(shared_resource, N::ID); if let Err(e) = Manager::initialize_networking(manager.clone(), dlisten).await { - error!("init networking server {}", e); + error!("Init networking server failed {}", e); } - // manager status updater - let status_manager = manager.clone(); - let (router, handler) = oneshot::channel(); - tokio::spawn(async move { - let _ = router.send(()); - loop { - { - info!( - "online workers: {}", - status_manager.workers.read().await.len() - ); - info!( - "pending taskes in queue: {}", - status_manager.task_queue.read().await.len() - ); - info!( - "pending account to scan: {:?}", - status_manager.accounts_to_scan.read().await - ); - } - sleep(Duration::from_secs(60)).await; - } - }); - let _ = handler.await; + if let Err(e) = Manager::initialize_status_updater(manager.clone()).await { + error!("Init status updater failed {}", e); + } { - info!("warmup, wait for worker to join"); + info!("Warmup, waiting for workers to join"); sleep(Duration::from_secs(60)).await; } @@ -158,7 +138,7 @@ pub async fn run_dserver( tokio::spawn(async move { let _ = router.send(()); loop { - sleep(RESCHEDULING_DURATION).await; + sleep(N::RESCHEDULING_DURATION).await; if !schduler.accounts_to_scan.read().await.is_empty() { if !schduler.account_mappling.read().await.is_empty() { continue; @@ -175,7 +155,7 @@ pub async fn run_dserver( let scan_end = schduler .shared .rpc_handler - .get_block(latest.index.parse::().unwrap() - REORG_DEPTH) + .get_block(latest.index.parse::().unwrap() - N::REORG_DEPTH) .unwrap() .data .block; @@ -191,6 +171,8 @@ pub async fn run_dserver( .get(&account.address) .is_some() { + // should never happen + warn!("Unexpected duplicated account to scan {}", account.address); continue; } let head = account.head.clone().unwrap(); @@ -209,10 +191,11 @@ pub async fn run_dserver( if accounts_should_scan.is_empty() { continue; } - info!("accounts to scanning, {:?}", accounts_should_scan); - let blocks_to_scan = blocks_range(scan_start..scan_end.sequence + 1, PRIMARY_BATCH); + info!("accounts to scan, {:?}", accounts_should_scan); + let blocks_to_scan = + blocks_range(scan_start..scan_end.sequence + 1, N::PRIMARY_BATCH); for group in blocks_to_scan { - let blocks = match group.end <= LOCAL_BLOCKS_CHECKPOINT { + let blocks = match group.end <= N::LOCAL_BLOCKS_CHECKPOINT { true => schduler .shared .db_handler @@ -253,6 +236,7 @@ pub async fn run_dserver( tokio::spawn(async move { let _ = router.send(()); loop { + let mut keys_to_reschedule = vec![]; for key in secondary .task_mapping .read() @@ -261,34 +245,72 @@ pub async fn run_dserver( .filter(|(_k, v)| v.since.elapsed().as_secs() >= 600) .map(|(k, _)| k.to_string()) { - info!("rescheduling task: {:?}", key); - match secondary.task_mapping.write().await.remove(&key) { - Some(task_info) => { - let address = task_info.address.to_string(); - let sequence = task_info.sequence; - if let Some(account) = secondary.account_mappling.read().await.get(&address) - { - if let Ok(block) = secondary.shared.rpc_handler.get_block(sequence) { - let block = block.data.block.to_inner(); - let _ = scheduling_tasks( - secondary.clone(), - &vec![ScanRequest { - address: address.clone(), - in_vk: account.in_vk.clone(), - out_vk: account.out_vk.clone(), - head: Some(account.start_block.clone()), - }], - vec![block], - ) - .await - .unwrap(); + keys_to_reschedule.push(key); + } + let keys_count = keys_to_reschedule.len(); + if keys_count > 0 { + info!("Rescheduling {} tasks", keys_count); + } + let mut tasks_to_resechedule = vec![]; + for key in keys_to_reschedule { + let key_maybe = secondary.task_mapping.write().await.remove(&key).clone(); + if let Some(task_info) = key_maybe { + let address = task_info.address; + let sequence = task_info.sequence; + let address_maybe = secondary + .account_mappling + .read() + .await + .get(&address) + .cloned(); + if let Some(account) = address_maybe { + if let Ok(block) = secondary.shared.rpc_handler.get_block(sequence) { + let block = block.data.block.to_inner(); + tasks_to_resechedule.push(( + vec![ScanRequest { + address: address.clone(), + in_vk: account.in_vk.clone(), + out_vk: account.out_vk.clone(), + head: Some(account.start_block.clone()), + }], + vec![block], + )); + if tasks_to_resechedule.len() % 500 == 0 { + info!( + "Tasks to reschedule len now {:?}", + tasks_to_resechedule.len() + ); + } + // We dont want to reschedule so many tasks at once + if tasks_to_resechedule.len() >= 20000 { + break; } } + } else { + error!("Account info missed for exist task, account {}", address); } - None => {} } } - sleep(RESCHEDULING_DURATION).await; + if !tasks_to_resechedule.is_empty() { + info!( + "Done prepping tasks to be rescheduled.. now rescheduling {:?}", + tasks_to_resechedule.len() + ); + } + let mut count = 0; + for (scan_request, blocks) in tasks_to_resechedule { + scheduling_tasks(secondary.clone(), &scan_request, blocks) + .await + .unwrap(); + if count % 1000 == 0 { + info!("Rescheduled tasks so far {:?}", count); + } + count += 1; + } + if count > 0 { + info!("Done rescheduling {:?} tasks", count); + } + sleep(N::RESCHEDULING_DURATION).await; } }); let _ = handler.await; @@ -343,7 +365,9 @@ pub async fn account_scanner_handler( &manager.shared.secp_key.pk, ) { if x { - let _ = manager.accounts_to_scan.write().await.push(message); + if !manager.should_skip_request(message.address.clone()).await { + let _ = manager.accounts_to_scan.write().await.push(message); + } return Json(SuccessResponse { success: true }); } } diff --git a/crates/dservice/src/main.rs b/crates/dservice/src/main.rs index 20ea164..a3e3b0f 100644 --- a/crates/dservice/src/main.rs +++ b/crates/dservice/src/main.rs @@ -2,10 +2,11 @@ use std::net::SocketAddr; use anyhow::Result; use clap::Parser; -use db_handler::{DBHandler, DbConfig, PgHandler}; +use db_handler::load_db; use dotenv::dotenv; use dservice::run_dserver; -use utils::{handle_signals, initialize_logger}; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; +use utils::{handle_signals, initialize_logger, initialize_logger_filter, EnvFilter}; #[derive(Parser, Debug, Clone)] pub struct Command { @@ -27,6 +28,9 @@ pub struct Command { /// The server to connect to #[clap(short, long, default_value = "127.0.0.1:9093")] pub server: String, + /// The network id, 0 for mainnet, 1 for testnet. + #[clap(long)] + pub network: u8, } #[tokio::main] @@ -46,20 +50,38 @@ async fn main() -> Result<()> { dbconfig, node, server, + network, } = args; initialize_logger(verbosity); + initialize_logger_filter(EnvFilter::from_default_env()); handle_signals().await?; - let db_config = DbConfig::load(dbconfig).unwrap(); - let db_handler = PgHandler::from_config(&db_config); - run_dserver( - dlisten.into(), - restful.into(), - node, - db_handler, - server, - sk_u8, - pk_u8, - ) - .await?; + let db_handler = load_db(dbconfig).unwrap(); + match network { + Mainnet::ID => { + run_dserver::( + dlisten.into(), + restful.into(), + node, + db_handler, + server, + sk_u8, + pk_u8, + ) + .await?; + } + Testnet::ID => { + run_dserver::( + dlisten.into(), + restful.into(), + node, + db_handler, + server, + sk_u8, + pk_u8, + ) + .await?; + } + _ => panic!("Invalid network used"), + } Ok(()) } diff --git a/crates/dservice/src/manager.rs b/crates/dservice/src/manager.rs index 59efe19..94bbaf8 100644 --- a/crates/dservice/src/manager.rs +++ b/crates/dservice/src/manager.rs @@ -7,8 +7,7 @@ use std::{ }; use anyhow::Result; -use constants::{MAINNET_GENESIS_HASH, MAINNET_GENESIS_SEQUENCE}; -use db_handler::{DBHandler, PgHandler}; +use db_handler::DBHandler; use futures::{SinkExt, StreamExt}; use networking::{ decryption_message::{DecryptionMessage, ScanRequest}, @@ -17,6 +16,7 @@ use networking::{ server_handler::ServerHandler, socket_message::codec::{DMessage, DMessageCodec, DRequest, DResponse}, }; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; use priority_queue::PriorityQueue; use serde::{Deserialize, Serialize}; use tokio::{ @@ -26,7 +26,7 @@ use tokio::{ mpsc::{self, Sender}, oneshot, RwLock, }, - time::timeout, + time::{sleep, timeout}, }; use tokio_util::codec::{FramedRead, FramedWrite}; use tracing::{debug, error, info, warn}; @@ -97,19 +97,23 @@ pub struct SecpKey { pub pk: [u8; 33], } -#[derive(Debug, Clone)] -pub struct SharedState { - pub db_handler: T, +pub struct SharedState { + pub db_handler: Box, pub rpc_handler: RpcHandler, pub server_handler: ServerHandler, pub secp_key: SecpKey, } -impl SharedState -where - T: DBHandler, -{ - pub fn new(db_handler: T, endpoint: &str, server: &str, secp_key: SecpKey) -> Self { +unsafe impl Send for SharedState {} +unsafe impl Sync for SharedState {} + +impl SharedState { + pub fn new( + db_handler: Box, + endpoint: &str, + server: &str, + secp_key: SecpKey, + ) -> Self { Self { db_handler: db_handler, rpc_handler: RpcHandler::new(endpoint.into()), @@ -119,18 +123,18 @@ where } } -#[derive(Debug, Clone)] pub struct Manager { pub workers: Arc>>, pub task_queue: Arc>>>, pub task_mapping: Arc>>, pub account_mappling: Arc>>, - pub shared: Arc>, + pub shared: Arc, pub accounts_to_scan: Arc>>, + pub network: u8, } impl Manager { - pub fn new(shared: Arc>) -> Arc { + pub fn new(shared: Arc, network: u8) -> Arc { Arc::new(Self { workers: Arc::new(RwLock::new(HashMap::new())), task_queue: Arc::new(RwLock::new(PriorityQueue::new())), @@ -138,9 +142,74 @@ impl Manager { account_mappling: Arc::new(RwLock::new(HashMap::new())), shared, accounts_to_scan: Arc::new(RwLock::new(vec![])), + network: network, }) } + pub fn genesis_block(&self) -> BlockInfo { + match self.network { + Mainnet::ID => BlockInfo { + hash: Mainnet::GENESIS_BLOCK_HASH.to_string(), + sequence: Mainnet::GENESIS_BLOCK_HEIGHT, + }, + Testnet::ID => BlockInfo { + hash: Testnet::GENESIS_BLOCK_HASH.to_string(), + sequence: Testnet::GENESIS_BLOCK_HEIGHT, + }, + _ => BlockInfo { + hash: Mainnet::GENESIS_BLOCK_HASH.to_string(), + sequence: Mainnet::GENESIS_BLOCK_HEIGHT, + }, + } + } + + pub async fn should_skip_request(&self, address: String) -> bool { + if self + .accounts_to_scan + .read() + .await + .iter() + .find(|account| account.address == address.clone()) + .is_some() + || self.account_mappling.read().await.get(&address).is_some() + { + return true; + } + false + } + + pub async fn initialize_status_updater(server: Arc) -> Result<()> { + let (router, handler) = oneshot::channel(); + tokio::spawn(async move { + let _ = router.send(()); + loop { + { + info!("online workers: {}", server.workers.read().await.len()); + info!( + "pending taskes in queue: {}", + server.task_queue.read().await.len() + ); + info!( + "scanning tasks: {:?}", + server.task_mapping.read().await.len() + ); + info!( + "pending account to scan: {:?}", + server.accounts_to_scan.read().await + ); + info!( + "scanning accounts: {:?}", + server.account_mappling.read().await + ); + } + sleep(Duration::from_secs(60)).await; + } + }); + let _ = handler.await; + info!("Status updater installed!"); + Ok(()) + } + pub async fn initialize_networking(server: Arc, addr: SocketAddr) -> Result<()> { let (router, handler) = oneshot::channel(); let listener = TcpListener::bind(&addr).await?; @@ -203,7 +272,7 @@ impl Manager { tokio::select! { _ = timer.tick() => { debug!("no message from worker {} for 5 mins, exit", worker_name); - let _ = worker_server.workers.write().await.remove(&worker_name).unwrap(); + let _ = worker_server.workers.write().await.remove(&worker_name); break; }, result = outbound_r.next() => { @@ -219,7 +288,7 @@ impl Manager { false => { let worker = ServerWorker::new(tx.clone()); worker_name = register.name; - debug!("new worker: {}", worker_name.clone()); + info!("new worker: {}", worker_name.clone()); let _ = worker_server.workers.write().await.insert(worker_name.clone(), worker); let data = worker_server.task_queue.write().await.pop(); match data { @@ -233,7 +302,7 @@ impl Manager { }, DMessage::DRequest(_) => { error!("invalid message from worker, should never happen"); - let _ = worker_server.workers.write().await.remove(&worker_name).unwrap(); + let _ = worker_server.workers.write().await.remove(&worker_name); break; }, DMessage::DResponse(response) => { @@ -251,7 +320,7 @@ impl Manager { }, _ => { warn!("unknown message"); - let _ = worker_server.workers.write().await.remove(&worker_name).unwrap(); + let _ = worker_server.workers.write().await.remove(&worker_name); break; }, } @@ -268,19 +337,16 @@ impl Manager { let address = response.address.clone(); let task_id = response.id.clone(); let mut update_account = false; - let mut latest_scanned_block = BlockInfo { - hash: MAINNET_GENESIS_HASH.to_string(), - sequence: MAINNET_GENESIS_SEQUENCE as u64, - }; match self.account_mappling.write().await.get_mut(&address) { Some(account) => { - if let Some(task_info) = self.task_mapping.read().await.get(&task_id) { - let block_hash = task_info.hash.to_string(); + let maybe_task = self.task_mapping.read().await.get(&task_id).cloned(); + if let Some(task_info) = maybe_task { + let block_hash = task_info.hash.clone(); if !response.data.is_empty() { - info!("account info: {:?}", account); + debug!("account info: {:?}", account); info!("new available block {} for account {}", block_hash, address); account.blocks.insert( - block_hash, + block_hash.clone(), response .data .into_iter() @@ -289,15 +355,9 @@ impl Manager { ); } account.remaining_task -= 1; - if account.remaining_task % 5000 == 0 { + if account.remaining_task == 0 { update_account = true; } - if task_info.sequence > latest_scanned_block.sequence as i64 { - latest_scanned_block = BlockInfo { - hash: task_info.hash.clone(), - sequence: task_info.sequence as u64, - }; - } } } None => { @@ -314,9 +374,9 @@ impl Manager { .clone(); let set_account_head_request = RpcSetAccountHeadRequest { account: address.clone(), - start: account_info.start_block.hash.to_string(), - end: latest_scanned_block.hash.clone(), - scan_complete: account_info.remaining_task == 0, + start: account_info.start_block.hash, + end: account_info.end_block.hash, + scan_complete: true, blocks: account_info .blocks .iter() @@ -335,14 +395,24 @@ impl Manager { message: set_account_head_request, signature, }; - match self.shared.server_handler.submit_scan_response(request) { - Ok(msg) => { - if msg.success && account_info.end_block.hash == latest_scanned_block.hash { - let _ = self.account_mappling.write().await.remove(&address); - } + let mut retry = 0; + loop { + if retry == 3 { + break; + } + if let Err(e) = self + .shared + .server_handler + .submit_scan_response(request.clone()) + { + error!("Submit scan result failed {}", e); + } else { + break; } - Err(e) => error!("failed to submit decryption response to server, {:?}", e), + retry += 1; } + info!("Scanning for account {} completed", address); + let _ = self.account_mappling.write().await.remove(&address); } let _ = self.task_mapping.write().await.remove(&task_id); Ok(()) diff --git a/crates/dworker/Cargo.toml b/crates/dworker/Cargo.toml index 0e8585e..a18e8c9 100644 --- a/crates/dworker/Cargo.toml +++ b/crates/dworker/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ironfish_rust = { package = "ironfish", git = "https://github.com/iron-fish/ironfish.git", branch = "master" } +ironfish_rust = { package = "ironfish", git = "https://github.com/oreoslabs/ironfish-optimize.git", branch = "feature/support-wasm" } anyhow = "1.0.79" clap = { version = "4.4.13", features = ["derive"] } tokio = { version = "1.35.1", features = ["full"] } @@ -15,7 +15,6 @@ tokio-util = { version = "0.7.3", features = ["codec"] } bytes = "1" futures = { version = "0.3.30" } tracing = "0.1.40" -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } networking = { path = "../networking" } diff --git a/crates/dworker/src/main.rs b/crates/dworker/src/main.rs index 74312e2..056e2ff 100644 --- a/crates/dworker/src/main.rs +++ b/crates/dworker/src/main.rs @@ -4,7 +4,7 @@ use dworker::start_worker; use rand::Rng; use std::net::SocketAddr; use tracing::info; -use utils::{handle_signals, initialize_logger}; +use utils::{handle_signals, initialize_logger, initialize_logger_filter, EnvFilter}; #[derive(Parser, Debug)] #[command(version, about)] @@ -24,6 +24,7 @@ struct Cli { async fn main() -> Result<()> { let mut args = Cli::parse(); initialize_logger(args.verbosity); + initialize_logger_filter(EnvFilter::from_default_env()); handle_signals().await?; if args.name.is_none() { args.name = Some( diff --git a/crates/networking/Cargo.toml b/crates/networking/Cargo.toml index a0a496c..fa125be 100644 --- a/crates/networking/Cargo.toml +++ b/crates/networking/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] serde = { version = "1.0.199", features = ["derive"] } serde_json = "1.0.111" -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } anyhow = "1.0.82" @@ -22,6 +21,7 @@ uuid = { version = "1.8.0", features = [ "fast-rng", # Use a faster (but still sufficiently random) RNG "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs ] } +params = { path = "../params" } [dev-dependencies] tokio = { version = "1.35.1", features = ["full"] } diff --git a/crates/networking/src/decryption_message.rs b/crates/networking/src/decryption_message.rs index a0aad89..97ef621 100644 --- a/crates/networking/src/decryption_message.rs +++ b/crates/networking/src/decryption_message.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::rpc_abi::BlockInfo; pub use crate::rpc_abi::RpcSetAccountHeadRequest as ScanResponse; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct DecryptionMessage { pub message: T, pub signature: String, diff --git a/crates/networking/src/orescriptions.rs b/crates/networking/src/orescriptions.rs index c3c822f..7db530f 100644 --- a/crates/networking/src/orescriptions.rs +++ b/crates/networking/src/orescriptions.rs @@ -1,4 +1,4 @@ -use constants::{IRON_NATIVE_ASSET, OREOSRIPTIONS_ENDPOINT, OREOS_VALUE}; +use params::network::Network; use serde::{Deserialize, Serialize}; use crate::rpc_abi::AssetBalance; @@ -14,25 +14,27 @@ pub struct Ores { pub removed_by_owner: bool, } -pub fn is_ores_local(asset: &AssetBalance) -> bool { - asset.asset_id != IRON_NATIVE_ASSET.to_string() - && asset.confirmed == OREOS_VALUE.to_string() - && asset.unconfirmed == OREOS_VALUE.to_string() +pub fn is_ores_local(asset: &AssetBalance) -> bool { + asset.asset_id != N::NATIVE_ASSET_ID.to_string() + && asset.confirmed == "1".to_string() + && asset.unconfirmed == "1".to_string() } -pub async fn get_ores(id: &str) -> anyhow::Result { - let path = format!("{}/orescription/{}", OREOSRIPTIONS_ENDPOINT, id); +pub async fn get_ores(id: &str) -> anyhow::Result { + let path = format!("{}/orescription/{}", N::OREOSRIPTIONS_ENDPOINT, id); Ok(ureq::get(&path).call()?.into_json()?) } #[cfg(test)] mod tests { + use params::mainnet::Mainnet; + use crate::orescriptions::get_ores; #[tokio::test] pub async fn check_ores_should_work() { let asset_id = "6272e464d84761d9c6247d9d4d2feb42964a5b2a71b9b179df27bbe0730c88af"; - let ores = get_ores(asset_id).await; + let ores = get_ores::(asset_id).await; assert!(ores.is_ok()); match ores { Ok(ore) => { @@ -45,7 +47,7 @@ mod tests { #[tokio::test] pub async fn check_ores_should_fail() { let asset_id = "6272e464d84761d9c6247d9d4d2feb42964a5b2a71b9b179df27bbe0x30c88af"; - let ores = get_ores(asset_id).await; + let ores = get_ores::(asset_id).await; assert!(ores.is_err()); match ores { Ok(ore) => { diff --git a/crates/networking/src/rpc_abi.rs b/crates/networking/src/rpc_abi.rs index 8686f91..93e57a0 100644 --- a/crates/networking/src/rpc_abi.rs +++ b/crates/networking/src/rpc_abi.rs @@ -1,5 +1,5 @@ use axum::{response::IntoResponse, Json}; -use constants::IRON_NATIVE_ASSET; +use params::network::Network; use serde::{Deserialize, Serialize}; use ureq::json; @@ -13,7 +13,7 @@ pub struct RpcResponse { #[derive(Debug, Deserialize, Serialize)] pub struct RpcResponseStream { - pub data: T + pub data: T, } impl IntoResponse for RpcResponse { @@ -28,6 +28,14 @@ pub struct BlockInfo { pub sequence: u64, } +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CreatedAt { + pub hash: String, + pub sequence: u64, + pub network_id: u8, +} + #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct RpcImportAccountRequest { @@ -37,7 +45,7 @@ pub struct RpcImportAccountRequest { pub incoming_view_key: String, pub outgoing_view_key: String, pub public_address: String, - pub created_at: Option, + pub created_at: Option, pub spending_key: Option, } @@ -105,6 +113,14 @@ pub struct RpcSetAccountHeadRequest { pub scan_complete: bool, } +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct RpcSetAccountHeadRequestV2 { + pub account: String, + pub start: String, + pub end: String, + pub blocks: Vec, +} + #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct RpcResetAccountRequest { @@ -135,6 +151,7 @@ pub struct AssetBalance { pub available: String, pub sequence: Option, pub asset_verification: AssetStatus, + pub decimals: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -144,14 +161,14 @@ pub struct RpcGetBalancesResponse { } impl RpcGetBalancesResponse { - pub fn verified_asset(base: Self) -> Self { + pub fn verified_asset(base: Self) -> Self { Self { balances: base .balances .into_iter() .filter(|x| { x.asset_verification.status == "verified".to_string() - || x.asset_id == IRON_NATIVE_ASSET + || x.asset_id == N::NATIVE_ASSET_ID.to_string() || x.asset_name == "6f7265736372697074696f6e7300000000000000000000000000000000000000" .to_string() @@ -161,13 +178,13 @@ impl RpcGetBalancesResponse { } } - pub async fn ores(base: Self) -> Vec { + pub async fn ores(base: Self) -> Vec { let mut result = vec![]; for asset in base.balances.iter() { - if !is_ores_local(asset) { + if !is_ores_local::(asset) { continue; } - if let Ok(ores) = get_ores(&asset.asset_id).await { + if let Ok(ores) = get_ores::(&asset.asset_id).await { result.push(ores); } } @@ -186,10 +203,10 @@ pub struct OutPut { } impl OutPut { - pub fn from(base: OutPut) -> Self { + pub fn from(base: OutPut) -> Self { let memo = Some(base.memo.unwrap_or("".into())); let memo_hex = Some(base.memo_hex.unwrap_or("".into())); - let asset_id = Some(base.asset_id.unwrap_or(IRON_NATIVE_ASSET.into())); + let asset_id = Some(base.asset_id.unwrap_or(N::NATIVE_ASSET_ID.into())); Self { memo, memo_hex, @@ -383,3 +400,20 @@ pub struct SendTransactionResponse { pub account: String, pub hash: String, } + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RpcAssetVerification { + pub status: String, + pub symbol: Option, + pub decimals: Option, + pub logo_uri: Option, + pub website: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RpcAsset { + pub id: String, + pub verification: RpcAssetVerification, +} diff --git a/crates/networking/src/rpc_handler/handler.rs b/crates/networking/src/rpc_handler/handler.rs index 7c4190b..d6f388e 100644 --- a/crates/networking/src/rpc_handler/handler.rs +++ b/crates/networking/src/rpc_handler/handler.rs @@ -8,17 +8,18 @@ use ureq::{Agent, AgentBuilder, Error, Response}; use crate::{ rpc_abi::{ - RpcAddTxRequest, RpcAddTxResponse, RpcCreateTxRequest, RpcCreateTxResponse, + RpcAddTxRequest, RpcAddTxResponse, RpcAsset, RpcCreateTxRequest, RpcCreateTxResponse, RpcExportAccountResponse, RpcGetAccountStatusRequest, RpcGetAccountStatusResponse, RpcGetAccountTransactionRequest, RpcGetAccountTransactionResponse, RpcGetBalancesRequest, RpcGetBalancesResponse, RpcGetBlockRequest, RpcGetBlockResponse, RpcGetBlocksRequest, RpcGetBlocksResponse, RpcGetLatestBlockResponse, RpcGetTransactionsRequest, RpcGetTransactionsResponse, RpcImportAccountRequest, RpcImportAccountResponse, RpcRemoveAccountRequest, RpcRemoveAccountResponse, RpcResetAccountRequest, RpcResponse, - RpcSetAccountHeadRequest, RpcSetScanningRequest, SendTransactionRequest, - SendTransactionResponse, TransactionStatus, + RpcSetAccountHeadRequest, RpcSetAccountHeadRequestV2, RpcSetScanningRequest, + SendTransactionRequest, SendTransactionResponse, TransactionStatus, }, - rpc_handler::RpcError, stream::ResponseExt, + rpc_handler::RpcError, + stream::ResponseExt, }; #[derive(Debug, Clone)] @@ -43,7 +44,8 @@ impl RpcHandler { request: RpcImportAccountRequest, ) -> Result, OreoError> { let path = format!("http://{}/wallet/importAccount", self.endpoint); - let account_str = serde_json::to_string(&request).map_err(|_|OreoError::InternalRpcError("JSON serialization failed".to_string()))?; + let account_str = serde_json::to_string(&request) + .map_err(|_| OreoError::InternalRpcError("JSON serialization failed".to_string()))?; let resp = self .agent .clone() @@ -106,6 +108,19 @@ impl RpcHandler { &self, request: RpcSetAccountHeadRequest, ) -> Result>, OreoError> { + let RpcSetAccountHeadRequest { + account, + start, + end, + blocks, + .. + } = request; + let request = RpcSetAccountHeadRequestV2 { + account, + start, + end, + blocks, + }; let path = format!("http://{}/wallet/setAccountHead", self.endpoint); let resp = self.agent.clone().post(&path).send_json(&request); handle_response(resp) @@ -144,13 +159,12 @@ impl RpcHandler { ) -> Result, OreoError> { let path = format!("http://{}/wallet/getAccountTransactions", self.endpoint); let resp = self.agent.clone().post(&path).send_json(&request); - + match resp { Ok(response) => { - let transactions: Result, OreoError> = response - .into_stream::() - .collect(); - + let transactions: Result, OreoError> = + response.into_stream::().collect(); + Ok(RpcResponse { status: 200, data: RpcGetTransactionsResponse { @@ -209,7 +223,11 @@ impl RpcHandler { .agent .clone() .post(&path) - .send_json(RpcGetBlocksRequest { start, end, serialized: true }); + .send_json(RpcGetBlocksRequest { + start, + end, + serialized: true, + }); handle_response(resp) } @@ -221,6 +239,12 @@ impl RpcHandler { let resp = self.agent.clone().post(&path).send_json(request); handle_response(resp) } + + pub fn get_asset(&self, id: String) -> Result, OreoError> { + let path = format!("http://{}/chain/getAsset", self.endpoint); + let resp = self.agent.clone().post(&path).send_json(json!({"id": id})); + handle_response(resp) + } } pub fn handle_response Deserialize<'a>>( @@ -296,4 +320,16 @@ mod tests { }); assert!(result.is_ok()); } + + #[test] + pub fn get_asset_should_work() { + let rpc_handler = RpcHandler::new("127.0.0.1:8021".into()); + let header = rpc_handler.get_latest_block(); + println!("chain header {:?}", header); + let result = rpc_handler.get_asset( + "8e36e31d677a47cbd883843a345654c814b1e9ec1e0125bac9031f052ced9174".to_string(), + ); + println!("asset info: {:?}", result); + assert!(result.is_ok()); + } } diff --git a/crates/networking/src/stream.rs b/crates/networking/src/stream.rs index cdc8b5f..a5eb335 100644 --- a/crates/networking/src/stream.rs +++ b/crates/networking/src/stream.rs @@ -20,46 +20,54 @@ enum ResponseItem { Status { status: u16 }, } -impl StreamReader where T: DeserializeOwned, R: Read { +impl StreamReader +where + T: DeserializeOwned, + R: Read, +{ pub fn new(reader: R) -> Self { - Self { - reader: BufReader::new(reader), - _marker: PhantomData, - } + Self { + reader: BufReader::new(reader), + _marker: PhantomData, + } } fn read_item(&mut self) -> Result>, OreoError> { - let mut item = Vec::new(); - loop { - let bytes_read = self.reader.read_until(b'\x0c', &mut item) - .map_err(|e| OreoError::RpcStreamError(e.to_string()))?; - if bytes_read == 0 { - break; - } - if item.last() == Some(&b'\x0c') { - item.pop(); - break; - } - } - match item.len() { - 0 => Ok(None), - _ => Ok(Some(item)) - } + let mut item = Vec::new(); + loop { + let bytes_read = self + .reader + .read_until(b'\x0c', &mut item) + .map_err(|e| OreoError::RpcStreamError(e.to_string()))?; + if bytes_read == 0 { + break; + } + if item.last() == Some(&b'\x0c') { + item.pop(); + break; + } + } + match item.len() { + 0 => Ok(None), + _ => Ok(Some(item)), + } } - /// Parses a chunk of data into a `ResponseItem`. fn parse_item(&self, chunk: &[u8]) -> Result, OreoError> { - match serde_json::from_slice::>(chunk) { - Ok(ResponseItem::Data(item)) => Ok(Some(item.data)), - Ok(ResponseItem::Status { status: 200 }) => Ok(None), - Ok(ResponseItem::Status { status }) => Err(OreoError::RpcStreamError(format!("Received error status: {}", status))), - Err(e) => { - let err_str = format!("Failed to parse JSON object: {:?}", e); - Err(OreoError::RpcStreamError(err_str)) - } - } - } + match serde_json::from_slice::>(chunk) { + Ok(ResponseItem::Data(item)) => Ok(Some(item.data)), + Ok(ResponseItem::Status { status: 200 }) => Ok(None), + Ok(ResponseItem::Status { status }) => Err(OreoError::RpcStreamError(format!( + "Received error status: {}", + status + ))), + Err(e) => { + let err_str = format!("Failed to parse JSON object: {:?}", e); + Err(OreoError::RpcStreamError(err_str)) + } + } + } } impl Iterator for StreamReader @@ -83,11 +91,15 @@ where } pub trait ResponseExt { - fn into_stream(self) -> StreamReader>; + fn into_stream( + self, + ) -> StreamReader>; } impl ResponseExt for Response { - fn into_stream(self) -> StreamReader> { + fn into_stream( + self, + ) -> StreamReader> { let reader = self.into_reader(); StreamReader::new(Box::new(reader)) } @@ -103,15 +115,17 @@ mod tests { fn test_stream_reader_with_status() { // Prepare some test data. let transaction_status = TransactionStatus { - hash: "cde4c2a5bc7cb6cbad93a414ff76176e07412fbd48f2f3d1ee8f7fc1238626a5".to_string(), - fee: "1".to_string(), - r#type: "type".to_string(), - status: "status".to_string(), - block_sequence: Some(1), - timestamp: 1, - asset_balance_deltas: Vec::new(), + hash: "cde4c2a5bc7cb6cbad93a414ff76176e07412fbd48f2f3d1ee8f7fc1238626a5".to_string(), + fee: "1".to_string(), + r#type: "type".to_string(), + status: "status".to_string(), + block_sequence: Some(1), + timestamp: 1, + asset_balance_deltas: Vec::new(), + }; + let item1: RpcResponseStream = RpcResponseStream { + data: transaction_status.clone(), }; - let item1: RpcResponseStream = RpcResponseStream { data: transaction_status.clone() }; let response1 = ResponseItem::Data(item1); let status = ResponseItem::::Status { status: 200 }; @@ -129,9 +143,15 @@ mod tests { assert_eq!(returned_status.fee, transaction_status.fee); assert_eq!(returned_status.r#type, transaction_status.r#type); assert_eq!(returned_status.status, transaction_status.status); - assert_eq!(returned_status.block_sequence, transaction_status.block_sequence); + assert_eq!( + returned_status.block_sequence, + transaction_status.block_sequence + ); assert_eq!(returned_status.timestamp, transaction_status.timestamp); - assert_eq!(returned_status.asset_balance_deltas.len(), transaction_status.asset_balance_deltas.len()); + assert_eq!( + returned_status.asset_balance_deltas.len(), + transaction_status.asset_balance_deltas.len() + ); } #[test] @@ -155,8 +175,10 @@ mod tests { assert_eq!(items[0], Ok(42u32)); match &items[1] { - Err(OreoError::RpcStreamError(msg)) => assert!(msg.contains("Received error status: 500")), + Err(OreoError::RpcStreamError(msg)) => { + assert!(msg.contains("Received error status: 500")) + } _ => panic!("Expected error with status code 500"), } } - } \ No newline at end of file +} diff --git a/crates/networking/src/web_abi.rs b/crates/networking/src/web_abi.rs index 4eba0a2..8bff43a 100644 --- a/crates/networking/src/web_abi.rs +++ b/crates/networking/src/web_abi.rs @@ -1,4 +1,3 @@ -use constants::MAINNET_GENESIS_SEQUENCE; use db_handler::{address_to_name, Account}; use oreo_errors::OreoError; use serde::{Deserialize, Serialize}; @@ -23,7 +22,7 @@ pub struct ImportAccountResponse { } impl ImportAccountRequest { - pub fn to_account(&self, genesis_hash: String) -> Account { + pub fn to_account(&self, genesis: BlockInfo) -> Account { let (create_head, create_hash) = match &self.created_at { Some(creat) => (Some(creat.sequence as i64), Some(creat.hash.clone())), None => (None, None), @@ -33,8 +32,8 @@ impl ImportAccountRequest { name: address_to_name(&self.public_address), create_head, create_hash: create_hash.clone(), - head: create_head.unwrap_or(MAINNET_GENESIS_SEQUENCE), - hash: create_hash.unwrap_or(genesis_hash), + head: create_head.unwrap_or(genesis.sequence as i64), + hash: create_hash.unwrap_or(genesis.hash), in_vk: self.incoming_view_key.clone(), out_vk: self.outgoing_view_key.clone(), vk: self.view_key.clone(), @@ -72,7 +71,8 @@ impl TransactionDetail { notes, } = tx; let notes = notes.unwrap(); - let note = notes.iter() + let note = notes + .iter() .find(|asset| asset.owner != asset.sender) .or_else(|| notes.iter().find(|note| !note.memo.is_empty())) .or_else(|| notes.first()); diff --git a/crates/oreo_errors/src/lib.rs b/crates/oreo_errors/src/lib.rs index f436385..80ff9d9 100644 --- a/crates/oreo_errors/src/lib.rs +++ b/crates/oreo_errors/src/lib.rs @@ -21,6 +21,10 @@ pub enum OreoError { DBError, #[error("Internal Ironfish rpc error")] InternalRpcError(String), + #[error("Too many proofs to handle")] + TooManyProofs, + #[error("Generate `{0}` proof failed")] + GenerateProofError(String), #[error("The `{0}` spend circuit can not generate proof")] GenerateSpendProofFailed(u32), #[error("The `{0}` output circuit can not generate proof")] @@ -53,7 +57,9 @@ impl IntoResponse for OreoError { OreoError::NoImported(_) => (StatusCode::from_u16(602).unwrap(), self.to_string()), OreoError::Scanning(_) => (StatusCode::from_u16(603).unwrap(), self.to_string()), OreoError::Syncing => (StatusCode::from_u16(604).unwrap(), self.to_string()), - OreoError::InternalRpcError(_) => (StatusCode::from_u16(605).unwrap(), self.to_string()), + OreoError::InternalRpcError(_) => { + (StatusCode::from_u16(605).unwrap(), self.to_string()) + } OreoError::GenerateSpendProofFailed(_) => { (StatusCode::from_u16(606).unwrap(), self.to_string()) } @@ -73,6 +79,10 @@ impl IntoResponse for OreoError { OreoError::DServerError => (StatusCode::from_u16(614).unwrap(), self.to_string()), OreoError::Unauthorized => (StatusCode::UNAUTHORIZED, self.to_string()), OreoError::RpcStreamError(_) => (StatusCode::from_u16(615).unwrap(), self.to_string()), + OreoError::TooManyProofs => (StatusCode::from_u16(616).unwrap(), self.to_string()), + OreoError::GenerateProofError(_) => { + (StatusCode::from_u16(617).unwrap(), self.to_string()) + } }; Json(json!({"code": status_code.as_u16(), "error": err_msg})).into_response() } diff --git a/crates/params/Cargo.toml b/crates/params/Cargo.toml new file mode 100644 index 0000000..dc85598 --- /dev/null +++ b/crates/params/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "params" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/crates/params/src/lib.rs b/crates/params/src/lib.rs new file mode 100644 index 0000000..f385195 --- /dev/null +++ b/crates/params/src/lib.rs @@ -0,0 +1,3 @@ +pub mod mainnet; +pub mod network; +pub mod testnet; diff --git a/crates/params/src/mainnet.rs b/crates/params/src/mainnet.rs new file mode 100644 index 0000000..1bb294d --- /dev/null +++ b/crates/params/src/mainnet.rs @@ -0,0 +1,32 @@ +use crate::network::Network; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct Mainnet; + +impl Network for Mainnet { + const ID: u8 = 1; + + const NAME: &'static str = "mainnet"; + + const GENESIS_BLOCK_HASH: &'static str = + "eac623b099b8081d2bde92d43a4a7795385c94e2c0ae4097ef488972e83ff2b3"; + + const GENESIS_BLOCK_HEIGHT: u64 = 1; + + const NATIVE_ASSET_ID: &'static str = + "51f33a2f14f92735e562dc658a5639279ddca3d5079a6d1242b2a588a9cbf44c"; + + const ACCOUNT_VERSION: u8 = 2; + + const OREOSRIPTIONS_ENDPOINT: &'static str = "https://api.orescriptions.com/v1/api"; + + const REORG_DEPTH: i64 = 100; + + const PRIMARY_BATCH: u64 = 100; + + const SECONDARY_BATCH: i64 = 10000; + + const RESCHEDULING_DURATION: std::time::Duration = std::time::Duration::from_secs(30); + + const LOCAL_BLOCKS_CHECKPOINT: u64 = 900_000; +} diff --git a/crates/params/src/network.rs b/crates/params/src/network.rs new file mode 100644 index 0000000..81737bb --- /dev/null +++ b/crates/params/src/network.rs @@ -0,0 +1,28 @@ +use std::{fmt::Debug, time::Duration}; + +pub trait Network: 'static + Send + Sync + Debug + Eq + PartialEq + Copy + Clone { + /// The network ID. + const ID: u8; + /// The network name. + const NAME: &'static str; + /// The block hash of the genesis block. + const GENESIS_BLOCK_HASH: &'static str; + /// The block height of the genesis block. + const GENESIS_BLOCK_HEIGHT: u64; + /// The native token ID. + const NATIVE_ASSET_ID: &'static str; + /// The account version. + const ACCOUNT_VERSION: u8; + /// The orescriptions endpoint. + const OREOSRIPTIONS_ENDPOINT: &'static str; + /// The reorg-depth to handle. + const REORG_DEPTH: i64; + /// The batch size for primary scan scheduling. + const PRIMARY_BATCH: u64; + /// The batch size for secondary scan scheduling. + const SECONDARY_BATCH: i64; + /// The time duration to rescheduling scan task. + const RESCHEDULING_DURATION: Duration; + /// The local block checkpoint for scanning. + const LOCAL_BLOCKS_CHECKPOINT: u64; +} diff --git a/crates/params/src/testnet.rs b/crates/params/src/testnet.rs new file mode 100644 index 0000000..bdfba39 --- /dev/null +++ b/crates/params/src/testnet.rs @@ -0,0 +1,32 @@ +use crate::network::Network; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct Testnet; + +impl Network for Testnet { + const ID: u8 = 0; + + const NAME: &'static str = "testnet"; + + const GENESIS_BLOCK_HASH: &'static str = + "7999c680bbd15d9adb7392e0c27a7caac7e596de5560c18e96365d0fd68140e3"; + + const GENESIS_BLOCK_HEIGHT: u64 = 1; + + const NATIVE_ASSET_ID: &'static str = + "51f33a2f14f92735e562dc658a5639279ddca3d5079a6d1242b2a588a9cbf44c"; + + const ACCOUNT_VERSION: u8 = 2; + + const OREOSRIPTIONS_ENDPOINT: &'static str = "https://testnet_api.orescriptions.com/v1/api"; + + const REORG_DEPTH: i64 = 100; + + const PRIMARY_BATCH: u64 = 100; + + const SECONDARY_BATCH: i64 = 10000; + + const RESCHEDULING_DURATION: std::time::Duration = std::time::Duration::from_secs(30); + + const LOCAL_BLOCKS_CHECKPOINT: u64 = 830_000; +} diff --git a/crates/prover/Cargo.toml b/crates/prover/Cargo.toml index 6a4c1ac..98a9bbb 100644 --- a/crates/prover/Cargo.toml +++ b/crates/prover/Cargo.toml @@ -15,13 +15,14 @@ tower = { version = "0.4.13", features = ["timeout"] } tower-http = { version = "0.5.0", features = ["cors"] } tracing = "0.1.40" utils = { path = "../utils" } -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } networking = { path = "../networking" } -ironfish_rust = { package = "ironfish", git = "https://github.com/iron-fish/ironfish.git", branch = "master" } -ironfish_zkp = { package = "ironfish_zkp", git = "https://github.com/iron-fish/ironfish.git", branch = "master" } -ironfish-bellperson = { version = "0.1.0", features = ["groth16"] } +ironfish_rust = { package = "ironfish", git = "https://github.com/oreoslabs/ironfish-optimize.git", branch = "feature/support-wasm" } +ironfish_zkp = { package = "ironfish_zkp", git = "https://github.com/oreoslabs/ironfish-optimize.git", branch = "feature/support-wasm" } +bellperson = { git = "https://github.com/iron-fish/bellperson.git", branch = "blstrs", features = [ + "groth16", +] } blst = "=0.3.10" blstrs = { version = "0.6.0", features = ["portable"] } rand = "0.8.5" diff --git a/crates/prover/src/handlers.rs b/crates/prover/src/handlers.rs index ddc0171..9e64f7a 100644 --- a/crates/prover/src/handlers.rs +++ b/crates/prover/src/handlers.rs @@ -1,7 +1,5 @@ -use std::sync::{Arc, Mutex}; - use axum::{extract, response::IntoResponse, Json}; -use ironfish_bellperson::groth16; +use bellperson::groth16; use ironfish_rust::sapling_bls12::SAPLING; use ironfish_zkp::proofs::{MintAsset, Output, Spend}; use networking::web_abi::{GenerateProofRequest, GenerateProofResponse}; @@ -9,18 +7,24 @@ use oreo_errors::OreoError; use rand::thread_rng; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use serde_json::json; -use tracing::{error, info}; +use tracing::info; + +use crate::MAX_SPEND_PROOFS; pub async fn generate_proof_handler( extract::Json(request): extract::Json, ) -> impl IntoResponse { - info!("calling generate_proof_handler"); - let failed_index = Arc::new(Mutex::new(0u32)); + info!("New proof generation task"); + let spend_proofs_needed = request.spend_circuits.len(); + if spend_proofs_needed >= MAX_SPEND_PROOFS { + return OreoError::TooManyProofs.into_response(); + } + let spend_proofs = request .spend_circuits .par_iter() .enumerate() - .map(|(idx, bytes)| { + .map(|(_, bytes)| { let proof_bytes = if let Ok(spend) = Spend::read(&bytes[..]) { let proof = groth16::create_random_proof(spend, &SAPLING.spend_params, &mut thread_rng()); @@ -34,25 +38,21 @@ pub async fn generate_proof_handler( } else { None }; - if proof_bytes.is_none() { - *failed_index.lock().unwrap() = idx as u32 + 1; - error!("generate spend proof failed"); - return vec![]; - } - proof_bytes.unwrap() + proof_bytes }) - .collect(); + .flatten() + .collect::>>(); - let idx = *failed_index.lock().unwrap(); - if idx > 0 { - return OreoError::GenerateSpendProofFailed(idx - 1).into_response(); + if spend_proofs.len() < spend_proofs_needed { + return OreoError::GenerateProofError("spend".to_string()).into_response(); } + let output_proofs_needed = request.output_circuits.len(); let output_proofs = request .output_circuits .par_iter() .enumerate() - .map(|(idx, bytes)| { + .map(|(_, bytes)| { let proof_bytes = if let Ok(output) = Output::read(&bytes[..]) { let proof = groth16::create_random_proof(output, &SAPLING.output_params, &mut thread_rng()); @@ -66,25 +66,21 @@ pub async fn generate_proof_handler( } else { None }; - if proof_bytes.is_none() { - *failed_index.lock().unwrap() = idx as u32 + 1; - error!("generate output proof failed"); - return vec![]; - } - proof_bytes.unwrap() + proof_bytes }) - .collect(); + .flatten() + .collect::>>(); - let idx = *failed_index.lock().unwrap(); - if idx > 0 { - return OreoError::GenerateSpendProofFailed(idx - 1).into_response(); + if output_proofs.len() < output_proofs_needed { + return OreoError::GenerateProofError("output".to_string()).into_response(); } + let mint_asset_proofs_needed = request.mint_asset_circuits.len(); let mint_asset_proofs = request .mint_asset_circuits .par_iter() .enumerate() - .map(|(idx, bytes)| { + .map(|(_, bytes)| { let proof_bytes = if let Ok(mint_asset) = MintAsset::read(&bytes[..]) { let proof = groth16::create_random_proof( mint_asset, @@ -101,18 +97,13 @@ pub async fn generate_proof_handler( } else { None }; - if proof_bytes.is_none() { - *failed_index.lock().unwrap() = idx as u32 + 1; - error!("generate mint asset proof failed"); - return vec![]; - } - proof_bytes.unwrap() + proof_bytes }) - .collect(); + .flatten() + .collect::>>(); - let idx = *failed_index.lock().unwrap(); - if idx > 0 { - return OreoError::GenerateMintAssetProofFailed(idx - 1).into_response(); + if mint_asset_proofs.len() < mint_asset_proofs_needed { + return OreoError::GenerateProofError("mint asset".to_string()).into_response(); } let proof = GenerateProofResponse { @@ -120,7 +111,7 @@ pub async fn generate_proof_handler( output_proofs, mint_asset_proofs, }; - + info!("New proof generated"); Json(json!({"code": 200, "data": proof})).into_response() } diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index 3a0efb3..77ec6c9 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -7,7 +7,7 @@ use axum::{ routing::{get, post}, BoxError, Router, }; -use tokio::net::TcpListener; +use tokio::{net::TcpListener, signal, time::sleep}; use tower::{timeout::TimeoutLayer, ServiceBuilder}; use tower_http::cors::{Any, CorsLayer}; use tracing::info; @@ -15,6 +15,7 @@ use tracing::info; use crate::handlers::{generate_proof_handler, health_check_handler}; pub mod handlers; +pub const MAX_SPEND_PROOFS: usize = 15; pub async fn run_prover(listen: SocketAddr) -> anyhow::Result<()> { let router = Router::new() @@ -36,10 +37,42 @@ pub async fn run_prover(listen: SocketAddr) -> anyhow::Result<()> { let listener = TcpListener::bind(&listen).await?; let app = router.fallback(handler_404); info!("Prover listening on {}", listen); - axum::serve(listener, app).await?; + axum::serve(listener, app) + .with_graceful_shutdown(shutdown_signal()) + .await?; Ok(()) } async fn handler_404() -> impl IntoResponse { (StatusCode::NOT_FOUND, "Not Found") } + +async fn shutdown_signal() { + let ctrl_c = async { + signal::ctrl_c() + .await + .expect("failed to install Ctrl+C handler"); + }; + + #[cfg(unix)] + let terminate = async { + signal::unix::signal(signal::unix::SignalKind::terminate()) + .expect("failed to install signal handler") + .recv() + .await; + }; + + #[cfg(not(unix))] + let terminate = std::future::pending::<()>(); + + tokio::select! { + _ = ctrl_c => { + info!("Ctrl+C received, exit"); + sleep(Duration::from_secs(3)).await; + }, + _ = terminate => { + info!("terminate signal received, exit"); + sleep(Duration::from_secs(3)).await; + }, + } +} diff --git a/crates/prover/src/main.rs b/crates/prover/src/main.rs index 9d5b91e..77f541a 100644 --- a/crates/prover/src/main.rs +++ b/crates/prover/src/main.rs @@ -3,24 +3,26 @@ use std::net::SocketAddr; use anyhow::Result; use clap::Parser; use prover::run_prover; -use utils::{handle_signals, initialize_logger}; +use tracing::info; +use utils::{initialize_logger, initialize_logger_filter, EnvFilter}; #[derive(Parser, Debug, Clone)] -pub struct Command { - /// The ip:port server will listen on +pub struct Prover { + /// The ip:port prover will listen on #[clap(short, long, default_value = "0.0.0.0:10002")] - pub listen: SocketAddr, - /// Set your logger level + listen: SocketAddr, + /// Set prover logger level #[clap(short, long, default_value = "0")] - pub verbosity: u8, + verbosity: u8, } #[tokio::main] async fn main() -> Result<()> { - let args = Command::parse(); - let Command { listen, verbosity } = args; - initialize_logger(verbosity); - handle_signals().await?; - run_prover(listen.into()).await?; + let prover = Prover::parse(); + initialize_logger(prover.verbosity); + let filter = EnvFilter::from_default_env().add_directive("bellperson=off".parse().unwrap()); + initialize_logger_filter(filter); + info!("Prover starts {:?}", prover); + run_prover(prover.listen).await?; Ok(()) } diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index a15efdd..8bbc9dc 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -16,7 +16,6 @@ tower-http = { version = "0.5.0", features = ["cors"] } tracing = "0.1.40" utils = { path = "../utils" } networking = { path = "../networking" } -constants = { path = "../constants" } oreo_errors = { path = "../oreo_errors" } db_handler = { path = "../db_handler" } serde_json = "1.0.117" @@ -24,3 +23,4 @@ dotenv = "0.15.0" bincode = "1.3.3" hex = "0.4.3" sha2 = "0.10.8" +params = { path = "../params" } diff --git a/crates/server/src/handlers.rs b/crates/server/src/handlers.rs index 22166e8..f2a2cc5 100644 --- a/crates/server/src/handlers.rs +++ b/crates/server/src/handlers.rs @@ -5,32 +5,33 @@ use axum::{ response::IntoResponse, Json, }; -use constants::{ACCOUNT_VERSION, MAINNET_GENESIS_SEQUENCE}; -use db_handler::DBHandler; use networking::{ decryption_message::{DecryptionMessage, ScanRequest, ScanResponse, SuccessResponse}, rpc_abi::{ - BlockInfo, OutPut, RpcAddTxRequest, RpcCreateTxRequest, RpcGetAccountStatusRequest, - RpcGetAccountTransactionRequest, RpcGetBalancesRequest, RpcGetBalancesResponse, - RpcGetTransactionsRequest, RpcImportAccountRequest, RpcImportAccountResponse, - RpcRemoveAccountRequest, RpcResetAccountRequest, RpcResponse, RpcSetScanningRequest, + BlockInfo, CreatedAt, OutPut, RpcAddTxRequest, RpcCreateTxRequest, + RpcGetAccountStatusRequest, RpcGetAccountTransactionRequest, RpcGetBalancesRequest, + RpcGetBalancesResponse, RpcGetTransactionsRequest, RpcImportAccountRequest, + RpcImportAccountResponse, RpcRemoveAccountRequest, RpcResetAccountRequest, RpcResponse, + RpcSetScanningRequest, }, web_abi::{GetTransactionDetailResponse, ImportAccountRequest, RescanAccountResponse}, }; use oreo_errors::OreoError; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; use serde_json::json; use tracing::error; use utils::{default_secp, sign, verify, Signature}; use crate::SharedState; -pub async fn import_account_handler( - State(shared): State>>, +pub async fn import_account_handler( + State(shared): State>, extract::Json(import): extract::Json, ) -> impl IntoResponse { + let genesis = shared.genesis().clone(); let account_name = shared .db_handler - .save_account(import.clone().to_account(shared.genesis_hash.clone()), 0) + .save_account(import.clone().to_account(genesis.clone()), 0) .await; if let Err(e) = account_name { return e.into_response(); @@ -43,13 +44,19 @@ pub async fn import_account_handler( public_address, created_at, } = import; + + let created_at = created_at.map(|created_at| CreatedAt { + hash: created_at.hash, + sequence: created_at.sequence, + network_id: shared.network(), + }); let rpc_data = RpcImportAccountRequest { view_key, incoming_view_key: incoming_view_key.clone(), outgoing_view_key: outgoing_view_key.clone(), public_address: public_address.clone(), spending_key: None, - version: ACCOUNT_VERSION, + version: shared.account_version(), name: account_name.clone(), created_at, }; @@ -69,8 +76,8 @@ pub async fn import_account_handler( }) .map(|x| { let head = x.data.account.head.unwrap_or(BlockInfo { - hash: shared.genesis_hash.clone(), - sequence: MAINNET_GENESIS_SEQUENCE as u64, + hash: genesis.hash.clone(), + sequence: genesis.sequence, }); if latest_height - head.sequence > 1000 { let _ = shared.rpc_handler.set_scanning(RpcSetScanningRequest { @@ -110,8 +117,8 @@ pub async fn import_account_handler( } } -pub async fn remove_account_handler( - State(shared): State>>, +pub async fn remove_account_handler( + State(shared): State>, extract::Json(remove_account): extract::Json, ) -> impl IntoResponse { let db_account = shared @@ -141,8 +148,8 @@ pub async fn remove_account_handler( } } -pub async fn account_status_handler( - State(shared): State>>, +pub async fn account_status_handler( + State(shared): State>, extract::Json(account): extract::Json, ) -> impl IntoResponse { let db_account = shared.db_handler.get_account(account.account.clone()).await; @@ -154,14 +161,15 @@ pub async fn account_status_handler( .get_account_status(RpcGetAccountStatusRequest { account: db_account.unwrap().name, }); + let genesis = shared.genesis().clone(); match result { Ok(mut result) => { match result.data.account.head { Some(_) => {} None => { result.data.account.head = Some(BlockInfo { - hash: shared.genesis_hash.clone(), - sequence: MAINNET_GENESIS_SEQUENCE as u64, + hash: genesis.hash.clone(), + sequence: genesis.sequence, }) } } @@ -172,8 +180,8 @@ pub async fn account_status_handler( .into_response() } -pub async fn rescan_account_handler( - State(shared): State>>, +pub async fn rescan_account_handler( + State(shared): State>, extract::Json(account): extract::Json, ) -> impl IntoResponse { let db_account = shared.db_handler.get_account(account.account.clone()).await; @@ -194,16 +202,17 @@ pub async fn rescan_account_handler( .db_handler .update_scan_status(account.address.clone(), true) .await; - if let Ok(status) = shared + if let Ok(x) = shared .rpc_handler .get_account_status(RpcGetAccountStatusRequest { account: account.name.clone(), }) { - let head = BlockInfo { - hash: account.create_hash.unwrap_or(shared.genesis_hash.clone()), - sequence: account.create_head.unwrap_or(MAINNET_GENESIS_SEQUENCE) as u64, - }; + let genesis = shared.genesis().clone(); + let head = x.data.account.head.unwrap_or(BlockInfo { + hash: genesis.hash.clone(), + sequence: genesis.sequence, + }); let scan_request = ScanRequest { address: account.address.clone(), in_vk: account.in_vk.clone(), @@ -226,8 +235,8 @@ pub async fn rescan_account_handler( .into_response() } -pub async fn update_scan_status_handler( - State(shared): State>>, +pub async fn update_scan_status_handler( + State(shared): State>, extract::Json(response): extract::Json>, ) -> impl IntoResponse { let DecryptionMessage { @@ -249,15 +258,6 @@ pub async fn update_scan_status_handler( return e.into_response(); } let account = db_account.unwrap(); - let reset_created_at = account.create_head.is_none() || account.create_head.unwrap() == 1; - let reset = shared.rpc_handler.reset_account(RpcResetAccountRequest { - account: account.name.clone(), - reset_scanning_enabled: Some(false), - reset_created_at: Some(reset_created_at), - }); - if let Err(e) = reset { - return e.into_response(); - } message.account = account.name.clone(); let resp = shared.rpc_handler.set_account_head(message.clone()); @@ -280,8 +280,8 @@ pub async fn update_scan_status_handler( Json(SuccessResponse { success: false }).into_response() } -pub async fn get_balances_handler( - State(shared): State>>, +pub async fn get_balances_handler( + State(shared): State>, extract::Json(get_balance): extract::Json, ) -> impl IntoResponse { let db_account = shared @@ -296,19 +296,25 @@ pub async fn get_balances_handler( confirmations: Some(get_balance.confirmations.unwrap_or(10)), }); match resp { - Ok(res) => { - let response = RpcResponse { - status: 200, - data: RpcGetBalancesResponse::verified_asset(res.data), + Ok(mut res) => { + for item in res.data.balances.iter_mut() { + if let Ok(asset) = shared.rpc_handler.get_asset(item.asset_id.clone()) { + item.decimals = asset.data.verification.decimals; + } + } + let data = match shared.network() { + Testnet::ID => RpcGetBalancesResponse::verified_asset::(res.data), + _ => RpcGetBalancesResponse::verified_asset::(res.data), }; + let response = RpcResponse { status: 200, data }; response.into_response() } Err(e) => e.into_response(), } } -pub async fn get_ores_handler( - State(shared): State>>, +pub async fn get_ores_handler( + State(shared): State>, extract::Json(get_balance): extract::Json, ) -> impl IntoResponse { let db_account = shared @@ -324,18 +330,19 @@ pub async fn get_ores_handler( }); match resp { Ok(res) => { - let response = RpcResponse { - status: 200, - data: RpcGetBalancesResponse::ores(res.data).await, + let data = match shared.network() { + Testnet::ID => RpcGetBalancesResponse::ores::(res.data).await, + _ => RpcGetBalancesResponse::ores::(res.data).await, }; + let response = RpcResponse { status: 200, data }; response.into_response() } Err(e) => e.into_response(), } } -pub async fn get_transaction_handler( - State(shared): State>>, +pub async fn get_transaction_handler( + State(shared): State>, extract::Json(account): extract::Json, ) -> impl IntoResponse { let db_account = shared.db_handler.get_account(account.account.clone()).await; @@ -366,8 +373,8 @@ pub async fn get_transaction_handler( } } -pub async fn get_transactions_handler( - State(shared): State>>, +pub async fn get_transactions_handler( + State(shared): State>, extract::Json(get_transactions): extract::Json, ) -> impl IntoResponse { let db_account = shared @@ -387,8 +394,8 @@ pub async fn get_transactions_handler( .into_response() } -pub async fn create_transaction_handler( - State(shared): State>>, +pub async fn create_transaction_handler( + State(shared): State>, extract::Json(create_transaction): extract::Json, ) -> impl IntoResponse { let db_account = shared @@ -402,7 +409,10 @@ pub async fn create_transaction_handler( .outputs .unwrap_or(vec![]) .iter() - .map(|output| OutPut::from(output.clone())) + .map(|output| match shared.network() { + Testnet::ID => OutPut::from::(output.clone()), + _ => OutPut::from::(output.clone()), + }) .collect(); let mut mints = vec![]; for item in create_transaction.mints.unwrap_or(vec![]).into_iter() { @@ -426,8 +436,8 @@ pub async fn create_transaction_handler( .into_response() } -pub async fn add_transaction_handler( - State(shared): State>>, +pub async fn add_transaction_handler( + State(shared): State>, extract::Json(broadcast_transaction): extract::Json, ) -> impl IntoResponse { shared @@ -436,9 +446,7 @@ pub async fn add_transaction_handler( .into_response() } -pub async fn latest_block_handler( - State(shared): State>>, -) -> impl IntoResponse { +pub async fn latest_block_handler(State(shared): State>) -> impl IntoResponse { shared.rpc_handler.get_latest_block().into_response() } diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 4e6c7ed..41d437a 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -1,18 +1,29 @@ -use std::{env, net::SocketAddr, sync::Arc, time::Duration}; -use axum_extra::{headers::{authorization::Basic, Authorization}, TypedHeader}; -use sha2::{Sha256, Digest}; +use axum_extra::{ + headers::{authorization::Basic, Authorization}, + TypedHeader, +}; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; +use sha2::{Digest, Sha256}; use std::str; +use std::{env, net::SocketAddr, sync::Arc, time::Duration}; use anyhow::Result; use axum::{ - body::Body, error_handling::HandleErrorLayer, extract::State, http::{Request, StatusCode}, middleware::{from_fn_with_state, Next}, response::IntoResponse, routing::{get, post}, BoxError, Router + body::Body, + error_handling::HandleErrorLayer, + extract::State, + http::{Request, StatusCode}, + middleware::{from_fn_with_state, Next}, + response::IntoResponse, + routing::{get, post}, + BoxError, Router, }; -use db_handler::{DBHandler, PgHandler}; -use networking::{rpc_handler::RpcHandler, server_handler::ServerHandler}; +use db_handler::DBHandler; +use networking::{rpc_abi::BlockInfo, rpc_handler::RpcHandler, server_handler::ServerHandler}; use tokio::net::TcpListener; use tower::{timeout::TimeoutLayer, ServiceBuilder}; use tower_http::cors::{Any, CorsLayer}; -use tracing::info; +use tracing::{error, info}; use crate::handlers::{ account_status_handler, add_transaction_handler, create_transaction_handler, @@ -29,43 +40,74 @@ pub struct SecpKey { pub pk: [u8; 33], } -#[derive(Debug, Clone)] -pub struct SharedState { - pub db_handler: T, +pub struct SharedState { + pub db_handler: Box, pub rpc_handler: RpcHandler, pub scan_handler: ServerHandler, pub secp: SecpKey, - pub genesis_hash: String, + pub network: u8, } -impl SharedState -where - T: DBHandler, -{ - pub fn new(db_handler: T, endpoint: &str, scan: &str, secp: SecpKey, genesis_hash: String) -> Self { +impl SharedState { + pub fn new( + db_handler: Box, + endpoint: &str, + scan: &str, + secp: SecpKey, + network: u8, + ) -> Self { Self { db_handler: db_handler, rpc_handler: RpcHandler::new(endpoint.into()), scan_handler: ServerHandler::new(scan.into()), secp, - genesis_hash, + network, + } + } + + pub fn network(&self) -> u8 { + self.network + } + + pub fn genesis(&self) -> BlockInfo { + match self.network() { + Testnet::ID => BlockInfo { + hash: Testnet::GENESIS_BLOCK_HASH.to_string(), + sequence: Testnet::GENESIS_BLOCK_HEIGHT, + }, + _ => BlockInfo { + hash: Mainnet::GENESIS_BLOCK_HASH.to_string(), + sequence: Mainnet::GENESIS_BLOCK_HEIGHT, + }, + } + } + + pub fn account_version(&self) -> u8 { + match self.network() { + Testnet::ID => Testnet::ACCOUNT_VERSION, + _ => Mainnet::ACCOUNT_VERSION, } } } +unsafe impl Send for SharedState {} +unsafe impl Sync for SharedState {} + // Authentication middleware function -pub async fn auth( - State(shared_state): State>>, +pub async fn auth( + State(shared_state): State>, TypedHeader(Authorization(basic)): TypedHeader>, - req: Request, - next: Next -) -> impl IntoResponse - where - T: DBHandler + Send + Sync + 'static, -{ - match shared_state.db_handler.get_account(basic.username().to_string()).await { + req: Request, + next: Next, +) -> impl IntoResponse { + match shared_state + .db_handler + .get_account(basic.username().to_string()) + .await + { Ok(account) => { - let bytes = hex::decode(account.vk).map_err(|_| (StatusCode::UNAUTHORIZED, "Invalid token"))?; + let bytes = + hex::decode(account.vk).map_err(|_| (StatusCode::UNAUTHORIZED, "Invalid token"))?; let token = Sha256::digest(bytes); let token_hex = hex::encode(token); if token_hex != basic.password() { @@ -79,11 +121,11 @@ pub async fn auth( } } } - -pub async fn run_server( + +pub async fn run_server( listen: SocketAddr, rpc_server: String, - db_handler: PgHandler, + db_handler: Box, scan: String, sk_u8: [u8; 32], pk_u8: [u8; 33], @@ -94,7 +136,13 @@ pub async fn run_server( let latest_block_response = temp_handler.get_latest_block()?.data; genesis_hash = latest_block_response.genesis_block_identifier.hash; } + info!("Genesis hash: {}", genesis_hash); + if N::GENESIS_BLOCK_HASH.to_lowercase() != genesis_hash.to_lowercase() { + error!("Network genesis hash doesnt match, exit!"); + return Ok(()); + } + let shared_resource = Arc::new(SharedState::new( db_handler, &rpc_server, @@ -103,12 +151,14 @@ pub async fn run_server( sk: sk_u8, pk: pk_u8, }, - genesis_hash, + N::ID, )); let auth_middleware = from_fn_with_state(shared_resource.clone(), auth); let no_auth_router = Router::new() .route("/import", post(import_account_handler)) + .route("/healthCheck", get(health_check_handler)) + .route("/updateScan", post(update_scan_status_handler)) .with_state(shared_resource.clone()); let mut auth_router = Router::new() @@ -117,20 +167,18 @@ pub async fn run_server( .route("/getTransaction", post(get_transaction_handler)) .route("/getTransactions", post(get_transactions_handler)) .route("/createTx", post(create_transaction_handler)) - .route("/broadcastTx", post(add_transaction_handler)) // TODO: Remove after front end updates to addTx - .route("/addTx", post(add_transaction_handler)) + .route("/broadcastTx", post(add_transaction_handler)) + .route("/addTx", post(add_transaction_handler)) .route("/accountStatus", post(account_status_handler)) .route("/latestBlock", get(latest_block_handler)) .route("/ores", post(get_ores_handler)) .route("/rescan", post(rescan_account_handler)) - .route("/healthCheck", get(health_check_handler)) - .route("/updateScan", post(update_scan_status_handler)) .with_state(shared_resource.clone()); if env::var("ENABLE_AUTH").unwrap_or_else(|_| "false".to_string()) == "true" { auth_router = auth_router.layer(auth_middleware); } - + let router = no_auth_router .merge(auth_router) .layer( diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 8488b97..9adb90f 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -2,10 +2,11 @@ use std::net::SocketAddr; use anyhow::Result; use clap::Parser; -use db_handler::{DBHandler, DbConfig, PgHandler}; +use db_handler::load_db; use dotenv::dotenv; +use params::{mainnet::Mainnet, network::Network, testnet::Testnet}; use server::run_server; -use utils::{handle_signals, initialize_logger}; +use utils::{handle_signals, initialize_logger, initialize_logger_filter, EnvFilter}; #[derive(Parser, Debug, Clone)] pub struct Command { @@ -24,6 +25,9 @@ pub struct Command { /// The scan server to connect to #[clap(long, default_value = "127.0.0.1:9093")] pub scan: String, + /// The network id, 0 for mainnet, 1 for testnet. + #[clap(long)] + pub network: u8, } #[tokio::main] @@ -42,11 +46,23 @@ async fn main() -> Result<()> { verbosity, node, scan, + network, } = args; initialize_logger(verbosity); + let filter = EnvFilter::from_default_env() + .add_directive("ureq=off".parse().unwrap()) + .add_directive("rustls=off".parse().unwrap()); + initialize_logger_filter(filter); handle_signals().await?; - let db_config = DbConfig::load(dbconfig).unwrap(); - let db_handler = PgHandler::from_config(&db_config); - run_server(listen.into(), node, db_handler, scan, sk_u8, pk_u8).await?; + let db_handler = load_db(dbconfig).unwrap(); + match network { + Mainnet::ID => { + run_server::(listen.into(), node, db_handler, scan, sk_u8, pk_u8).await?; + } + Testnet::ID => { + run_server::(listen.into(), node, db_handler, scan, sk_u8, pk_u8).await?; + } + _ => panic!("Invalid network used"), + } Ok(()) } diff --git a/crates/transfer-tool/Cargo.toml b/crates/transfer-tool/Cargo.toml deleted file mode 100644 index c277e7d..0000000 --- a/crates/transfer-tool/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "transfer-tool" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -anyhow = "1.0.79" -clap = { version = "4.4.13", features = ["derive"] } -tokio = { version = "1.35.1", features = ["full"] } -tracing = "0.1.40" -utils = { path = "../utils" } -networking = { path = "../networking" } -db_handler = { path = "../db_handler" } -constants = { path = "../constants" } diff --git a/crates/transfer-tool/src/main.rs b/crates/transfer-tool/src/main.rs deleted file mode 100644 index eb8f9c2..0000000 --- a/crates/transfer-tool/src/main.rs +++ /dev/null @@ -1,89 +0,0 @@ -use anyhow::Result; -use clap::Parser; -use constants::IRON_NATIVE_ASSET; -use db_handler::{DBHandler, DbConfig, PgHandler}; -use networking::{ - rpc_abi::{OutPut, SendTransactionRequest}, - rpc_handler::RpcHandler, -}; -use tracing::info; -use utils::{handle_signals, initialize_logger}; -#[derive(Parser, Debug, Clone)] -pub struct Command { - /// The path to db config file - #[clap(long)] - pub dbconfig: String, - /// Set your logger level - #[clap(short, long, default_value = "0")] - pub verbosity: u8, - /// The Ironfish rpc node to connect to - #[clap(short, long, default_value = "127.0.0.1:9092")] - pub node: String, - /// The account used to transfer from - #[clap(long)] - pub account: String, - /// The bonus amount - #[clap(long)] - pub bonus: String, -} - -#[tokio::main] -async fn main() -> Result<()> { - let cli = Command::parse(); - let Command { - dbconfig, - verbosity, - node, - account, - bonus, - } = cli; - initialize_logger(verbosity); - handle_signals().await?; - let db_config = DbConfig::load(dbconfig).unwrap(); - let db_handler = PgHandler::from_config(&db_config); - let rpc_handler = RpcHandler::new(node); - match db_handler.get_unpaid_addresses().await { - Ok(accounts) => { - info!("bonus accounts: {:?}", accounts); - let mut outputs = vec![]; - for account in accounts.iter() { - if account.paid { - continue; - } - outputs.push(OutPut { - public_address: account.address.clone(), - amount: bonus.clone(), - memo: Some("OreoWallet-Bonus".to_string()), - memo_hex: Some("".into()), - asset_id: Some(IRON_NATIVE_ASSET.to_string()), - }); - } - if outputs.is_empty() { - info!("no new bonus address"); - return Ok(()); - } - let send_request = SendTransactionRequest { - account: account.clone(), - fee: "10".to_string(), - expiration_delta: 30, - outputs, - }; - let result = rpc_handler.send_transaction(send_request); - match result { - Ok(result) => { - info!("transaction sent, {}", result.data.hash); - for account in accounts.iter() { - let _ = db_handler - .update_firstseen_status(account.address.clone()) - .await; - } - } - Err(e) => { - tracing::error!("failed to send transaction, {:?}", e); - } - } - } - Err(e) => tracing::error!("failed to get accounts, {:?}", e), - } - Ok(()) -} diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index e2b1558..c79cbb7 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -7,7 +7,7 @@ use secp256k1::{ }; use tokio::sync::oneshot; use tracing::{info, warn}; -use tracing_subscriber::EnvFilter; +pub use tracing_subscriber::EnvFilter; pub use secp256k1::ecdsa::Signature; @@ -37,11 +37,10 @@ pub fn initialize_logger(verbosity: u8) { 2 | 3 | 4 => std::env::set_var("RUST_LOG", "trace"), _ => std::env::set_var("RUST_LOG", "info"), }; - tracing_subscriber::fmt() - .with_env_filter( - EnvFilter::from_default_env().add_directive("ironfish-server=info".parse().unwrap()), - ) - .init(); +} + +pub fn initialize_logger_filter(filter: EnvFilter) { + tracing_subscriber::fmt().with_env_filter(filter).init(); } pub fn blocks_range(blocks: Range, batch: u64) -> Vec> {