From 7b2c4a21df8468554a21992b6011c6faff58929d Mon Sep 17 00:00:00 2001 From: Conner Swann Date: Thu, 28 Oct 2021 22:40:26 +0200 Subject: [PATCH] refactor: split updater tasks for safety (#909) * refactor: split updater tasks, refactor opticsdb * feature: asrefs for db types * refactor: refactor typeddb to hold entity and pair with all loads/stores * ci: cargo +nightly * ci: use nightly toolchain * fix: use 1.56 stable not nightly * fix: updater can never overwrite an existing update with a conflicting one * fix: also check suggested update for state change guard Co-authored-by: Luke Tchang --- .github/CODEOWNERS | 2 +- .github/workflows/rust.yml | 6 +- rust-toolchain | 2 +- rust/Cargo.lock | 575 ++++++------------ rust/Cargo.toml | 4 +- rust/Dockerfile | 6 +- rust/agents/kathy/Cargo.toml | 2 +- rust/agents/processor/Cargo.toml | 2 +- rust/agents/processor/src/processor.rs | 17 +- rust/agents/processor/src/prover_sync.rs | 40 +- rust/agents/processor/src/push.rs | 4 +- rust/agents/relayer/Cargo.toml | 2 +- rust/agents/updater/Cargo.toml | 3 +- rust/agents/updater/src/main.rs | 2 + rust/agents/updater/src/produce.rs | 122 ++++ rust/agents/updater/src/submit.rs | 55 ++ rust/agents/updater/src/updater.rs | 220 +------ rust/agents/watcher/Cargo.toml | 2 +- rust/agents/watcher/src/watcher.rs | 2 +- rust/chains/optics-ethereum/Cargo.toml | 2 +- rust/chains/optics-ethereum/src/home.rs | 39 +- rust/chains/optics-ethereum/src/lib.rs | 6 +- rust/chains/optics-ethereum/src/replica.rs | 10 +- rust/chains/optics-ethereum/src/xapp.rs | 1 - rust/optics-base/Cargo.toml | 2 +- rust/optics-core/Cargo.toml | 3 +- rust/optics-core/src/chain.rs | 6 +- rust/optics-core/src/db/mod.rs | 12 +- rust/optics-core/src/db/optics_db.rs | 251 +++----- rust/optics-core/src/db/typed_db.rs | 43 +- rust/optics-core/src/lib.rs | 19 +- rust/optics-core/src/models/replica.rs | 2 + rust/optics-core/src/utils.rs | 1 + rust/optics-test/Cargo.toml | 2 +- rust/optics-test/src/test_utils.rs | 20 +- rust/tools/balance-exporter/Cargo.toml | 2 +- rust/tools/kms-cli/Cargo.toml | 4 +- rust/tools/kms-cli/src/main.rs | 20 +- rust/tools/optics-cli/Cargo.toml | 2 +- .../optics-cli/src/subcommands/db_state.rs | 14 +- .../tools/optics-cli/src/subcommands/prove.rs | 12 +- 41 files changed, 660 insertions(+), 881 deletions(-) create mode 100644 rust/agents/updater/src/produce.rs create mode 100644 rust/agents/updater/src/submit.rs diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a309ad4695..85b61ba79f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ * @prestwich @anna-carroll @erinhales -rust/ @prestwich @emberian +rust/ @prestwich @emberian @ltchang diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 143407e5d9..987e952afd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.54.0 + toolchain: stable - uses: Swatinem/rust-cache@v1 with: working-directory: ./rust @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.54.0 + toolchain: stable - uses: Swatinem/rust-cache@v1 with: working-directory: ./rust @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.54.0 + toolchain: stable - uses: Swatinem/rust-cache@v1 with: working-directory: ./rust diff --git a/rust-toolchain b/rust-toolchain index 89a5915c38..eb30602350 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "1.54" +channel = "1.56" profile = "default" diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 0d6088caed..a0e70203a8 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom 0.2.3", "once_cell", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" +checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" [[package]] name = "arrayvec" @@ -178,9 +178,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.61" +version = "0.3.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01" +checksum = "091bcdf2da9950f96aa522681ce805e6857f6ca8df73833d35736ab2dc78e152" dependencies = [ "addr2line", "cc", @@ -195,7 +195,7 @@ dependencies = [ name = "balance-exporter" version = "0.1.0" dependencies = [ - "clap 3.0.0-beta.4", + "clap 3.0.0-beta.5", "color-eyre", "futures", "human-panic", @@ -208,12 +208,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "base-x" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" - [[package]] name = "base58" version = "0.1.0" @@ -244,9 +238,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "base64ct" -version = "1.0.1" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" +checksum = "e6b4d9b1225d28d360ec6a231d65af1fd99a2a095154c8040689617290569c5c" [[package]] name = "bech32" @@ -388,15 +382,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" [[package]] name = "byte-slice-cast" -version = "1.0.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" +checksum = "1d30c751592b77c499e7bce34d99d67c2c11bdc0574e9a488ddade14150a4698" [[package]] name = "byte-tools" @@ -452,9 +446,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" dependencies = [ "jobserver", ] @@ -530,9 +524,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.0-beta.4" +version = "3.0.0-beta.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406" +checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" dependencies = [ "atty", "bitflags", @@ -543,14 +537,14 @@ dependencies = [ "strsim 0.10.0", "termcolor", "textwrap 0.14.2", - "vec_map", + "unicase", ] [[package]] name = "clap_derive" -version = "3.0.0-beta.4" +version = "3.0.0-beta.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac" +checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3" dependencies = [ "heck", "proc-macro-error", @@ -676,21 +670,21 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.6.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c32f031ea41b4291d695026c023b95d59db2d8a2c7640800ed56bc8f510f22" +checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" [[package]] -name = "const_fn" -version = "0.4.8" +name = "convert_case" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-foundation" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" dependencies = [ "core-foundation-sys", "libc", @@ -698,9 +692,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" @@ -833,9 +827,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.2.6" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e49339137316df1914fdb54a5eae75a73f45068fd0d2178fe235b11d93238a6e" +checksum = "f83bd3bb4314701c568e340cd8cf78c975aa0ca79e03d3f6d1677d5b0c9c0c03" dependencies = [ "generic-array 0.14.4", "rand_core 0.6.3", @@ -863,16 +857,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ctor" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "ctr" version = "0.7.0" @@ -894,9 +878,9 @@ dependencies = [ [[package]] name = "der" -version = "0.4.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e21d2d0f22cde6e88694108429775c0219760a07779bf96503b434a03d7412" +checksum = "28e98c534e9c8a0483aa01d6f6913bc063de254311bd267c9cf535e9b70e15b2" dependencies = [ "const-oid", ] @@ -946,12 +930,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "downcast" version = "0.10.0" @@ -994,9 +972,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.28" +version = "0.8.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +checksum = "a74ea89a0a1b98f6332de42c95baff457ada66d1cb4030f9ff151b2041a1c746" dependencies = [ "cfg-if 1.0.0", ] @@ -1031,9 +1009,9 @@ dependencies = [ [[package]] name = "ethabi" -version = "14.1.0" +version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01317735d563b3bad2d5f90d2e1799f414165408251abb762510f40e790e69a" +checksum = "f76ef192b63e8a44b3d08832acebbb984c3fba154b5c26f70037c860202a0d4b" dependencies = [ "anyhow", "ethereum-types", @@ -1047,9 +1025,9 @@ dependencies = [ [[package]] name = "ethbloom" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779864b9c7f7ead1f092972c3257496c6a84b46dba2ce131dd8a282cb2cc5972" +checksum = "bfb684ac8fa8f6c5759f788862bb22ec6fe3cb392f6bfd08e3c64b603661e3f8" dependencies = [ "crunchy", "fixed-hash", @@ -1060,9 +1038,9 @@ dependencies = [ [[package]] name = "ethereum-types" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64b5df66a228d85e4b17e5d6c6aa43b0310898ffe8a85988c4c032357aaabfd" +checksum = "05136f7057fe789f06e6d41d07b34e6f70d8c86e5693b60f97aaa6553553bdaf" dependencies = [ "ethbloom", "fixed-hash", @@ -1074,8 +1052,8 @@ dependencies = [ [[package]] name = "ethers" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "ethers-contract", "ethers-core", @@ -1086,8 +1064,8 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1104,8 +1082,8 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "Inflector", "anyhow", @@ -1126,8 +1104,8 @@ dependencies = [ [[package]] name = "ethers-contract-derive" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "ethers-contract-abigen", "ethers-core", @@ -1140,11 +1118,12 @@ dependencies = [ [[package]] name = "ethers-core" -version = "0.5.2" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.4" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "arrayvec 0.7.1", "bytes", + "convert_case", "ecdsa", "elliptic-curve", "ethabi", @@ -1153,11 +1132,16 @@ dependencies = [ "glob", "hex", "k256", + "once_cell", + "proc-macro2", + "quote", "rand 0.8.4", "rlp", "rlp-derive", + "semver 1.0.4", "serde 1.0.130", "serde_json", + "syn", "thiserror", "tiny-keccak", "tokio", @@ -1165,8 +1149,8 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "async-trait", "ethers-contract", @@ -1188,8 +1172,8 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "0.5.2" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.4" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "async-trait", "auto_impl", @@ -1221,8 +1205,8 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "0.5.1" -source = "git+https://github.com/gakonst/ethers-rs?branch=master#b54f8b7d456e35cdc9ef15b0f8633378cd2faf73" +version = "0.5.3" +source = "git+https://github.com/gakonst/ethers-rs?branch=master#d815dab9adc9dd3ea956e1959cd71635f4b7b3da" dependencies = [ "async-trait", "coins-bip32", @@ -1236,6 +1220,7 @@ dependencies = [ "rand 0.8.4", "rusoto_core", "rusoto_kms", + "semver 1.0.4", "sha2 0.9.8", "spki", "thiserror", @@ -1501,9 +1486,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.4" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f3675cfef6a30c8031cf9e6493ebdc3bb3272a3fea3923c4210d1830e6a472" +checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55" dependencies = [ "bytes", "fnv", @@ -1529,18 +1514,18 @@ dependencies = [ [[package]] name = "headers" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" +checksum = "a4c4eb0471fcb85846d8b0690695ef354f9afb11cb03cac2e1d7c9253351afb0" dependencies = [ "base64 0.13.0", "bitflags", "bytes", "headers-core", "http", + "httpdate", "mime", "sha-1", - "time 0.1.43", ] [[package]] @@ -1588,9 +1573,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ "bytes", "fnv", @@ -1599,9 +1584,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", @@ -1637,9 +1622,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.12" +version = "0.14.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13f67199e765030fa08fe0bd581af683f0d5bc04ea09c2b1102012c5fb90e7fd" +checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b" dependencies = [ "bytes", "futures-channel", @@ -1763,13 +1748,12 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", "js-sys", - "time 0.2.27", "wasm-bindgen", "web-sys", ] @@ -1803,9 +1787,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.54" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -1856,7 +1840,7 @@ checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" name = "kms-cli" version = "0.1.0" dependencies = [ - "clap 3.0.0-beta.4", + "clap 3.0.0-beta.5", "color-eyre", "ethers", "ethers-signers", @@ -1895,15 +1879,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.101" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" [[package]] name = "libloading" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -1912,7 +1896,7 @@ dependencies = [ [[package]] name = "librocksdb-sys" version = "6.20.3" -source = "git+https://github.com/rust-rocksdb/rust-rocksdb#e2e8834975cc9f2cef63ae85d7ea376e7cdc816d" +source = "git+https://github.com/rust-rocksdb/rust-rocksdb#eb2d302682418b361a80ad8f4dcf335ade60dcf5" dependencies = [ "bindgen", "cc", @@ -2032,9 +2016,9 @@ dependencies = [ [[package]] name = "metrics-exporter-prometheus" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db7052a7cb0b0c0922a1ce499c9e78576763b1d47499ba980a4fe731b96909d" +checksum = "343a5ceb38235928e7a5687412590f07e6d281522dcd9ff51246f8856eef5fe5" dependencies = [ "hyper", "ipnet", @@ -2062,9 +2046,9 @@ dependencies = [ [[package]] name = "metrics-util" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a58e622a425b7308e73e4390c68b8cb3df4443f2a57495e391b978412531638c" +checksum = "74c9b6aee519e1461b678952d3671652bb341d0664b1188f895a436a4e2e6ffa" dependencies = [ "ahash", "aho-corasick", @@ -2111,9 +2095,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", @@ -2341,9 +2325,9 @@ dependencies = [ [[package]] name = "object" -version = "0.26.2" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" dependencies = [ "memchr", ] @@ -2388,9 +2372,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.66" +version = "0.9.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1996d2d305e561b70d1ee0c53f1542833f4e1ac6ce9a6708b6ff2738ca67dc82" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" dependencies = [ "autocfg", "cc", @@ -2524,7 +2508,6 @@ dependencies = [ name = "optics-core" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "bytes", "color-eyre", @@ -2609,9 +2592,12 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "3.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d" +checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799" +dependencies = [ + "memchr", +] [[package]] name = "os_type" @@ -2630,9 +2616,9 @@ checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" [[package]] name = "parity-scale-codec" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8975095a2a03bbbdc70a74ab11a4f76a6d0b84680d87c68d722531b0ac28e8a9" +checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" dependencies = [ "arrayvec 0.7.1", "bitvec 0.20.4", @@ -2644,9 +2630,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40dbbfef7f0a1143c5b06e0d76a6278e25dac0bc1af4be51a0fbb73f07e7ad09" +checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2774,9 +2760,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbee84ed13e44dd82689fa18348a49934fa79cc774a344c42fc9b301c71b140a" +checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" dependencies = [ "der", "spki", @@ -2784,15 +2770,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" [[package]] name = "predicates" @@ -2815,19 +2801,19 @@ checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7dd0fd014130206c9352efbdc92be592751b2b9274dff685348341082c6ea3d" +checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7" dependencies = [ "predicates-core", - "treeline", + "termtree", ] [[package]] name = "primitive-types" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e" +checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" dependencies = [ "fixed-hash", "impl-codec", @@ -2838,9 +2824,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fdbd1df62156fbc5945f4762632564d7d038153091c3fcf1067f6aef7cff92" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" dependencies = [ "thiserror", "toml", @@ -2884,9 +2870,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" dependencies = [ "unicode-xid", ] @@ -2935,22 +2921,23 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.25.1" +version = "2.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23129d50f2c9355ced935fce8a08bd706ee2e7ce2b3b33bf61dace0e379ac63a" +checksum = "47c327e191621a2158159df97cdbc2e7074bb4e940275e35abf38eb3d2595754" [[package]] name = "quanta" -version = "0.7.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e76a3afdefd0ce2c0363bf3146271e947782240ea617885dd64e56c4de9fb3c9" +checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" dependencies = [ - "atomic-shim", - "ctor", + "crossbeam-utils 0.8.5", "libc", "mach", "once_cell", "raw-cpuid", + "wasi 0.10.2+wasi-snapshot-preview1", + "web-sys", "winapi", ] @@ -2962,9 +2949,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] @@ -3080,9 +3067,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "9.1.1" +version = "10.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1733f6f80c9c24268736a501cd00d41a9849b4faa7a9f9334c096e5d10553206" +checksum = "929f54e29691d4e6a9cc558479de70db7aa3d98cd6fe7ab86d7507aa2886b9d2" dependencies = [ "bitflags", ] @@ -3167,9 +3154,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.4" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280" dependencies = [ "base64 0.13.0", "bytes", @@ -3254,7 +3241,7 @@ dependencies = [ [[package]] name = "rocksdb" version = "0.17.0" -source = "git+https://github.com/rust-rocksdb/rust-rocksdb#e2e8834975cc9f2cef63ae85d7ea376e7cdc816d" +source = "git+https://github.com/rust-rocksdb/rust-rocksdb#eb2d302682418b361a80ad8f4dcf335ade60dcf5" dependencies = [ "libc", "librocksdb-sys", @@ -3380,15 +3367,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.3.3" @@ -3522,22 +3500,13 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser 0.7.0", -] - [[package]] name = "semver" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" dependencies = [ - "semver-parser 0.10.2", + "semver-parser", ] [[package]] @@ -3549,12 +3518,6 @@ dependencies = [ "serde 1.0.130", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "semver-parser" version = "0.10.2" @@ -3621,9 +3584,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ "itoa", "ryu", @@ -3664,12 +3627,6 @@ dependencies = [ "opaque-debug 0.3.0", ] -[[package]] -name = "sha1" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" - [[package]] name = "sha2" version = "0.8.2" @@ -3709,9 +3666,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] @@ -3733,9 +3690,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19772be3c4dd2ceaacf03cb41d5885f2a02c4d8804884918e3a258480803335" +checksum = "f2807892cfa58e081aa1f1111391c7a0649d4fa127a4ffbe34bcbfb35a1171a4" dependencies = [ "digest 0.9.0", "rand_core 0.6.3", @@ -3749,21 +3706,21 @@ checksum = "76a77a8fd93886010f05e7ea0720e569d6d16c65329dbe3ec033bbbccccb017b" [[package]] name = "slab" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "socket2" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765f090f0e423d2b55843402a07915add955e7d60657db13707a159727326cad" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" dependencies = [ "libc", "winapi", @@ -3777,77 +3734,19 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spki" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "987637c5ae6b3121aba9d513f869bd2bff11c4cc086c22473befd6649c0bd521" +checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" dependencies = [ "der", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde 1.0.130", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde 1.0.130", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "strsim" version = "0.8.0" @@ -3862,9 +3761,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "structopt" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" dependencies = [ "clap 2.33.3", "lazy_static", @@ -3873,9 +3772,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.16" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error", @@ -3892,9 +3791,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.76" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ "proc-macro2", "quote", @@ -3930,6 +3829,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76565a2f8df1d2170b5c365aa39d0623fd93fec20545edde299233cea82d0f16" + [[package]] name = "textwrap" version = "0.11.0" @@ -3950,18 +3855,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", @@ -3999,54 +3904,6 @@ dependencies = [ "threadpool", ] -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - [[package]] name = "tiny-keccak" version = "2.0.2" @@ -4058,9 +3915,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" dependencies = [ "tinyvec_macros", ] @@ -4073,9 +3930,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4efe6fc2395938c8155973d7be49fe8d03a843726e285e100a8a383cc0154ce" +checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" dependencies = [ "autocfg", "bytes", @@ -4092,9 +3949,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.3.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" +checksum = "b2dd85aeaba7b68df939bd357c6afb36c87951be9e80bf9c859f2fc3e9fca0fd" dependencies = [ "proc-macro2", "quote", @@ -4207,9 +4064,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.26" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", "log", @@ -4220,9 +4077,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2", "quote", @@ -4231,9 +4088,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ca517f43f0fb96e0c3072ed5c275fe5eece87e8cb52f4a77b69226d3b1c9df8" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" dependencies = [ "lazy_static", ] @@ -4294,9 +4151,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.20" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cbe87a2fa7e35900ce5de20220a582a9483a7063811defce79d7cbd59d4cfe" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" dependencies = [ "ansi_term 0.12.1", "chrono", @@ -4314,12 +4171,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "treeline" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" - [[package]] name = "try-lock" version = "0.2.3" @@ -4422,9 +4273,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -4443,9 +4294,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -4468,6 +4319,7 @@ dependencies = [ "config 0.11.0", "ethers", "futures-util", + "hex", "log", "mockall", "optics-base", @@ -4586,21 +4438,19 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.77" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if 1.0.0", - "serde 1.0.130", - "serde_json", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.77" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", @@ -4613,9 +4463,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a87d738d4abc4cf22f6eb142f5b9a81301331ee3c767f2fef2fda4e325492060" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -4625,9 +4475,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.77" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4635,9 +4485,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.77" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ "proc-macro2", "quote", @@ -4648,9 +4498,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.77" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wasm-timer" @@ -4667,38 +4517,11 @@ dependencies = [ "web-sys", ] -[[package]] -name = "watcher" -version = "0.1.0" -dependencies = [ - "async-trait", - "color-eyre", - "config 0.10.1", - "ethers", - "futures-util", - "log", - "optics-base", - "optics-core", - "optics-ethereum", - "optics-test", - "paste", - "prometheus", - "rocksdb", - "serde 1.0.130", - "serde_json", - "thiserror", - "tokio", - "tokio-test", - "tracing", - "tracing-futures", - "tracing-subscriber", -] - [[package]] name = "web-sys" -version = "0.3.54" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", @@ -4804,6 +4627,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "377db0846015f7ae377174787dd452e1c5f5a9050bc6f954911d01f116daa0cd" +checksum = "bf68b08513768deaa790264a7fac27a58cbf2705cfcdc9448362229217d7e970" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index eb24b666a5..07fd9311bf 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,3 +1,5 @@ +cargo-features = ["edition2021"] + [workspace] members = [ @@ -8,7 +10,7 @@ members = [ "agents/kathy", "agents/updater", "agents/relayer", - "agents/watcher", + # "agents/watcher", "agents/processor", "tools/kms-cli", "tools/optics-cli", diff --git a/rust/Dockerfile b/rust/Dockerfile index 3e027ca47f..04dfbe4eeb 100644 --- a/rust/Dockerfile +++ b/rust/Dockerfile @@ -1,13 +1,13 @@ # syntax=docker/dockerfile:experimental -FROM rust:1.54 as builder +FROM rust:1.56 as builder WORKDIR /usr/src # 1a: Prepare for static linking RUN apt-get update && \ apt-get dist-upgrade -y && \ - apt-get install -y musl-tools clang-6.0 && \ - rustup target add x86_64-unknown-linux-musl + apt-get install -y musl-tools clang && \ + rustup target add x86_64-unknown-linux-musl # Add workspace to workdir COPY agents ./agents diff --git a/rust/agents/kathy/Cargo.toml b/rust/agents/kathy/Cargo.toml index 3fb85a7af2..cb15659ee8 100644 --- a/rust/agents/kathy/Cargo.toml +++ b/rust/agents/kathy/Cargo.toml @@ -2,7 +2,7 @@ name = "kathy" version = "0.1.0" authors = ["James Prestwich "] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/rust/agents/processor/Cargo.toml b/rust/agents/processor/Cargo.toml index 1d5eb9e987..bfe287fff5 100644 --- a/rust/agents/processor/Cargo.toml +++ b/rust/agents/processor/Cargo.toml @@ -2,7 +2,7 @@ name = "processor" version = "0.1.0" authors = ["anna-caroll "] -edition = "2018" +edition = "2021" [dependencies] tokio = { version = "1.0.1", features = ["rt", "macros"] } diff --git a/rust/agents/processor/src/processor.rs b/rust/agents/processor/src/processor.rs index 464ec2c0d3..9067b99b2c 100644 --- a/rust/agents/processor/src/processor.rs +++ b/rust/agents/processor/src/processor.rs @@ -73,7 +73,7 @@ impl Replica { // 5. Submit the proof to the replica let mut next_message_nonce: u32 = self .db - .retrieve_latest_nonce(self.home.name(), domain)? + .retrieve_latest_nonce(domain)? .map(|n: u32| n + 1) .unwrap_or_default(); @@ -108,7 +108,7 @@ impl Replica { { Ok(Flow::Advance) => { self.db - .store_latest_nonce(self.home.name(), domain, next_message_nonce)?; + .store_latest_nonce(domain, next_message_nonce)?; next_message_nonce += 1; self.next_message_nonce @@ -199,10 +199,7 @@ impl Replica { return Ok(Flow::Advance); } - let proof = match self - .db - .proof_by_leaf_index(self.home.name(), message.leaf_index) - { + let proof = match self.db.proof_by_leaf_index(message.leaf_index) { Ok(Some(p)) => p, Ok(None) => { info!( @@ -359,7 +356,7 @@ impl OpticsAgent for Processor { let home = self.home(); let next_message_nonce = self.next_message_nonce.clone(); let interval = self.interval; - let db = OpticsDB::new(self.db()); + let db = OpticsDB::new(home.name(), self.db()); let replica_opt = self.replica_by_name(name); let name = name.to_owned(); @@ -394,8 +391,8 @@ impl OpticsAgent for Processor { // tree sync info!("Starting ProverSync"); - let sync = - ProverSync::from_disk(self.home().name().to_owned(), OpticsDB::new(self.db())); + let db = OpticsDB::new(self.home().name().to_owned(), self.db()); + let sync = ProverSync::from_disk(db.clone()); let sync_task = sync.spawn(); info!("Starting indexer"); @@ -434,7 +431,7 @@ impl OpticsAgent for Processor { self.core.home.name(), &config.bucket, config.region.parse().expect("invalid s3 region"), - OpticsDB::new(self.db()), + db.clone(), ) .spawn(), ) diff --git a/rust/agents/processor/src/prover_sync.rs b/rust/agents/processor/src/prover_sync.rs index 09496bf9a5..40effec14f 100644 --- a/rust/agents/processor/src/prover_sync.rs +++ b/rust/agents/processor/src/prover_sync.rs @@ -13,7 +13,6 @@ use tracing::{debug, error, info, info_span, instrument, instrument::Instrumente /// Struct to sync prover. #[derive(Debug)] pub struct ProverSync { - home_name: String, db: OpticsDB, prover: Prover, incremental: IncrementalMerkle, @@ -71,7 +70,7 @@ impl ProverSync { fn store_proof(&self, leaf_index: u32) -> Result<(), ProverSyncError> { match self.prover.prove(leaf_index as usize) { Ok(proof) => { - self.db.store_proof(&self.home_name, leaf_index, &proof)?; + self.db.store_proof(leaf_index, &proof)?; info!( leaf_index, root = ?self.prover.root(), @@ -91,14 +90,14 @@ impl ProverSync { /// Given rocksdb handle `db` containing merkle tree leaves, /// instantiates new `ProverSync` and fills prover's merkle tree #[instrument(level = "debug", skip(db))] - pub fn from_disk(home_name: String, db: OpticsDB) -> Self { + pub fn from_disk(db: OpticsDB) -> Self { // Ingest all leaves in db into prover tree let mut prover = Prover::default(); let mut incremental = IncrementalMerkle::default(); - if let Some(root) = db.retrieve_latest_root(&home_name).expect("db error") { + if let Some(root) = db.retrieve_latest_root().expect("db error") { for i in 0.. { - match db.leaf_by_leaf_index(&home_name, i) { + match db.leaf_by_leaf_index(i) { Ok(Some(leaf)) => { debug!(leaf_index = i, "Ingesting leaf from_disk"); prover.ingest(leaf).expect("!tree full"); @@ -119,7 +118,6 @@ impl ProverSync { } let sync = Self { - home_name: home_name.to_owned(), prover, incremental, db, @@ -128,10 +126,8 @@ impl ProverSync { // Ensure proofs exist for all leaves for i in 0..sync.prover.count() as u32 { match ( - sync.db.leaf_by_leaf_index(&home_name, i).expect("db error"), - sync.db - .proof_by_leaf_index(&home_name, i) - .expect("db error"), + sync.db.leaf_by_leaf_index(i).expect("db error"), + sync.db.proof_by_leaf_index(i).expect("db error"), ) { (Some(_), None) => sync.store_proof(i).expect("db error"), (None, _) => break, @@ -158,7 +154,7 @@ impl ProverSync { let mut leaves = vec![]; for i in range { - let leaf = self.db.wait_for_leaf(&self.home_name, i as u32).await?; + let leaf = self.db.wait_for_leaf(i as u32).await?; if leaf.is_none() { break; } @@ -219,11 +215,7 @@ impl ProverSync { // store all calculated proofs in the db // TODO(luke): refactor prover_sync so we dont have to iterate over every leaf (match from_disk implementation) for idx in 0..self.prover.count() { - if self - .db - .proof_by_leaf_index(&self.home_name, idx as u32)? - .is_none() - { + if self.db.proof_by_leaf_index(idx as u32)?.is_none() { self.store_proof(idx as u32)?; } } @@ -270,11 +262,7 @@ impl ProverSync { // As we fill the incremental merkle, its tree_size will always be // equal to the index of the next leaf we want (e.g. if tree_size // is 3, we want the 4th leaf, which is at index 3) - if let Some(leaf) = self - .db - .wait_for_leaf(&self.home_name, tree_size as u32) - .await? - { + if let Some(leaf) = self.db.wait_for_leaf(tree_size as u32).await? { info!( index = tree_size, leaf = ?leaf, @@ -317,9 +305,7 @@ impl ProverSync { tokio::spawn(async move { loop { let local_root = self.local_root(); - let signed_update_opt = self - .db - .update_by_previous_root(&self.home_name, local_root)?; + let signed_update_opt = self.db.update_by_previous_root(local_root)?; // This if block is somewhat ugly. // First we check if there is a signed update with the local root. @@ -335,11 +321,7 @@ impl ProverSync { ); self.update_full(local_root, signed_update.update.new_root) .await?; - } else if !local_root.is_zero() - && self - .db - .update_by_new_root(&self.home_name, local_root)? - .is_none() + } else if !local_root.is_zero() && self.db.update_by_new_root(local_root)?.is_none() { bail!(ProverSyncError::InvalidLocalRoot { local_root }); } diff --git a/rust/agents/processor/src/push.rs b/rust/agents/processor/src/push.rs index e42edfc410..5a9cf81b39 100644 --- a/rust/agents/processor/src/push.rs +++ b/rust/agents/processor/src/push.rs @@ -112,12 +112,12 @@ impl Pusher { tokio::spawn(async move { let mut index = 0; loop { - let proof = self.db.proof_by_leaf_index(&self.name, index)?; + let proof = self.db.proof_by_leaf_index(index)?; match proof { Some(proof) => { let message = self .db - .message_by_leaf_index(&self.name, index)? + .message_by_leaf_index(index)? .ok_or_else(|| eyre!("Missing message for known proof"))?; let proven = ProvenMessage { proof, diff --git a/rust/agents/relayer/Cargo.toml b/rust/agents/relayer/Cargo.toml index aeca6d7890..a04096d63a 100644 --- a/rust/agents/relayer/Cargo.toml +++ b/rust/agents/relayer/Cargo.toml @@ -2,7 +2,7 @@ name = "relayer" version = "0.1.0" authors = ["ltchang "] -edition = "2018" +edition = "2021" [dependencies] tokio = { version = "1.0.1", features = ["rt", "macros"] } diff --git a/rust/agents/updater/Cargo.toml b/rust/agents/updater/Cargo.toml index 0c8898c6b5..c77413a0ff 100644 --- a/rust/agents/updater/Cargo.toml +++ b/rust/agents/updater/Cargo.toml @@ -2,7 +2,7 @@ name = "updater" version = "0.1.0" authors = ["James Prestwich "] -edition = "2018" +edition = "2021" [dependencies] tokio = { version = "1.0.1", features = ["rt", "macros"] } @@ -27,6 +27,7 @@ paste = "1.0.5" prometheus = "0.12" warp = "0.3" +hex = "0.4.3" [dev-dependencies] mockall = "0.9.1" diff --git a/rust/agents/updater/src/main.rs b/rust/agents/updater/src/main.rs index a7f6997e38..e5af868609 100644 --- a/rust/agents/updater/src/main.rs +++ b/rust/agents/updater/src/main.rs @@ -7,7 +7,9 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] +mod produce; mod settings; +mod submit; mod updater; use color_eyre::Result; diff --git a/rust/agents/updater/src/produce.rs b/rust/agents/updater/src/produce.rs new file mode 100644 index 0000000000..11abc36d56 --- /dev/null +++ b/rust/agents/updater/src/produce.rs @@ -0,0 +1,122 @@ +use ethers::core::types::H256; +use prometheus::IntCounterVec; +use std::{sync::Arc, time::Duration}; + +use color_eyre::Result; +use optics_base::{Homes, OpticsAgent}; +use optics_core::{db::OpticsDB, Common, Home, Signers}; +use tokio::{task::JoinHandle, time::sleep}; +use tracing::{debug, info, info_span, instrument::Instrumented, Instrument}; + +use crate::updater::Updater; + +#[derive(Debug)] +pub(crate) struct UpdateProducer { + home: Arc, + db: OpticsDB, + signer: Arc, + interval_seconds: u64, + update_pause: u64, + signed_attestation_count: IntCounterVec, +} + +impl UpdateProducer { + pub(crate) fn new( + home: Arc, + db: OpticsDB, + signer: Arc, + interval_seconds: u64, + update_pause: u64, + signed_attestation_count: IntCounterVec, + ) -> Self { + Self { + home, + db, + signer, + interval_seconds, + update_pause, + signed_attestation_count, + } + } + + fn find_latest_root(&self) -> Result { + // If db latest root is empty, this will produce `H256::default()` + // which is equal to `H256::zero()` + Ok(self.db.retrieve_latest_root()?.unwrap_or_default()) + } + + pub(crate) fn spawn(self) -> Instrumented>> { + let span = info_span!("UpdateProducer"); + tokio::spawn(async move { + loop { + // We sleep at the top to make continues work fine + sleep(Duration::from_secs(self.interval_seconds)).await; + + let current_root = self.find_latest_root()?; + + if let Some(suggested) = self.home.produce_update().await? { + if suggested.previous_root != current_root { + // This either indicates that the indexer is catching + // up or that the chain is awaiting a new update. We + // should ignore it. + debug!( + local = ?suggested.previous_root, + remote = ?current_root, + "Local root not equal to chain root. Skipping update." + ); + continue; + } + + // Ensure we have not already signed a conflicting update. + // Ignore suggested if we have. + if let Some(existing) = self.db.retrieve_produced_update(suggested.previous_root)? { + if existing.update.new_root != suggested.new_root { + info!("Updater ignoring conflicting suggested update. Indicates chain awaiting already produced update. Existing update: {:?}. Suggested conflicting update: {:?}.", &existing, &suggested); + + continue; + } + } + + // Sleep for `update_pause` seconds so we can check for + // unwanted state changes afterwards + sleep(Duration::from_secs(self.update_pause)).await; + + // If HomeIndexer found new root from that doesn't + // match our most current root, continue + if self.find_latest_root()? != current_root { + continue; + } + + // If home produced update builds off a different root than + // our suggested update's previous root, continue + if let Some(check_suggested) = self.home.produce_update().await? { + if check_suggested.previous_root != suggested.previous_root { + continue; + } + } else { + continue; + } + + // If the suggested matches our local view, sign an update + // and store it as locally produced + let signed = suggested.sign_with(self.signer.as_ref()).await?; + + self.signed_attestation_count + .with_label_values(&[self.home.name(), Updater::AGENT_NAME]) + .inc(); + + let hex_signature = format!("0x{}", hex::encode(signed.signature.to_vec())); + info!( + previous_root = ?signed.update.previous_root, + new_root = ?signed.update.new_root, + hex_signature = %hex_signature, + "Storing new update in DB for broadcast" + ); + + self.db.store_produced_update(&signed)?; + } + } + }) + .instrument(span) + } +} diff --git a/rust/agents/updater/src/submit.rs b/rust/agents/updater/src/submit.rs new file mode 100644 index 0000000000..d57a20eb02 --- /dev/null +++ b/rust/agents/updater/src/submit.rs @@ -0,0 +1,55 @@ +use std::sync::Arc; + +use optics_base::Homes; +use optics_core::{db::OpticsDB, Common}; +use std::time::Duration; + +use color_eyre::Result; +use tokio::{task::JoinHandle, time::sleep}; +use tracing::{info, info_span, instrument::Instrumented, Instrument}; + +pub(crate) struct UpdateSubmitter { + home: Arc, + db: OpticsDB, + interval_seconds: u64, +} + +impl UpdateSubmitter { + pub(crate) fn new(home: Arc, db: OpticsDB, interval_seconds: u64) -> Self { + Self { + home, + db, + interval_seconds, + } + } + + pub(crate) fn spawn(self) -> Instrumented>> { + let span = info_span!("UpdateSubmitter"); + + tokio::spawn(async move { + // start from the chain state + let mut committed_root = self.home.committed_root().await?; + + loop { + sleep(Duration::from_secs(self.interval_seconds)).await; + + // if we have produced an update building off the committed root + // submit it + if let Some(signed) = self.db.retrieve_produced_update(committed_root)? { + let hex_signature = format!("0x{}", hex::encode(signed.signature.to_vec())); + info!( + previous_root = ?signed.update.previous_root, + new_root = ?signed.update.new_root, + hex_signature = %hex_signature, + "Submitting update to chain" + ); + self.home.update(&signed).await?; + + // continue from local state + committed_root = signed.update.new_root; + } + } + }) + .instrument(span) + } +} diff --git a/rust/agents/updater/src/updater.rs b/rust/agents/updater/src/updater.rs index 698fba30e8..8ec4fd7b9b 100644 --- a/rust/agents/updater/src/updater.rs +++ b/rust/agents/updater/src/updater.rs @@ -1,200 +1,18 @@ -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; use async_trait::async_trait; -use color_eyre::{ - eyre::{bail, ensure, Context}, - Result, -}; +use color_eyre::{eyre::ensure, Result}; use ethers::{signers::Signer, types::Address}; use futures_util::future::select_all; use prometheus::IntCounterVec; -use tokio::{ - sync::{ - mpsc::{self, error::TrySendError, Receiver, Sender}, - Mutex, - }, - task::JoinHandle, - time::sleep, -}; -use tracing::{error, info, instrument::Instrumented, Instrument}; - -use crate::settings::UpdaterSettings as Settings; -use optics_base::{AgentCore, Homes, OpticsAgent}; -use optics_core::{db::OpticsDB, Common, Home, SignedUpdate, Signers, Update}; - -#[derive(Debug)] -struct UpdateHandler { - home: Arc, - - rx: Receiver, - update_pause: u64, - signer: Arc, - db: OpticsDB, - mutex: Arc>, - signed_attestation_count: IntCounterVec, -} - -impl std::fmt::Display for UpdateHandler { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "UpdateHandler: {{ home: {:?}, signer: {:?}, update_pause: {} }}", - self.home, self.signer, self.update_pause - ) - } -} - -impl UpdateHandler { - fn new( - home: Arc, - rx: Receiver, - update_pause: u64, - signer: Arc, - db: OpticsDB, - mutex: Arc>, - signed_attestation_count: IntCounterVec, - ) -> Self { - Self { - home, - rx, - update_pause, - signer, - db, - mutex, - signed_attestation_count, - } - } - - fn check_conflict(&self, update: &Update) -> Option { - self.db - .update_by_previous_root(self.home.name(), update.previous_root) - .expect("db failure") - } - - #[tracing::instrument(err, skip(self), fields(self = %self))] - async fn acceptable(&self, update: &Update) -> Result { - // Poll chain API to see if queue still contains new root - // and old root still equals home's current root - let (in_queue, committed_root) = tokio::join!( - self.home.queue_contains(update.new_root), - self.home.committed_root() - ); - - if in_queue.is_err() { - info!("Update no longer in queue"); - } - if committed_root.is_err() { - error!("Connection gone"); - } - - let in_queue = in_queue?; - let committed_root = committed_root?; - - let old_root = update.previous_root; - Ok(in_queue && committed_root == old_root) - } - - #[tracing::instrument(err, skip(self), fields(self = %self))] - async fn handle_update(&self, update: Update) -> Result<()> { - info!("Have an update, awaiting the tick"); - - // We poll acceptable immediately, to prevent waiting on - // any unacceptable updates that got into the channel - // We poll it AGAIN after sleeping to ensure that the update - // is still acceptable. - - // TODO(james): later refactor this to only allow acceptable - // updates into the channel? - if !self.acceptable(&update).await? { - info!("Declined to submit update. No longer current"); - return Ok(()); - } - - // Wait `update_pause` seconds - sleep(Duration::from_secs(self.update_pause)).await; - - if !self.acceptable(&update).await? { - info!("Declined to submit update. No longer current"); - return Ok(()); - } +use tokio::task::JoinHandle; +use tracing::{instrument::Instrumented, Instrument}; - // acquire guard. If the guard can't be acquired, that - // means a tx is in flight and we should try again later. - let _guard = self - .mutex - .try_lock() - .wrap_err("Declined to submit update.")?; - - // If update still valid and doesn't conflict with local - // history of signed updates, sign and submit update. Note - // that because we acquire a guard, only one task - // can check and enter the below `if` block at a time, - // protecting from races between threads. - - if self.check_conflict(&update).is_some() { - bail!("Found conflicting update in DB"); - } - - // If we have a conflict, we grab that one instead - let signed = update.sign_with(self.signer.as_ref()).await.unwrap(); - - // If successfully submitted update, record in db - info!( - "Dispatching signed update to contract. Current root is {:?}, new root is {:?}", - &signed.update.previous_root, &signed.update.new_root - ); - - self.signed_attestation_count - .with_label_values(&[self.home.name(), Updater::AGENT_NAME]) - .inc(); - self.home.update(&signed).await?; - - info!("Storing signed update in db"); - self.db.store_latest_update(self.home.name(), &signed)?; - Ok(()) - // guard dropped here - } - - fn spawn(mut self) -> Instrumented>> { - tokio::spawn(async move { - while let Some(update) = self.rx.recv().await { - self.handle_update(update).await?; - } - Ok(()) - }) - .in_current_span() - } -} - -struct UpdatePoller { - home: Arc, - tx: Sender, - interval_seconds: u64, -} - -impl UpdatePoller { - fn new(home: Arc, tx: Sender, interval_seconds: u64) -> Self { - Self { - home, - tx, - interval_seconds, - } - } - - fn spawn(self) -> Instrumented>> { - tokio::spawn(async move { - loop { - if let Some(update) = self.home.produce_update().await? { - if let Err(TrySendError::Closed(_)) = self.tx.try_send(update) { - bail!("UpdatePoller died"); - } - } - sleep(Duration::from_secs(self.interval_seconds)).await; - } - }) - .in_current_span() - } -} +use crate::{ + produce::UpdateProducer, settings::UpdaterSettings as Settings, submit::UpdateSubmitter, +}; +use optics_base::{AgentCore, OpticsAgent}; +use optics_core::{db::OpticsDB, Common, Signers}; /// An updater agent #[derive(Debug)] @@ -258,19 +76,19 @@ impl OpticsAgent for Updater { // First we check that we have the correct key to sign with. let home = self.home(); let address = self.signer.address(); + let db = OpticsDB::new(self.home().name(), self.db()); - let (tx, rx) = mpsc::channel(1); - let poller = UpdatePoller::new(self.home(), tx, self.interval_seconds); - let handler = UpdateHandler::new( + let produce = UpdateProducer::new( self.home(), - rx, - self.update_pause, + db.clone(), self.signer.clone(), - OpticsDB::new(self.db()), - Default::default(), + self.interval_seconds, + self.update_pause, self.signed_attestation_count.clone(), ); + let submit = UpdateSubmitter::new(self.home(), db, self.interval_seconds); + tokio::spawn(async move { let expected: Address = home.updater().await?.into(); ensure!( @@ -279,10 +97,10 @@ impl OpticsAgent for Updater { expected, address ); - let poller_task = poller.spawn(); - let handler_task = handler.spawn(); + let produce_task = produce.spawn(); + let submit_task = submit.spawn(); - let (res, _, rem) = select_all(vec![poller_task, handler_task]).await; + let (res, _, rem) = select_all(vec![produce_task, submit_task]).await; for task in rem.into_iter() { task.into_inner().abort(); diff --git a/rust/agents/watcher/Cargo.toml b/rust/agents/watcher/Cargo.toml index 1fcbd26636..3e1c36ce38 100644 --- a/rust/agents/watcher/Cargo.toml +++ b/rust/agents/watcher/Cargo.toml @@ -2,7 +2,7 @@ name = "watcher" version = "0.1.0" authors = ["Luke Tchang "] -edition = "2018" +edition = "2021" [dependencies] tokio = { version = "1.0.1", features = ["rt", "macros"] } diff --git a/rust/agents/watcher/src/watcher.rs b/rust/agents/watcher/src/watcher.rs index 2f385e4798..471580c379 100644 --- a/rust/agents/watcher/src/watcher.rs +++ b/rust/agents/watcher/src/watcher.rs @@ -681,7 +681,7 @@ mod test { let (_tx, rx) = mpsc::channel(200); let mut handler = UpdateHandler { rx, - db: OpticsDB::new(db), + db: OpticsDB::new("home", db), home: Arc::new(mock_home.into()), }; diff --git a/rust/chains/optics-ethereum/Cargo.toml b/rust/chains/optics-ethereum/Cargo.toml index adf702ec4c..e14512fd29 100644 --- a/rust/chains/optics-ethereum/Cargo.toml +++ b/rust/chains/optics-ethereum/Cargo.toml @@ -2,7 +2,7 @@ name = "optics-ethereum" version = "0.1.0" authors = ["Erin Hales "] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/rust/chains/optics-ethereum/src/home.rs b/rust/chains/optics-ethereum/src/home.rs index 7e06e7cbbc..ab7dbc5143 100644 --- a/rust/chains/optics-ethereum/src/home.rs +++ b/rust/chains/optics-ethereum/src/home.rs @@ -33,17 +33,24 @@ use crate::report_tx; static LAST_INSPECTED: &str = "homeIndexerLastInspected"; -#[allow(missing_docs)] abigen!( EthereumHomeInternal, "./chains/optics-ethereum/abis/Home.abi.json" ); +impl std::fmt::Display for EthereumHomeInternal +where + M: ethers::providers::Middleware, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + struct HomeIndexer where M: ethers::providers::Middleware, { - home_name: String, contract: Arc>, provider: Arc, db: OpticsDB, @@ -95,9 +102,8 @@ where for update_with_meta in updates_with_meta { self.db - .store_latest_update(&self.home_name, &update_with_meta.signed_update)?; + .store_latest_update(&update_with_meta.signed_update)?; self.db.store_update_metadata( - &self.home_name, update_with_meta.signed_update.update.new_root, update_with_meta.metadata, )?; @@ -130,8 +136,7 @@ where }); for message in messages { - self.db - .store_raw_committed_message(&self.home_name, &message)?; + self.db.store_raw_committed_message(&message)?; let committed_message: CommittedMessage = message.try_into()?; info!( @@ -152,7 +157,7 @@ where tokio::spawn(async move { let mut next_height: u32 = self .db - .retrieve_decodable(&self.home_name, "", LAST_INSPECTED) + .retrieve_decodable("", LAST_INSPECTED) .expect("db failure") .unwrap_or(self.from_height); info!( @@ -180,8 +185,7 @@ where self.sync_leaves(next_height, to) )?; - self.db - .store_encodable(&self.home_name, "", LAST_INSPECTED, &next_height)?; + self.db.store_encodable("", LAST_INSPECTED, &next_height)?; next_height = to; // sleep here if we've caught up if to == tip { @@ -225,7 +229,7 @@ where contract: Arc::new(EthereumHomeInternal::new(address, provider.clone())), domain: *domain, name: name.to_owned(), - db: OpticsDB::new(db), + db: OpticsDB::new(name.to_owned(), db), provider, } } @@ -278,7 +282,7 @@ where old_root: H256, ) -> Result, ChainCommunicationError> { loop { - if let Some(update) = self.db.update_by_previous_root(&self.name, old_root)? { + if let Some(update) = self.db.update_by_previous_root(old_root)? { return Ok(Some(update)); } sleep(Duration::from_millis(500)).await; @@ -291,14 +295,14 @@ where new_root: H256, ) -> Result, ChainCommunicationError> { loop { - if let Some(update) = self.db.update_by_new_root(&self.name, new_root)? { + if let Some(update) = self.db.update_by_new_root(new_root)? { return Ok(Some(update)); } sleep(Duration::from_millis(500)).await; } } - #[tracing::instrument(err, skip(self), fields(hexSignature = %format!("0x{}", hex::encode(update.signature.to_vec()))))] + #[tracing::instrument(err, skip(self), fields(hex_signature = %format!("0x{}", hex::encode(update.signature.to_vec()))))] async fn update(&self, update: &SignedUpdate) -> Result { let tx = self.contract.update( update.update.previous_root.to_fixed_bytes(), @@ -346,7 +350,6 @@ where indexed_height: prometheus::IntGauge, ) -> Instrumented>> { let indexer = HomeIndexer { - home_name: self.name.to_owned(), contract: self.contract.clone(), db: self.db.clone(), from_height, @@ -364,7 +367,7 @@ where nonce: u32, ) -> Result, ChainCommunicationError> { loop { - if let Some(update) = self.db.message_by_nonce(&self.name, destination, nonce)? { + if let Some(update) = self.db.message_by_nonce(destination, nonce)? { return Ok(Some(update)); } sleep(Duration::from_millis(500)).await; @@ -377,7 +380,7 @@ where leaf: H256, ) -> Result, ChainCommunicationError> { loop { - if let Some(update) = self.db.message_by_leaf(&self.name, leaf)? { + if let Some(update) = self.db.message_by_leaf(leaf)? { return Ok(Some(update)); } sleep(Duration::from_millis(500)).await; @@ -389,7 +392,7 @@ where tree_index: usize, ) -> Result, ChainCommunicationError> { loop { - if let Some(update) = self.db.leaf_by_leaf_index(&self.name, tree_index as u32)? { + if let Some(update) = self.db.leaf_by_leaf_index(tree_index as u32)? { return Ok(Some(update)); } sleep(Duration::from_millis(500)).await; @@ -416,7 +419,7 @@ where Ok(self.contract.queue_contains(root.into()).call().await?) } - #[tracing::instrument(err, skip(self), fields(hexSignature = %format!("0x{}", hex::encode(update.signature.to_vec()))))] + #[tracing::instrument(err, skip(self), fields(hex_signature = %format!("0x{}", hex::encode(update.signature.to_vec()))))] async fn improper_update( &self, update: &SignedUpdate, diff --git a/rust/chains/optics-ethereum/src/lib.rs b/rust/chains/optics-ethereum/src/lib.rs index 3b06a6c763..f0e109e0db 100644 --- a/rust/chains/optics-ethereum/src/lib.rs +++ b/rust/chains/optics-ethereum/src/lib.rs @@ -4,6 +4,7 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] +use color_eyre::eyre::Result; use ethers::prelude::*; use num::Num; use optics_core::*; @@ -69,10 +70,7 @@ contract!( #[async_trait::async_trait] impl optics_core::Chain for Chain { - async fn query_balance( - &self, - addr: optics_core::Address, - ) -> anyhow::Result { + async fn query_balance(&self, addr: optics_core::Address) -> Result { let balance = format!( "{:x}", self.ethers diff --git a/rust/chains/optics-ethereum/src/replica.rs b/rust/chains/optics-ethereum/src/replica.rs index 0f1157fcac..1845cedc62 100644 --- a/rust/chains/optics-ethereum/src/replica.rs +++ b/rust/chains/optics-ethereum/src/replica.rs @@ -10,7 +10,6 @@ use std::{convert::TryFrom, error::Error as StdError, sync::Arc}; use crate::report_tx; -#[allow(missing_docs)] abigen!( EthereumReplicaInternal, "./chains/optics-ethereum/abis/Replica.abi.json", @@ -20,6 +19,15 @@ abigen!( }, ); +impl std::fmt::Display for EthereumReplicaInternal +where + M: ethers::providers::Middleware, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + /// A struct that provides access to an Ethereum replica contract #[derive(Debug)] pub struct EthereumReplica diff --git a/rust/chains/optics-ethereum/src/xapp.rs b/rust/chains/optics-ethereum/src/xapp.rs index a34ccba7f9..ea46720124 100644 --- a/rust/chains/optics-ethereum/src/xapp.rs +++ b/rust/chains/optics-ethereum/src/xapp.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use crate::report_tx; -#[allow(missing_docs)] abigen!( EthereumConnectionManagerInternal, "./chains/optics-ethereum/abis/XAppConnectionManager.abi.json" diff --git a/rust/optics-base/Cargo.toml b/rust/optics-base/Cargo.toml index 80f76e3fa5..1a1c3a74f9 100644 --- a/rust/optics-base/Cargo.toml +++ b/rust/optics-base/Cargo.toml @@ -2,7 +2,7 @@ name = "optics-base" version = "0.1.0" authors = ["James Prestwich "] -edition = "2018" +edition = "2021" [dependencies] diff --git a/rust/optics-core/Cargo.toml b/rust/optics-core/Cargo.toml index 91ef86315b..46a4dab333 100644 --- a/rust/optics-core/Cargo.toml +++ b/rust/optics-core/Cargo.toml @@ -2,7 +2,7 @@ name = "optics-core" version = "0.1.0" authors = ["James Prestwich "] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -25,7 +25,6 @@ rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb" } prometheus = "0.12.0" bytes = { version = "1", features = ["serde"]} num = {version="0", features=["serde"]} -anyhow = "1" [dev-dependencies] tokio = {version = "1.0.1", features = ["rt", "time"]} diff --git a/rust/optics-core/src/chain.rs b/rust/optics-core/src/chain.rs index a8f00669d6..7cd83eb048 100644 --- a/rust/optics-core/src/chain.rs +++ b/rust/optics-core/src/chain.rs @@ -1,11 +1,12 @@ #![allow(missing_docs)] +use color_eyre::eyre::Result; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Address(pub bytes::Bytes); -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize)] pub struct Balance(pub num::BigInt); #[derive(Debug, Clone, Serialize, Deserialize)] @@ -26,7 +27,8 @@ impl std::fmt::Display for ContractLocator { #[async_trait::async_trait] pub trait Chain { - async fn query_balance(&self, addr: Address) -> anyhow::Result; + /// Query the balance on a chain + async fn query_balance(&self, addr: Address) -> Result; } impl From
for ethers::types::H160 { diff --git a/rust/optics-core/src/db/mod.rs b/rust/optics-core/src/db/mod.rs index 7a5d6bdbe9..ca54f0b630 100644 --- a/rust/optics-core/src/db/mod.rs +++ b/rust/optics-core/src/db/mod.rs @@ -14,7 +14,7 @@ pub use typed_db::*; mod optics_db; pub use optics_db::*; -use crate::{Decode, Encode, OpticsError}; +use crate::{Decode, Encode, OpticsError, Update}; #[derive(Debug, Clone)] /// A KV Store @@ -35,6 +35,16 @@ pub enum DbError { /// Optics Error #[error("{0}")] OpticsError(#[from] OpticsError), + /// UpdaterConflictError + /// + /// TODO(luke): move this agent-related stuff into optics-base + #[error("Updater attempted to store conflicting signed update. Existing: {existing:?}. New conflicting: {conflicting:?}.")] + UpdaterConflictError { + /// Existing signed update + existing: Update, + /// Conflicting signed update + conflicting: Update, + }, } type Result = std::result::Result; diff --git a/rust/optics-core/src/db/optics_db.rs b/rust/optics-core/src/db/optics_db.rs index b59e821af6..4102fddf3e 100644 --- a/rust/optics-core/src/db/optics_db.rs +++ b/rust/optics-core/src/db/optics_db.rs @@ -1,13 +1,13 @@ use crate::db::{DbError, TypedDB, DB}; use crate::UpdateMeta; use crate::{ - accumulator::merkle::Proof, traits::RawCommittedMessage, utils, Decode, Encode, OpticsMessage, + accumulator::merkle::Proof, traits::RawCommittedMessage, utils, Decode, OpticsMessage, SignedUpdate, }; use color_eyre::Result; use ethers::core::types::H256; use tokio::time::sleep; -use tracing::{debug, warn}; +use tracing::{debug, error, warn}; use std::future::Future; use std::time::Duration; @@ -24,59 +24,38 @@ static UPDATE_META: &str = "update_metadata_"; static LATEST_ROOT: &str = "update_latest_root_"; static LATEST_NONCE: &str = "latest_nonce_"; static LATEST_LEAF_INDEX: &str = "latest_known_leaf_index_"; +static UPDATER_PRODUCED_UPDATE: &str = "updater_produced_update_"; /// DB handle for storing data tied to a specific home. /// -/// Key structure: ```__``` +/// Key structure: ```__``` #[derive(Debug, Clone)] pub struct OpticsDB(TypedDB); -impl OpticsDB { - /// Instantiated new `OpticsDB` - pub fn new(db: DB) -> Self { - Self(TypedDB::new(db)) - } +impl std::ops::Deref for OpticsDB { + type Target = TypedDB; - /// Store encodable value - pub fn store_encodable( - &self, - entity: impl AsRef<[u8]>, - prefix: impl AsRef<[u8]>, - key: impl AsRef<[u8]>, - value: &V, - ) -> Result<(), DbError> { - self.0.store_encodable(entity, prefix, key, value) + fn deref(&self) -> &Self::Target { + &self.0 } +} - /// Retrieve decodable value - pub fn retrieve_decodable( - &self, - entity: impl AsRef<[u8]>, - prefix: impl AsRef<[u8]>, - key: impl AsRef<[u8]>, - ) -> Result, DbError> { - self.0.retrieve_decodable(entity, prefix, key) +impl AsRef for OpticsDB { + fn as_ref(&self) -> &TypedDB { + &self.0 } +} - /// Store encodable kv pair - pub fn store_keyed_encodable( - &self, - entity: impl AsRef<[u8]>, - prefix: impl AsRef<[u8]>, - key: &K, - value: &V, - ) -> Result<(), DbError> { - self.0.store_keyed_encodable(entity, prefix, key, value) +impl AsRef for OpticsDB { + fn as_ref(&self) -> &DB { + self.0.as_ref() } +} - /// Retrieve decodable value given encodable key - pub fn retrieve_keyed_decodable( - &self, - entity: impl AsRef<[u8]>, - prefix: impl AsRef<[u8]>, - key: &K, - ) -> Result, DbError> { - self.0.retrieve_keyed_decodable(entity, prefix, key) +impl OpticsDB { + /// Instantiated new `OpticsDB` + pub fn new(entity: impl AsRef, db: DB) -> Self { + Self(TypedDB::new(entity.as_ref().to_owned(), db)) } /// Store a raw committed message @@ -85,11 +64,7 @@ impl OpticsDB { /// - `destination_and_nonce` --> `leaf` /// - `leaf_index` --> `leaf` /// - `leaf` --> `message` - pub fn store_raw_committed_message( - &self, - home_name: impl AsRef<[u8]>, - message: &RawCommittedMessage, - ) -> Result<()> { + pub fn store_raw_committed_message(&self, message: &RawCommittedMessage) -> Result<()> { let parsed = OpticsMessage::read_from(&mut message.message.clone().as_slice())?; let destination_and_nonce = parsed.destination_and_nonce(); @@ -104,39 +79,31 @@ impl OpticsDB { leaf_index = message.leaf_index, "storing raw committed message in db" ); - self.store_leaf(&home_name, message.leaf_index, destination_and_nonce, leaf)?; - self.store_keyed_encodable(&home_name, MESSAGE, &leaf, message)?; + self.store_leaf(message.leaf_index, destination_and_nonce, leaf)?; + self.store_keyed_encodable(MESSAGE, &leaf, message)?; Ok(()) } /// Store the latest known leaf_index /// /// Key --> value: `LATEST_LEAF_INDEX` --> `leaf_index` - pub fn update_latest_leaf_index( - &self, - home_name: impl AsRef<[u8]>, - leaf_index: u32, - ) -> Result<(), DbError> { - if let Ok(Some(idx)) = self.retrieve_latest_leaf_index(&home_name) { + pub fn update_latest_leaf_index(&self, leaf_index: u32) -> Result<(), DbError> { + if let Ok(Some(idx)) = self.retrieve_latest_leaf_index() { if leaf_index <= idx { return Ok(()); } } - self.store_encodable(&home_name, "", LATEST_LEAF_INDEX, &leaf_index) + self.store_encodable("", LATEST_LEAF_INDEX, &leaf_index) } /// Retrieve the highest known leaf_index - pub fn retrieve_latest_leaf_index( - &self, - home_name: impl AsRef<[u8]>, - ) -> Result, DbError> { - self.retrieve_decodable(home_name, "", LATEST_LEAF_INDEX) + pub fn retrieve_latest_leaf_index(&self) -> Result, DbError> { + self.retrieve_decodable("", LATEST_LEAF_INDEX) } /// Store the leaf keyed by leaf_index fn store_leaf( &self, - home_name: impl AsRef<[u8]>, leaf_index: u32, destination_and_nonce: u64, leaf: H256, @@ -146,64 +113,49 @@ impl OpticsDB { leaf = ?leaf, "storing leaf hash keyed by index and dest+nonce" ); - self.store_keyed_encodable(&home_name, LEAF, &destination_and_nonce, &leaf)?; - self.store_keyed_encodable(&home_name, LEAF, &leaf_index, &leaf)?; - self.update_latest_leaf_index(&home_name, leaf_index) + self.store_keyed_encodable(LEAF, &destination_and_nonce, &leaf)?; + self.store_keyed_encodable(LEAF, &leaf_index, &leaf)?; + self.update_latest_leaf_index(leaf_index) } /// Retrieve a raw committed message by its leaf hash - pub fn message_by_leaf( - &self, - home_name: impl AsRef<[u8]>, - leaf: H256, - ) -> Result, DbError> { - self.retrieve_keyed_decodable(home_name, MESSAGE, &leaf) + pub fn message_by_leaf(&self, leaf: H256) -> Result, DbError> { + self.retrieve_keyed_decodable(MESSAGE, &leaf) } /// Retrieve the leaf hash keyed by leaf index - pub fn leaf_by_leaf_index( - &self, - home_name: impl AsRef<[u8]>, - leaf_index: u32, - ) -> Result, DbError> { - self.retrieve_keyed_decodable(home_name, LEAF, &leaf_index) + pub fn leaf_by_leaf_index(&self, leaf_index: u32) -> Result, DbError> { + self.retrieve_keyed_decodable(LEAF, &leaf_index) } /// Retrieve the leaf hash keyed by destination and nonce - pub fn leaf_by_nonce( - &self, - home_name: impl AsRef<[u8]>, - destination: u32, - nonce: u32, - ) -> Result, DbError> { + pub fn leaf_by_nonce(&self, destination: u32, nonce: u32) -> Result, DbError> { let dest_and_nonce = utils::destination_and_nonce(destination, nonce); - self.retrieve_keyed_decodable(home_name, LEAF, &dest_and_nonce) + self.retrieve_keyed_decodable(LEAF, &dest_and_nonce) } /// Retrieve a raw committed message by its leaf hash pub fn message_by_nonce( &self, - home_name: impl AsRef<[u8]>, destination: u32, nonce: u32, ) -> Result, DbError> { - let leaf = self.leaf_by_nonce(&home_name, destination, nonce)?; + let leaf = self.leaf_by_nonce(destination, nonce)?; match leaf { None => Ok(None), - Some(leaf) => self.message_by_leaf(&home_name, leaf), + Some(leaf) => self.message_by_leaf(leaf), } } /// Retrieve a raw committed message by its leaf index pub fn message_by_leaf_index( &self, - home_name: impl AsRef<[u8]>, index: u32, ) -> Result, DbError> { - let leaf: Option = self.leaf_by_leaf_index(&home_name, index)?; + let leaf: Option = self.leaf_by_leaf_index(index)?; match leaf { None => Ok(None), - Some(leaf) => self.message_by_leaf(&home_name, leaf), + Some(leaf) => self.message_by_leaf(leaf), } } @@ -211,35 +163,26 @@ impl OpticsDB { /// /// Keys --> Values: /// - `replica_domain` --> `nonce` - pub fn store_latest_nonce( - &self, - home_name: impl AsRef<[u8]>, - replica_domain: u32, - nonce: u32, - ) -> Result<(), DbError> { - self.store_keyed_encodable(home_name, LATEST_NONCE, &replica_domain, &nonce)?; + pub fn store_latest_nonce(&self, replica_domain: u32, nonce: u32) -> Result<(), DbError> { + self.store_keyed_encodable(LATEST_NONCE, &replica_domain, &nonce)?; Ok(()) } /// Retrieves the latest inspected nonce for a given replica domain - pub fn retrieve_latest_nonce( - &self, - home_name: impl AsRef<[u8]>, - replica_domain: u32, - ) -> Result, DbError> { - self.retrieve_keyed_decodable(home_name, LATEST_NONCE, &replica_domain) + pub fn retrieve_latest_nonce(&self, replica_domain: u32) -> Result, DbError> { + self.retrieve_keyed_decodable(LATEST_NONCE, &replica_domain) } /// Store the latest committed - fn store_latest_root(&self, entity: impl AsRef<[u8]>, root: H256) -> Result<(), DbError> { + fn store_latest_root(&self, root: H256) -> Result<(), DbError> { debug!(root = ?root, "storing new latest root in DB"); - self.store_encodable(entity, "", LATEST_ROOT, &root) + self.store_encodable("", LATEST_ROOT, &root) } /// Retrieve the latest committed - pub fn retrieve_latest_root(&self, entity: impl AsRef<[u8]>) -> Result, DbError> { - self.retrieve_decodable(entity, "", LATEST_ROOT) + pub fn retrieve_latest_root(&self) -> Result, DbError> { + self.retrieve_decodable("", LATEST_ROOT) } /// Store update metadata (by update's new root) @@ -248,22 +191,17 @@ impl OpticsDB { /// - `update_new_root` --> `update_metadata` pub fn store_update_metadata( &self, - entity: impl AsRef<[u8]>, new_root: H256, metadata: UpdateMeta, ) -> Result<(), DbError> { debug!(new_root = ?new_root, metadata = ?metadata, "storing update metadata in DB"); - self.store_keyed_encodable(entity, UPDATE_META, &new_root, &metadata) + self.store_keyed_encodable(UPDATE_META, &new_root, &metadata) } /// Retrieve update metadata (by update's new root) - pub fn retrieve_update_metadata( - &self, - entity: impl AsRef<[u8]>, - new_root: H256, - ) -> Result, DbError> { - self.retrieve_keyed_decodable(entity, UPDATE_META, &new_root) + pub fn retrieve_update_metadata(&self, new_root: H256) -> Result, DbError> { + self.retrieve_keyed_decodable(UPDATE_META, &new_root) } /// Store a signed update building off latest root @@ -272,11 +210,7 @@ impl OpticsDB { /// - `LATEST_ROOT` --> `root` /// - `new_root` --> `prev_root` /// - `prev_root` --> `update` - pub fn store_latest_update( - &self, - entity: impl AsRef<[u8]>, - update: &SignedUpdate, - ) -> Result<(), DbError> { + pub fn store_latest_update(&self, update: &SignedUpdate) -> Result<(), DbError> { debug!( previous_root = ?update.update.previous_root, new_root = ?update.update.new_root, @@ -285,10 +219,10 @@ impl OpticsDB { // If there is no latest root, or if this update is on the latest root // update latest root - match self.retrieve_latest_root(&entity)? { + match self.retrieve_latest_root()? { Some(root) => { if root == update.update.previous_root { - self.store_latest_root(&entity, update.update.new_root)?; + self.store_latest_root(update.update.new_root)?; } else { warn!( "Attempted to store update not building off latest root: {:?}", @@ -296,12 +230,11 @@ impl OpticsDB { ) } } - None => self.store_latest_root(&entity, update.update.new_root)?, + None => self.store_latest_root(update.update.new_root)?, } - self.store_keyed_encodable(&entity, UPDATE, &update.update.previous_root, update)?; + self.store_keyed_encodable(UPDATE, &update.update.previous_root, update)?; self.store_keyed_encodable( - &entity, PREV_ROOT, &update.update.new_root, &update.update.previous_root, @@ -311,70 +244,86 @@ impl OpticsDB { /// Retrieve an update by its previous root pub fn update_by_previous_root( &self, - entity: impl AsRef<[u8]>, previous_root: H256, ) -> Result, DbError> { - self.retrieve_keyed_decodable(entity, UPDATE, &previous_root) + self.retrieve_keyed_decodable(UPDATE, &previous_root) } /// Retrieve an update by its new root - pub fn update_by_new_root( - &self, - entity: impl AsRef<[u8]>, - new_root: H256, - ) -> Result, DbError> { - let prev_root: Option = - self.retrieve_keyed_decodable(&entity, PREV_ROOT, &new_root)?; + pub fn update_by_new_root(&self, new_root: H256) -> Result, DbError> { + let prev_root: Option = self.retrieve_keyed_decodable(PREV_ROOT, &new_root)?; match prev_root { - Some(prev_root) => self.update_by_previous_root(&entity, prev_root), + Some(prev_root) => self.update_by_previous_root(prev_root), None => Ok(None), } } /// Iterate over all leaves pub fn leaf_iterator(&self) -> PrefixIterator { - PrefixIterator::new(self.0.db().prefix_iterator(LEAF_IDX), LEAF_IDX.as_ref()) + PrefixIterator::new(self.0.as_ref().prefix_iterator(LEAF_IDX), LEAF_IDX.as_ref()) } /// Store a proof by its leaf index /// /// Keys --> Values: /// - `leaf_index` --> `proof` - pub fn store_proof( - &self, - home_name: impl AsRef<[u8]>, - leaf_index: u32, - proof: &Proof, - ) -> Result<(), DbError> { + pub fn store_proof(&self, leaf_index: u32, proof: &Proof) -> Result<(), DbError> { debug!(leaf_index, "storing proof in DB"); - self.store_keyed_encodable(home_name, PROOF, &leaf_index, proof) + self.store_keyed_encodable(PROOF, &leaf_index, proof) } /// Retrieve a proof by its leaf index - pub fn proof_by_leaf_index( - &self, - home_name: impl AsRef<[u8]>, - leaf_index: u32, - ) -> Result, DbError> { - self.retrieve_keyed_decodable(home_name, PROOF, &leaf_index) + pub fn proof_by_leaf_index(&self, leaf_index: u32) -> Result, DbError> { + self.retrieve_keyed_decodable(PROOF, &leaf_index) } // TODO(james): this is a quick-fix for the prover_sync and I don't like it /// poll db ever 100 milliseconds waitinf for a leaf. pub fn wait_for_leaf( &self, - home_name: impl AsRef<[u8]>, leaf_index: u32, ) -> impl Future, DbError>> { let slf = self.clone(); async move { loop { - if let Some(leaf) = slf.leaf_by_leaf_index(&home_name, leaf_index)? { + if let Some(leaf) = slf.leaf_by_leaf_index(leaf_index)? { return Ok(Some(leaf)); } sleep(Duration::from_millis(100)).await } } } + + /// Store a pending update in the DB for potential submission. + /// + /// This does not produce update meta or update the latest update db value. + /// It is used by update production and submission. + pub fn store_produced_update(&self, update: &SignedUpdate) -> Result<(), DbError> { + let existing_opt = self.retrieve_produced_update(update.update.previous_root)?; + if let Some(existing) = existing_opt { + if existing.update.new_root != update.update.new_root { + error!("Updater attempted to store conflicting update. Existing update: {:?}. New conflicting update: {:?}.", &existing, &update); + + return Err(DbError::UpdaterConflictError { + existing: existing.update, + conflicting: update.update, + }); + } + } + + self.store_keyed_encodable( + UPDATER_PRODUCED_UPDATE, + &update.update.previous_root, + update, + ) + } + + /// Retrieve a pending update from the DB (if one exists). + pub fn retrieve_produced_update( + &self, + previous_root: H256, + ) -> Result, DbError> { + self.retrieve_keyed_decodable(UPDATER_PRODUCED_UPDATE, &previous_root) + } } diff --git a/rust/optics-core/src/db/typed_db.rs b/rust/optics-core/src/db/typed_db.rs index f67b3a1eb2..6bdbfb8e34 100644 --- a/rust/optics-core/src/db/typed_db.rs +++ b/rust/optics-core/src/db/typed_db.rs @@ -6,22 +6,26 @@ use color_eyre::Result; /// /// Key structure: ```__``` #[derive(Debug, Clone)] -pub struct TypedDB(DB); +pub struct TypedDB { + entity: String, + db: DB, +} -impl TypedDB { - /// Instantiate new `TypedDB` - pub fn new(db: DB) -> Self { - Self(db) +impl AsRef for TypedDB { + fn as_ref(&self) -> &DB { + &self.db } +} - /// Return reference to raw db - pub fn db(&self) -> &DB { - &self.0 +impl TypedDB { + /// Instantiate new `TypedDB` + pub fn new(entity: String, db: DB) -> Self { + Self { entity, db } } - fn full_prefix(entity: impl AsRef<[u8]>, prefix: impl AsRef<[u8]>) -> Vec { + fn full_prefix(&self, prefix: impl AsRef<[u8]>) -> Vec { let mut full_prefix = vec![]; - full_prefix.extend(entity.as_ref()); + full_prefix.extend(self.entity.as_ref() as &[u8]); full_prefix.extend("_".as_bytes()); full_prefix.extend(prefix.as_ref()); full_prefix @@ -30,46 +34,41 @@ impl TypedDB { /// Store encodable value pub fn store_encodable( &self, - entity: impl AsRef<[u8]>, prefix: impl AsRef<[u8]>, key: impl AsRef<[u8]>, value: &V, ) -> Result<(), DbError> { - self.0 - .store_encodable(TypedDB::full_prefix(entity, prefix), key, value) + self.db + .store_encodable(self.full_prefix(prefix), key, value) } /// Retrieve decodable value pub fn retrieve_decodable( &self, - entity: impl AsRef<[u8]>, prefix: impl AsRef<[u8]>, key: impl AsRef<[u8]>, ) -> Result, DbError> { - self.0 - .retrieve_decodable(TypedDB::full_prefix(entity, prefix), key) + self.db.retrieve_decodable(self.full_prefix(prefix), key) } /// Store encodable kv pair pub fn store_keyed_encodable( &self, - entity: impl AsRef<[u8]>, prefix: impl AsRef<[u8]>, key: &K, value: &V, ) -> Result<(), DbError> { - self.0 - .store_keyed_encodable(TypedDB::full_prefix(entity, prefix), key, value) + self.db + .store_keyed_encodable(self.full_prefix(prefix), key, value) } /// Retrieve decodable value given encodable key pub fn retrieve_keyed_decodable( &self, - entity: impl AsRef<[u8]>, prefix: impl AsRef<[u8]>, key: &K, ) -> Result, DbError> { - self.0 - .retrieve_keyed_decodable(TypedDB::full_prefix(entity, prefix), key) + self.db + .retrieve_keyed_decodable(self.full_prefix(prefix), key) } } diff --git a/rust/optics-core/src/lib.rs b/rust/optics-core/src/lib.rs index e9e50cf6b0..be4c7e5506 100644 --- a/rust/optics-core/src/lib.rs +++ b/rust/optics-core/src/lib.rs @@ -24,6 +24,7 @@ pub mod models { /// Async Traits for Homes & Replicas for use in applications mod traits; +use ethers_signers::WalletError; pub use traits::*; /// Utilities to match contract values @@ -53,7 +54,10 @@ pub use identifiers::OpticsIdentifier; use async_trait::async_trait; use ethers::{ core::types::{Address as EthAddress, Signature, SignatureError, H256}, - prelude::{transaction::eip2718::TypedTransaction, AwsSigner}, + prelude::{ + transaction::{eip2718::TypedTransaction, eip712::Eip712}, + AwsSigner, + }, signers::{AwsSignerError, LocalWallet, Signer}, }; @@ -86,6 +90,9 @@ pub enum SignersError { /// AWS Signer Error #[error("{0}")] AwsSignerError(#[from] AwsSignerError), + /// Wallet Signer Error + #[error("{0}")] + WalletError(#[from] WalletError), } impl From for SignersError { @@ -157,6 +164,16 @@ impl Signer for Signers { Signers::Aws(signer) => signer.chain_id(), } } + + async fn sign_typed_data( + &self, + payload: &T, + ) -> Result { + match self { + Signers::Local(signer) => Ok(signer.sign_typed_data(payload).await?), + Signers::Aws(signer) => Ok(signer.sign_typed_data(payload).await?), + } + } } #[async_trait] diff --git a/rust/optics-core/src/models/replica.rs b/rust/optics-core/src/models/replica.rs index f31c925eee..576f3a4250 100644 --- a/rust/optics-core/src/models/replica.rs +++ b/rust/optics-core/src/models/replica.rs @@ -8,6 +8,7 @@ pub struct Waiting { } /// Pending update state +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct Pending { root: H256, @@ -103,6 +104,7 @@ impl Replica { update: &SignedUpdate, now: impl FnOnce() -> U256, ) -> Result, Self> { + #[allow(clippy::question_mark)] if self.check_sig(update).is_err() { return Err(self); } diff --git a/rust/optics-core/src/utils.rs b/rust/optics-core/src/utils.rs index eda5c992c8..a33238039a 100644 --- a/rust/optics-core/src/utils.rs +++ b/rust/optics-core/src/utils.rs @@ -58,6 +58,7 @@ impl HexString { } // Lazy. Should do the check as a cheaper action + #[allow(clippy::question_mark)] if hex::decode(s).is_err() { bail!("String is not hex"); } diff --git a/rust/optics-test/Cargo.toml b/rust/optics-test/Cargo.toml index 361c1276d7..b0d88dc5bf 100644 --- a/rust/optics-test/Cargo.toml +++ b/rust/optics-test/Cargo.toml @@ -2,7 +2,7 @@ name = "optics-test" version = "0.1.0" authors = ["Luke Tchang "] -edition = "2018" +edition = "2021" [dependencies] tokio = { version = "1.0.1", features = ["rt", "macros"] } diff --git a/rust/optics-test/src/test_utils.rs b/rust/optics-test/src/test_utils.rs index 5f55a3f00b..5789f8a45a 100644 --- a/rust/optics-test/src/test_utils.rs +++ b/rust/optics-test/src/test_utils.rs @@ -49,7 +49,7 @@ mod test { async fn db_stores_and_retrieves_messages() { run_test_db(|db| async move { let home_name = "home_1".to_owned(); - let db = OpticsDB::new(db); + let db = OpticsDB::new(home_name, db); let m = OpticsMessage { origin: 10, @@ -67,23 +67,19 @@ mod test { }; assert_eq!(m.to_leaf(), message.leaf()); - db.store_raw_committed_message(&home_name, &message) - .unwrap(); + db.store_raw_committed_message(&message).unwrap(); let by_nonce = db - .message_by_nonce(&home_name, m.destination, m.nonce) + .message_by_nonce(m.destination, m.nonce) .unwrap() .unwrap(); assert_eq!(by_nonce, message); - let by_leaf = db - .message_by_leaf(&home_name, message.leaf()) - .unwrap() - .unwrap(); + let by_leaf = db.message_by_leaf(message.leaf()).unwrap().unwrap(); assert_eq!(by_leaf, message); let by_index = db - .message_by_leaf_index(&home_name, message.leaf_index) + .message_by_leaf_index(message.leaf_index) .unwrap() .unwrap(); assert_eq!(by_index, message); @@ -95,16 +91,16 @@ mod test { async fn db_stores_and_retrieves_proofs() { run_test_db(|db| async move { let home_name = "home_1".to_owned(); - let db = OpticsDB::new(db); + let db = OpticsDB::new(home_name, db); let proof = Proof { leaf: H256::from_low_u64_be(15), index: 32, path: Default::default(), }; - db.store_proof(&home_name, 13, &proof).unwrap(); + db.store_proof(13, &proof).unwrap(); - let by_index = db.proof_by_leaf_index(&home_name, 13).unwrap().unwrap(); + let by_index = db.proof_by_leaf_index(13).unwrap().unwrap(); assert_eq!(by_index, proof); }) .await; diff --git a/rust/tools/balance-exporter/Cargo.toml b/rust/tools/balance-exporter/Cargo.toml index f1eafa5a76..f1c257aa17 100644 --- a/rust/tools/balance-exporter/Cargo.toml +++ b/rust/tools/balance-exporter/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "balance-exporter" version = "0.1.0" -edition = "2018" +edition = "2021" description = "Polls chains for optics contract wallet balances and reports them in OpenMetrics format" authors = ["ember arlynx "] license = "Apache-2.0" diff --git a/rust/tools/kms-cli/Cargo.toml b/rust/tools/kms-cli/Cargo.toml index f98ec8e9ba..d2ac62f3d0 100644 --- a/rust/tools/kms-cli/Cargo.toml +++ b/rust/tools/kms-cli/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "kms-cli" version = "0.1.0" -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "3.0.0-beta.4" +clap = "3.0.0-beta.5" color-eyre = "0.5.11" ethers = { git = "https://github.com/gakonst/ethers-rs", branch = "master" } ethers-signers = { git = "https://github.com/gakonst/ethers-rs", branch = "master", features = ["aws"] } diff --git a/rust/tools/kms-cli/src/main.rs b/rust/tools/kms-cli/src/main.rs index b481c6b5cc..22e2c11dc7 100644 --- a/rust/tools/kms-cli/src/main.rs +++ b/rust/tools/kms-cli/src/main.rs @@ -11,12 +11,11 @@ use once_cell::sync::OnceCell; use rusoto_core::{credential::EnvironmentProvider, HttpClient}; use rusoto_kms::KmsClient; -use clap::Clap; +use clap::Parser; static KMS_CLIENT: OnceCell = OnceCell::new(); fn init_kms(region: String) { - // setup KMS let client = rusoto_core::Client::new_with(EnvironmentProvider::default(), HttpClient::new().unwrap()); if KMS_CLIENT @@ -30,7 +29,7 @@ fn init_kms(region: String) { } } -#[derive(Clap)] +#[derive(Parser)] pub struct Tx { // TX /// The TX value (in wei) @@ -61,19 +60,20 @@ pub struct Tx { rpc: String, } -#[derive(Clap)] +#[derive(Parser)] pub struct Info {} -#[derive(Clap)] +#[derive(Parser)] /// Subcommands +#[allow(clippy::large_enum_variant)] pub enum SubCommands { /// Send a tx signed by the KMS key - Tx(Tx), + Transaction(Tx), /// Print the key info (region, id, address) Info(Info), } -#[derive(Clap)] +#[derive(Parser)] #[clap(version = "0.1", author = "James Prestwich")] pub struct Opts { #[clap(subcommand)] @@ -141,7 +141,7 @@ fn prep_tx_request(opts: &Tx) -> TransactionRequest { async fn _send_tx(signer: &AwsSigner<'_>, opts: &Opts) -> Result<()> { let tx: &Tx = match opts.sub { - SubCommands::Tx(ref tx) => tx, + SubCommands::Transaction(ref tx) => tx, SubCommands::Info(_) => unreachable!(), }; @@ -192,7 +192,7 @@ async fn _main() -> Result<()> { let opts: Opts = Opts::parse(); init_kms(opts.region.to_owned()); let chain_id = match opts.sub { - SubCommands::Tx(ref tx) => tx.chain_id.unwrap_or(1), + SubCommands::Transaction(ref tx) => tx.chain_id.unwrap_or(1), SubCommands::Info(_) => 1, }; @@ -201,7 +201,7 @@ async fn _main() -> Result<()> { .with_chain_id(chain_id); match opts.sub { - SubCommands::Tx(_) => _send_tx(&signer, &opts).await, + SubCommands::Transaction(_) => _send_tx(&signer, &opts).await, SubCommands::Info(_) => _print_info(&signer, &opts).await, } } diff --git a/rust/tools/optics-cli/Cargo.toml b/rust/tools/optics-cli/Cargo.toml index 7d54dac09d..986cb2cf8d 100644 --- a/rust/tools/optics-cli/Cargo.toml +++ b/rust/tools/optics-cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "optics-cli" version = "0.1.0" -edition = "2018" +edition = "2021" [dependencies] color-eyre = "0.5.11" diff --git a/rust/tools/optics-cli/src/subcommands/db_state.rs b/rust/tools/optics-cli/src/subcommands/db_state.rs index de43526292..d6f67ab016 100644 --- a/rust/tools/optics-cli/src/subcommands/db_state.rs +++ b/rust/tools/optics-cli/src/subcommands/db_state.rs @@ -29,7 +29,7 @@ type OutputVec = Vec<((H256, u64), Vec)>; impl DbStateCommand { pub async fn run(&self) -> Result<()> { - let db = OpticsDB::new(DB::from_path(&self.db_path)?); + let db = OpticsDB::new(self.home_name.to_owned(), DB::from_path(&self.db_path)?); let messages_by_committed_roots = self.create_comitted_root_to_message_map(&db)?; @@ -50,9 +50,9 @@ impl DbStateCommand { ) -> Result>> { let mut messages_by_committed_roots: HashMap> = HashMap::new(); for index in 0.. { - match db.message_by_leaf_index(&self.home_name, index)? { + match db.message_by_leaf_index(index)? { Some(message) => { - if db.proof_by_leaf_index(&self.home_name, index)?.is_none() { + if db.proof_by_leaf_index(index)?.is_none() { println!("Failed to find proof for leaf index {}!", index); } @@ -89,15 +89,13 @@ impl DbStateCommand { // Create mapping of (update root, block_number) to [messages] let mut output_map: HashMap<(H256, u64), Vec> = HashMap::new(); for (committed_root, bucket) in messages_by_committed_roots { - let containing_update_opt = - db.update_by_previous_root(&self.home_name, committed_root)?; + let containing_update_opt = db.update_by_previous_root(committed_root)?; match containing_update_opt { Some(containing_update) => { let new_root = containing_update.update.new_root; - let update_metadata = db - .retrieve_update_metadata(&self.home_name, new_root)? - .unwrap_or_else(|| { + let update_metadata = + db.retrieve_update_metadata(new_root)?.unwrap_or_else(|| { panic!("Couldn't find metadata for update {:?}", containing_update) }); diff --git a/rust/tools/optics-cli/src/subcommands/prove.rs b/rust/tools/optics-cli/src/subcommands/prove.rs index 9650ef880d..7fffa1622c 100644 --- a/rust/tools/optics-cli/src/subcommands/prove.rs +++ b/rust/tools/optics-cli/src/subcommands/prove.rs @@ -110,23 +110,19 @@ impl ProveCommand { } fn fetch_proof(&self) -> Result<(OpticsMessage, Proof)> { - let db = OpticsDB::new(DB::from_path(&self.db_path)?); + let db = OpticsDB::new(self.home_name.to_owned(), DB::from_path(&self.db_path)?); let idx = match (self.leaf_index, self.leaf) { (Some(idx), _) => idx, - (None, Some(digest)) => match db.message_by_leaf(&self.home_name, digest)? { + (None, Some(digest)) => match db.message_by_leaf(digest)? { Some(leaf) => leaf.leaf_index, None => bail!("No leaf index or "), }, (None, None) => bail!("Must provide leaf index or leaf hash"), }; - let proof = db - .proof_by_leaf_index(&self.home_name, idx)? - .expect("no proof"); - let message = db - .message_by_leaf_index(&self.home_name, idx)? - .expect("no message"); + let proof = db.proof_by_leaf_index(idx)?.expect("no proof"); + let message = db.message_by_leaf_index(idx)?.expect("no message"); let message = OpticsMessage::read_from(&mut message.message.as_slice())?; Ok((message, proof))