From 4bd5238acdad9ccf008b9c0d4c659266d126e169 Mon Sep 17 00:00:00 2001 From: BaldyAsh Date: Tue, 16 Jul 2019 22:02:25 +0300 Subject: [PATCH] removed old data restore --- Cargo.lock | 187 ------- Cargo.toml | 1 - core/data_restore/Cargo.toml | 21 - core/data_restore/src/accounts_state/mod.rs | 492 ------------------ core/data_restore/src/block_events/mod.rs | 397 -------------- core/data_restore/src/blocks/mod.rs | 34 -- core/data_restore/src/data_restore_driver.rs | 307 ----------- .../src/franklin_transaction/mod.rs | 88 ---- core/data_restore/src/helpers/mod.rs | 178 ------- core/data_restore/src/lib.rs | 62 --- 10 files changed, 1767 deletions(-) delete mode 100644 core/data_restore/Cargo.toml delete mode 100644 core/data_restore/src/accounts_state/mod.rs delete mode 100644 core/data_restore/src/block_events/mod.rs delete mode 100644 core/data_restore/src/blocks/mod.rs delete mode 100644 core/data_restore/src/data_restore_driver.rs delete mode 100644 core/data_restore/src/franklin_transaction/mod.rs delete mode 100644 core/data_restore/src/helpers/mod.rs delete mode 100644 core/data_restore/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 381489ee2f..16208c6172 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -236,11 +236,6 @@ name = "bitflags" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bitvec" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "blake2-rfc_bellman_edition" version = "0.0.1" @@ -516,42 +511,6 @@ name = "crunchy" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "data_restore" -version = "0.1.0" -dependencies = [ - "bigdecimal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitvec 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "models 0.0.1", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "plasma 0.1.1", - "sapling-crypto_ce 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "web3 0.7.0 (git+https://github.com/tomusdrw/rust-web3)", -] - -[[package]] -name = "derive_more" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "diesel" version = "1.4.2" @@ -729,20 +688,6 @@ dependencies = [ "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethabi" -version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethbloom" version = "0.5.3" @@ -755,18 +700,6 @@ dependencies = [ "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethbloom" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethereum-tx-sign" version = "0.0.2" @@ -794,19 +727,6 @@ dependencies = [ "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethereum-types" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethereum-types-serialize" version = "0.2.2" @@ -869,18 +789,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "fixed-hash" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "flate2" version = "1.0.7" @@ -1108,22 +1016,6 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "impl-rlp" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "impl-serde" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "indexmap" version = "0.4.1" @@ -1187,18 +1079,6 @@ dependencies = [ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "jsonrpc-core" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -2059,15 +1939,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rlp" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rust-crypto" version = "0.2.36" @@ -2381,11 +2252,6 @@ name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "static_assertions" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "storage" version = "0.0.1" @@ -2881,17 +2747,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "uint" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "unicase" version = "1.4.2" @@ -3044,34 +2899,6 @@ dependencies = [ "websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "web3" -version = "0.7.0" -source = "git+https://github.com/tomusdrw/rust-web3#21cb38c7203a026f292d65059272b88e2050626e" -dependencies = [ - "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "websocket" version = "0.21.1" @@ -3189,7 +3016,6 @@ dependencies = [ "checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum bitvec 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b67491e1cc6f37da6c4415cd743cb8d2e2c65388acc91ca3094a054cbf3cbd0c" "checksum blake2-rfc_bellman_edition 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdc60350286c7c3db13b98e91dbe5c8b6830a6821bc20af5b0c310ce94d74915" "checksum bodyparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f023abfa58aad6f6bc4ae0630799e24d5ee0ab8bb2e49f651d9b1f9aa4f52f30" "checksum brotli-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" @@ -3219,8 +3045,6 @@ dependencies = [ "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d24935ba50c4a8dc375a0fd1f8a2ba6bdbdc4125713126a74b965d6a01a06d7" "checksum diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62a27666098617d52c487a41f70de23d44a1dc1f3aa5877ceba2790fb1f1cab4" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" @@ -3239,19 +3063,15 @@ dependencies = [ "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46" "checksum ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eb362fde43ed0b50b258bb0c72b72b3dccfd29f8de9506295eaf9251c49ca31" -"checksum ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be9a03ff8f3d495d9b73d59fd166acc91d0fd81779911b0b8b4c87b6024a670a" "checksum ethbloom 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6294da962646baa738414e8e718d1a1f0360a51d92de89ccbf91870418f5360" -"checksum ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3932e82d64d347a045208924002930dc105a138995ccdc1479d0f05f0359f17c" "checksum ethereum-tx-sign 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e52cd032ced69abdef1113b2862b4d12feddd87f86c6c5d9f711a1ec25cab94f" "checksum ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e742184dc63a01c8ea0637369f8faa27c40f537949908a237f95c05e68d2c96" -"checksum ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b054df51e53f253837ea422681215b42823c02824bde982699d0dceecf6165a1" "checksum ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f6edceb5dc64db5e46acb519af5d994b004bc150230498527c3f9e55c94c842" "checksum ff_derive_ce 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "189b37f93ec30f72d7420f1e6f2f07031ed0245073ab46c02b57fba696f4365a" "checksum fixed-hash 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7afe6ce860afb14422711595a7b26ada9ed7de2f43c0b2ab79d09ee196287273" -"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" "checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" @@ -3276,15 +3096,12 @@ dependencies = [ "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum im 12.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "de38d1511a0ce7677538acb1e31b5df605147c458e061b2cdb89858afb1cd182" -"checksum impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f39b9963cf5f12fcc4ae4b30a6927ed67d6b4ea4cbe7d17a41131163b401303b" -"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum indexmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7164c96d6e18ccc3ce43f3dedac996c21a220670a106c275b96ad92110401362" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum ipconfig 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc" "checksum iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8e17268922834707e1c29e8badbf9c712c9c43378e1b6a3388946baff10be2" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" -"checksum jsonrpc-core 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97b83fdc5e0218128d0d270f2f2e7a5ea716f3240c8518a58bc89e6716ba8581" "checksum jsonrpc-core 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf83704f4e79979a424d1082dd2c1e52683058056c9280efa19ac5f6bc9033c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" @@ -3370,7 +3187,6 @@ dependencies = [ "checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" "checksum rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "524c5ad554859785dfc8469df3ed5e0b5784d4d335877ed47c8d90fc0eb238fe" "checksum rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d1effe9845d54f90e7be8420ee49e5c94623140b97ee4bc6fb5bfddb745720" -"checksum rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b0d56c1450bfbef1181fdeb78b902dc1d23178de77c23d705317508e03d1b7c" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" @@ -3405,7 +3221,6 @@ dependencies = [ "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum socket2 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4e626972d3593207547f14bf5fc9efa4d0e7283deb73fef1dff313dae9ab8878" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum string 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0bbfb8937e38e34c3444ff00afb28b0811d9554f15c5ad64d12b0308d1d1995" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)" = "641e117d55514d6d918490e47102f7e08d096fdde360247e4a10f7a91a8478d3" @@ -3448,7 +3263,6 @@ dependencies = [ "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" -"checksum uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "082df6964410f6aa929a61ddfafc997e4f32c62c22490e439ac351cec827f436" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -3466,7 +3280,6 @@ dependencies = [ "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "deff75304fe1d0aadb0debac42722c4e63a168619e71e077bc2def73c250db4e" -"checksum web3 0.7.0 (git+https://github.com/tomusdrw/rust-web3)" = "" "checksum websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c9faed2bff8af2ea6b9f8b917d3d00b467583f6781fe3def174a9e33c879703" "checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index 5e20a5d6b7..fdee66631a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "core/data_restore", "core/key_generator", "core/merkle_tree", "core/eth_client", diff --git a/core/data_restore/Cargo.toml b/core/data_restore/Cargo.toml deleted file mode 100644 index 149ea9413b..0000000000 --- a/core/data_restore/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "data_restore" -version = "0.1.0" -edition = "2018" - -[dependencies] -bigdecimal = { version = "0.1.0", features = ["serde"]} -futures = "0.1.26" -web3 = { git = "https://github.com/tomusdrw/rust-web3" } -tiny-keccak = "1.4.2" -ethabi = "7.0.0" -hex = "0.3.2" -sapling-crypto = { package = "sapling-crypto_ce", version = "0.0.5" } -ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } -pairing = { package = "pairing_ce", version = "0.17.0" } -tokio = "0.1" -bitvec = "0.11" -log = "0.4" - -plasma = { path = "../plasma" } -models = { path = "../models" } diff --git a/core/data_restore/src/accounts_state/mod.rs b/core/data_restore/src/accounts_state/mod.rs deleted file mode 100644 index 206fbc7635..0000000000 --- a/core/data_restore/src/accounts_state/mod.rs +++ /dev/null @@ -1,492 +0,0 @@ -use std::cmp::Ordering; -use std::collections::{HashMap, HashSet}; -use std::convert::TryInto; - -use ff::{Field, PrimeField, PrimeFieldRepr}; -use sapling_crypto::jubjub::{edwards, Unknown}; -use web3::futures::Future; -use web3::types::{BlockNumber, Filter, FilterBuilder, H256, U256}; - -use bigdecimal::{BigDecimal, Num, Zero}; - -use models::plasma::params; -use models::plasma::tx::{DepositTx, ExitTx, TransferTx, TxSignature}; -use models::plasma::{Account, AccountId}; -use models::plasma::{Engine, Fr}; -use plasma::state::PlasmaState; -use web3::types::Log; - -use crate::franklin_transaction::{FranklinTransaction, FranklinTransactionType}; -use crate::helpers::*; - -pub struct FranklinAccountsStates { - pub config: DataRestoreConfig, - pub plasma_state: PlasmaState, -} - -impl FranklinAccountsStates { - pub fn new(config: DataRestoreConfig) -> Self { - Self { - config, - plasma_state: PlasmaState::empty(), - } - } - - pub fn update_accounts_states_from_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let tx_type = transaction.franklin_transaction_type; - match tx_type { - FranklinTransactionType::Deposit => { - Ok(self.update_accounts_states_from_deposit_transaction(transaction)?) - } - FranklinTransactionType::FullExit => { - Ok(self.update_accounts_states_from_full_exit_transaction(transaction)?) - } - FranklinTransactionType::Transfer => { - Ok(self.update_accounts_states_from_transfer_transaction(transaction)?) - } - _ => Err(DataRestoreError::WrongType), - } - } - - pub fn get_accounts(&self) -> Vec<(u32, Account)> { - self.plasma_state.get_accounts() - } - - pub fn root_hash(&self) -> Fr { - self.plasma_state.root_hash() - } - - pub fn get_account(&self, account_id: AccountId) -> Option { - self.plasma_state.get_account(account_id) - } - - fn update_accounts_states_from_transfer_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - // debug!("tx: {:?}", transaction.ethereum_transaction.hash); - let transfer_txs_block = self - .get_all_transactions_from_transfer_block(transaction) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in transfer_txs_block { - if let Some(mut from) = self.plasma_state.balance_tree.items.get(&tx.from).cloned() { - let mut transacted_amount = BigDecimal::zero(); - // debug!("amount tx: {:?}", &tx.amount); - transacted_amount += &tx.amount; - transacted_amount += &tx.fee; - - if from.balance < transacted_amount { - return Err(DataRestoreError::WrongAmount); - } - - let mut to = Account::default(); - if let Some(existing_to) = self.plasma_state.balance_tree.items.get(&tx.to) { - to = existing_to.clone(); - } - - from.balance -= transacted_amount; - - from.nonce += 1; - if tx.to != 0 { - to.balance += &tx.amount; - } - - self.plasma_state.balance_tree.insert(tx.from, from); - self.plasma_state.balance_tree.insert(tx.to, to); - } else { - return Err(DataRestoreError::NonexistentAccount); - } - } - Ok(()) - } - - fn update_accounts_states_from_deposit_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let batch_number = self.get_batch_number(transaction); - // let block_number = self.get_block_number_from_deposit(transaction); - let deposit_txs_block = self - .get_all_transactions_from_deposit_batch(batch_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in deposit_txs_block { - let mut account = self - .plasma_state - .balance_tree - .items - .remove(&tx.account) - .unwrap_or_else(|| { - let mut new_account = Account::default(); - new_account.public_key_x = tx.pub_x; - new_account.public_key_y = tx.pub_y; - new_account.balance = BigDecimal::zero(); - new_account - }); - account.balance += tx.amount; - self.plasma_state.balance_tree.insert(tx.account, account); - } - Ok(()) - } - - fn update_accounts_states_from_full_exit_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let batch_number = self.get_batch_number(transaction); - // let block_number = self.get_block_number_from_full_exit(transaction); - let exit_txs_block = self - .get_all_transactions_from_full_exit_batch(batch_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in exit_txs_block { - let _acc = self - .plasma_state - .balance_tree - .items - .get(&tx.account) - .cloned(); - if _acc.is_none() { - return Err(DataRestoreError::NonexistentAccount); - } - self.plasma_state.balance_tree.delete(tx.account); - } - Ok(()) - } - - fn get_batch_number(&self, transaction: &FranklinTransaction) -> U256 { - U256::from(&transaction.commitment_data[0..32]) - } - - // fn get_block_number_from_deposit(&self, transaction: &FranklinTransaction) -> U256 { - // let block_vec = transaction.commitment_data[64..96].to_vec(); - // let block_slice = block_vec.as_slice(); - // U256::from(block_slice) - // } - - // fn get_block_number_from_full_exit(&self, transaction: &FranklinTransaction) -> U256 { - // let block_vec = transaction.commitment_data[64..96].to_vec(); - // let block_slice = block_vec.as_slice(); - // U256::from(block_slice) - // } - - pub fn get_all_transactions_from_transfer_block( - &self, - transaction: &FranklinTransaction, - ) -> Result, DataRestoreError> { - let mut tx_data_vec = transaction.commitment_data.clone(); - // debug!("tx_data_vec: {:?}", tx_data_vec); - // let block_number = &transaction.commitment_data.clone()[0..32]; - // debug!("block_number: {:?}", block_number); - let tx_data_len = tx_data_vec.len(); - // debug!("tx_data_len: {:?}", tx_data_len); - tx_data_vec.reverse(); - tx_data_vec.truncate(tx_data_len - 160); - tx_data_vec.reverse(); - // debug!("tx_data_vec final: {:?}", tx_data_vec); - // tx_data_len = tx_data_vec.len(); - // debug!("tx_data_len final: {:?}", tx_data_len); - let txs = tx_data_vec.chunks(9); - - let mut transfers: Vec = vec![]; - for (i, tx) in txs.enumerate() { - // if tx != [0, 0, 2, 0, 0, 0, 0, 0, 0] { - // let from = U256::from(&tx[0..3]); - // let to = U256::from(&tx[3..6]); - // let amount = U256::from(&tx[6..8]); - // let fee = U256::from(tx[8]); - // let transfer_tx = TransferTx { - // from: from.as_u32(), - // to: to.as_u32(), - // amount: BigDecimal::from_str_radix(&format!("{}", amount), 10).unwrap(), - // fee: BigDecimal::from_str_radix(&format!("{}", fee), 10).unwrap(), - // nonce: 0, - // good_until_block: 0, - // signature: TxSignature::default(), - // cached_pub_key: None, - // }; - // transfers.push(transfer_tx); - // } - let from = U256::from(&tx[0..3]).as_u32(); - let to = U256::from(&tx[3..6]).as_u32(); - let amount = amount_bytes_slice_to_big_decimal(&tx[6..8]); - let fee = fee_bytes_slice_to_big_decimal(tx[8]); - let transfer_tx = TransferTx { - from, - to, - amount: amount.clone(), //BigDecimal::from_str_radix("0", 10).unwrap(), - fee, //BigDecimal::from_str_radix("0", 10).unwrap(), - nonce: i.try_into().unwrap(), - good_until_block: 0, - signature: TxSignature::default(), - cached_pub_key: None, - }; - info!( - "Transaction from account {:?} to account {:?}, amount = {:?}", - from, to, amount - ); - transfers.push(transfer_tx); - } - - Ok(transfers) - } - - fn load_sorted_events( - &self, - action_filter: Filter, - cancel_filter: Filter, - ) -> Result, DataRestoreError> { - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let action_events = web3 - .eth() - .logs(action_filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let cancel_events = web3 - .eth() - .logs(cancel_filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - - // now we have to merge and apply - let mut all_events = vec![]; - all_events.extend(action_events.into_iter()); - all_events.extend(cancel_events.into_iter()); - - all_events = all_events - .into_iter() - .filter(|el| !el.is_removed()) - .collect(); - - // sort by index - let mut error_flag = false; - all_events.sort_by(|l, r| { - let l_block = l.block_number.unwrap(); - let r_block = r.block_number.unwrap(); - - let l_index = l.log_index.unwrap(); - let r_index = r.log_index.unwrap(); - - let ordering = l_block.cmp(&r_block).then(l_index.cmp(&r_index)); - if ordering == Ordering::Equal { - error_flag = true; - } - ordering - }); - if error_flag { - return Err(DataRestoreError::Unknown( - "Logs can not have same indexes".to_string(), - )); - } - Ok(all_events) - } - - pub fn get_all_transactions_from_deposit_batch( - &self, - batch_number: U256, - ) -> Result, DataRestoreError> { - let deposit_event = self - .config - .franklin_contract - .event("LogDepositRequest") - .unwrap() - .clone(); - let deposit_event_topic = deposit_event.signature(); - - let deposit_canceled_event = self - .config - .franklin_contract - .event("LogCancelDepositRequest") - .unwrap() - .clone(); - let deposit_canceled_topic = deposit_canceled_event.signature(); - - let deposits_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![deposit_event_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - let cancels_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![deposit_canceled_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let all_events = self.load_sorted_events(deposits_filter, cancels_filter)?; - - let mut this_batch: HashMap = HashMap::new(); - - for event in all_events { - let topic = event.topics[0]; - match () { - () if topic == deposit_event_topic => { - let data_bytes: Vec = event.data.0; - let account_id = U256::from(event.topics[2]); - let public_key = U256::from(event.topics[3]); - let deposit_amount = U256::from_big_endian(&data_bytes); - let _existing_record = this_batch.get(&account_id).cloned(); - if let Some(record) = _existing_record { - let mut existing_balance = record.0; - existing_balance += deposit_amount; - this_batch.insert(account_id, (existing_balance, record.1)); - } else { - this_batch.insert(account_id, (deposit_amount, public_key)); - } - continue; - } - () if topic == deposit_canceled_topic => { - let account_id = U256::from(event.topics[2]); - let _existing_record = this_batch - .get(&account_id) - .cloned() - .ok_or("existing_record not found for deposits")?; - this_batch.remove(&account_id); - continue; - } - _ => return Err(DataRestoreError::Unknown("unexpected topic".to_string())), - } - } - - let mut all_deposits = vec![]; - for (k, v) in this_batch.iter() { - info!( - "Into account {:?} with public key {:x}, deposit amount = {:?}", - k, v.1, v.0 - ); - let mut public_key_bytes = vec![0u8; 32]; - v.1.to_big_endian(&mut public_key_bytes); - let x_sign = public_key_bytes[0] & 0x80 > 0; - public_key_bytes[0] &= 0x7f; - let mut fe_repr = Fr::zero().into_repr(); - fe_repr - .read_be(public_key_bytes.as_slice()) - .expect("read public key point"); - let y = Fr::from_repr(fe_repr); - if y.is_err() { - return Err(DataRestoreError::WrongPubKey); - } - let public_key_point = edwards::Point::::get_for_y( - y.unwrap(), - x_sign, - ¶ms::JUBJUB_PARAMS, - ); - if public_key_point.is_none() { - return Err(DataRestoreError::WrongPubKey); - } - - let (pub_x, pub_y) = public_key_point.unwrap().into_xy(); - - let tx: DepositTx = DepositTx { - account: k.as_u32(), - amount: BigDecimal::from_str_radix(&format!("{}", v.0), 10).unwrap(), - pub_x, - pub_y, - }; - all_deposits.push(tx); - } - Ok(all_deposits) - } - - pub fn get_all_transactions_from_full_exit_batch( - &self, - batch_number: U256, - ) -> Result, DataRestoreError> { - let exit_event = self - .config - .franklin_contract - .event("LogExitRequest") - .unwrap() - .clone(); - let exit_event_topic = exit_event.signature(); - - let exit_canceled_event = self - .config - .franklin_contract - .event("LogCancelExitRequest") - .unwrap() - .clone(); - let exit_canceled_topic = exit_canceled_event.signature(); - - let exits_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![exit_event_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let cancels_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![exit_canceled_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let all_events = self.load_sorted_events(exits_filter, cancels_filter)?; - - let mut this_batch: HashSet = HashSet::new(); - - for event in all_events { - let topic = event.topics[0]; - match () { - () if topic == exit_event_topic => { - let account_id = U256::from(event.topics[2]); - let existing_record = this_batch.get(&account_id).cloned(); - if existing_record.is_some() { - return Err(DataRestoreError::DoubleExit); - } else { - this_batch.insert(account_id); - } - continue; - } - () if topic == exit_canceled_topic => { - let account_id = U256::from(event.topics[2]); - this_batch - .get(&account_id) - .cloned() - .ok_or_else(|| "existing_record fetch failed".to_owned())?; - this_batch.remove(&account_id); - continue; - } - _ => return Err(DataRestoreError::Unknown("unexpected topic".to_string())), - } - } - - let mut all_exits = vec![]; - for k in this_batch.iter() { - info!("Exit from account {:?}", k); - - let tx: ExitTx = ExitTx { - account: k.as_u32(), - amount: BigDecimal::zero(), - }; - all_exits.push(tx); - } - - Ok(all_exits) - } -} diff --git a/core/data_restore/src/block_events/mod.rs b/core/data_restore/src/block_events/mod.rs deleted file mode 100644 index a96e8f5f4d..0000000000 --- a/core/data_restore/src/block_events/mod.rs +++ /dev/null @@ -1,397 +0,0 @@ -// use std::rc::Rc; - -use web3::futures::Future; -use web3::types::{BlockNumber, FilterBuilder, Log, H256, U256}; -// use tokio_core::reactor::Core; - -use crate::blocks::{BlockType, LogBlockData}; -use crate::helpers::*; - -type ComAndVerBlocksVecs = (Vec, Vec); -type BlockNumber256 = U256; - -#[derive(Debug, Clone)] -pub struct BlockEventsFranklin { - pub config: DataRestoreConfig, - pub committed_blocks: Vec, - pub verified_blocks: Vec, - pub last_watched_block_number: BlockNumber256, -} - -// Set new -// Get last block -// Get blocks till last - delta, set last watching block -// Subscribe on new blocks -// New blocks -> last watching block ++ -// Check if txs in last watching block -impl BlockEventsFranklin { - pub fn new(config: DataRestoreConfig) -> Self { - Self { - // ws_endpoint_string: ws_infura_endpoint_string, - config, - committed_blocks: vec![], - verified_blocks: vec![], - last_watched_block_number: U256::from(0), - } - } - - pub fn get_past_state_from_genesis_with_blocks_delta( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result { - let mut this = BlockEventsFranklin::new(config); - let (blocks, to_block_number): (ComAndVerBlocksVecs, BlockNumber256) = this - .get_sorted_past_logs_from_genesis(genesis_block, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - this.committed_blocks = blocks.0; - this.verified_blocks = blocks.1; - this.last_watched_block_number = U256::from(to_block_number.as_u64()); - Ok(this) - } - - pub fn update_state_from_last_watched_block_with_blocks_delta_and_return_new_blocks( - &mut self, - blocks_delta: U256, - ) -> Result { - let (blocks, to_block_number): (ComAndVerBlocksVecs, BlockNumber256) = self - .get_sorted_past_logs_from_last_watched_block(blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let blocks_for_return = blocks.clone(); - self.committed_blocks.extend(blocks.0); - self.verified_blocks.extend(blocks.1); - self.last_watched_block_number = U256::from(to_block_number.as_u64()); - Ok(blocks_for_return) - } - - pub fn get_only_verified_committed_blocks( - &self, - verified_blocks: &[LogBlockData], - ) -> Vec<&LogBlockData> { - let iter_ver_blocks = verified_blocks.iter(); - // let committed_blocks_iter = &mut self.com_blocks.iter(); - let mut ver_com_blocks = vec![]; - for block in iter_ver_blocks { - let find_com_block = self.check_committed_block_with_same_number_as_verified(block); - if find_com_block.is_none() { - continue; - } - ver_com_blocks.push(find_com_block.unwrap()) - } - ver_com_blocks.sort_by_key(|&x| x.block_num); - ver_com_blocks - } - - // pub fn get_only_verified_committed_blocks(&self) -> Vec<&LogBlockData> { - // let ver_blocks = &mut self.verified_blocks.iter(); - // // let committed_blocks_iter = &mut self.com_blocks.iter(); - // let mut ver_com_blocks = vec![]; - // for block in ver_blocks { - // let find_com_block = self.check_committed_block_with_same_number_as_verified(block); - // if find_com_block.is_none() { - // continue; - // } - // ver_com_blocks.push(find_com_block.unwrap()) - // } - // ver_com_blocks.sort_by_key(|&x| x.block_num); - // ver_com_blocks - // } - - pub fn check_committed_block_with_same_number_as_verified( - &self, - verified_block: &LogBlockData, - ) -> Option<&LogBlockData> { - let committed_blocks_iter = &mut self.committed_blocks.iter(); - committed_blocks_iter.find(|&&x| x.block_num == verified_block.block_num) - } - - pub fn get_committed_blocks(&self) -> &Vec { - &self.committed_blocks - } - - pub fn get_verified_blocks(&self) -> &Vec { - &self.verified_blocks - } - - pub fn get_last_block_number(&mut self) -> Result { - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let last_block_number = web3 - .eth() - .block_number() - .wait() - .map_err(|e| DataRestoreError::Unknown(e.to_string()))?; - Ok(last_block_number) - } - - // returns (committed blocks logs, verified blocks logs) - fn sort_logs(&mut self, logs: &[Log]) -> Result { - if logs.is_empty() { - return Err(DataRestoreError::NoData("No logs in list".to_string())); - } - let mut committed_blocks: Vec = vec![]; - let mut verified_blocks: Vec = vec![]; - let block_verified_topic = "BlockVerified(uint32)"; - let block_committed_topic = "BlockCommitted(uint32)"; - let block_verified_topic_h256: H256 = get_topic_keccak_hash(block_verified_topic); - let block_committed_topic_h256: H256 = get_topic_keccak_hash(block_committed_topic); - for log in logs { - let mut block: LogBlockData = LogBlockData { - block_num: 0, - transaction_hash: H256::zero(), - block_type: BlockType::Unknown, - }; - // Log data - let tx_hash = log.transaction_hash; - let topic = log.topics[0]; - let block_num = log.topics[1]; - - match tx_hash { - Some(hash) => { - block.block_num = U256::from(block_num).as_u32(); - block.transaction_hash = hash; - - if topic == block_verified_topic_h256 { - block.block_type = BlockType::Verified; - verified_blocks.push(block); - // let result = self.check_committed_block_with_same_number_as_verified(&block); - // debug!("Block exists: {:?}", result); - // let tx = result.unwrap().clone().transaction_hash; - // debug!("--- Starting getting tx"); - // let data = FranklinTransaction::get_transaction(InfuraEndpoint::Rinkeby, &tx); - // debug!("TX data committed: {:?}", data); - } else if topic == block_committed_topic_h256 { - block.block_type = BlockType::Committed; - committed_blocks.push(block); - } - } - None => warn!("No tx hash"), - }; - } - committed_blocks.sort_by_key(|x| x.block_num); - verified_blocks.sort_by_key(|x| x.block_num); - Ok((committed_blocks, verified_blocks)) - } - - fn get_logs( - &mut self, - from_block_number: BlockNumber, - to_block_number: BlockNumber, - ) -> Result, DataRestoreError> { - // let contract = Contract::new(web3.eth(), franklin_address.clone(), franklin_contract.clone()); - - // Events topics - let block_verified_topic = "BlockVerified(uint32)"; - let block_committed_topic = "BlockCommitted(uint32)"; - let block_verified_topic_h256: H256 = get_topic_keccak_hash(block_verified_topic); - let block_committed_topic_h256: H256 = get_topic_keccak_hash(block_committed_topic); - - let topics_vec_h256: Vec = - vec![block_verified_topic_h256, block_committed_topic_h256]; - - // Filter - let filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(from_block_number) - .to_block(to_block_number) - .topics(Some(topics_vec_h256), None, None, None) - .build(); - - // Filter result - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let result = web3 - .eth() - .logs(filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - if result.is_empty() { - return Err(DataRestoreError::NoData("No logs in list".to_string())); - } - Ok(result) - } - - pub fn get_sorted_logs_in_block( - &mut self, - block_number: BlockNumber256, - ) -> Result { - let block_to_get_logs = BlockNumber::Number(block_number.as_u64()); - let logs = self - .get_logs(block_to_get_logs, block_to_get_logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let result = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok(result) - } - - fn get_past_logs( - &mut self, - from_block_number: U256, - blocks_delta: U256, - ) -> Result<(Vec, BlockNumber256), DataRestoreError> { - // Set web3 - let last_block_number = self - .get_last_block_number() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let to_block_numer_256 = last_block_number - blocks_delta; - to_block_numer_256 - .checked_sub(from_block_number) - .ok_or_else(|| DataRestoreError::NoData("No new blocks".to_string()))?; - let to_block_number = BlockNumber::Number(to_block_numer_256.as_u64()); - let from_block_number = BlockNumber::Number(from_block_number.as_u64()); - - let logs = self - .get_logs(from_block_number, to_block_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((logs, to_block_numer_256)) - } - - // returns (committed blocks logs, verified blocks logs) from genesis to (last block minus delta) - fn get_sorted_past_logs_from_last_watched_block( - &mut self, - blocks_delta: U256, - ) -> Result<(ComAndVerBlocksVecs, BlockNumber256), DataRestoreError> { - let from_block_number = self.last_watched_block_number + 1; - let (logs, to_block_number) = self - .get_past_logs(from_block_number, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let sorted_logs = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((sorted_logs, to_block_number)) - } - - // returns (committed blocks logs, verified blocks logs) from genesis to (last block minus delta) - fn get_sorted_past_logs_from_genesis( - &mut self, - genesis_block: U256, - blocks_delta: U256, - ) -> Result<(ComAndVerBlocksVecs, BlockNumber256), DataRestoreError> { - let from_block_number = genesis_block; - let (logs, to_block_number) = self - .get_past_logs(from_block_number, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let sorted_logs = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((sorted_logs, to_block_number)) - } - - // // - Get new block - // // - Need to watch block + 1 - // // - Get events from need to watch block - // // - Sort them to committed and verified - // // - Write to committed_blocks and verified_blocks - // pub fn make_new_sorted_logs_subscription(&mut self, eloop: &mut Core) { - // // Setup loop and web3 - // // let mut eloop = Core::new().unwrap(); - // let handle = eloop.handle(); - // let web3_endpoint = Rc::new(web3::Web3::new( - // web3::transports::WebSocket::with_event_loop(self.ws_endpoint_string.as_str(), &handle) - // .unwrap(), - // )); - - // // Subscription - // debug!("subscribing to new blocks"); - - // let future = web3_endpoint.eth_subscribe() - // .subscribe_new_heads() - // .and_then(|sub| { - // sub.for_each(|log| { - // debug!("---"); - // debug!("Got block number {:?}", log.number); - // let number_to_watch = self.last_watched_block_number + 1; - // self.last_watched_block_number = number_to_watch; - // debug!("Block to watch {:?}", &number_to_watch); - // match self.get_sorted_logs_in_block(number_to_watch) { - // Ok(mut result) => { - // debug!("Old committed blocks array len: {:?}", &self.committed_blocks.len()); - // debug!("Old verified blocks array len: {:?}", &self.verified_blocks.len()); - // debug!("Got sorted logs"); - // debug!("Committed: {:?}", &result.0); - // debug!("Verified: {:?}", &result.1); - // self.committed_blocks.append(&mut result.0); - // self.verified_blocks.append(&mut result.1); - // debug!("New committed blocks array len: {:?}", &self.committed_blocks.len()); - // debug!("New verified blocks array len: {:?}", &self.verified_blocks.len()); - - // }, - // Err(_) => { - // debug!("No new blocks"); - // } - // }; - // Ok(()) - // }) - // }) - // .map_err(|e| error!("franklin log err: {}", e)); - - // // Run eloop - // if let Err(_err) = eloop.run(future) { - // error!("Cant run eloop"); - // } - // } - - // pub fn subscribe_to_logs(&mut self) { - - // // Get topic keccak hash - // let block_verified_topic = "BlockVerified(uint32)"; - // let block_committed_topic = "BlockCommitted(uint32)"; - // let block_verified_topic_h256: H256 = helpers::get_topic_keccak_hash(block_verified_topic); - // let block_committed_topic_h256: H256 = helpers::get_topic_keccak_hash(block_committed_topic); - - // let topics_vec_h256: Vec = vec![block_verified_topic_h256, block_committed_topic_h256]; - - // // Setup loop and web3 - // let mut eloop = Core::new().unwrap(); - // let handle = eloop.handle(); - // let w3 = Rc::new(web3::Web3::new( - // web3::transports::WebSocket::with_event_loop(self.ws_endpoint_string.as_str(), &handle) - // .unwrap(), - // )); - - // // Subscription - // debug!("subscribing to franklin logs {:?} {:?}...", block_verified_topic, block_committed_topic); - - // let filter = FilterBuilder::default() - // .address(vec![self.franklin_contract_address.clone()]) - // .topics( - // Some(topics_vec_h256), - // None, - // None, - // None, - // ) - // .build(); - - // let future = w3.eth_subscribe() - // .subscribe_logs(filter) - // .and_then(|sub| { - // sub.for_each(|log| { - // debug!("---"); - // debug!("got log from subscription: {:?}", log); - - // let mut sorted_blocks = self.sort_logs(&vec![log]).unwrap(); - // self.committed_blocks.append(&mut sorted_blocks.0); - // self.verified_blocks.append(&mut sorted_blocks.1); - // // let result = self.check_committed_block_with_same_number_as_verified(&block); - // // debug!("Block exists: {:?}", result); - // // let tx = result.unwrap().clone().transaction_hash; - // // debug!("--- Starting getting tx"); - // // let data = FranklinTransaction::get_transaction(InfuraEndpoint::Rinkeby, &tx); - // // debug!("TX data committed: {:?}", data); - - // debug!("Verified blocks in storage: {:?}", self.verified_blocks); - // debug!("Committed blocks in storage: {:?}", self.committed_blocks); - // Ok(()) - // }) - // }) - // .map_err(|e| error!("franklin log err: {}", e)); - - // // Run eloop - // if let Err(_err) = eloop.run(future) { - // error!("ERROR"); - // } - // } -} diff --git a/core/data_restore/src/blocks/mod.rs b/core/data_restore/src/blocks/mod.rs deleted file mode 100644 index 5ae1d60e0d..0000000000 --- a/core/data_restore/src/blocks/mod.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::cmp::Ordering; -use web3::types::H256; - -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum BlockType { - Committed, - Verified, - Unknown, -} - -#[derive(Debug, Copy, Clone, Eq)] -pub struct LogBlockData { - pub block_num: u32, - pub transaction_hash: H256, - pub block_type: BlockType, -} - -impl PartialOrd for LogBlockData { - fn partial_cmp(&self, other: &LogBlockData) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for LogBlockData { - fn cmp(&self, other: &LogBlockData) -> Ordering { - self.block_num.cmp(&other.block_num) - } -} - -impl PartialEq for LogBlockData { - fn eq(&self, other: &LogBlockData) -> bool { - self.block_num == other.block_num - } -} diff --git a/core/data_restore/src/data_restore_driver.rs b/core/data_restore/src/data_restore_driver.rs deleted file mode 100644 index a2d687dd14..0000000000 --- a/core/data_restore/src/data_restore_driver.rs +++ /dev/null @@ -1,307 +0,0 @@ -use crate::accounts_state::FranklinAccountsStates; -use crate::block_events::BlockEventsFranklin; -use crate::blocks::LogBlockData; -use crate::franklin_transaction::FranklinTransaction; -use crate::helpers::*; -use models::plasma::Fr; -use std::sync::mpsc::Sender; -use web3::types::U256; - -#[allow(dead_code)] -pub struct ProtoAccountsState { - errored: bool, - root_hash: Fr, -} - -pub struct DataRestoreDriver { - pub channel: Option>, - pub config: DataRestoreConfig, - pub genesis_block: U256, - pub blocks_delta: U256, - pub run_updates: bool, - pub block_events: BlockEventsFranklin, - pub account_states: FranklinAccountsStates, -} - -impl DataRestoreDriver { - pub fn new( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - channel: Option>, - ) -> Self { - Self { - channel, - config: config.clone(), - genesis_block, - blocks_delta, - run_updates: false, - block_events: BlockEventsFranklin::new(config.clone()), - account_states: FranklinAccountsStates::new(config.clone()), - } - } - - pub fn load_past_state(&mut self) -> Result<(), DataRestoreError> { - info!("Loading past state"); - let states = DataRestoreDriver::get_past_franklin_blocks_events_and_accounts_tree_state( - self.config.clone(), - self.genesis_block, - self.blocks_delta, - ) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - self.block_events = states.0; - self.account_states = states.1; - - // let accs = &self.account_states.get_accounts(); - // debug!("Accs: {:?}", accs); - let root = self.account_states.root_hash(); - debug!("Root: {:?}", &root); - debug!("______________"); - - if let Some(ref _channel) = self.channel { - let state = ProtoAccountsState { - errored: false, - root_hash: root, - }; - let _send_result = _channel.send(state); - if _send_result.is_err() { - return Err(DataRestoreError::StateUpdate( - "Cant send last state".to_string(), - )); - } - } - debug!("Finished loading past state"); - Ok(()) - } - - pub fn stop_state_updates(&mut self) { - self.run_updates = false - } - - pub fn run_state_updates(&mut self) -> Option { - info!("Start state updates"); - self.run_updates = true; - let mut err: Option = None; - while self.run_updates { - // match DataRestoreDriver::update_franklin_blocks_events_and_accounts_tree_state(self) { - // Err(error) => { - // error!("Something goes wrong: {:?}", error); - // self.run_updates = false; - // err = Some(DataRestoreError::StateUpdate(format!( - // "Error occured: {:?}", - // error - // ))); - // } - // Ok(()) => { - // // debug!("Updated, last watched ethereum block: {:?}", &self.block_events.last_watched_block_number); - // // debug!("Committed franklin blocks count: {:?}", &self.block_events.committed_blocks.len()); - // // debug!("Last committed franklin block: {:?}", &self.block_events.committed_blocks.last()); - // // debug!("Verified franklin blocks count: {:?}", &self.block_events.verified_blocks.len()); - // // debug!("Last verified franklin block: {:?}", &self.block_events.verified_blocks.last()); - // // let accs = self.account_states.get_accounts(); - // // let root = self.account_states.root_hash(); - // // debug!("Accs: {:?}", accs); - // // debug!("Root: {:?}", &root); - // } - // }; - if let Err(error) = - DataRestoreDriver::update_franklin_blocks_events_and_accounts_tree_state(self) - { - error!("Something goes wrong: {:?}", error); - self.run_updates = false; - err = Some(DataRestoreError::StateUpdate(format!( - "Error occured: {:?}", - error - ))); - } - let root = self.account_states.root_hash(); - debug!("New root: {:?}", root); - debug!("______________"); - if let Some(ref _channel) = self.channel { - let state = ProtoAccountsState { - errored: !self.run_updates, - root_hash: root, - }; - let _send_result = _channel.send(state); - if _send_result.is_err() { - self.run_updates = false; - err = Some(DataRestoreError::StateUpdate( - "Cant send last state".to_string(), - )); - } - } - } - debug!("Stopped state updates"); - err - } - - fn get_past_franklin_blocks_events_and_accounts_tree_state( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result<(BlockEventsFranklin, FranklinAccountsStates), DataRestoreError> { - let events_state = - DataRestoreDriver::get_past_blocks_state(config.clone(), genesis_block, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - // debug!("Last watched block: {:?}", events_state.last_watched_block_number); - let verified_blocks = events_state.verified_blocks.clone(); - let txs = DataRestoreDriver::get_verified_committed_blocks_transactions_from_blocks_state( - &events_state, - &verified_blocks, - ); - let sorted_txs = DataRestoreDriver::sort_transactions_by_block_number(txs); - // debug!("Transactions: {:?}", sorted_txs); - - let mut accounts_state = FranklinAccountsStates::new(config.clone()); - DataRestoreDriver::update_accounts_state_from_transactions( - &mut accounts_state, - &sorted_txs, - ) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - info!("Accounts and events state finished update"); - Ok((events_state, accounts_state)) - } - - fn get_past_blocks_state( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result { - let events = BlockEventsFranklin::get_past_state_from_genesis_with_blocks_delta( - config, - genesis_block, - blocks_delta, - ) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - debug!( - "Got past events state till ethereum block: {:?}", - &events.last_watched_block_number - ); - debug!( - "Committed franklin blocks count: {:?}", - &events.committed_blocks.len() - ); - debug!( - "Last committed franklin block: {:?}", - &events.committed_blocks.last() - ); - debug!( - "Verified franklin blocks count: {:?}", - &events.verified_blocks.len() - ); - debug!( - "Last verified franklin block: {:?}", - &events.verified_blocks.last() - ); - Ok(events) - } - - fn get_verified_committed_blocks_transactions_from_blocks_state( - block_events_state: &BlockEventsFranklin, - verified_blocks: &[LogBlockData], - ) -> Vec { - let committed_blocks = - block_events_state.get_only_verified_committed_blocks(verified_blocks); - // debug!("Committed verified blocks: {:?}", committed_blocks); - let mut transactions = vec![]; - for block in committed_blocks { - let tx = FranklinTransaction::get_transaction(&block_events_state.config, &block); - if tx.is_none() { - continue; - } - transactions.push(tx.unwrap()); - } - debug!("Transactions sorted: only verified commited"); - transactions - } - - fn sort_transactions_by_block_number( - transactions: Vec, - ) -> Vec { - let mut sorted_transactions = transactions; - sorted_transactions.sort_by_key(|x| x.block_number); - debug!("Transactions sorted: by number"); - sorted_transactions - } - - fn update_accounts_state_from_transactions( - state: &mut FranklinAccountsStates, - transactions: &[FranklinTransaction], - ) -> Result<(), DataRestoreError> { - // let mut state = accounts_state::FranklinAccountsStates::new(config); - debug!("Start accounts state updating"); - for transaction in transactions { - state - .update_accounts_states_from_transaction(&transaction) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - } - debug!("Finished accounts state updating"); - Ok(()) - } - - fn update_franklin_blocks_events_and_accounts_tree_state( - data_restore_driver: &mut DataRestoreDriver, - ) -> Result<(), DataRestoreError> { - let mut new_events: (Vec, Vec) = (vec![], vec![]); - while data_restore_driver.run_updates { - let ne = data_restore_driver - .block_events - .update_state_from_last_watched_block_with_blocks_delta_and_return_new_blocks( - data_restore_driver.blocks_delta, - ); - match ne { - Ok(result) => new_events = result, - Err(error) => { - debug!("Got no events: {:?}", error); - continue; - } - } - if new_events.1.is_empty() { - debug!("No new verified blocks"); - continue; - // return Err(DataRestoreError::NoData("No verified blocks".to_string())) - } else { - debug!( - "Got new events state till ethereum block: {:?}", - &data_restore_driver.block_events.last_watched_block_number - ); - debug!( - "Committed franklin blocks count: {:?}", - &data_restore_driver.block_events.committed_blocks.len() - ); - debug!( - "Last committed franklin block: {:?}", - &data_restore_driver.block_events.committed_blocks.last() - ); - debug!( - "Verified franklin blocks count: {:?}", - &data_restore_driver.block_events.verified_blocks.len() - ); - debug!( - "Last verified franklin block: {:?}", - &data_restore_driver.block_events.verified_blocks.last() - ); - break; - } - } - if !data_restore_driver.run_updates { - return Err(DataRestoreError::StateUpdate( - "Stopped getting new blocks".to_string(), - )); - } - let verified_blocks = &new_events.1; - let txs = DataRestoreDriver::get_verified_committed_blocks_transactions_from_blocks_state( - &data_restore_driver.block_events, - &verified_blocks, - ); - let sorted_txs = DataRestoreDriver::sort_transactions_by_block_number(txs); - - DataRestoreDriver::update_accounts_state_from_transactions( - &mut data_restore_driver.account_states, - &sorted_txs, - ) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - - Ok(()) - } -} diff --git a/core/data_restore/src/franklin_transaction/mod.rs b/core/data_restore/src/franklin_transaction/mod.rs deleted file mode 100644 index 995fe32513..0000000000 --- a/core/data_restore/src/franklin_transaction/mod.rs +++ /dev/null @@ -1,88 +0,0 @@ -use web3::futures::Future; -use web3::types::{Transaction, TransactionId, H256}; - -use crate::blocks::LogBlockData; -use crate::helpers::*; - -#[derive(Debug, Copy, Clone)] -pub enum FranklinTransactionType { - Deposit, - Transfer, - FullExit, - Unknown, -} - -#[derive(Debug, Clone)] -pub struct FranklinTransaction { - pub franklin_transaction_type: FranklinTransactionType, - pub block_number: u32, - pub ethereum_transaction: Transaction, - pub commitment_data: Vec, -} - -impl FranklinTransaction { - pub fn get_transaction( - config: &DataRestoreConfig, - franklin_block: &LogBlockData, - ) -> Option { - let transaction = FranklinTransaction::get_ethereum_transaction( - config, - &franklin_block.transaction_hash, - )?; - let input_data = - FranklinTransaction::get_input_data_from_ethereum_transaction(&transaction); - let tx_type = FranklinTransaction::get_transaction_type(&input_data); - let commitment_data = - FranklinTransaction::get_commitment_data_from_input_data(&input_data)?; - let this = Self { - franklin_transaction_type: tx_type, - block_number: franklin_block.block_num, - ethereum_transaction: transaction, - commitment_data, - }; - Some(this) - } - - fn get_ethereum_transaction( - config: &DataRestoreConfig, - &transaction_hash: &H256, - ) -> Option { - let tx_id = TransactionId::Hash(transaction_hash); - let (_eloop, transport) = - web3::transports::Http::new(config.web3_endpoint.as_str()).ok()?; - let web3 = web3::Web3::new(transport); - let web3_transaction = web3.eth().transaction(tx_id).wait(); - match web3_transaction { - Ok(tx) => tx, - Err(_) => None, - } - } - - fn get_input_data_from_ethereum_transaction(transaction: &Transaction) -> Vec { - transaction.clone().input.0 - } - - fn get_commitment_data_from_input_data(input_data: &[u8]) -> Option> { - if input_data.len() > 4 { - Some(input_data[4..input_data.len()].to_vec()) - } else { - None - } - } - - fn get_transaction_type(input_data: &[u8]) -> FranklinTransactionType { - if input_data.len() <= 4 { - return FranklinTransactionType::Unknown; - } - let deposit_method_bytes: Vec = vec![83, 61, 227, 10]; - let transaction_method_bytes: Vec = vec![244, 135, 178, 142]; - let full_exit_method_bytes: Vec = vec![121, 178, 173, 112]; - let method_bytes: Vec = input_data[0..4].to_vec(); - match method_bytes { - _ if method_bytes == deposit_method_bytes => FranklinTransactionType::Deposit, - _ if method_bytes == transaction_method_bytes => FranklinTransactionType::Transfer, - _ if method_bytes == full_exit_method_bytes => FranklinTransactionType::FullExit, - _ => FranklinTransactionType::Unknown, - } - } -} diff --git a/core/data_restore/src/helpers/mod.rs b/core/data_restore/src/helpers/mod.rs deleted file mode 100644 index 13e84a8b6b..0000000000 --- a/core/data_restore/src/helpers/mod.rs +++ /dev/null @@ -1,178 +0,0 @@ -use bigdecimal::BigDecimal; -use bitvec::prelude::*; -use ethabi::Contract; -use models::abi::{PROD_PLASMA, TEST_PLASMA_ALWAYS_VERIFY}; -use models::config::RuntimeConfig; -use models::plasma::params as plasma_constants; -use sapling_crypto::circuit::float_point::parse_float_to_u128; -use tiny_keccak::keccak256; -use web3::types::{Address, H256}; - -/// Configuratoin of DataRestore driver -#[derive(Debug, Clone)] -pub struct DataRestoreConfig { - /// Web3 endpoint url string - pub web3_endpoint: String, - /// Provides Ethereum Franklin contract unterface - pub franklin_contract: Contract, - /// Ethereum Franklin contract address is type of H160 - pub franklin_contract_address: Address, -} - -impl DataRestoreConfig { - /// Return the configuration for setted Infura web3 endpoint - /// - /// # Arguments - /// - /// * `network` - Infura web3 endpoint - /// - pub fn new(network: InfuraEndpoint) -> Self { - let config = RuntimeConfig::new(); - match network { - InfuraEndpoint::Mainnet => { - Self { - web3_endpoint: config.mainnet_http_endpoint_string, //"https://rinkeby.infura.io/".to_string(), - franklin_contract: ethabi::Contract::load(PROD_PLASMA.0).unwrap(), - franklin_contract_address: config - .mainnet_franklin_contract_address - .as_str() - .parse() - .unwrap(), //"4fbf331db438c88a83b1316d072b7d73d8366367".parse().unwrap() - } - } - InfuraEndpoint::Rinkeby => { - Self { - web3_endpoint: config.rinkeby_http_endpoint_string, //"https://rinkeby.infura.io/".to_string() - franklin_contract: ethabi::Contract::load(TEST_PLASMA_ALWAYS_VERIFY.0).unwrap(), - franklin_contract_address: config - .rinkeby_franklin_contract_address - .as_str() - .parse() - .unwrap(), //"4fbf331db438c88a83b1316d072b7d73d8366367".parse().unwrap() - } - } - } - } -} - -/// Infura web3 endpoint -#[derive(Debug, Copy, Clone)] -pub enum InfuraEndpoint { - Mainnet, - Rinkeby, -} - -/// Returns bytes vec of keccak256 hash from bytes -/// -/// # Arguments -/// -/// * `bytes` - ref to bytes array -/// -pub fn keccak256_hash(bytes: &[u8]) -> Vec { - keccak256(bytes).iter().cloned().collect() -} - -/// Returns keccak256 topic hash (H256) from topic str -/// -/// # Arguments -/// -/// * `topic` - indexed func name and args, represented in ref to str -/// -pub fn get_topic_keccak_hash(topic: &str) -> web3::types::H256 { - let topic_data: Vec = From::from(topic); - let topic_data_vec: &[u8] = topic_data.as_slice(); - let topic_keccak_data: Vec = keccak256_hash(topic_data_vec); - let topic_keccak_data_vec: &[u8] = topic_keccak_data.as_slice(); - H256::from_slice(topic_keccak_data_vec) -} - -/// Returns BigDecimal repr of amount bytes slice -/// -/// # Arguments -/// -/// * `bytes` - amount bytes slice -/// -pub fn amount_bytes_slice_to_big_decimal(bytes: &[u8]) -> BigDecimal { - let vec = bytes.to_vec(); - let bit_vec: BitVec = vec.into(); - let mut bool_vec: Vec = vec![]; - for i in bit_vec { - bool_vec.push(i); - } - let amount_u128: u128 = parse_float_to_u128( - bool_vec, - plasma_constants::AMOUNT_EXPONENT_BIT_WIDTH, - plasma_constants::AMOUNT_MANTISSA_BIT_WIDTH, - 10, - ) - .unwrap_or(0); - let amount_u64 = amount_u128 as u64; - // amount_f64 = amount_f64 / f64::from(1000000); - BigDecimal::from(amount_u64) -} - -/// Returns BigDecimal repr of fee bytes slice -/// -/// # Arguments -/// -/// * `bytes` - fee bytes slice -/// -pub fn fee_bytes_slice_to_big_decimal(byte: u8) -> BigDecimal { - let bit_vec: BitVec = BitVec::from_element(byte); - let mut bool_vec: Vec = vec![]; - for i in bit_vec { - bool_vec.push(i); - } - let fee_u128: u128 = parse_float_to_u128( - bool_vec, - plasma_constants::FEE_EXPONENT_BIT_WIDTH, - plasma_constants::FEE_MANTISSA_BIT_WIDTH, - 10, - ) - .unwrap_or(0); - let fee_u64 = fee_u128 as u64; - // fee_f64 = fee_f64 / f64::from(1000000); - BigDecimal::from(fee_u64) -} - -/// Specific errors that may occure during data restoring -#[derive(Debug, Clone)] -pub enum DataRestoreError { - Unknown(String), - WrongType, - NoData(String), - NonexistentAccount, - WrongAmount, - WrongEndpoint, - WrongPubKey, - DoubleExit, - StateUpdate(String), -} - -impl std::string::ToString for DataRestoreError { - fn to_string(&self) -> String { - match self { - DataRestoreError::Unknown(text) => format!("Unknown {}", text), - DataRestoreError::WrongType => "Wrong type".to_owned(), - DataRestoreError::NoData(text) => format!("No data {}", text), - DataRestoreError::NonexistentAccount => "Nonexistent account".to_owned(), - DataRestoreError::WrongAmount => "Wrong amount".to_owned(), - DataRestoreError::WrongEndpoint => "Wrong endpoint".to_owned(), - DataRestoreError::WrongPubKey => "Wrong pubkey".to_owned(), - DataRestoreError::DoubleExit => "Double exit".to_owned(), - DataRestoreError::StateUpdate(text) => format!("Error during state update {}", text), - } - } -} - -impl std::convert::From<&str> for DataRestoreError { - fn from(a: &str) -> Self { - DataRestoreError::Unknown(a.to_string()) - } -} - -impl std::convert::From for DataRestoreError { - fn from(a: String) -> Self { - DataRestoreError::Unknown(a) - } -} diff --git a/core/data_restore/src/lib.rs b/core/data_restore/src/lib.rs deleted file mode 100644 index 972015ebde..0000000000 --- a/core/data_restore/src/lib.rs +++ /dev/null @@ -1,62 +0,0 @@ -#[macro_use] -extern crate log; - -pub mod accounts_state; -pub mod block_events; -pub mod blocks; -pub mod data_restore_driver; -pub mod franklin_transaction; -pub mod helpers; - -use crate::data_restore_driver::{DataRestoreDriver, ProtoAccountsState}; -use std::sync::mpsc::Sender; -use web3::types::U256; - -pub fn create_new_data_restore_driver( - config: helpers::DataRestoreConfig, - from: U256, - delta: U256, - channel: Option>, -) -> DataRestoreDriver { - DataRestoreDriver::new(config, from, delta, channel) -} - -pub fn load_past_state_for_data_restore_driver(driver: &mut DataRestoreDriver) { - driver.load_past_state().expect("Cant get past state"); -} - -pub fn load_new_states_for_data_restore_driver(driver: &'static mut DataRestoreDriver) { - std::thread::Builder::new() - .name("data_restore".to_string()) - .spawn(move || { - driver.run_state_updates().expect("Cant update state"); - }) - .expect("Load new states for data restore thread"); -} - -pub fn start_data_restore_driver(driver: &'static mut DataRestoreDriver) { - std::thread::Builder::new() - .name("data_restore".to_string()) - .spawn(move || { - driver.load_past_state().expect("Cant get past state"); - driver.run_state_updates().expect("Cant update state"); - }) - .expect("Data restore driver thread"); -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_complete_task() { - let config = helpers::DataRestoreConfig::new(helpers::InfuraEndpoint::Rinkeby); - let from = U256::from(0); - let delta = U256::from(15); - let mut data_restore_driver = create_new_data_restore_driver(config, from, delta, None); - data_restore_driver - .load_past_state() - .expect("Cant get past state"); - data_restore_driver.run_state_updates(); - } -}