diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..80fa3c56 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [0.4.12](https://github.com/dashpay/dash-shared-core/compare/v0.4.11...v0.4.12) + +### Features + +* **dash-spv-masternode-processor:** upgrade core ([v20.0.0-beta.5](https://github.com/dashpay/dash/releases/tag/v20.0.0-beta.5)) diff --git a/Cargo.lock b/Cargo.lock index 7013c1f1..f9182624 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -83,9 +83,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -98,9 +98,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.2" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "base64ct" @@ -114,7 +114,7 @@ version = "0.60.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "clap 3.2.25", @@ -137,7 +137,7 @@ version = "0.65.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static", @@ -150,7 +150,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.25", + "syn 2.0.38", "which", ] @@ -192,6 +192,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "blake3" version = "0.3.8" @@ -209,16 +215,15 @@ dependencies = [ [[package]] name = "blake3" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec 0.7.4", "cc", "cfg-if 1.0.0", "constant_time_eq 0.3.0", - "digest 0.10.7", ] [[package]] @@ -256,9 +261,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byte" @@ -268,9 +273,9 @@ checksum = "7cfd4a5b862cb6bfcaf4b9803e887a22393dd5c1ac9e2d1e131d516047eabd01" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cbindgen" @@ -312,9 +317,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cexpr" @@ -366,7 +374,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags", + "bitflags 1.3.2", "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", @@ -380,7 +388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap", "strsim 0.10.0", @@ -399,9 +407,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "constant_time_eq" @@ -442,9 +450,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -471,9 +479,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-rc.3" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436ace70fc06e06f7f689d2624dc4e2f0ea666efb5aa704215f7249ae6e047a7" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -494,7 +502,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] @@ -509,7 +517,7 @@ dependencies = [ "bip38", "bitcoin_hashes", "bitcoinconsensus", - "blake3 1.4.1", + "blake3 1.5.0", "bls-signatures", "byte", "cbindgen 0.24.5", @@ -529,7 +537,7 @@ dependencies = [ [[package]] name = "dash_spv_apple_bindings" -version = "0.4.10" +version = "0.4.11" dependencies = [ "cbindgen 0.24.5", "dash-spv-masternode-processor", @@ -538,14 +546,23 @@ dependencies = [ [[package]] name = "der" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.9.0" @@ -610,9 +627,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.1" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb04eee5d9d907f29e80ee6b0e78f7e2c82342c63e3580d8c4f69d9d5aad963" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8", "signature", @@ -620,9 +637,9 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0-rc.3" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa8e9049d5d72bfc12acbc05914731b5322f79b5e2f195e9f2d705fca22ab4c" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" dependencies = [ "curve25519-dalek", "ed25519", @@ -633,15 +650,15 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if 1.0.0", ] @@ -661,25 +678,14 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "failure" version = "0.1.8" @@ -704,18 +710,15 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fiat-crypto" -version = "0.1.20" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" [[package]] name = "fnv" @@ -818,9 +821,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -830,9 +833,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -879,9 +882,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hmac" @@ -892,6 +895,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "http" version = "0.2.9" @@ -922,9 +934,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humantime" @@ -949,7 +961,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -998,37 +1010,17 @@ dependencies = [ "generic-array", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.2", - "libc", - "windows-sys", -] - [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itoa" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" @@ -1053,9 +1045,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -1069,15 +1061,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1085,15 +1077,15 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "merk" @@ -1128,9 +1120,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "wasi", @@ -1171,7 +1163,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", ] @@ -1186,9 +1178,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -1201,11 +1193,11 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.55" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags", + "bitflags 2.4.1", "cfg-if 1.0.0", "foreign-types", "libc", @@ -1222,7 +1214,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] @@ -1233,9 +1225,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.90" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", @@ -1245,9 +1237,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parking_lot" @@ -1261,13 +1253,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "smallvec", "windows-targets", ] @@ -1296,9 +1288,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1324,9 +1316,15 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "platforms" -version = "3.0.2" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" @@ -1336,28 +1334,28 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] name = "proc-macro2" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1407,7 +1405,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1416,7 +1414,16 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", ] [[package]] @@ -1432,9 +1439,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -1444,9 +1451,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.3" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -1455,15 +1462,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64", "bytes", @@ -1486,6 +1493,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -1554,13 +1562,12 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ - "bitflags", + "bitflags 2.4.1", "errno", - "io-lifetimes", "libc", "linux-raw-sys", "windows-sys", @@ -1568,9 +1575,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "salsa20" @@ -1592,9 +1599,9 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scrypt" @@ -1629,11 +1636,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -1642,9 +1649,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -1652,35 +1659,35 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.17" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.171" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] name = "serde_json" -version = "1.0.102" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5062a995d481b2308b6064e9af76011f2921c35f97b0468811ed9f6cd91dfed" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -1701,9 +1708,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -1712,9 +1719,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" [[package]] name = "signal-hook-registry" @@ -1744,29 +1751,39 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "spki" version = "0.7.2" @@ -1808,9 +1825,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.25" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -1835,7 +1852,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] @@ -1852,11 +1869,10 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.6.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "autocfg", "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", @@ -1890,33 +1906,35 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.43" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.43" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] name = "time" -version = "0.3.23" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ + "deranged", "itoa", "libc", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -1924,15 +1942,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -1954,11 +1972,10 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -1967,7 +1984,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", "windows-sys", ] @@ -1980,7 +1997,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", ] [[package]] @@ -1995,9 +2012,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -2024,20 +2041,19 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if 1.0.0", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] @@ -2050,9 +2066,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" @@ -2062,9 +2078,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -2083,9 +2099,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -2095,9 +2111,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -2158,7 +2174,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -2192,7 +2208,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2215,13 +2231,14 @@ dependencies = [ [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] @@ -2242,9 +2259,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -2266,9 +2283,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -2281,53 +2298,54 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if 1.0.0", + "windows-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0c0c68e1..117e6bdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "dash-spv-apple-bindings", "dash-spv-example-app", diff --git a/DashSharedCore.podspec b/DashSharedCore.podspec index 43a4d9f7..28765283 100644 --- a/DashSharedCore.podspec +++ b/DashSharedCore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'DashSharedCore' - s.version = '0.4.11' + s.version = '0.4.12' s.summary = 'Dash Core SPV written in Rust' s.author = 'Dash' s.description = "C-bindings for Dash Core SPV that can be used in projects for Apple platform" diff --git a/dash-spv-apple-bindings/Cargo.toml b/dash-spv-apple-bindings/Cargo.toml index 2bda712a..84114962 100644 --- a/dash-spv-apple-bindings/Cargo.toml +++ b/dash-spv-apple-bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dash_spv_apple_bindings" -version = "0.4.11" +version = "0.4.12" description = "C-bindings for using and interoperating with Dash SPV" readme = "README.md" edition = "2021" @@ -24,8 +24,8 @@ cbindgen = "0.24.3" name = "dash_spv_apple_bindings" crate-type = ["staticlib", "cdylib"] -#[profile.release] -#lto = "thin" -#opt-level = 3 -##debug = true +[profile.release] +lto = "thin" +opt-level = 3 +#debug = true diff --git a/dash-spv-masternode-processor/Cargo.toml b/dash-spv-masternode-processor/Cargo.toml index 0ff6da54..04d05bec 100644 --- a/dash-spv-masternode-processor/Cargo.toml +++ b/dash-spv-masternode-processor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dash-spv-masternode-processor" -version = "0.4.10" +version = "0.4.12" description = "Library for processing masternodes and quorums (SPV)" edition = "2021" diff --git a/dash-spv-masternode-processor/src/bindings/common.rs b/dash-spv-masternode-processor/src/bindings/common.rs index 27302689..d367a799 100644 --- a/dash-spv-masternode-processor/src/bindings/common.rs +++ b/dash-spv-masternode-processor/src/bindings/common.rs @@ -5,8 +5,8 @@ use simplelog::{ColorChoice, CombinedLogger, ConfigBuilder, LevelFilter, Termina use crate::crypto::byte_util::ConstDecodable; use crate::crypto::UInt256; use crate::ffi::boxer::boxed; -use crate::ffi::callbacks::{AddInsightBlockingLookup, GetBlockHashByHeight, GetBlockHeightByHash, GetLLMQSnapshotByBlockHash, HashDestroy, LLMQSnapshotDestroy, MasternodeListDestroy, MasternodeListLookup, MasternodeListSave, MerkleRootLookup, SaveLLMQSnapshot, ShouldProcessDiffWithRange}; -use crate::ffi::unboxer::{unbox_any, unbox_block, unbox_llmq_snapshot, unbox_llmq_validation_data, unbox_masternode_list, unbox_mn_list_diff_result, unbox_qr_info_result, unbox_vec_ptr}; +use crate::ffi::callbacks::{AddInsightBlockingLookup, GetBlockHashByHeight, GetBlockHeightByHash, GetCLSignatureByBlockHash, GetLLMQSnapshotByBlockHash, HashDestroy, LLMQSnapshotDestroy, MasternodeListDestroy, MasternodeListLookup, MasternodeListSave, MerkleRootLookup, SaveCLSignature, SaveLLMQSnapshot, ShouldProcessDiffWithRange}; +use crate::ffi::unboxer::{unbox_any, unbox_vec_ptr}; use crate::processing::{MasternodeProcessor, MasternodeProcessorCache}; use crate::types; @@ -56,6 +56,8 @@ pub unsafe extern "C" fn register_processor( get_block_hash_by_height: GetBlockHashByHeight, get_llmq_snapshot_by_block_hash: GetLLMQSnapshotByBlockHash, save_llmq_snapshot: SaveLLMQSnapshot, + get_cl_signature_by_block_hash: GetCLSignatureByBlockHash, + save_cl_signature: SaveCLSignature, get_masternode_list_by_block_hash: MasternodeListLookup, save_masternode_list: MasternodeListSave, destroy_masternode_list: MasternodeListDestroy, @@ -70,6 +72,8 @@ pub unsafe extern "C" fn register_processor( get_block_hash_by_height, get_llmq_snapshot_by_block_hash, save_llmq_snapshot, + get_cl_signature_by_block_hash, + save_cl_signature, get_masternode_list_by_block_hash, save_masternode_list, destroy_masternode_list, @@ -154,55 +158,53 @@ pub unsafe extern "C" fn processor_destroy_block_hash(block_hash: *mut [u8; 32]) unbox_any(block_hash); } -/// Destroys anonymous internal holder for UInt256 +/// Destroys anonymous internal holder for UInt768 /// # Safety #[no_mangle] -pub unsafe extern "C" fn processor_destroy_byte_array(data: *const u8, len: usize) { - unbox_vec_ptr(data as *mut u8, len); +pub unsafe extern "C" fn processor_destroy_cl_signature(cl_signature: *mut [u8; 96]) { + unbox_any(cl_signature); } -/// Destroys types::LLMQValidationData +/// Destroys anonymous internal holder for UInt256 /// # Safety #[no_mangle] -pub unsafe extern "C" fn processor_destroy_llmq_validation_data( - data: *mut types::LLMQValidationData, -) { - unbox_llmq_validation_data(data); +pub unsafe extern "C" fn processor_destroy_byte_array(data: *const u8, len: usize) { + unbox_vec_ptr(data as *mut u8, len); } /// # Safety /// Destroys types::MNListDiffResult #[no_mangle] pub unsafe extern "C" fn processor_destroy_masternode_list(list: *mut types::MasternodeList) { - unbox_masternode_list(list); + unbox_any(list); } /// Destroys types::MNListDiffResult /// # Safety #[no_mangle] pub unsafe extern "C" fn processor_destroy_mnlistdiff_result(result: *mut types::MNListDiffResult) { - unbox_mn_list_diff_result(result); + unbox_any(result); } /// Destroys types::LLMQRotationInfoResult /// # Safety #[no_mangle] pub unsafe extern "C" fn processor_destroy_qr_info_result(result: *mut types::QRInfoResult) { - unbox_qr_info_result(result); + unbox_any(result); } /// Destroys types::LLMQSnapshot /// # Safety #[no_mangle] pub unsafe extern "C" fn processor_destroy_llmq_snapshot(result: *mut types::LLMQSnapshot) { - unbox_llmq_snapshot(result); + unbox_any(result); } /// Destroys types::Block /// # Safety #[no_mangle] pub unsafe extern "C" fn processor_destroy_block(result: *mut types::Block) { - unbox_block(result); + unbox_any(result); } // Here we have temporary replacement for DSKey from the DashSync diff --git a/dash-spv-masternode-processor/src/bindings/masternode.rs b/dash-spv-masternode-processor/src/bindings/masternode.rs index deff1c1e..f16ad74d 100644 --- a/dash-spv-masternode-processor/src/bindings/masternode.rs +++ b/dash-spv-masternode-processor/src/bindings/masternode.rs @@ -4,7 +4,7 @@ use byte::BytesExt; use crate::{models, types}; use crate::chain::common::{ChainType, IHaveChainSettings, LLMQType}; use crate::consensus::encode; -use crate::crypto::{UInt256, byte_util::{BytesDecodable, ConstDecodable}}; +use crate::crypto::{UInt256, byte_util::{BytesDecodable, ConstDecodable}, UInt768}; use crate::ffi::{boxer::{boxed, boxed_vec}, ByteArray, from::FromFFI, to::ToFFI}; use crate::processing::{MasternodeProcessor, MasternodeProcessorCache, ProcessingError}; @@ -194,15 +194,14 @@ pub unsafe extern "C" fn processor_cache_masternode_list(block_hash: *const u8, /// # Safety #[no_mangle] -pub unsafe extern "C" fn validate_masternode_list(list: *const types::MasternodeList, quorum: *const types::LLMQEntry, block_height: u32, chain_type: ChainType) -> bool { +pub unsafe extern "C" fn validate_masternode_list(list: *const types::MasternodeList, quorum: *const types::LLMQEntry, block_height: u32, chain_type: ChainType, best_cl_signature: *const u8) -> bool { let list = (*list).decode(); let mut quorum = (*quorum).decode(); let is_valid_payload = quorum.validate_payload(); if !is_valid_payload { return false; } - let hpmn_only = quorum.llmq_type == chain_type.platform_type() && !quorum.version.use_bls_legacy(); - let valid_masternodes = models::MasternodeList::get_masternodes_for_quorum(quorum.llmq_type, list.masternodes, quorum.llmq_quorum_hash(), block_height, hpmn_only); + let valid_masternodes = models::MasternodeList::get_masternodes_for_quorum(&quorum, chain_type, list.masternodes, block_height, UInt768::from_const(best_cl_signature)); return quorum.validate(valid_masternodes, block_height); } @@ -219,10 +218,12 @@ pub extern "C" fn quorum_threshold_for_type(llmq_type: LLMQType) -> u32 { llmq_type.threshold() } +/// quorum_hash: u256 +/// best_cl_signature: Option /// # Safety #[no_mangle] -pub extern "C" fn quorum_build_llmq_hash(llmq_type: LLMQType, quorum_hash: *const u8) -> ByteArray { - models::LLMQEntry::build_llmq_quorum_hash(llmq_type, UInt256::from_const(quorum_hash).unwrap()).into() +pub extern "C" fn quorum_build_llmq_hash(llmq_type: LLMQType, quorum_hash: *const u8, best_cl_signature: *const u8) -> ByteArray { + models::LLMQEntry::build_llmq_quorum_hash(llmq_type, UInt256::from_const(quorum_hash).unwrap(), UInt768::from_const(best_cl_signature)).into() } /// # Safety diff --git a/dash-spv-masternode-processor/src/chain/common/chain_type.rs b/dash-spv-masternode-processor/src/chain/common/chain_type.rs index bfc092cf..4cc240b8 100644 --- a/dash-spv-masternode-processor/src/chain/common/chain_type.rs +++ b/dash-spv-masternode-processor/src/chain/common/chain_type.rs @@ -1,4 +1,4 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use hashes::hex::FromHex; use crate::chain::{BIP32ScriptMap, DIP14ScriptMap, ScriptMap, SporkParams}; use crate::chain::common::LLMQType; @@ -334,6 +334,15 @@ impl IHaveChainSettings for DevnetType { } // Params impl ChainType { + pub fn from_magic(magic: u32) -> Option { + // Note: any new entries here must be added to `magic` below + match magic { + 0xbd6b0cbf => Some(Self::MainNet), + 0xffcae2ce => Some(Self::TestNet), + _ => None + } + } + pub fn magic(&self) -> u32 { match self { ChainType::MainNet => 0xbd6b0cbf, @@ -369,8 +378,8 @@ impl ChainType { pub fn protocol_version(&self) -> u32 { match self { ChainType::MainNet => 70228, - ChainType::TestNet => 70228, - ChainType::DevNet(_) => 70228 + ChainType::TestNet => 70230, + ChainType::DevNet(_) => 70230 } } @@ -465,4 +474,15 @@ impl ChainType { } } + pub fn core20_activation_height(&self) -> u32 { + // TODO: make this real when aware + match self { + ChainType::TestNet => 899770, + _ => u32::MAX + } + } + pub fn core20_is_active_at(&self, height: u32) -> bool { + height >= self.core20_activation_height() + } + } diff --git a/dash-spv-masternode-processor/src/chain/constants.rs b/dash-spv-masternode-processor/src/chain/constants.rs index 4618b578..38d3fef2 100644 --- a/dash-spv-masternode-processor/src/chain/constants.rs +++ b/dash-spv-masternode-processor/src/chain/constants.rs @@ -3,4 +3,5 @@ pub const DASH_MESSAGE_MAGIC: &str = "DarkCoin Signed Message:\n"; pub const CORE_PROTO_BLS_BASIC: u32 = 70225; pub const CORE_PROTO_19: u32 = 70227; pub const CORE_PROTO_19_2: u32 = 70228; -pub const CORE_PROTO_20: u32 = 70229; \ No newline at end of file +pub const CORE_PROTO_DIFF_VERSION_ORDER: u32 = 70229; +pub const CORE_PROTO_20: u32 = 70330; \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/crypto/byte_util.rs b/dash-spv-masternode-processor/src/crypto/byte_util.rs index db72a7d8..e50e5ec1 100644 --- a/dash-spv-masternode-processor/src/crypto/byte_util.rs +++ b/dash-spv-masternode-processor/src/crypto/byte_util.rs @@ -122,15 +122,23 @@ macro_rules! impl_decodable { impl<'a> ConstDecodable<'a, $var_type> for $var_type { #[allow(clippy::not_unsafe_ptr_arg_deref)] fn from_const(bytes: *const u8) -> Option { - let safe_bytes = unsafe { slice::from_raw_parts(bytes, $byte_len) }; - safe_bytes.read_with::(&mut 0, LE).ok() + if bytes.is_null() { + None + } else { + let safe_bytes = unsafe { slice::from_raw_parts(bytes, $byte_len) }; + safe_bytes.read_with::(&mut 0, LE).ok() + } } } impl<'a> MutDecodable<'a, $var_type> for $var_type { #[allow(clippy::not_unsafe_ptr_arg_deref)] fn from_mut(bytes: *mut u8) -> Option { - let safe_bytes = unsafe { slice::from_raw_parts_mut(bytes, $byte_len) }; - safe_bytes.read_with::(&mut 0, LE).ok() + if bytes.is_null() { + None + } else { + let safe_bytes = unsafe { slice::from_raw_parts_mut(bytes, $byte_len) }; + safe_bytes.read_with::(&mut 0, LE).ok() + } } } } diff --git a/dash-spv-masternode-processor/src/ffi/callbacks.rs b/dash-spv-masternode-processor/src/ffi/callbacks.rs index a5b5ccd1..9f6d0d50 100644 --- a/dash-spv-masternode-processor/src/ffi/callbacks.rs +++ b/dash-spv-masternode-processor/src/ffi/callbacks.rs @@ -1,7 +1,7 @@ extern crate libc; use std::ffi::c_void; use crate::{models, types}; -use crate::crypto::{byte_util::MutDecodable, UInt256}; +use crate::crypto::{byte_util::MutDecodable, UInt256, UInt768}; use crate::ffi::from::FromFFI; use crate::processing::ProcessingError; @@ -39,6 +39,15 @@ pub type SaveLLMQSnapshot = unsafe extern "C" fn( snapshot: *mut types::LLMQSnapshot, context: *const c_void, ) -> bool; +pub type GetCLSignatureByBlockHash = unsafe extern "C" fn( + block_hash: *mut [u8; 32], + context: *const c_void, +) -> *mut u8; +pub type SaveCLSignature = unsafe extern "C" fn( + block_hash: *mut [u8; 32], + cl_signature: *mut [u8; 96], + context: *const c_void, +) -> bool; pub type HashDestroy = unsafe extern "C" fn(hash: *mut u8); pub type LLMQSnapshotDestroy = unsafe extern "C" fn(snapshot: *mut types::LLMQSnapshot); @@ -118,3 +127,22 @@ where None } } + +pub fn lookup_cl_signature_by_block_hash( + block_hash: UInt256, + cl_signature_lookup: SL, + cl_signature_destroy: SD, +) -> Option + where + SL: Fn(UInt256) -> *mut u8 + Copy, + SD: Fn(*mut u8), +{ + let lookup_result = cl_signature_lookup(block_hash); + if !lookup_result.is_null() { + let data = UInt768::from_mut(lookup_result); + cl_signature_destroy(lookup_result); + data + } else { + None + } +} diff --git a/dash-spv-masternode-processor/src/ffi/from.rs b/dash-spv-masternode-processor/src/ffi/from.rs index 7b9381ea..f533165b 100644 --- a/dash-spv-masternode-processor/src/ffi/from.rs +++ b/dash-spv-masternode-processor/src/ffi/from.rs @@ -100,7 +100,8 @@ impl FromFFI for types::CoinbaseTransaction { None } else { Some(UInt768(*self.best_cl_signature)) - } + }, + credit_pool_balance: Some(self.credit_pool_balance) } } } @@ -134,12 +135,12 @@ impl FromFFI for types::MasternodeList { quorums: (0..self.llmq_type_maps_count).into_iter().fold( BTreeMap::new(), |mut acc, i| { - let llmq_map = *(*self.llmq_type_maps.add(i)); + let llmq_map = &*(*self.llmq_type_maps.add(i)); let key = chain::common::LLMQType::from(llmq_map.llmq_type); let value: BTreeMap = (0..llmq_map.count) .into_iter() .fold(BTreeMap::new(), |mut acc, j| { - let raw_value = *(*llmq_map.values.add(j)); + let raw_value = &*(*llmq_map.values.add(j)); let value = raw_value.decode(); let key = value.llmq_hash; acc.insert(key, value); @@ -204,7 +205,7 @@ impl FromFFI for types::MasternodeEntry { previous_entry_hashes: (0..self.previous_entry_hashes_count).into_iter().fold( BTreeMap::new(), |mut acc, i| { - let obj = *self.previous_entry_hashes.add(i); + let obj = &*self.previous_entry_hashes.add(i); let key = common::Block { height: obj.block_height, hash: UInt256(obj.block_hash), diff --git a/dash-spv-masternode-processor/src/ffi/to.rs b/dash-spv-masternode-processor/src/ffi/to.rs index 442939dc..f27bad6b 100644 --- a/dash-spv-masternode-processor/src/ffi/to.rs +++ b/dash-spv-masternode-processor/src/ffi/to.rs @@ -106,7 +106,8 @@ impl ToFFI for tx::CoinbaseTransaction { null_mut() } else { boxed(self.best_cl_signature.unwrap().0) - } + }, + credit_pool_balance: self.credit_pool_balance.unwrap_or(u64::MIN) } } } diff --git a/dash-spv-masternode-processor/src/ffi/unboxer.rs b/dash-spv-masternode-processor/src/ffi/unboxer.rs index 00b45b4d..4eb58306 100644 --- a/dash-spv-masternode-processor/src/ffi/unboxer.rs +++ b/dash-spv-masternode-processor/src/ffi/unboxer.rs @@ -3,7 +3,6 @@ use std::ffi::CString; use std::os::raw::c_char; -use crate::types; use crate::types::opaque_key::{OpaqueKey, OpaqueKeys, OpaqueSerializedKeys}; /// # Safety @@ -21,342 +20,14 @@ pub unsafe fn unbox_vec_ptr(ptr: *mut T, count: usize) -> Vec { Vec::from_raw_parts(ptr, count, count) } -/// # Safety -pub unsafe fn unbox_masternode_entry(x: *mut types::MasternodeEntry) { - let entry = unbox_any(x); - unbox_any(entry.confirmed_hash); - if !entry - .confirmed_hash_hashed_with_provider_registration_transaction_hash - .is_null() - { - unbox_any(entry.confirmed_hash_hashed_with_provider_registration_transaction_hash); - } - unbox_any(entry.key_id_voting); - unbox_any(entry.entry_hash); - unbox_any(entry.operator_public_key); - unbox_vec_ptr( - entry.previous_entry_hashes, - entry.previous_entry_hashes_count, - ); - unbox_vec_ptr( - entry.previous_operator_public_keys, - entry.previous_operator_public_keys_count, - ); - unbox_vec_ptr(entry.previous_validity, entry.previous_validity_count); - unbox_any(entry.provider_registration_transaction_hash); - unbox_any(entry.ip_address); - unbox_any(entry.platform_node_id); -} - -/// # Safety -pub unsafe fn unbox_llmq_entry(x: *mut types::LLMQEntry) { - let entry = unbox_any(x); - unbox_any(entry.all_commitment_aggregated_signature); - if !entry.commitment_hash.is_null() { - unbox_any(entry.commitment_hash); - } - unbox_any(entry.entry_hash); - unbox_any(entry.llmq_hash); - unbox_any(entry.public_key); - unbox_any(entry.threshold_signature); - unbox_any(entry.verification_vector_hash); - unbox_any(std::ptr::slice_from_raw_parts_mut::( - entry.signers_bitset, - entry.signers_bitset_length, - )); - unbox_any(std::ptr::slice_from_raw_parts_mut::( - entry.valid_members_bitset, - entry.valid_members_bitset_length, - )); -} - -/// # Safety -pub unsafe fn unbox_llmq_map(x: *mut types::LLMQMap) { - let entry = unbox_any(x); - let values = unbox_vec_ptr(entry.values, entry.count); - for &x in values.iter() { - unbox_llmq_entry(x); - } -} - -/// # Safety -pub unsafe fn unbox_masternode_list(list: *mut types::MasternodeList) { - let masternode_list = unbox_any(list); - unbox_any(masternode_list.block_hash); - if !masternode_list.masternode_merkle_root.is_null() { - unbox_any(masternode_list.masternode_merkle_root); - } - if !masternode_list.llmq_merkle_root.is_null() { - unbox_any(masternode_list.llmq_merkle_root); - } - unbox_masternode_vec(unbox_vec_ptr( - masternode_list.masternodes, - masternode_list.masternodes_count, - )); - unbox_llmq_map_vec(unbox_vec_ptr( - masternode_list.llmq_type_maps, - masternode_list.llmq_type_maps_count, - )); -} -/// # Safety -pub unsafe fn unbox_quorums_cl_sigs_object(x: *mut types::QuorumsCLSigsObject) { - let result = unbox_any(x); - unbox_any(result.signature); - let index_set = unbox_vec_ptr(result.index_set, result.index_set_count); - drop(index_set); - -} -/// # Safety -pub unsafe fn unbox_quorums_cl_sigs_vec(vec: Vec<*mut types::QuorumsCLSigsObject>) { - for &x in vec.iter() { - unbox_quorums_cl_sigs_object(x); - } -} - -/// # Safety -pub unsafe fn unbox_masternode_vec(vec: Vec<*mut types::MasternodeEntry>) { - for &x in vec.iter() { - unbox_masternode_entry(x); - } -} - -/// # Safety -pub unsafe fn unbox_llmq_vec(vec: Vec<*mut types::LLMQEntry>) { - for &x in vec.iter() { - unbox_llmq_entry(x); - } -} - -/// # Safety -pub unsafe fn unbox_llmq_map_vec(vec: Vec<*mut types::LLMQMap>) { +pub unsafe fn unbox_any_vec(vec: Vec<*mut T>) { for &x in vec.iter() { - unbox_llmq_map(x); + unbox_any(x); } } -/// # Safety -pub unsafe fn unbox_llmq_hash_vec(vec: Vec<*mut types::LLMQTypedHash>) { - for &x in vec.iter() { - unbox_llmq_typed_hash(x); - } -} - -/// # Safety -pub unsafe fn unbox_llmq_typed_hash(typed_hash: *mut types::LLMQTypedHash) { - let hash = unbox_any(typed_hash); - unbox_any(hash.llmq_hash); -} - -/// # Safety -pub unsafe fn unbox_llmq_validation_data(llmq_validation_data: *mut types::LLMQValidationData) { - let result = unbox_any(llmq_validation_data); - unbox_any(result.all_commitment_aggregated_signature); - unbox_any(result.commitment_hash); - unbox_any(result.public_key); - unbox_any(result.threshold_signature); - unbox_vec(unbox_vec_ptr(result.items, result.count)); -} - -/// # Safety -pub unsafe fn unbox_snapshot_vec(vec: Vec<*mut types::LLMQSnapshot>) { - for &x in vec.iter() { - unbox_llmq_snapshot(x); - } -} - -/// # Safety -pub unsafe fn unbox_mn_list_diff_result_vec(vec: Vec<*mut types::MNListDiffResult>) { - for &x in vec.iter() { - unbox_mn_list_diff_result(x); - } -} - -/// # Safety -pub unsafe fn unbox_block(block: *mut types::Block) { - let result = unbox_any(block); - unbox_any(result.hash); -} - -/// # Safety -pub unsafe fn unbox_llmq_indexed_hash(indexed_hash: *mut types::LLMQIndexedHash) { - let result = unbox_any(indexed_hash); - unbox_any(result.hash); -} - -/// # Safety -pub unsafe fn unbox_llmq_snapshot(quorum_snapshot: *mut types::LLMQSnapshot) { - let result = unbox_any(quorum_snapshot); - let member_list = unbox_vec_ptr(result.member_list, result.member_list_length); - drop(member_list); - let skip_list = unbox_vec_ptr(result.skip_list, result.skip_list_length); - drop(skip_list); -} - -/// # Safety -pub unsafe fn unbox_tx_input(result: *mut types::TransactionInput) { - let input = unbox_any(result); - unbox_any(input.input_hash); - if !input.script.is_null() && input.script_length > 0 { - unbox_any( - std::ptr::slice_from_raw_parts_mut(input.script, input.script_length) as *mut [u8], - ); - } - if !input.signature.is_null() && input.signature_length > 0 { - unbox_any( - std::ptr::slice_from_raw_parts_mut(input.signature, input.signature_length) - as *mut [u8], - ); - } -} - -/// # Safety -pub unsafe fn unbox_tx_output(result: *mut types::TransactionOutput) { - let output = unbox_any(result); - if !output.script.is_null() && output.script_length > 0 { - unbox_any( - std::ptr::slice_from_raw_parts_mut(output.script, output.script_length) as *mut [u8], - ); - } - if !output.address.is_null() && output.address_length > 0 { - unbox_any( - std::ptr::slice_from_raw_parts_mut(output.address, output.address_length) - as *mut [u8], - ); - } -} - -/// # Safety -pub unsafe fn unbox_tx_input_vec(result: Vec<*mut types::TransactionInput>) { - for &x in result.iter() { - unbox_tx_input(x); - } -} - -/// # Safety -pub unsafe fn unbox_tx_output_vec(result: Vec<*mut types::TransactionOutput>) { - for &x in result.iter() { - unbox_tx_output(x); - } -} - -/// # Safety -pub unsafe fn unbox_tx(result: *mut types::Transaction) { - let tx = unbox_any(result); - unbox_tx_input_vec(unbox_vec_ptr(tx.inputs, tx.inputs_count)); - unbox_tx_output_vec(unbox_vec_ptr(tx.outputs, tx.outputs_count)); - unbox_any(tx.tx_hash); -} - -/// # Safety -pub unsafe fn unbox_coinbase_tx(result: *mut types::CoinbaseTransaction) { - let ctx = unbox_any(result); - unbox_tx(ctx.base); - unbox_any(ctx.merkle_root_mn_list); - if !ctx.merkle_root_llmq_list.is_null() { - unbox_any(ctx.merkle_root_llmq_list); - } - if !ctx.best_cl_signature.is_null() { - unbox_any(ctx.best_cl_signature); - } -} - -/// # Safety -pub unsafe fn unbox_mn_list_diff_result(result: *mut types::MNListDiffResult) { - let res = unbox_any(result); - if !res.base_block_hash.is_null() { - unbox_any(res.base_block_hash); - } - if !res.block_hash.is_null() { - unbox_any(res.block_hash); - } - if !res.masternode_list.is_null() { - unbox_masternode_list(res.masternode_list); - } - if !res.needed_masternode_lists.is_null() { - unbox_vec(unbox_vec_ptr( - res.needed_masternode_lists, - res.needed_masternode_lists_count, - )); - } - if !res.added_masternodes.is_null() { - unbox_masternode_vec(unbox_vec_ptr( - res.added_masternodes, - res.added_masternodes_count, - )); - } - if !res.modified_masternodes.is_null() { - unbox_masternode_vec(unbox_vec_ptr( - res.modified_masternodes, - res.modified_masternodes_count, - )); - } - if !res.added_llmq_type_maps.is_null() { - unbox_llmq_map_vec(unbox_vec_ptr( - res.added_llmq_type_maps, - res.added_llmq_type_maps_count, - )); - } - if !res.quorums_cl_sigs.is_null() { - unbox_quorums_cl_sigs_vec(unbox_vec_ptr( - res.quorums_cl_sigs, - res.quorums_cl_sigs_count, - )); - } -} - -/// # Safety -pub unsafe fn unbox_qr_info_result(result: *mut types::QRInfoResult) { - let res = unbox_any(result); - if !res.result_at_tip.is_null() { - unbox_mn_list_diff_result(res.result_at_tip); - } - if !res.result_at_h.is_null() { - unbox_mn_list_diff_result(res.result_at_h); - } - if !res.result_at_h_c.is_null() { - unbox_mn_list_diff_result(res.result_at_h_c); - } - if !res.result_at_h_2c.is_null() { - unbox_mn_list_diff_result(res.result_at_h_2c); - } - if !res.result_at_h_3c.is_null() { - unbox_mn_list_diff_result(res.result_at_h_3c); - } - if !res.snapshot_at_h_c.is_null() { - unbox_llmq_snapshot(res.snapshot_at_h_c); - } - if !res.snapshot_at_h_2c.is_null() { - unbox_llmq_snapshot(res.snapshot_at_h_2c); - } - if !res.snapshot_at_h_3c.is_null() { - unbox_llmq_snapshot(res.snapshot_at_h_3c); - } - if res.extra_share { - if !res.result_at_h_4c.is_null() { - unbox_mn_list_diff_result(res.result_at_h_4c); - } - if !res.snapshot_at_h_4c.is_null() { - unbox_llmq_snapshot(res.snapshot_at_h_4c); - } - } - if !res.last_quorum_per_index.is_null() { - unbox_llmq_vec(unbox_vec_ptr( - res.last_quorum_per_index, - res.last_quorum_per_index_count, - )); - } - if !res.quorum_snapshot_list.is_null() { - unbox_snapshot_vec(unbox_vec_ptr( - res.quorum_snapshot_list, - res.quorum_snapshot_list_count, - )); - } - if !res.mn_list_diff_list.is_null() { - unbox_mn_list_diff_result_vec(unbox_vec_ptr( - res.mn_list_diff_list, - res.mn_list_diff_list_count, - )); - } +pub unsafe fn unbox_any_vec_ptr(ptr: *mut *mut T, count: usize) { + unbox_any_vec(unbox_vec_ptr(ptr, count)); } /// # Safety diff --git a/dash-spv-masternode-processor/src/lib_tests.rs b/dash-spv-masternode-processor/src/lib_tests.rs index 8910e6a9..e9110859 100644 --- a/dash-spv-masternode-processor/src/lib_tests.rs +++ b/dash-spv-masternode-processor/src/lib_tests.rs @@ -14,13 +14,13 @@ pub mod tests { use crate::ffi::boxer::boxed; use crate::ffi::from::FromFFI; use crate::ffi::to::ToFFI; - use crate::ffi::unboxer::unbox_any; use crate::chain::common::chain_type::{ChainType, IHaveChainSettings}; use crate::consensus::encode; use crate::crypto::byte_util::{BytesDecodable, Reversable, UInt256, UInt384}; use crate::models; use crate::processing::{MasternodeProcessorCache, MasternodeProcessor, MNListDiffResult, ProcessingError, QRInfoResult}; use crate::{unwrap_or_diff_processing_failure, unwrap_or_qr_processing_failure, unwrap_or_return, types}; + use crate::crypto::UInt768; use crate::tests::block_store::{init_mainnet_store, init_testnet_store}; // This regex can be used to omit timestamp etc. while replacing after paste from xcode console log @@ -328,6 +328,8 @@ pub mod tests { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -339,9 +341,9 @@ pub mod tests { } } - pub fn process_mnlistdiff(bytes: Vec, processor: *mut MasternodeProcessor, context: &mut FFIContext, protocol_version: u32, use_insight: bool, is_from_snapshot: bool) -> types::MNListDiffResult { + pub fn process_mnlistdiff(bytes: Vec, processor: *mut MasternodeProcessor, context: &mut FFIContext, protocol_version: u32, use_insight: bool, is_from_snapshot: bool) -> *mut types::MNListDiffResult { unsafe { - *process_mnlistdiff_from_message( + process_mnlistdiff_from_message( bytes.as_ptr(), bytes.len(), context.chain, @@ -355,9 +357,9 @@ pub mod tests { } } - pub fn process_qrinfo(bytes: Vec, processor: *mut MasternodeProcessor, context: &mut FFIContext, version: u32, use_insight: bool, is_from_snapshot: bool) -> types::QRInfoResult { + pub fn process_qrinfo(bytes: Vec, processor: *mut MasternodeProcessor, context: &mut FFIContext, version: u32, use_insight: bool, is_from_snapshot: bool) -> *mut types::QRInfoResult { unsafe { - *process_qrinfo_from_message( + process_qrinfo_from_message( bytes.as_ptr(), bytes.len(), context.chain, @@ -379,8 +381,9 @@ pub mod tests { get_file_as_byte_vec(&filepath) } - pub fn assert_diff_result(context: &mut FFIContext, result: types::MNListDiffResult) { - let masternode_list = unsafe { (*result.masternode_list).decode() }; + pub fn assert_diff_result(context: &mut FFIContext, result: *mut types::MNListDiffResult) { + let result = unsafe { &*result }; + let masternode_list = unsafe { (&*result.masternode_list).decode() }; //print!("block_hash: {} ({})", masternode_list.block_hash, masternode_list.block_hash.reversed()); let bh = context.block_for_hash(masternode_list.block_hash).unwrap().height; assert!(result.has_found_coinbase, "has no coinbase {}", bh); @@ -392,19 +395,20 @@ pub mod tests { println!("Diff is ok at {}", bh); } - pub fn assert_qrinfo_result(context: &mut FFIContext, result: types::QRInfoResult) { + pub fn assert_qrinfo_result(context: &mut FFIContext, result: *mut types::QRInfoResult) { + let result = unsafe { &*result }; if result.mn_list_diff_list_count > 0 { - let diff_result = unsafe { **result.mn_list_diff_list }; + let diff_result = unsafe { *result.mn_list_diff_list }; assert_diff_result(context, diff_result); } if result.extra_share { - assert_diff_result(context, unsafe { *result.result_at_h_4c }); + assert_diff_result(context, result.result_at_h_4c); } - assert_diff_result(context, unsafe { *result.result_at_h_3c }); - assert_diff_result(context, unsafe { *result.result_at_h_2c }); - assert_diff_result(context, unsafe { *result.result_at_h_c }); - assert_diff_result(context, unsafe { *result.result_at_h }); - assert_diff_result(context, unsafe { *result.result_at_tip }); + assert_diff_result(context, result.result_at_h_3c); + assert_diff_result(context, result.result_at_h_2c); + assert_diff_result(context, result.result_at_h_c); + assert_diff_result(context, result.result_at_h); + assert_diff_result(context, result.result_at_tip); } pub unsafe extern "C" fn get_block_height_by_hash_from_context( @@ -472,6 +476,19 @@ pub mod tests { } } + pub unsafe extern "C" fn get_cl_signature_by_block_hash_from_context( + block_hash: *mut [u8; 32], + context: *const std::ffi::c_void, + ) -> *mut u8 { + let h = UInt256(*(block_hash)); + let data: &mut FFIContext = &mut *(context as *mut FFIContext); + if let Some(sig) = data.cache.cl_signatures.get(&h) { + boxed(sig.0) as *mut _ + } else { + null_mut() + } + } + pub unsafe extern "C" fn get_masternode_list_by_block_hash_default( _block_hash: *mut [u8; 32], _context: *const std::ffi::c_void, @@ -511,7 +528,7 @@ pub mod tests { ) -> bool { let h = UInt256(*(block_hash)); let data: &mut FFIContext = &mut *(context as *mut FFIContext); - let masternode_list = *masternode_list; + let masternode_list = &*masternode_list; let masternode_list_decoded = masternode_list.decode(); //println!("masternode_list_save_in_cache: {}", h); data.cache.mn_lists.insert(h, masternode_list_decoded); @@ -532,6 +549,7 @@ pub mod tests { ProcessingError::None } pub unsafe extern "C" fn snapshot_destroy_default(_snapshot: *mut types::LLMQSnapshot) {} + pub unsafe extern "C" fn destroy_cl_signature_in_cache(_cl_signature: *mut [u8; 96]) {} pub unsafe extern "C" fn add_insight_lookup_default( _hash: *mut [u8; 32], _context: *const std::ffi::c_void, @@ -554,6 +572,16 @@ pub mod tests { data.cache.add_snapshot(h, (*snapshot).decode()); true } + pub unsafe extern "C" fn save_cl_signature_in_cache( + block_hash: *mut [u8; 32], + cl_signature: *mut [u8; 96], + context: *const std::ffi::c_void, + ) -> bool { + let h = UInt256(*(block_hash)); + let data: &mut FFIContext = &mut *(context as *mut FFIContext); + data.cache.add_cl_signature(h, UInt768(*cl_signature)); + true + } pub unsafe extern "C" fn get_merkle_root_by_hash_default( block_hash: *mut [u8; 32], @@ -659,6 +687,8 @@ pub mod tests { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -681,8 +711,10 @@ pub mod tests { context, )}; println!("result: {:?}", result); - let result = unsafe { unbox_any(result) }; - let masternode_list = unsafe { (*unbox_any(result.masternode_list)).decode() }; + + + let result = unsafe { &*result }; + let masternode_list = unsafe { (&*result.masternode_list).decode() }; let masternodes = masternode_list.masternodes; let mut pro_tx_hashes: Vec = masternodes.clone().into_keys().collect(); pro_tx_hashes.sort(); @@ -714,13 +746,7 @@ pub mod tests { }) .collect(); verify_smle_hashes.sort(); - assert_eq!( - masternode_list_hashes, verify_smle_hashes, - "SMLE transaction hashes" - ); - assert!( - result.has_found_coinbase, - "The coinbase was not part of provided hashes" - ); + assert_eq!(masternode_list_hashes, verify_smle_hashes, "SMLE transaction hashes"); + assert!(result.has_found_coinbase, "The coinbase was not part of provided hashes"); } } diff --git a/dash-spv-masternode-processor/src/models/llmq_entry.rs b/dash-spv-masternode-processor/src/models/llmq_entry.rs index 30ed3ce7..6300f7fc 100644 --- a/dash-spv-masternode-processor/src/models/llmq_entry.rs +++ b/dash-spv-masternode-processor/src/models/llmq_entry.rs @@ -231,15 +231,18 @@ impl LLMQEntry { ) } - pub fn build_llmq_quorum_hash(llmq_type: LLMQType, llmq_hash: UInt256) -> UInt256 { - let mut writer: Vec = Vec::with_capacity(33); + pub fn build_llmq_quorum_hash(llmq_type: LLMQType, llmq_hash: UInt256, best_cl_signature: Option) -> UInt256 { + let mut writer = vec![]; VarInt(llmq_type as u64).enc(&mut writer); llmq_hash.enc(&mut writer); + if let Some(best_cl_signature) = best_cl_signature { + best_cl_signature.enc(&mut writer); + } UInt256::sha256d(writer) } - pub fn llmq_quorum_hash(&self) -> UInt256 { - Self::build_llmq_quorum_hash(self.llmq_type, self.llmq_hash) + pub fn llmq_quorum_hash(&self, best_cl_signature: Option) -> UInt256 { + Self::build_llmq_quorum_hash(self.llmq_type, self.llmq_hash, best_cl_signature) } pub fn commitment_data(&self) -> Vec { diff --git a/dash-spv-masternode-processor/src/models/masternode_list.rs b/dash-spv-masternode-processor/src/models/masternode_list.rs index 8a02f77f..0cff58f8 100644 --- a/dash-spv-masternode-processor/src/models/masternode_list.rs +++ b/dash-spv-masternode-processor/src/models/masternode_list.rs @@ -1,9 +1,9 @@ use std::cmp::min; use std::collections::BTreeMap; -use crate::chain::common::LLMQType; +use crate::chain::common::{ChainType, IHaveChainSettings, LLMQType}; use crate::common::MasternodeType; use crate::consensus::Encodable; -use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256}; +use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256, UInt768}; use crate::models::{LLMQEntry, MasternodeEntry}; use crate::tx::CoinbaseTransaction; use crate::util::data_ops::merkle_root_from_hashes; @@ -221,8 +221,10 @@ impl MasternodeList { ) .collect() } - - pub fn get_masternodes_for_quorum(llmq_type: LLMQType, masternodes: BTreeMap, quorum_modifier: UInt256, block_height: u32, hpmn_only: bool) -> Vec { + pub fn get_masternodes_for_quorum(quorum: &LLMQEntry, chain_type: ChainType, masternodes: BTreeMap, block_height: u32, best_cl_signature: Option) -> Vec { + let llmq_type = quorum.llmq_type; + let hpmn_only = llmq_type == chain_type.platform_type() && !quorum.version.use_bls_legacy(); + let quorum_modifier = quorum.llmq_quorum_hash(best_cl_signature); let quorum_count = llmq_type.size(); let masternodes_in_list_count = masternodes.len(); let mut score_dictionary = Self::score_masternodes_map(masternodes, quorum_modifier, block_height, hpmn_only); diff --git a/dash-spv-masternode-processor/src/models/mn_list_diff.rs b/dash-spv-masternode-processor/src/models/mn_list_diff.rs index d8542793..2a1b7951 100644 --- a/dash-spv-masternode-processor/src/models/mn_list_diff.rs +++ b/dash-spv-masternode-processor/src/models/mn_list_diff.rs @@ -2,7 +2,7 @@ use byte::BytesExt; use hashes::hex::ToHex; use std::collections::BTreeMap; use crate::chain::common::LLMQType; -use crate::chain::constants::{CORE_PROTO_20, CORE_PROTO_BLS_BASIC}; +use crate::chain::constants::{CORE_PROTO_20, CORE_PROTO_BLS_BASIC, CORE_PROTO_DIFF_VERSION_ORDER}; use crate::consensus::encode::VarInt; use crate::crypto::byte_util::{BytesDecodable, Reversable}; use crate::crypto::var_array::VarArray; @@ -23,7 +23,7 @@ pub struct MNListDiff { pub deleted_masternode_hashes: Vec, pub added_or_modified_masternodes: BTreeMap, pub deleted_quorums: BTreeMap>, - pub added_quorums: BTreeMap>, + pub added_quorums: Vec, pub base_block_height: u32, pub block_height: u32, // 0: protocol_version < 70225 @@ -33,7 +33,8 @@ pub struct MNListDiff { // protocol_version > 70228 // 19.2 goes with 70228 - // 20.0 goes with 70228+? + // 19.3 goes with 70229? + // 20.0 goes with 70230+ pub quorums_cls_sigs: Vec, } @@ -54,6 +55,7 @@ impl std::fmt::Debug for MNListDiff { .field("base_block_height", &self.base_block_height) .field("block_height", &self.block_height) .field("version", &self.version) + .field("quorums_cls_sigs", &self.quorums_cls_sigs) .finish() } } @@ -65,6 +67,11 @@ impl MNListDiff { block_height_lookup: F, protocol_version: u32, ) -> Option { + let version = if protocol_version >= CORE_PROTO_DIFF_VERSION_ORDER { + u16::from_bytes(message, offset)? + } else { + 1 + }; let base_block_hash = UInt256::from_bytes(message, offset)?; let block_hash = UInt256::from_bytes(message, offset)?; let base_block_height = block_height_lookup(base_block_hash); @@ -77,7 +84,7 @@ impl MNListDiff { Err(_err) => { return None; }, }; let coinbase_transaction = CoinbaseTransaction::from_bytes(message, offset)?; - let version = if protocol_version >= CORE_PROTO_BLS_BASIC { + let version = if (CORE_PROTO_BLS_BASIC..CORE_PROTO_DIFF_VERSION_ORDER).contains(&protocol_version) { // BLS Basic u16::from_bytes(message, offset)? } else { @@ -101,7 +108,7 @@ impl MNListDiff { }); let mut deleted_quorums: BTreeMap> = BTreeMap::new(); - let mut added_quorums: BTreeMap> = BTreeMap::new(); + let mut added_quorums = Vec::::new(); let quorums_active = coinbase_transaction.coinbase_transaction_version >= 2; if quorums_active { let deleted_quorums_count = VarInt::from_bytes(message, offset)?.0; @@ -115,12 +122,7 @@ impl MNListDiff { } let added_quorums_count = VarInt::from_bytes(message, offset)?.0; for _i in 0..added_quorums_count { - if let Some(entry) = LLMQEntry::from_bytes(message, offset) { - added_quorums - .entry(entry.llmq_type) - .or_insert_with(BTreeMap::new) - .insert(entry.llmq_hash, entry); - } + added_quorums.push(LLMQEntry::from_bytes(message, offset)?); } } let mut quorums_cls_sigs = Vec::new(); diff --git a/dash-spv-masternode-processor/src/network/constants.rs b/dash-spv-masternode-processor/src/network/constants.rs index eb5c7b67..7c4f5556 100644 --- a/dash-spv-masternode-processor/src/network/constants.rs +++ b/dash-spv-masternode-processor/src/network/constants.rs @@ -28,13 +28,13 @@ //! # Example: encoding a network's magic bytes //! //! ```rust -//! use bitcoin::network::constants::Network; -//! use bitcoin::consensus::encode::serialize; +//! use dash_spv_masternode_processor::consensus::encode::serialize; +//! use dash_spv_masternode_processor::chain::common::ChainType; //! -//! let network = Network::Bitcoin; +//! let network = ChainType::MainNet; //! let bytes = serialize(&network.magic()); //! -//! assert_eq!(&bytes[..], &[0xF9, 0xBE, 0xB4, 0xD9]); +//! assert_eq!(&bytes[..], &[191, 12, 107, 189]); //! ``` use core::{fmt, ops, convert::From}; @@ -78,10 +78,10 @@ impl Network { /// # Examples /// /// ```rust - /// use bitcoin::network::constants::Network; + /// use dash_spv_masternode_processor::chain::common::ChainType; /// - /// assert_eq!(Some(Network::Bitcoin), Network::from_magic(0xD9B4BEF9)); - /// assert_eq!(None, Network::from_magic(0xFFFFFFFF)); + /// let network = ChainType::from_magic(0xbd6b0cbf); + /// assert_eq!(network, Some(ChainType::MainNet)); /// ``` pub fn from_magic(magic: u32) -> Option { // Note: any new entries here must be added to `magic` below @@ -100,10 +100,10 @@ impl Network { /// # Examples /// /// ```rust - /// use bitcoin::network::constants::Network; + /// use dash_spv_masternode_processor::chain::common::ChainType; /// - /// let network = Network::Bitcoin; - /// assert_eq!(network.magic(), 0xD9B4BEF9); + /// let network = ChainType::MainNet; + /// assert_eq!(network.magic(), 0xbd6b0cbf); /// ``` pub fn magic(self) -> u32 { // Note: any new entries here must be added to `from_magic` above @@ -382,5 +382,4 @@ mod tests { let flag = ServiceFlags::WITNESS | 0xf0.into(); assert_eq!("ServiceFlags(WITNESS|COMPACT_FILTERS|0xb0)", flag.to_string()); } -} - +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/processing/mn_listdiff_result.rs b/dash-spv-masternode-processor/src/processing/mn_listdiff_result.rs index db8a458e..c4eee49e 100644 --- a/dash-spv-masternode-processor/src/processing/mn_listdiff_result.rs +++ b/dash-spv-masternode-processor/src/processing/mn_listdiff_result.rs @@ -1,9 +1,8 @@ use std::collections::BTreeMap; use crate::{models, types}; -use crate::chain::common; -use crate::crypto::UInt256; +use crate::crypto::{UInt256, UInt768}; use crate::ffi::boxer::{boxed, boxed_vec}; -use crate::ffi::to::{encode_masternodes_map, encode_quorums_map, ToFFI}; +use crate::ffi::to::{encode_masternodes_map, ToFFI}; use crate::processing::ProcessingError; pub struct MNListDiffResult { @@ -18,9 +17,9 @@ pub struct MNListDiffResult { pub masternode_list: models::MasternodeList, pub added_masternodes: BTreeMap, pub modified_masternodes: BTreeMap, - pub added_quorums: BTreeMap>, + pub added_quorums: Vec, pub needed_masternode_lists: Vec, - pub quorums_cl_sigs: Vec, + pub cl_signatures: BTreeMap, } impl std::fmt::Debug for MNListDiffResult { @@ -63,9 +62,9 @@ impl Default for MNListDiffResult { masternode_list: Default::default(), added_masternodes: Default::default(), modified_masternodes: Default::default(), - added_quorums: Default::default(), + added_quorums: vec![], needed_masternode_lists: vec![], - quorums_cl_sigs: vec![], + cl_signatures: Default::default() } } } @@ -92,8 +91,11 @@ impl MNListDiffResult { added_masternodes_count: self.added_masternodes.len(), modified_masternodes: encode_masternodes_map(&self.modified_masternodes), modified_masternodes_count: self.modified_masternodes.len(), - added_llmq_type_maps: encode_quorums_map(&self.added_quorums), - added_llmq_type_maps_count: self.added_quorums.len(), + added_quorums_count: self.added_quorums.len(), + added_quorums: boxed_vec(self.added_quorums + .iter() + .map(|quorum| boxed(quorum.encode())) + .collect()), needed_masternode_lists: boxed_vec( self.needed_masternode_lists .iter() @@ -101,11 +103,16 @@ impl MNListDiffResult { .collect(), ), needed_masternode_lists_count: self.needed_masternode_lists.len(), - quorums_cl_sigs_count: self.quorums_cl_sigs.len(), - quorums_cl_sigs: boxed_vec( - self.quorums_cl_sigs - .iter() - .map(|h| boxed(h.encode())) + quorums_cl_sigs_count: self.cl_signatures.len(), + quorums_cl_signatures_hashes: boxed_vec( + self.cl_signatures + .keys() + .map(|h| boxed(h.0)) + .collect()), + quorums_cl_signatures: boxed_vec( + self.cl_signatures + .values() + .map(|h| boxed(h.0)) .collect()) } } diff --git a/dash-spv-masternode-processor/src/processing/processor.rs b/dash-spv-masternode-processor/src/processing/processor.rs index 84322239..d2f1ac31 100644 --- a/dash-spv-masternode-processor/src/processing/processor.rs +++ b/dash-spv-masternode-processor/src/processing/processor.rs @@ -2,11 +2,12 @@ use std::collections::BTreeMap; use std::ptr::null; use crate::{common, models, types}; use crate::chain::common::{ChainType, IHaveChainSettings, LLMQType, LLMQParams}; -use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256}; +use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256, UInt768}; use crate::ffi::boxer::boxed; use crate::ffi::callbacks; -use crate::ffi::callbacks::{AddInsightBlockingLookup, GetBlockHashByHeight, GetBlockHeightByHash, GetLLMQSnapshotByBlockHash, HashDestroy, LLMQSnapshotDestroy, MasternodeListDestroy, MasternodeListLookup, MasternodeListSave, MerkleRootLookup, SaveLLMQSnapshot, ShouldProcessDiffWithRange}; +use crate::ffi::callbacks::{AddInsightBlockingLookup, GetBlockHashByHeight, GetBlockHeightByHash, GetCLSignatureByBlockHash, GetLLMQSnapshotByBlockHash, HashDestroy, LLMQSnapshotDestroy, MasternodeListDestroy, MasternodeListLookup, MasternodeListSave, MerkleRootLookup, SaveCLSignature, SaveLLMQSnapshot, ShouldProcessDiffWithRange}; use crate::ffi::to::ToFFI; +use crate::models::QuorumsCLSigsObject; use crate::processing::{MasternodeProcessorCache, MNListDiffResult, ProcessingError}; // https://github.com/rust-lang/rfcs/issues/2770 @@ -20,7 +21,9 @@ pub struct MasternodeProcessor { pub get_merkle_root_by_hash: MerkleRootLookup, get_block_hash_by_height: GetBlockHashByHeight, get_llmq_snapshot_by_block_hash: GetLLMQSnapshotByBlockHash, + get_cl_signature_by_block_hash: GetCLSignatureByBlockHash, save_llmq_snapshot: SaveLLMQSnapshot, + save_cl_signature: SaveCLSignature, get_masternode_list_by_block_hash: MasternodeListLookup, save_masternode_list: MasternodeListSave, destroy_masternode_list: MasternodeListDestroy, @@ -45,6 +48,8 @@ impl MasternodeProcessor { get_block_hash_by_height: GetBlockHashByHeight, get_llmq_snapshot_by_block_hash: GetLLMQSnapshotByBlockHash, save_llmq_snapshot: SaveLLMQSnapshot, + get_cl_signature_by_block_hash: GetCLSignatureByBlockHash, + save_cl_signature: SaveCLSignature, get_masternode_list_by_block_hash: MasternodeListLookup, save_masternode_list: MasternodeListSave, destroy_masternode_list: MasternodeListDestroy, @@ -59,6 +64,8 @@ impl MasternodeProcessor { get_block_hash_by_height, get_llmq_snapshot_by_block_hash, save_llmq_snapshot, + get_cl_signature_by_block_hash, + save_cl_signature, get_masternode_list_by_block_hash, save_masternode_list, destroy_masternode_list, @@ -122,6 +129,20 @@ impl MasternodeProcessor { } } + pub(crate) fn find_cl_signature( + &self, + block_hash: UInt256, + cached_cl_signatures: &BTreeMap, + ) -> Option { + if let Some(cached) = cached_cl_signatures.get(&block_hash) { + // Getting it from local cache stored as opaque in FFI context + Some(cached.clone()) + } else { + self.lookup_cl_signature_by_block_hash(block_hash) + } + } + + pub(crate) fn get_list_diff_result_with_base_lookup( &self, list_diff: models::MNListDiff, @@ -187,6 +208,15 @@ impl MasternodeProcessor { // self.save_masternode_list(block_hash, &masternode_list); } + fn cache_cl_signatures( + &self, + block_hash: UInt256, + cl_signature: UInt768, + cache: &mut MasternodeProcessorCache, + ) { + cache.cl_signatures.insert(block_hash, cl_signature); + } + pub(crate) fn get_list_diff_result_internal( &self, base_list: Option, @@ -200,6 +230,7 @@ impl MasternodeProcessor { let base_block_hash = list_diff.base_block_hash; let block_hash = list_diff.block_hash; let block_height = list_diff.block_height; + let quorums_cl_sigs = list_diff.quorums_cls_sigs; let (base_masternodes, base_quorums) = match base_list { Some(list) => (list.masternodes, list.quorums), None => (BTreeMap::new(), BTreeMap::new()), @@ -213,10 +244,18 @@ impl MasternodeProcessor { block_height, block_hash, ); - let (added_quorums, quorums, has_valid_quorums) = self.classify_quorums( + + + + // self.cache_cl_signatures(block_hash, quorums_cl_sigs.clone(), cache); + let (added_quorums, + quorums, + cl_signatures, + has_valid_quorums) = self.classify_quorums( base_quorums, list_diff.added_quorums, list_diff.deleted_quorums, + quorums_cl_sigs.clone(), should_process_quorums, skip_removed_masternodes, is_dip_0024, @@ -257,7 +296,7 @@ impl MasternodeProcessor { modified_masternodes, added_quorums, needed_masternode_lists, - quorums_cl_sigs: list_diff.quorums_cls_sigs, + cl_signatures, }; result } @@ -317,27 +356,37 @@ impl MasternodeProcessor { pub fn classify_quorums( &self, mut base_quorums: BTreeMap>, - mut added_quorums: BTreeMap>, + mut added_quorums: Vec, deleted_quorums: BTreeMap>, + cl_signatures: Vec, should_process_quorums: bool, skip_removed_masternodes: bool, is_dip_0024: bool, is_rotated_quorums_presented: bool, cache: &mut MasternodeProcessorCache, ) -> ( + Vec, BTreeMap>, - BTreeMap>, + BTreeMap, bool, ) { let mut has_valid_quorums = true; + let mut signatures = BTreeMap::::new(); if should_process_quorums { - for (&llmq_type, llmqs_of_type) in &mut added_quorums { - if self.should_process_quorum(llmq_type, is_dip_0024, is_rotated_quorums_presented) { - for (&llmq_block_hash, quorum) in llmqs_of_type { - has_valid_quorums &= self.validate_quorum(quorum, skip_removed_masternodes, llmq_block_hash, cache); + added_quorums + .iter_mut() + .enumerate() + .for_each(|(index, quorum)| { + if let Some(sigs_obj) = cl_signatures.get(index) { + let idx = index as u16; + if sigs_obj.index_set.contains(&idx) { + signatures.insert(quorum.llmq_hash, sigs_obj.signature); + } } - } - } + if self.should_process_quorum(quorum.llmq_type, is_dip_0024, is_rotated_quorums_presented) { + has_valid_quorums &= self.validate_quorum(quorum, skip_removed_masternodes, cache); + } + }) } for (llmq_type, keys_to_delete) in &deleted_quorums { if let Some(llmq_map) = base_quorums.get_mut(llmq_type) { @@ -346,25 +395,24 @@ impl MasternodeProcessor { } } } - for (llmq_type, keys_to_add) in added_quorums.iter() { - base_quorums - .entry(*llmq_type) + added_quorums.iter().for_each(|llmq_entry| { + base_quorums.entry(llmq_entry.llmq_type.clone()) .or_insert_with(BTreeMap::new) - .extend(keys_to_add.clone()); - } - (added_quorums, base_quorums, has_valid_quorums) + .insert(llmq_entry.llmq_hash, llmq_entry.clone()); + }); + (added_quorums, base_quorums, signatures, has_valid_quorums) } - pub fn validate_quorum(&self, quorum: &mut models::LLMQEntry, skip_removed_masternodes: bool, llmq_block_hash: UInt256, cache: &mut MasternodeProcessorCache) -> bool { - //println!("get list for quorum {}: find_masternode_list for", llmq_block_hash); - if let Some(models::MasternodeList { masternodes, .. }) = self.find_masternode_list(llmq_block_hash, &cache.mn_lists, &mut cache.needed_masternode_lists) { - let valid = self.validate_quorum_with_masternodes(quorum, skip_removed_masternodes, llmq_block_hash, masternodes, cache); - // TMP Testnet Platform LLMQ fail verification - // if llmq_type != LLMQType::Llmqtype25_67 { - return valid; - // } + pub fn validate_quorum(&self, quorum: &mut models::LLMQEntry, skip_removed_masternodes: bool, cache: &mut MasternodeProcessorCache) -> bool { + let llmq_block_hash = quorum.llmq_hash; + if let Some(models::MasternodeList { masternodes, .. }) = self.find_masternode_list( + llmq_block_hash, + &cache.mn_lists, + &mut cache.needed_masternode_lists) { + self.validate_quorum_with_masternodes(quorum, skip_removed_masternodes, llmq_block_hash, masternodes, cache) + } else { + true } - true } pub fn validate_quorum_with_masternodes( @@ -385,16 +433,17 @@ impl MasternodeProcessor { &mut cache.llmq_indexed_members, &cache.mn_lists, &cache.llmq_snapshots, + &cache.cl_signatures, &mut cache.needed_masternode_lists, skip_removed_masternodes, ) } else { models::MasternodeList::get_masternodes_for_quorum( - quorum.llmq_type, + quorum, + self.chain_type, masternodes, - quorum.llmq_quorum_hash(), block_height, - quorum.llmq_type == self.chain_type.platform_type() && !quorum.version.use_bls_legacy() + self.lookup_cl_signature_by_block_hash(block_hash) ) }; //crate::util::java::generate_final_commitment_test_file(self.chain_type, block_height, &quorum, &valid_masternodes); @@ -430,6 +479,7 @@ impl MasternodeProcessor { quorum_base_block_height: u32, cached_lists: &BTreeMap, cached_snapshots: &BTreeMap, + cached_cl_signatures: &BTreeMap, unknown_lists: &mut Vec, ) -> Vec> { let work_block_height = quorum_base_block_height - 8; @@ -450,7 +500,12 @@ impl MasternodeProcessor { // java::generate_snapshot(&snapshot, work_block_height); // java::generate_llmq_hash(llmq_type, work_block_hash.reversed()); // java::generate_masternode_list_from_map(&masternode_list.masternodes); - let quorum_modifier = models::LLMQEntry::build_llmq_quorum_hash(llmq_type, work_block_hash); + let best_cl_signature = if self.chain_type.core20_is_active_at(work_block_height) { + self.lookup_cl_signature_by_block_hash(work_block_hash) + } else { + None + }; + let quorum_modifier = models::LLMQEntry::build_llmq_quorum_hash(llmq_type, work_block_hash, best_cl_signature); // println!("quorum_modifier: {}", quorum_modifier); // println!("snapshot: {:?}", snapshot); let scored_masternodes = models::MasternodeList::score_masternodes_map(masternode_list.masternodes, quorum_modifier, work_block_height, false); @@ -564,7 +619,8 @@ impl MasternodeProcessor { }); //Self::log_masternodes(&used_at_h_masternodes, format!("••••• USED AT H {} ••••••• ", work_block_height)); //Self::log_masternodes(&unused_at_h_masternodes, format!("••••• UNUSED AT H {} •••••••", work_block_height)); - let quorum_modifier = models::LLMQEntry::build_llmq_quorum_hash(params.r#type, work_block_hash); + let best_cl_signature = self.lookup_cl_signature_by_block_hash(work_block_hash); + let quorum_modifier = models::LLMQEntry::build_llmq_quorum_hash(params.r#type, work_block_hash, best_cl_signature); let sorted_used_mns_list = Self::valid_masternodes_for_rotated_quorum_map(used_at_h_masternodes, quorum_modifier, work_block_height); let sorted_unused_mns_list = Self::valid_masternodes_for_rotated_quorum_map(unused_at_h_masternodes, quorum_modifier, work_block_height); //Self::log_masternodes(&sorted_unused_mns_list, format!("••••• SORTED UNUSED AT H {} ••••••• ", work_block_height)); @@ -642,6 +698,7 @@ impl MasternodeProcessor { llmq_params: LLMQParams, cached_lists: &BTreeMap, cached_snapshots: &BTreeMap, + cached_cl_signatures: &BTreeMap, unknown_lists: &mut Vec, skip_removed_masternodes: bool, ) -> Vec> { @@ -649,15 +706,15 @@ impl MasternodeProcessor { let cycle_length = llmq_params.dkg_params.interval; // println!("/////////////////////// rotate_members {}: {} /////////", cycle_quorum_base_block_height, cycle_length); let quorum_base_block_height = cycle_quorum_base_block_height - cycle_length; - let prev_q_h_m_c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, unknown_lists); + let prev_q_h_m_c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, cached_cl_signatures, unknown_lists); // println!("/////////////////////// prev_q_h_m_c : {} /////////", quorum_base_block_height); // println!("{:#?}", prev_q_h_m_c.iter().map(|p| p.iter().map(|n| n.provider_registration_transaction_hash.reversed()).collect::>()).collect::>()); let quorum_base_block_height = cycle_quorum_base_block_height - 2 * cycle_length; - let prev_q_h_m_2c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, unknown_lists); + let prev_q_h_m_2c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, cached_cl_signatures, unknown_lists); // println!("/////////////////////// prev_q_h_m_2c : {} /////////", quorum_base_block_height); // println!("{:#?}", prev_q_h_m_2c.iter().map(|p| p.iter().map(|n| n.provider_registration_transaction_hash.reversed()).collect::>()).collect::>()); let quorum_base_block_height = cycle_quorum_base_block_height - 3 * cycle_length; - let prev_q_h_m_3c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, unknown_lists); + let prev_q_h_m_3c = self.quorum_quarter_members_by_snapshot(llmq_params, quorum_base_block_height, cached_lists, cached_snapshots, cached_cl_signatures, unknown_lists); // println!("/////////////////////// prev_q_h_m_3c : {} /////////", quorum_base_block_height); // println!("{:#?}", prev_q_h_m_3c.iter().map(|p| p.iter().map(|n| n.provider_registration_transaction_hash.reversed()).collect::>()).collect::>()); @@ -698,6 +755,7 @@ impl MasternodeProcessor { cached_llmq_indexed_members: &mut BTreeMap>>, cached_mn_lists: &BTreeMap, cached_llmq_snapshots: &BTreeMap, + cached_cl_signatures: &BTreeMap, cached_needed_masternode_lists: &mut Vec, skip_removed_masternodes: bool, ) -> Vec { @@ -735,6 +793,7 @@ impl MasternodeProcessor { llmq_params, cached_mn_lists, cached_llmq_snapshots, + cached_cl_signatures, cached_needed_masternode_lists, skip_removed_masternodes, ); @@ -818,6 +877,28 @@ impl MasternodeProcessor { } } + pub fn lookup_cl_signature_by_block_hash(&self, block_hash: UInt256) -> Option { + callbacks::lookup_cl_signature_by_block_hash( + block_hash, + |h: UInt256| unsafe { + (self.get_cl_signature_by_block_hash)(boxed(h.0), self.opaque_context) + }, + |obj: *mut u8| unsafe { (self.destroy_hash)(obj) }, + ) + } + + pub fn save_cl_signature(&self, block_hash: UInt256, cl_signature: UInt768) -> bool { + #[cfg(feature = "generate-dashj-tests")] + crate::util::java::save_cl_signature_to_json(&cl_signature, self.lookup_block_height_by_hash(block_hash)); + unsafe { + (self.save_cl_signature)( + boxed(block_hash.0), + boxed(cl_signature.0), + self.opaque_context, + ) + } + } + pub fn lookup_merkle_root_by_hash(&self, block_hash: UInt256) -> Option { callbacks::lookup_merkle_root_by_hash( block_hash, diff --git a/dash-spv-masternode-processor/src/processing/processor_cache.rs b/dash-spv-masternode-processor/src/processing/processor_cache.rs index ac120b40..3546dbd5 100644 --- a/dash-spv-masternode-processor/src/processing/processor_cache.rs +++ b/dash-spv-masternode-processor/src/processing/processor_cache.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; use crate::chain::common; -use crate::crypto::UInt256; +use crate::crypto::{UInt256, UInt768}; use crate::models; #[derive(Clone, Default)] @@ -9,6 +9,7 @@ pub struct MasternodeProcessorCache { pub llmq_indexed_members: BTreeMap>>, pub mn_lists: BTreeMap, pub llmq_snapshots: BTreeMap, + pub cl_signatures: BTreeMap, pub needed_masternode_lists: Vec, } @@ -19,6 +20,7 @@ impl std::fmt::Debug for MasternodeProcessorCache { .field("llmq_indexed_members", &self.llmq_indexed_members) .field("llmq_snapshots", &self.llmq_snapshots) .field("mn_lists", &self.mn_lists) + .field("cl_signatures", &self.cl_signatures) .field("needed_masternode_lists", &self.needed_masternode_lists) .finish() } @@ -31,6 +33,7 @@ impl MasternodeProcessorCache { self.mn_lists.clear(); self.llmq_snapshots.clear(); self.needed_masternode_lists.clear(); + self.cl_signatures.clear(); } pub fn add_masternode_list(&mut self, block_hash: UInt256, list: models::MasternodeList) { self.mn_lists.insert(block_hash, list); @@ -44,6 +47,12 @@ impl MasternodeProcessorCache { pub fn remove_snapshot(&mut self, block_hash: &UInt256) { self.llmq_snapshots.remove(block_hash); } + pub fn add_cl_signature(&mut self, block_hash: UInt256, cl_signature: UInt768) { + self.cl_signatures.insert(block_hash, cl_signature); + } + pub fn remove_cl_signature(&mut self, block_hash: &UInt256) { + self.cl_signatures.remove(block_hash); + } pub fn get_quorum_members_of_type( &mut self, r#type: common::LLMQType, diff --git a/dash-spv-masternode-processor/src/tests/json_from_core_snapshot.rs b/dash-spv-masternode-processor/src/tests/json_from_core_snapshot.rs index c7df1d43..a1ad7a9e 100644 --- a/dash-spv-masternode-processor/src/tests/json_from_core_snapshot.rs +++ b/dash-spv-masternode-processor/src/tests/json_from_core_snapshot.rs @@ -94,6 +94,25 @@ pub struct Llmq { pub members_sig: String, } +impl From for models::LLMQEntry { + fn from(llmq: Llmq) -> Self { + models::LLMQEntry::new( + LLMQVersion::from(llmq.version as u16), + LLMQType::from(llmq.llmq_type as u8), + block_hash_to_block_hash(llmq.quorum_hash), + Some(llmq.quorum_index as u16), + VarInt(llmq.signers_count as u64), + VarInt(llmq.valid_members_count as u64), + llmq.signers.as_bytes().to_vec(), + llmq.valid_members.as_bytes().to_vec(), + UInt384::from_hex(llmq.quorum_public_key.as_str()).unwrap(), + UInt256::from_hex(llmq.quorum_vvec_hash.as_str()).unwrap(), + UInt768::from_hex(llmq.quorum_sig.as_str()).unwrap(), + UInt768::from_hex(llmq.members_sig.as_str()).unwrap() + ) + } +} + #[derive(Serialize, Deserialize)] pub struct Node { #[serde(rename = "proRegTxHash")] @@ -169,7 +188,7 @@ pub fn list_to_list(value: MNList) -> models::MasternodeList { let masternode_merkle_root = Some(block_hash_to_block_hash(value.masternode_merkle_root)); let llmq_merkle_root = Some(block_hash_to_block_hash(value.quorum_merkle_root)); let masternodes = nodes_to_masternodes(value.mn_list); - let quorums = quorums_to_quorums(value.new_quorums); + let quorums = quorums_to_quorums_map(value.new_quorums); models::MasternodeList { block_hash, known_height, @@ -212,23 +231,14 @@ pub fn value_to_masternode_list(value: &serde_json::Value) -> models::Masternode } } -pub fn quorums_to_quorums(value: Vec) -> BTreeMap> { +pub fn quorums_to_quorums_vec(value: Vec) -> Vec { + value.into_iter().map(models::LLMQEntry::from).collect() +} + +pub fn quorums_to_quorums_map(value: Vec) -> BTreeMap> { let mut quorums: BTreeMap> = BTreeMap::new(); - value.into_iter()/*.filter(|llmq| LLMQType::from(llmq.llmq_type as u8) == LLMQType::Llmqtype60_75)*/.for_each(|llmq| { - let entry = models::LLMQEntry::new( - LLMQVersion::from(llmq.version as u16), - LLMQType::from(llmq.llmq_type as u8), - block_hash_to_block_hash(llmq.quorum_hash), - Some(llmq.quorum_index as u16), - VarInt(llmq.signers_count as u64), - VarInt(llmq.valid_members_count as u64), - llmq.signers.as_bytes().to_vec(), - llmq.valid_members.as_bytes().to_vec(), - UInt384::from_hex(llmq.quorum_public_key.as_str()).unwrap(), - UInt256::from_hex(llmq.quorum_vvec_hash.as_str()).unwrap(), - UInt768::from_hex(llmq.quorum_sig.as_str()).unwrap(), - UInt768::from_hex(llmq.members_sig.as_str()).unwrap() - ); + value.into_iter().for_each(|llmq| { + let entry = models::LLMQEntry::from(llmq); quorums .entry(entry.llmq_type) .or_insert_with(BTreeMap::new) @@ -377,7 +387,7 @@ pub fn masternode_list_from_genesis_diff u32 + Copy>( let added_or_modified_masternodes = nodes_to_masternodes(diff.mn_list); // in that snapshot it's always empty let deleted_quorums = BTreeMap::default(); - let added_quorums = quorums_to_quorums(diff.new_quorums); + let added_quorums = quorums_to_quorums_vec(diff.new_quorums); println!("block_hash_tip: {}", block_hash); models::MNListDiff { base_block_hash, diff --git a/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation.rs b/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation.rs index 4a7b1223..20c9a1c7 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation.rs @@ -1,5 +1,5 @@ use crate::ffi::boxer::boxed; -use crate::lib_tests::tests::{add_insight_lookup_default, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, masternode_list_save_in_cache, message_from_file, process_mnlistdiff_from_message_internal, process_qrinfo_from_message_internal, save_llmq_snapshot_default, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext}; +use crate::lib_tests::tests::{add_insight_lookup_default, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, masternode_list_save_in_cache, message_from_file, process_mnlistdiff_from_message_internal, process_qrinfo_from_message_internal, save_llmq_snapshot_default, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_cl_signature_by_block_hash_from_context, save_cl_signature_in_cache}; use crate::chain::common::chain_type::{ChainType, DevnetType}; use crate::crypto::byte_util::{Reversable, UInt256}; use crate::hashes::hex::{FromHex, ToHex}; @@ -28,6 +28,8 @@ fn test_llmq_rotation() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -50,8 +52,8 @@ fn test_llmq_rotation() { context, )}; println!("{:?}", result); - let result_5078 = unsafe { *result }; - let result_at_h = unsafe { *result_5078.result_at_h }; + let result_5078 = unsafe { &*result }; + let result_at_h = unsafe { &*result_5078.result_at_h }; assert!( result_at_h.has_found_coinbase, "Did not find coinbase at height 5078" @@ -89,6 +91,8 @@ fn test_llmq_rotation_2() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -470,6 +474,8 @@ fn test_devnet_333() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -503,6 +509,8 @@ fn test_processor_devnet_333() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -722,6 +730,8 @@ fn test_processor_devnet_333_2() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -1419,6 +1429,8 @@ fn test_jack_daniels() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, diff --git a/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation_testnet.rs b/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation_testnet.rs index 65119138..2df79640 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation_testnet.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/llmq_rotation_testnet.rs @@ -1,9 +1,10 @@ +use std::collections::BTreeMap; use crate::bindings::common::{processor_create_cache, register_processor}; use crate::chain::common::ChainType; use crate::crypto::byte_util::Reversable; use crate::crypto::UInt256; use crate::hashes::hex::FromHex; -use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, process_qrinfo_from_message_internal, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, process_qrinfo_from_message_internal, save_cl_signature_in_cache, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::models; use crate::tests::block_store::init_mainnet_store; use crate::tests::json_from_core_snapshot::{block_hash_to_block_hash, ListDiff, masternode_list_from_genesis_diff, QRInfo, snapshot_to_snapshot}; @@ -30,9 +31,30 @@ fn testnet_quorum_quarters() { let block_hash_8792 = list_diff_8792.block_hash; let block_hash_8840 = list_diff_8840.block_hash; let block_hash_8888 = list_diff_8888.block_hash; - let masternode_list_8792 = models::MasternodeList::new(list_diff_8792.added_or_modified_masternodes, list_diff_8792.added_quorums, block_hash_8792, block_height_8792, true); - let masternode_list_8840 = models::MasternodeList::new(list_diff_8840.added_or_modified_masternodes, list_diff_8840.added_quorums, block_hash_8840, block_height_8840, true); - let masternode_list_8888 = models::MasternodeList::new(list_diff_8888.added_or_modified_masternodes, list_diff_8888.added_quorums, block_hash_8888, block_height_8888, true); + let added_quorums_8792 = list_diff_8792.added_quorums.iter() + .fold(BTreeMap::new(), |mut acc, entry| { + acc.entry(entry.llmq_type) + .or_insert_with(BTreeMap::new) + .insert(entry.llmq_hash, entry.clone()); + acc + }); + let added_quorums_8840 = list_diff_8840.added_quorums.iter() + .fold(BTreeMap::new(), |mut acc, entry| { + acc.entry(entry.llmq_type) + .or_insert_with(BTreeMap::new) + .insert(entry.llmq_hash, entry.clone()); + acc + }); + let added_quorums_8888 = list_diff_8888.added_quorums.iter() + .fold(BTreeMap::new(), |mut acc, entry| { + acc.entry(entry.llmq_type) + .or_insert_with(BTreeMap::new) + .insert(entry.llmq_hash, entry.clone()); + acc + }); + let masternode_list_8792 = models::MasternodeList::new(list_diff_8792.added_or_modified_masternodes, added_quorums_8792, block_hash_8792, block_height_8792, true); + let masternode_list_8840 = models::MasternodeList::new(list_diff_8840.added_or_modified_masternodes, added_quorums_8840, block_hash_8840, block_height_8840, true); + let masternode_list_8888 = models::MasternodeList::new(list_diff_8888.added_or_modified_masternodes, added_quorums_8888, block_hash_8888, block_height_8888, true); let processor = unsafe { &mut *register_processor( @@ -41,6 +63,8 @@ fn testnet_quorum_quarters() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -142,6 +166,7 @@ fn testnet_quorum_quarters() { &mut context.cache.llmq_indexed_members, &context.cache.mn_lists, &context.cache.llmq_snapshots, + &mut context.cache.cl_signatures, &mut context.cache.needed_masternode_lists, true ); diff --git a/dash-spv-masternode-processor/src/tests/listdiff/llmq_verification.rs b/dash-spv-masternode-processor/src/tests/listdiff/llmq_verification.rs index 75d925b5..d9aef671 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/llmq_verification.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/llmq_verification.rs @@ -7,7 +7,7 @@ use crate::ffi::from::FromFFI; use crate::ffi::to::ToFFI; use crate::chain::common::{ChainType, LLMQType}; use crate::crypto::UInt256; -use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context}; +use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, save_cl_signature_in_cache}; use crate::tests::block_store::init_testnet_store; #[test] @@ -31,6 +31,8 @@ fn testnet_llmq_verification() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -52,14 +54,15 @@ fn testnet_llmq_verification() { context as *mut _ as *mut std::ffi::c_void, )}; println!("{:?}", result); - let result_119064 = unsafe { *result }; + let result_119064 = result; assert_diff_result(context, result_119064); + let result_119064 = unsafe { &*result_119064 }; let is_valid = result_119064.is_valid(); println!("is_valid: {}", is_valid); if is_valid { let bytes = message_from_file("MNL_122928_123000.dat"); let block_hash_119064 = UInt256(unsafe { *result_119064.block_hash }); - let masternode_list_119064 = unsafe { *result_119064.masternode_list }; + let masternode_list_119064 = unsafe { &*result_119064.masternode_list }; let masternode_list_119064_decoded = unsafe { masternode_list_119064.decode() }; let masternode_list_119064_encoded = masternode_list_119064_decoded.encode(); let result = unsafe { process_mnlistdiff_from_message( @@ -74,24 +77,29 @@ fn testnet_llmq_verification() { context as *mut _ as *mut std::ffi::c_void, )}; println!("{:?}", result); - let result_119200 = unsafe { *result }; - assert_diff_result(context, result_119200); - let masternode_list_119200 = unsafe { *result_119200.masternode_list }; + assert_diff_result(context, result); + let result_119200 = unsafe { &*result }; + let masternode_list_119200 = unsafe { &*result_119200.masternode_list }; let masternode_list_119200_decoded = unsafe { masternode_list_119200.decode() }; - let added_quorums = (0..result_119200.added_llmq_type_maps_count) + let added_quorums = (0..result_119200.added_quorums_count) .into_iter() + .fold(BTreeMap::new(), |mut acc, i| unsafe { - let map = *(*(result_119200.added_llmq_type_maps.add(i))); - let llmq_type = LLMQType::from(map.llmq_type); - let entry_map = (0..map.count) - .into_iter() - .fold(BTreeMap::new(), |mut hacc, j| { - let raw_entry = *(*(map.values.add(j))); - let entry = raw_entry.decode(); - hacc.insert(entry.llmq_hash, entry); - hacc - }); - acc.insert(llmq_type, entry_map); + let map = &*(*(result_119200.added_quorums.add(i))); + let llmq_type = map.llmq_type; + let llmq_hash = UInt256(*map.llmq_hash); + acc.entry(llmq_type) + .or_insert_with(BTreeMap::new) + .insert(llmq_hash, map.decode()); + // let entry_map = (0..map.count) + // .into_iter() + // .fold(BTreeMap::new(), |mut hacc, j| { + // let raw_entry = *(*(map.values.add(j))); + // let entry = raw_entry.decode(); + // hacc.insert(entry.llmq_hash, entry); + // hacc + // }); + // acc.insert(llmq_type, entry_map); acc }); let hmm: BTreeMap> = added_quorums @@ -151,6 +159,8 @@ fn testnet_llmq_verification_using_processor_and_cache() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_119064, masternode_list_destroy_default, @@ -174,14 +184,14 @@ fn testnet_llmq_verification_using_processor_and_cache() { )}; println!("{:?}", result); - let result_119064 = unsafe { *result }; - assert_diff_result(context, result_119064); + assert_diff_result(context, result); + let result_119064 = unsafe { &*result }; let is_valid = result_119064.is_valid(); println!("is_valid: {}", is_valid); if is_valid { let bytes = message_from_file("MNL_122928_123000.dat"); let block_hash_119064 = UInt256(unsafe { *result_119064.block_hash }); - let masternode_list_119064 = unsafe { *result_119064.masternode_list }; + let masternode_list_119064 = unsafe { &*result_119064.masternode_list }; let masternode_list_119064_decoded = unsafe { masternode_list_119064.decode() }; let masternode_list_119064_encoded = masternode_list_119064_decoded.encode(); @@ -198,24 +208,19 @@ fn testnet_llmq_verification_using_processor_and_cache() { )}; println!("{:?}", result); - let result_119200 = unsafe { *result }; - assert_diff_result(context, result_119200); - let masternode_list_119200 = unsafe { *result_119200.masternode_list }; + assert_diff_result(context, result); + let result_119200 = unsafe { &*result }; + let masternode_list_119200 = unsafe { &*result_119200.masternode_list }; let masternode_list_119200_decoded = unsafe { masternode_list_119200.decode() }; - let added_quorums = (0..result_119200.added_llmq_type_maps_count) + let added_quorums = (0..result_119200.added_quorums_count) .into_iter() .fold(BTreeMap::new(), |mut acc, i| unsafe { - let map = *(*(result_119200.added_llmq_type_maps.add(i))); - let llmq_type = LLMQType::from(map.llmq_type); - let entry_map = (0..map.count) - .into_iter() - .fold(BTreeMap::new(), |mut hacc, j| { - let raw_entry = *(*(map.values.add(j))); - let entry = raw_entry.decode(); - hacc.insert(entry.llmq_hash, entry); - hacc - }); - acc.insert(llmq_type, entry_map); + let map = &*(*(result_119200.added_quorums.add(i))); + let llmq_type = map.llmq_type; + let llmq_hash = UInt256(*map.llmq_hash); + acc.entry(llmq_type) + .or_insert_with(BTreeMap::new) + .insert(llmq_hash, map.decode()); acc }); let hmm: BTreeMap> = added_quorums diff --git a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_core19.rs b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_core19.rs index 05875b6e..4b63c003 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_core19.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_core19.rs @@ -42,12 +42,13 @@ fn test_verify_chained_rotation2() { }); context.is_dip_0024 = true; let result = process_qrinfo(message_from_file("mainnet/QRINFO_0_1871755.dat"), processor, context, version, false, true); - assert_diff_result(context, unsafe { *result.result_at_h_4c }); - assert_diff_result(context, unsafe { *result.result_at_h_3c }); - assert_diff_result(context, unsafe { *result.result_at_h_2c }); - assert_diff_result(context, unsafe { *result.result_at_h_c }); - assert_diff_result(context, unsafe { *result.result_at_h }); - assert_diff_result(context, unsafe { *result.result_at_tip }); + let result = unsafe { &*result }; + assert_diff_result(context, result.result_at_h_4c); + assert_diff_result(context, result.result_at_h_3c); + assert_diff_result(context, result.result_at_h_2c); + assert_diff_result(context, result.result_at_h_c); + assert_diff_result(context, result.result_at_h); + assert_diff_result(context, result.result_at_tip); } // #[test] diff --git a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_reload.rs b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_reload.rs index 3b19b232..c4645503 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_reload.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_reload.rs @@ -4,7 +4,7 @@ use crate::bindings::masternode::process_mnlistdiff_from_message; use crate::ffi::from::FromFFI; use crate::chain::common::chain_type::ChainType; use crate::crypto::UInt256; -use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context}; +use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, save_cl_signature_in_cache}; use crate::models; use crate::tests::block_store::init_mainnet_store; @@ -67,6 +67,8 @@ pub fn load_masternode_lists_for_files( get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -92,15 +94,15 @@ pub fn load_masternode_lists_for_files( context.cache, context as *mut _ as *mut std::ffi::c_void, )}; - let result = unsafe { *result }; println!("result: [{:?}]", result); //println!("MNDiff: {} added, {} modified", result.added_masternodes_count, result.modified_masternodes_count); // println!("") if assert_validity { assert_diff_result(context, result); } + let result = unsafe { &*result }; let block_hash = UInt256(unsafe { *result.block_hash }); - let masternode_list = unsafe { *result.masternode_list }; + let masternode_list = unsafe { &*result.masternode_list }; let masternode_list_decoded = unsafe { masternode_list.decode() }; } // let c = unsafe { cache }; diff --git a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_test_invalid_mn_list_root.rs b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_test_invalid_mn_list_root.rs index 0ff69af1..6c9f41cd 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/mainnet_test_invalid_mn_list_root.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/mainnet_test_invalid_mn_list_root.rs @@ -1,4 +1,4 @@ -use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_cl_signature_in_cache, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::bindings::common::register_processor; use crate::bindings::masternode::process_mnlistdiff_from_message; use crate::chain::common::ChainType; @@ -25,6 +25,8 @@ fn mainnet_test_invalid_mn_list_root() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -41,7 +43,7 @@ fn mainnet_test_invalid_mn_list_root() { processor.save_masternode_list(masternode_list_1761048.block_hash, &masternode_list_1761048); processor.save_masternode_list(masternode_list_1761054.block_hash, &masternode_list_1761054); let result = unsafe { - *process_mnlistdiff_from_message( + &*process_mnlistdiff_from_message( bytes.as_ptr(), bytes.len(), chain, diff --git a/dash-spv-masternode-processor/src/tests/listdiff/masternode_list_saving_to_disk.rs b/dash-spv-masternode-processor/src/tests/listdiff/masternode_list_saving_to_disk.rs index 9e4c2718..32f4f4e0 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/masternode_list_saving_to_disk.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/masternode_list_saving_to_disk.rs @@ -4,7 +4,7 @@ use crate::chain::common::chain_type::ChainType; use crate::crypto::byte_util::UInt256; use crate::ffi::from::FromFFI; use crate::hashes::hex::FromHex; -use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context}; +use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default, FFIContext, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, save_cl_signature_in_cache}; use crate::tests::block_store::init_testnet_store; #[test] @@ -26,6 +26,8 @@ fn test_mnl_saving_to_disk() { get_block_hash_by_height_default, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -47,9 +49,10 @@ fn test_mnl_saving_to_disk() { context as *mut _ as *mut std::ffi::c_void, )}; println!("{:?}", result); - let result = unsafe { *result }; + assert_diff_result(context, result); + let result = unsafe { &*result }; let block_hash = UInt256(unsafe { *result.block_hash }); - let masternode_list = unsafe { *result.masternode_list }; + let masternode_list = unsafe { &*result.masternode_list }; let masternode_list_decoded = unsafe { masternode_list.decode() }; assert_eq!( UInt256::from_hex("94d0af97187af3b9311c98b1cf40c9c9849df0af55dc63b097b80d4cf6c816c5") @@ -57,5 +60,4 @@ fn test_mnl_saving_to_disk() { masternode_list_decoded.masternode_merkle_root.unwrap(), "MNList merkle root should be valid" ); - assert_diff_result(context, result); } diff --git a/dash-spv-masternode-processor/src/tests/listdiff/test_basic_bls_scheme.rs b/dash-spv-masternode-processor/src/tests/listdiff/test_basic_bls_scheme.rs index b2386632..703439b0 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/test_basic_bls_scheme.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/test_basic_bls_scheme.rs @@ -11,7 +11,7 @@ use crate::crypto::byte_util::Zeroable; use crate::ffi::boxer::boxed; use crate::ffi::to::ToFFI; use crate::keys::BLSKey; -use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, FFIContext, get_block_height_by_hash_from_context, get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, MerkleBlock, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default, register_logger}; +use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, FFIContext, get_block_height_by_hash_from_context, get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, MerkleBlock, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default, register_logger, get_cl_signature_by_block_hash_from_context, save_cl_signature_in_cache}; use crate::models::OperatorPublicKey; use crate::tests::block_store::init_testnet_store; @@ -79,6 +79,8 @@ fn test_basic_bls_scheme() { get_block_hash_by_height_chacha, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_at_9192, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -190,6 +192,8 @@ fn test_core_19_beta_6() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_mojito, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -221,7 +225,6 @@ fn test_core_19_beta_6() { context.cache, context as *mut _ as *mut std::ffi::c_void, )}; - let result = unsafe { *result }; assert_diff_result(context, result); } @@ -252,6 +255,8 @@ fn test_core_19_rc_2_testnet() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_mojito, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -280,7 +285,7 @@ fn test_core_19_rc_2_testnet() { context.cache, context as *mut _ as *mut std::ffi::c_void, )}; - let result = unsafe { *result }; + let result = unsafe { &*result }; println!("Result: {:#?}", &result); // todo: need add new blocks to the testnet store //assert_diff_result(context, result); diff --git a/dash-spv-masternode-processor/src/tests/listdiff/test_mainnet_checkpoints.rs b/dash-spv-masternode-processor/src/tests/listdiff/test_mainnet_checkpoints.rs index 2be32f28..3292ebd3 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/test_mainnet_checkpoints.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/test_mainnet_checkpoints.rs @@ -1,7 +1,7 @@ use crate::bindings::common::register_processor; use crate::bindings::masternode::process_mnlistdiff_from_message; use crate::chain::common::ChainType; -use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_cl_signature_in_cache, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::tests::block_store::init_mainnet_store; #[test] @@ -26,6 +26,8 @@ fn test_mainnet_checkpoint_1720000() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -36,7 +38,7 @@ fn test_mainnet_checkpoint_1720000() { ) }; let result = unsafe { - *process_mnlistdiff_from_message( + &*process_mnlistdiff_from_message( bytes.as_ptr(), bytes.len(), chain, diff --git a/dash-spv-masternode-processor/src/tests/listdiff/test_quorums_from_dash_core_snapshot.rs b/dash-spv-masternode-processor/src/tests/listdiff/test_quorums_from_dash_core_snapshot.rs index f42aae1c..5209f18d 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/test_quorums_from_dash_core_snapshot.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/test_quorums_from_dash_core_snapshot.rs @@ -1,7 +1,7 @@ use crate::bindings::common::{processor_create_cache, register_processor}; use crate::chain::common::{ChainType, IHaveChainSettings}; use crate::crypto::{byte_util::Reversable, UInt256}; -use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, message_from_file, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_default, get_masternode_list_by_block_hash_default, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_default, message_from_file, save_cl_signature_in_cache, save_llmq_snapshot_default, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::tests::block_store::init_testnet_store; use crate::tests::json_from_core_snapshot::{masternode_list_from_genesis_diff, QRInfo, snapshot_to_snapshot}; @@ -31,6 +31,8 @@ pub fn test_from_snapshot() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_default, save_llmq_snapshot_default, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_default, masternode_list_save_default, masternode_list_destroy_default, @@ -48,26 +50,27 @@ pub fn test_from_snapshot() { let get_height = |hash: UInt256| cached_blocks.iter().find(|block| block.hash == hash.reversed()).unwrap().height; let cached_llmq_members = &mut context.cache.llmq_members; let cached_llmq_indexed_members = &mut context.cache.llmq_indexed_members; - if let Some(rotated_quorums_h) = mn_list_diff_h.added_quorums.get(&chain.isd_llmq_type()) { - rotated_quorums_h.iter().for_each(|(&llmq_block_hash, entry)| { - println!("rotated_quorum: ({}: {})", llmq_block_hash, llmq_block_hash.reversed()); - let llmq_block_height = get_height(llmq_block_hash); - println!("rotated_quorum: ({}: {})\n {:#?}", llmq_block_height, llmq_block_hash, entry); - let masternodes = processor.get_rotated_masternodes_for_quorum( - entry.llmq_type, - llmq_block_hash, - llmq_block_height, - cached_llmq_members, - cached_llmq_indexed_members, - &context.cache.mn_lists, - &context.cache.llmq_snapshots, - &mut context.cache.needed_masternode_lists, - false - ); - println!("masternodes: {:#?}", masternodes); - }); - } + mn_list_diff_h.added_quorums.iter().filter(|q| q.llmq_type == chain.isd_llmq_type()).for_each(|entry| { + println!("rotated_quorum: ({}: {})", entry.llmq_hash, entry.llmq_hash.reversed()); + let llmq_block_height = get_height(entry.llmq_hash); + println!("rotated_quorum: ({}: {})\n {:#?}", llmq_block_height, entry.llmq_hash, entry); + + let masternodes = processor.get_rotated_masternodes_for_quorum( + entry.llmq_type, + entry.llmq_hash, + llmq_block_height, + cached_llmq_members, + cached_llmq_indexed_members, + &context.cache.mn_lists, + &context.cache.llmq_snapshots, + &context.cache.cl_signatures, + &mut context.cache.needed_masternode_lists, + false + ); + println!("masternodes: {:#?}", masternodes); + }); + // let masternodes = processor // .get_rotated_masternodes_for_quorum(chain.isd_llmq_type(), mn_list_diff_h.added_quorums) diff --git a/dash-spv-masternode-processor/src/tests/listdiff/testnet_core19.rs b/dash-spv-masternode-processor/src/tests/listdiff/testnet_core19.rs index 117dc042..26a33fb0 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/testnet_core19.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/testnet_core19.rs @@ -19,6 +19,7 @@ fn test_core19rc10() { let processor = register_default_processor(); let result = process_mnlistdiff(message_from_file("testnet/MNT530000.dat"), processor, context, 70219, false, true); assert_diff_result(context, result); + let result = unsafe { &*result }; unsafe { context.cache.mn_lists.insert(UInt256(*result.block_hash), (*result.masternode_list).decode()); } @@ -35,6 +36,7 @@ fn test_core19_70224() { let processor = register_default_processor(); let result = process_mnlistdiff(message_from_file("testnet/MNT530000.dat"), processor, context, 70219, false, true); assert_diff_result(context, result); + let result = unsafe { &*result }; unsafe { context.cache.mn_lists.insert(UInt256(*result.block_hash), (*result.masternode_list).decode()); } @@ -49,6 +51,7 @@ fn test_core19_70227() { let context = &mut create_default_context(ChainType::TestNet, false, cache); let processor = register_default_processor(); let result = process_mnlistdiff(message_from_file("testnet/MNT530000.dat"), processor, context, 70219, false, true); + let result = unsafe { &*result }; // assert_diff_result(context, result); unsafe { let list = (*result.masternode_list).decode(); @@ -110,12 +113,13 @@ fn test_mnlistdiff_and_qrinfo_core19() { }); context.is_dip_0024 = true; let result = process_qrinfo(message_from_file("QRINFO_0_870235.dat"), processor, context, version, false, true); - assert_diff_result(context, unsafe { *result.result_at_h_4c }); - assert_diff_result(context, unsafe { *result.result_at_h_3c }); - assert_diff_result(context, unsafe { *result.result_at_h_2c }); - assert_diff_result(context, unsafe { *result.result_at_h_c }); - //assert_diff_result(context, unsafe { *result.result_at_h }); - assert_diff_result(context, unsafe { *result.result_at_tip }); + let result = unsafe { &*result }; + assert_diff_result(context, result.result_at_h_4c); + assert_diff_result(context, result.result_at_h_3c); + assert_diff_result(context, result.result_at_h_2c); + assert_diff_result(context, result.result_at_h_c); + //assert_diff_result(context, result.result_at_h); + assert_diff_result(context, result.result_at_tip); } // #[test] @@ -125,12 +129,13 @@ fn test_qrinfo_core19() { let context = &mut create_default_context(ChainType::TestNet, true, cache); let processor = register_default_processor(); let result = process_qrinfo(message_from_file("QRINFO_0_870235.dat"), processor, context, 70227, false, true); - assert_diff_result(context, unsafe { *result.result_at_h_4c }); - assert_diff_result(context, unsafe { *result.result_at_h_3c }); - assert_diff_result(context, unsafe { *result.result_at_h_2c }); - assert_diff_result(context, unsafe { *result.result_at_h_c }); - assert_diff_result(context, unsafe { *result.result_at_h }); - assert_diff_result(context, unsafe { *result.result_at_tip }); + let result = unsafe { &*result }; + assert_diff_result(context, result.result_at_h_4c); + assert_diff_result(context, result.result_at_h_3c); + assert_diff_result(context, result.result_at_h_2c); + assert_diff_result(context, result.result_at_h_c); + assert_diff_result(context, result.result_at_h); + assert_diff_result(context, result.result_at_tip); } @@ -1153,11 +1158,9 @@ fn test_core19_2() { let cache = register_cache(); let context = &mut create_default_context(ChainType::TestNet, false, cache); let processor = register_default_processor(); - let diffs = vec![ - "MNL_0_530000_70228.dat", - "MNL_530000_852596.dat", - ].iter().for_each(|name| { - let result = process_mnlistdiff(message_from_file(format!("testnet/{}", name).as_str()), processor, context, version, false, true); - assert_diff_result(context, result); - }); + ["MNL_0_530000_70228.dat", "MNL_530000_852596.dat"].iter() + .for_each(|name| { + let result = process_mnlistdiff(message_from_file(format!("testnet/{}", name).as_str()), processor, context, version, false, true); + assert_diff_result(context, result); + }); } diff --git a/dash-spv-masternode-processor/src/tests/listdiff/testnet_test_retrieving.rs b/dash-spv-masternode-processor/src/tests/listdiff/testnet_test_retrieving.rs index dc25bc99..9a59aff6 100644 --- a/dash-spv-masternode-processor/src/tests/listdiff/testnet_test_retrieving.rs +++ b/dash-spv-masternode-processor/src/tests/listdiff/testnet_test_retrieving.rs @@ -5,7 +5,7 @@ use crate::chain::common::ChainType; use crate::crypto::byte_util::Reversable; use crate::crypto::UInt256; use crate::ffi::from::FromFFI; -use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_cl_signature_in_cache, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::tests::block_store::init_testnet_store; use crate::util::data_ops::merkle_root_from_hashes; @@ -355,6 +355,8 @@ fn testnet_test_retrieve_saved_hashes() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -365,7 +367,7 @@ fn testnet_test_retrieve_saved_hashes() { ) }; let result_122064 = unsafe { - *process_mnlistdiff_from_message( + &*process_mnlistdiff_from_message( bytes_122064.as_ptr(), bytes_122064.len(), chain, @@ -379,7 +381,7 @@ fn testnet_test_retrieve_saved_hashes() { assert!(result_122064.is_valid(), "Result must be valid"); let bytes_122088 = message_from_file("MNL_122064_122088.dat"); let result_122088 = unsafe { - *process_mnlistdiff_from_message( + &*process_mnlistdiff_from_message( bytes_122088.as_ptr(), bytes_122088.len(), chain, diff --git a/dash-spv-masternode-processor/src/tests/mod.rs b/dash-spv-masternode-processor/src/tests/mod.rs index 36ace63a..817c46e0 100644 --- a/dash-spv-masternode-processor/src/tests/mod.rs +++ b/dash-spv-masternode-processor/src/tests/mod.rs @@ -6,3 +6,4 @@ pub mod keys; pub mod listdiff; pub mod test_testnet_checkpoints; pub mod bindings; +pub mod tx; diff --git a/dash-spv-masternode-processor/src/tests/test_testnet_checkpoints.rs b/dash-spv-masternode-processor/src/tests/test_testnet_checkpoints.rs index cbbf374e..fc46afdf 100644 --- a/dash-spv-masternode-processor/src/tests/test_testnet_checkpoints.rs +++ b/dash-spv-masternode-processor/src/tests/test_testnet_checkpoints.rs @@ -1,7 +1,7 @@ use crate::bindings::common::register_processor; use crate::bindings::masternode::process_mnlistdiff_from_message; use crate::chain::common::ChainType; -use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; +use crate::lib_tests::tests::{add_insight_lookup_default, assert_diff_result, FFIContext, get_block_hash_by_height_from_context, get_block_height_by_hash_from_context, get_cl_signature_by_block_hash_from_context, get_llmq_snapshot_by_block_hash_from_context, get_masternode_list_by_block_hash_from_cache, get_merkle_root_by_hash_default, hash_destroy_default, masternode_list_destroy_default, masternode_list_save_in_cache, message_from_file, save_cl_signature_in_cache, save_llmq_snapshot_in_cache, should_process_diff_with_range_default, snapshot_destroy_default}; use crate::tests::block_store::init_testnet_store; #[test] @@ -16,6 +16,8 @@ fn test_checkpoint_530000() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -26,7 +28,7 @@ fn test_checkpoint_530000() { ) }; let result = unsafe { - *process_mnlistdiff_from_message( + &*process_mnlistdiff_from_message( bytes.as_ptr(), bytes.len(), chain, @@ -55,6 +57,8 @@ fn test_checkpoint_530000_70227() { get_block_hash_by_height_from_context, get_llmq_snapshot_by_block_hash_from_context, save_llmq_snapshot_in_cache, + get_cl_signature_by_block_hash_from_context, + save_cl_signature_in_cache, get_masternode_list_by_block_hash_from_cache, masternode_list_save_in_cache, masternode_list_destroy_default, @@ -65,7 +69,7 @@ fn test_checkpoint_530000_70227() { ) }; let result = unsafe { - *process_mnlistdiff_from_message( + process_mnlistdiff_from_message( bytes.as_ptr(), bytes.len(), chain, diff --git a/dash-spv-masternode-processor/src/tests/tx/coinbase.rs b/dash-spv-masternode-processor/src/tests/tx/coinbase.rs new file mode 100644 index 00000000..52c3457f --- /dev/null +++ b/dash-spv-masternode-processor/src/tests/tx/coinbase.rs @@ -0,0 +1,12 @@ +use hashes::hex::{FromHex, ToHex}; +use crate::crypto::byte_util::{BytesDecodable, Reversable}; +use crate::crypto::UInt256; +use crate::tx::CoinbaseTransaction; + +#[test] +pub fn test_coinbase_tx() { + let bytes = Vec::from_hex("03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff0502f6050105ffffffff0200c11a3d050000002321038df098a36af5f1b7271e32ad52947f64c1ad70c16a8a1a987105eaab5daa7ad2ac00c11a3d050000001976a914bfb885c89c83cd44992a8ade29b610e6ddf00c5788ac00000000260100f6050000aaaec8d6a8535a01bd844817dea1faed66f6c397b1dcaec5fe8c5af025023c35").unwrap(); + let tx = CoinbaseTransaction::from_bytes(&bytes, &mut 0).unwrap(); + assert_eq!(tx.to_data().to_hex(), bytes.to_hex(), "Coinbase transaction does not match it's data"); + assert_eq!(tx.base.tx_hash, Some(UInt256::from_hex("5b4e5e99e967e01e27627621df00c44525507a31201ceb7b96c6e1a452e82bef").unwrap().reversed()), "Coinbase transaction hash does not match it's data dash"); +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/tests/tx/mod.rs b/dash-spv-masternode-processor/src/tests/tx/mod.rs new file mode 100644 index 00000000..5aaff1df --- /dev/null +++ b/dash-spv-masternode-processor/src/tests/tx/mod.rs @@ -0,0 +1 @@ +pub mod coinbase; \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/tx/coinbase_transaction.rs b/dash-spv-masternode-processor/src/tx/coinbase_transaction.rs index 80479196..920ab565 100644 --- a/dash-spv-masternode-processor/src/tx/coinbase_transaction.rs +++ b/dash-spv-masternode-processor/src/tx/coinbase_transaction.rs @@ -5,6 +5,10 @@ use crate::consensus::Encodable; use crate::crypto::{UInt256, UInt768}; use crate::tx::{Transaction, TransactionType::Coinbase}; + +pub const COINBASE_TX_CORE_19: u16 = 2; +pub const COINBASE_TX_CORE_20: u16 = 3; + #[derive(Debug, Clone)] pub struct CoinbaseTransaction { pub base: Transaction, @@ -14,6 +18,7 @@ pub struct CoinbaseTransaction { pub merkle_root_llmq_list: Option, pub best_cl_height_diff: u32, pub best_cl_signature: Option, + pub credit_pool_balance: Option, } impl<'a> TryRead<'a, Endian> for CoinbaseTransaction { @@ -24,17 +29,19 @@ impl<'a> TryRead<'a, Endian> for CoinbaseTransaction { let coinbase_transaction_version = bytes.read_with::(offset, endian)?; let height = bytes.read_with::(offset, endian)?; let merkle_root_mn_list = bytes.read_with::(offset, endian)?; - let merkle_root_llmq_list = if coinbase_transaction_version >= 2 { + let merkle_root_llmq_list = if coinbase_transaction_version >= COINBASE_TX_CORE_19 { let root = bytes.read_with::(offset, endian)?; Some(root) } else { None }; - let (best_cl_height_diff, best_cl_signature) = if coinbase_transaction_version >= 3 { + let (best_cl_height_diff, best_cl_signature, credit_pool_balance) = if coinbase_transaction_version >= COINBASE_TX_CORE_20 { + // TODO: VarInt or u32?? (bytes.read_with::(offset, byte::LE)?, - bytes.read_with::(offset, byte::LE).ok()) + bytes.read_with::(offset, byte::LE).ok(), + bytes.read_with::(offset, byte::LE).ok().map(|var_int| var_int.0)) } else { - (u32::MAX, None) + (u32::MAX, None, None) }; base.tx_type = Coinbase; base.payload_offset = *offset; @@ -45,7 +52,8 @@ impl<'a> TryRead<'a, Endian> for CoinbaseTransaction { merkle_root_mn_list, merkle_root_llmq_list, best_cl_height_diff, - best_cl_signature + best_cl_signature, + credit_pool_balance }; tx.base.tx_hash = Some(UInt256::sha256d(tx.to_data())); Ok((tx, *offset)) @@ -58,15 +66,19 @@ impl CoinbaseTransaction { self.coinbase_transaction_version.enc(&mut buffer); self.height.enc(&mut buffer); self.merkle_root_mn_list.enc(&mut buffer); - if self.coinbase_transaction_version >= 2 { - if let Some(llmq_list) = self.merkle_root_llmq_list { - llmq_list.enc(&mut buffer); + + if self.coinbase_transaction_version >= COINBASE_TX_CORE_19 { + if let Some(llmq_root) = self.merkle_root_llmq_list { + llmq_root.enc(&mut buffer); } - } - if self.coinbase_transaction_version >= 3 { - self.best_cl_height_diff.enc(&mut buffer); - if let Some(sig) = self.best_cl_signature { - sig.enc(&mut buffer); + if self.coinbase_transaction_version >= COINBASE_TX_CORE_20 { + self.best_cl_height_diff.enc(&mut buffer); + if let Some(cl_sig) = self.best_cl_signature { + cl_sig.enc(&mut buffer); + } + if let Some(credit_pool_balance) = self.credit_pool_balance { + credit_pool_balance.enc(&mut buffer); + } } } buffer diff --git a/dash-spv-masternode-processor/src/tx/transaction.rs b/dash-spv-masternode-processor/src/tx/transaction.rs index 834b7a6f..343f2c56 100644 --- a/dash-spv-masternode-processor/src/tx/transaction.rs +++ b/dash-spv-masternode-processor/src/tx/transaction.rs @@ -20,13 +20,12 @@ pub enum TransactionType { ProviderUpdateRevocation = 4, Coinbase = 5, QuorumCommitment = 6, - SubscriptionRegistration = 8, - SubscriptionTopUp = 9, - SubscriptionResetKey = 10, + AssetLock = 8, + AssetUnlock = 9, + TypeMax = 10, SubscriptionCloseAccount = 11, Transition = 12, // tmp - /// TODO: find actual value for this type CreditFunding = 255, } @@ -41,9 +40,9 @@ impl From for TransactionType { 0x0004 => TransactionType::ProviderUpdateRevocation, 0x0005 => TransactionType::Coinbase, 0x0006 => TransactionType::QuorumCommitment, - 0x0008 => TransactionType::SubscriptionRegistration, - 0x0009 => TransactionType::SubscriptionTopUp, - 0x000A => TransactionType::SubscriptionResetKey, + 0x0008 => TransactionType::AssetLock, + 0x0009 => TransactionType::AssetUnlock, + 0x000A => TransactionType::TypeMax, 0x000B => TransactionType::SubscriptionCloseAccount, 0x000C => TransactionType::Transition, _ => TransactionType::Classic, @@ -312,11 +311,11 @@ impl<'a> TryRead<'a, Endian> for Transaction { let mut tx = Self { inputs, outputs, - tx_hash: None, version, tx_type, lock_time, payload_offset: *offset, + tx_hash: None, block_height: TX_UNCONFIRMED as u32, }; tx.tx_hash = (tx_type == TransactionType::Classic).then_some(UInt256::sha256d(tx.to_data())); diff --git a/dash-spv-masternode-processor/src/types/block.rs b/dash-spv-masternode-processor/src/types/block.rs index a6b36dfb..6bb195a8 100644 --- a/dash-spv-masternode-processor/src/types/block.rs +++ b/dash-spv-masternode-processor/src/types/block.rs @@ -1,6 +1,16 @@ +use crate::ffi::unboxer::unbox_any; + #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct Block { pub height: u32, pub hash: *mut [u8; 32], } + +impl Drop for Block { + fn drop(&mut self) { + unsafe { + unbox_any(self.hash); + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/coinbase_transaction.rs b/dash-spv-masternode-processor/src/types/coinbase_transaction.rs index 8cb22441..19797ff7 100644 --- a/dash-spv-masternode-processor/src/types/coinbase_transaction.rs +++ b/dash-spv-masternode-processor/src/types/coinbase_transaction.rs @@ -1,13 +1,8 @@ -use byte::ctx::Endian; -use byte::{BytesExt, TryRead, LE}; -use std::ptr::null_mut; -use crate::consensus; -use crate::crypto::{UInt256, UInt768}; -use crate::ffi::boxer::boxed; +use crate::ffi::unboxer::unbox_any; use crate::types::transaction::Transaction; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct CoinbaseTransaction { pub base: *mut Transaction, pub coinbase_transaction_version: u16, @@ -16,39 +11,22 @@ pub struct CoinbaseTransaction { pub merkle_root_llmq_list: *mut [u8; 32], pub best_cl_height_diff: u32, pub best_cl_signature: *mut [u8; 96], + pub credit_pool_balance: u64, } -impl<'a> TryRead<'a, Endian> for CoinbaseTransaction { - fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { - let offset = &mut 0; - let base = boxed(bytes.read_with::(offset, LE)?); - let _extra_payload_size_var_int = - bytes.read_with::(offset, LE)?; - let coinbase_transaction_version = bytes.read_with::(offset, LE)?; - let height = bytes.read_with::(offset, LE)?; - let merkle_root_mn_list = boxed(bytes.read_with::(offset, LE)?.0); - let merkle_root_llmq_list = if coinbase_transaction_version >= 2 { - boxed(bytes.read_with::(offset, LE)?.0) - } else { - null_mut() - }; - let (best_cl_height_diff, best_cl_signature) = if coinbase_transaction_version >= 3 { - (bytes.read_with::(offset, byte::LE)?, - boxed(bytes.read_with::(offset, byte::LE)?.0)) - } else { - (u32::MAX, null_mut()) - }; - Ok(( - Self { - base, - coinbase_transaction_version, - height, - merkle_root_mn_list, - merkle_root_llmq_list, - best_cl_height_diff, - best_cl_signature - }, - *offset, - )) +impl Drop for CoinbaseTransaction { + fn drop(&mut self) { + unsafe { + unbox_any(self.base); + if !self.merkle_root_mn_list.is_null() { + unbox_any(self.merkle_root_mn_list); + } + if !self.merkle_root_llmq_list.is_null() { + unbox_any(self.merkle_root_llmq_list); + } + if !self.best_cl_signature.is_null() { + unbox_any(self.best_cl_signature); + } + } } -} +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/llmq_cache.rs b/dash-spv-masternode-processor/src/types/llmq_cache.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/dash-spv-masternode-processor/src/types/llmq_entry.rs b/dash-spv-masternode-processor/src/types/llmq_entry.rs index e7567119..740e0f2c 100644 --- a/dash-spv-masternode-processor/src/types/llmq_entry.rs +++ b/dash-spv-masternode-processor/src/types/llmq_entry.rs @@ -6,9 +6,10 @@ use crate::common::LLMQVersion; use crate::consensus; use crate::crypto::byte_util::{UInt256, UInt384, UInt768}; use crate::ffi::boxer::{boxed, boxed_vec}; +use crate::ffi::unboxer::unbox_any; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct LLMQEntry { // 144 bytes pub all_commitment_aggregated_signature: *mut [u8; 96], @@ -30,6 +31,25 @@ pub struct LLMQEntry { pub verified: bool, pub version: LLMQVersion, } + +impl Drop for LLMQEntry { + fn drop(&mut self) { + unsafe { + unbox_any(self.all_commitment_aggregated_signature); + if !self.commitment_hash.is_null() { + unbox_any(self.commitment_hash); + } + unbox_any(self.entry_hash); + unbox_any(self.llmq_hash); + unbox_any(self.public_key); + unbox_any(self.threshold_signature); + unbox_any(self.verification_vector_hash); + unbox_any(std::ptr::slice_from_raw_parts_mut::(self.signers_bitset, self.signers_bitset_length)); + unbox_any(std::ptr::slice_from_raw_parts_mut::(self.valid_members_bitset, self.valid_members_bitset_length)); + } + } +} + impl<'a> TryRead<'a, Endian> for LLMQEntry { fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { let length = bytes.len(); diff --git a/dash-spv-masternode-processor/src/types/llmq_indexed_hash.rs b/dash-spv-masternode-processor/src/types/llmq_indexed_hash.rs index 6bc64900..d0585178 100644 --- a/dash-spv-masternode-processor/src/types/llmq_indexed_hash.rs +++ b/dash-spv-masternode-processor/src/types/llmq_indexed_hash.rs @@ -1,6 +1,16 @@ +use crate::ffi::unboxer::unbox_any; + #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct LLMQIndexedHash { pub index: u32, pub hash: *mut [u8; 32], } + +impl Drop for LLMQIndexedHash { + fn drop(&mut self) { + unsafe { + unbox_any(self.hash); + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/llmq_map.rs b/dash-spv-masternode-processor/src/types/llmq_map.rs index dd694948..f9e7aecb 100644 --- a/dash-spv-masternode-processor/src/types/llmq_map.rs +++ b/dash-spv-masternode-processor/src/types/llmq_map.rs @@ -1,9 +1,18 @@ +use crate::ffi::unboxer::unbox_any_vec_ptr; use crate::types::llmq_entry::LLMQEntry; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct LLMQMap { pub llmq_type: u8, pub values: *mut *mut LLMQEntry, pub count: usize, } + +impl Drop for LLMQMap { + fn drop(&mut self) { + unsafe { + unbox_any_vec_ptr(self.values, self.count); + } + } +} diff --git a/dash-spv-masternode-processor/src/types/llmq_snapshot.rs b/dash-spv-masternode-processor/src/types/llmq_snapshot.rs index f939e79c..69ba1f42 100644 --- a/dash-spv-masternode-processor/src/types/llmq_snapshot.rs +++ b/dash-spv-masternode-processor/src/types/llmq_snapshot.rs @@ -4,10 +4,11 @@ use crate::common::LLMQSnapshotSkipMode; use crate::consensus::encode; use crate::crypto::byte_util::BytesDecodable; use crate::ffi::boxer::boxed_vec; +use crate::ffi::unboxer::unbox_vec_ptr; use crate::impl_bytes_decodable; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct LLMQSnapshot { pub member_list_length: usize, pub member_list: *mut u8, @@ -20,6 +21,18 @@ pub struct LLMQSnapshot { impl_bytes_decodable!(LLMQSnapshot); +impl Drop for LLMQSnapshot { + fn drop(&mut self) { + unsafe { + let member_list = unbox_vec_ptr(self.member_list, self.member_list_length); + drop(member_list); + let skip_list = unbox_vec_ptr(self.skip_list, self.skip_list_length); + drop(skip_list); + + } + } +} + impl<'a> TryRead<'a, Endian> for LLMQSnapshot { fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { let offset = &mut 0; diff --git a/dash-spv-masternode-processor/src/types/llmq_typed_hash.rs b/dash-spv-masternode-processor/src/types/llmq_typed_hash.rs index 5ec8ba36..afce60a4 100644 --- a/dash-spv-masternode-processor/src/types/llmq_typed_hash.rs +++ b/dash-spv-masternode-processor/src/types/llmq_typed_hash.rs @@ -1,6 +1,16 @@ +use crate::ffi::unboxer::unbox_any; + #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct LLMQTypedHash { pub llmq_type: u8, pub llmq_hash: *mut [u8; 32], } + +impl Drop for LLMQTypedHash { + fn drop(&mut self) { + unsafe { + unbox_any(self.llmq_hash); + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/llmq_validation_data.rs b/dash-spv-masternode-processor/src/types/llmq_validation_data.rs deleted file mode 100644 index 760dd2b4..00000000 --- a/dash-spv-masternode-processor/src/types/llmq_validation_data.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::common::LLMQVersion; -use crate::types; - -#[repr(C)] -#[derive(Clone, Copy, Debug)] -pub struct LLMQValidationData { - pub items: *mut *mut types::OperatorPublicKey, - pub count: usize, - pub commitment_hash: *mut [u8; 32], - pub all_commitment_aggregated_signature: *mut [u8; 96], - pub threshold_signature: *mut [u8; 96], - pub public_key: *mut [u8; 48], - pub version: LLMQVersion, -} diff --git a/dash-spv-masternode-processor/src/types/masternode_entry.rs b/dash-spv-masternode-processor/src/types/masternode_entry.rs index 0f345734..0b788253 100644 --- a/dash-spv-masternode-processor/src/types/masternode_entry.rs +++ b/dash-spv-masternode-processor/src/types/masternode_entry.rs @@ -1,7 +1,8 @@ +use crate::ffi::unboxer::{unbox_any, unbox_vec_ptr}; use crate::types::{BlockOperatorPublicKey, MasternodeEntryHash, OperatorPublicKey, Validity}; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct MasternodeEntry { pub confirmed_hash: *mut [u8; 32], pub confirmed_hash_hashed_with_provider_registration_transaction_hash: *mut [u8; 32], // nullable @@ -26,3 +27,26 @@ pub struct MasternodeEntry { pub platform_http_port: u16, pub platform_node_id: *mut [u8; 20], } + +impl Drop for MasternodeEntry { + fn drop(&mut self) { + unsafe { + unbox_any(self.confirmed_hash); + if !self.confirmed_hash_hashed_with_provider_registration_transaction_hash.is_null() { + unbox_any(self.confirmed_hash_hashed_with_provider_registration_transaction_hash); + } + unbox_any(self.key_id_voting); + unbox_any(self.entry_hash); + unbox_any(self.operator_public_key); + unbox_vec_ptr(self.previous_entry_hashes, self.previous_entry_hashes_count); + unbox_vec_ptr(self.previous_operator_public_keys, self.previous_operator_public_keys_count); + unbox_vec_ptr(self.previous_validity, self.previous_validity_count); + unbox_any(self.provider_registration_transaction_hash); + unbox_any(self.ip_address); + if !self.platform_node_id.is_null() { + unbox_any(self.platform_node_id); + } + + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/masternode_entry_hash.rs b/dash-spv-masternode-processor/src/types/masternode_entry_hash.rs index eb13c87e..f3d0e019 100644 --- a/dash-spv-masternode-processor/src/types/masternode_entry_hash.rs +++ b/dash-spv-masternode-processor/src/types/masternode_entry_hash.rs @@ -1,5 +1,5 @@ #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct MasternodeEntryHash { pub block_hash: [u8; 32], pub block_height: u32, diff --git a/dash-spv-masternode-processor/src/types/masternode_list.rs b/dash-spv-masternode-processor/src/types/masternode_list.rs index ca6d202c..311b69aa 100644 --- a/dash-spv-masternode-processor/src/types/masternode_list.rs +++ b/dash-spv-masternode-processor/src/types/masternode_list.rs @@ -1,7 +1,8 @@ +use crate::ffi::unboxer::{unbox_any, unbox_any_vec_ptr}; use crate::types; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct MasternodeList { pub block_hash: *mut [u8; 32], pub known_height: u32, @@ -12,3 +13,19 @@ pub struct MasternodeList { pub llmq_type_maps: *mut *mut types::LLMQMap, pub llmq_type_maps_count: usize, } + +impl Drop for MasternodeList { + fn drop(&mut self) { + unsafe { + unbox_any(self.block_hash); + if !self.masternode_merkle_root.is_null() { + unbox_any(self.masternode_merkle_root); + } + if !self.llmq_merkle_root.is_null() { + unbox_any(self.llmq_merkle_root); + } + unbox_any_vec_ptr(self.masternodes, self.masternodes_count); + unbox_any_vec_ptr(self.llmq_type_maps, self.llmq_type_maps_count); + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/mn_list_diff_result.rs b/dash-spv-masternode-processor/src/types/mn_list_diff_result.rs index 9a786345..40934c96 100644 --- a/dash-spv-masternode-processor/src/types/mn_list_diff_result.rs +++ b/dash-spv-masternode-processor/src/types/mn_list_diff_result.rs @@ -1,9 +1,10 @@ use crate::types; use std::ptr::null_mut; +use crate::ffi::unboxer::{unbox_any, unbox_any_vec_ptr}; use crate::processing::ProcessingError; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct MNListDiffResult { pub error_status: ProcessingError, pub base_block_hash: *mut [u8; 32], @@ -18,11 +19,12 @@ pub struct MNListDiffResult { pub added_masternodes_count: usize, pub modified_masternodes: *mut *mut types::MasternodeEntry, pub modified_masternodes_count: usize, - pub added_llmq_type_maps: *mut *mut types::LLMQMap, - pub added_llmq_type_maps_count: usize, + pub added_quorums: *mut *mut types::LLMQEntry, + pub added_quorums_count: usize, pub needed_masternode_lists: *mut *mut [u8; 32], pub needed_masternode_lists_count: usize, - pub quorums_cl_sigs: *mut *mut types::QuorumsCLSigsObject, + pub quorums_cl_signatures_hashes: *mut *mut [u8; 32], + pub quorums_cl_signatures: *mut *mut [u8; 96], pub quorums_cl_sigs_count: usize, } impl MNListDiffResult { @@ -47,16 +49,51 @@ impl Default for MNListDiffResult { added_masternodes_count: 0, modified_masternodes: null_mut(), modified_masternodes_count: 0, - added_llmq_type_maps: null_mut(), - added_llmq_type_maps_count: 0, + added_quorums: null_mut(), + added_quorums_count: 0, needed_masternode_lists: null_mut(), needed_masternode_lists_count: 0, - quorums_cl_sigs: null_mut(), + quorums_cl_signatures_hashes: null_mut(), + quorums_cl_signatures: null_mut(), quorums_cl_sigs_count: 0, } } } +impl Drop for MNListDiffResult { + fn drop(&mut self) { + unsafe { + if !self.base_block_hash.is_null() { + unbox_any(self.base_block_hash); + } + if !self.block_hash.is_null() { + unbox_any(self.block_hash); + } + if !self.masternode_list.is_null() { + unbox_any(self.masternode_list); + } + if !self.needed_masternode_lists.is_null() { + unbox_any_vec_ptr(self.needed_masternode_lists, self.needed_masternode_lists_count); + } + if !self.added_masternodes.is_null() { + unbox_any_vec_ptr(self.added_masternodes, self.added_masternodes_count); + } + if !self.modified_masternodes.is_null() { + unbox_any_vec_ptr(self.modified_masternodes, self.modified_masternodes_count); + } + if !self.added_quorums.is_null() { + unbox_any_vec_ptr(self.added_quorums, self.added_quorums_count); + } + if !self.quorums_cl_signatures_hashes.is_null() { + unbox_any_vec_ptr(self.quorums_cl_signatures_hashes, self.quorums_cl_sigs_count); + } + if !self.quorums_cl_signatures.is_null() { + unbox_any_vec_ptr(self.quorums_cl_signatures, self.quorums_cl_sigs_count); + } + } + } +} + impl MNListDiffResult { pub fn is_valid(&self) -> bool { self.has_found_coinbase diff --git a/dash-spv-masternode-processor/src/types/mod.rs b/dash-spv-masternode-processor/src/types/mod.rs index 78a350dc..10b868cb 100644 --- a/dash-spv-masternode-processor/src/types/mod.rs +++ b/dash-spv-masternode-processor/src/types/mod.rs @@ -5,7 +5,6 @@ pub mod llmq_indexed_hash; pub mod llmq_map; pub mod llmq_snapshot; pub mod llmq_typed_hash; -pub mod llmq_validation_data; /// This types reflected for FFI pub mod masternode_entry; pub mod masternode_entry_hash; @@ -30,7 +29,6 @@ pub use self::llmq_indexed_hash::LLMQIndexedHash; pub use self::llmq_map::LLMQMap; pub use self::llmq_snapshot::LLMQSnapshot; pub use self::llmq_typed_hash::LLMQTypedHash; -pub use self::llmq_validation_data::LLMQValidationData; pub use self::masternode_entry::MasternodeEntry; pub use self::masternode_entry_hash::MasternodeEntryHash; pub use self::masternode_list::MasternodeList; diff --git a/dash-spv-masternode-processor/src/types/qr_info_result.rs b/dash-spv-masternode-processor/src/types/qr_info_result.rs index cefcdb46..d37857d6 100644 --- a/dash-spv-masternode-processor/src/types/qr_info_result.rs +++ b/dash-spv-masternode-processor/src/types/qr_info_result.rs @@ -1,9 +1,10 @@ use std::ptr::null_mut; +use crate::ffi::unboxer::{unbox_any, unbox_any_vec_ptr}; use crate::processing::ProcessingError; use crate::types; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone)] pub struct QRInfoResult { pub error_status: ProcessingError, pub result_at_tip: *mut types::MNListDiffResult, @@ -51,6 +52,54 @@ impl Default for QRInfoResult { } } +impl Drop for QRInfoResult { + fn drop(&mut self) { + unsafe { + if !self.result_at_tip.is_null() { + unbox_any(self.result_at_tip); + } + if !self.result_at_h.is_null() { + unbox_any(self.result_at_h); + } + if !self.result_at_h_c.is_null() { + unbox_any(self.result_at_h_c); + } + if !self.result_at_h_2c.is_null() { + unbox_any(self.result_at_h_2c); + } + if !self.result_at_h_3c.is_null() { + unbox_any(self.result_at_h_3c); + } + if !self.snapshot_at_h_c.is_null() { + unbox_any(self.snapshot_at_h_c); + } + if !self.snapshot_at_h_2c.is_null() { + unbox_any(self.snapshot_at_h_2c); + } + if !self.snapshot_at_h_3c.is_null() { + unbox_any(self.snapshot_at_h_3c); + } + if self.extra_share { + if !self.result_at_h_4c.is_null() { + unbox_any(self.result_at_h_4c); + } + if !self.snapshot_at_h_4c.is_null() { + unbox_any(self.snapshot_at_h_4c); + } + } + if !self.last_quorum_per_index.is_null() { + unbox_any_vec_ptr(self.last_quorum_per_index, self.last_quorum_per_index_count); + } + if !self.quorum_snapshot_list.is_null() { + unbox_any_vec_ptr(self.quorum_snapshot_list, self.quorum_snapshot_list_count); + } + if !self.mn_list_diff_list.is_null() { + unbox_any_vec_ptr(self.mn_list_diff_list, self.mn_list_diff_list_count); + } + } + } +} + impl QRInfoResult { pub fn default_with_error(error: ProcessingError) -> Self { Self { error_status: error, ..Default::default() } diff --git a/dash-spv-masternode-processor/src/types/quorums_cl_sigs_object.rs b/dash-spv-masternode-processor/src/types/quorums_cl_sigs_object.rs index 187b6cd3..c8b2975f 100644 --- a/dash-spv-masternode-processor/src/types/quorums_cl_sigs_object.rs +++ b/dash-spv-masternode-processor/src/types/quorums_cl_sigs_object.rs @@ -1,7 +1,19 @@ +use crate::ffi::unboxer::{unbox_any, unbox_vec_ptr}; + #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct QuorumsCLSigsObject { pub signature: *mut [u8; 96], pub index_set_count: usize, pub index_set: *mut u16, } + +impl Drop for QuorumsCLSigsObject { + fn drop(&mut self) { + unsafe { + unbox_any(self.signature); + let index_set = unbox_vec_ptr(self.index_set, self.index_set_count); + drop(index_set); + } + } +} \ No newline at end of file diff --git a/dash-spv-masternode-processor/src/types/transaction.rs b/dash-spv-masternode-processor/src/types/transaction.rs index b993031d..d1b7287c 100644 --- a/dash-spv-masternode-processor/src/types/transaction.rs +++ b/dash-spv-masternode-processor/src/types/transaction.rs @@ -3,11 +3,12 @@ use byte::{BytesExt, TryRead, LE}; use std::ptr::null_mut; use crate::consensus; use crate::ffi::boxer::{boxed, boxed_vec}; +use crate::ffi::unboxer::{unbox_any, unbox_any_vec_ptr}; use crate::tx::{TransactionType, TX_UNCONFIRMED}; use crate::types::{TransactionInput, TransactionOutput}; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct Transaction { pub inputs: *mut *mut TransactionInput, pub inputs_count: usize, @@ -20,6 +21,22 @@ pub struct Transaction { pub payload_offset: usize, pub block_height: u32, } + +impl Drop for Transaction { + fn drop(&mut self) { + unsafe { + if !self.inputs.is_null() { + unbox_any_vec_ptr(self.inputs, self.inputs_count); + } + if !self.outputs.is_null() { + unbox_any_vec_ptr(self.outputs, self.outputs_count); + } + if !self.tx_hash.is_null() { + unbox_any(self.tx_hash); + } + } + } +} impl<'a> TryRead<'a, Endian> for Transaction { fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { let offset = &mut 0; diff --git a/dash-spv-masternode-processor/src/types/transaction_input.rs b/dash-spv-masternode-processor/src/types/transaction_input.rs index 13c20757..3612cb09 100644 --- a/dash-spv-masternode-processor/src/types/transaction_input.rs +++ b/dash-spv-masternode-processor/src/types/transaction_input.rs @@ -1,11 +1,12 @@ use byte::ctx::Endian; use byte::{BytesExt, TryRead, LE}; -use std::ptr::null_mut; +use std::ptr::{null_mut, slice_from_raw_parts_mut}; use crate::crypto::{UInt256, VarBytes}; use crate::ffi::boxer::{boxed, boxed_vec}; +use crate::ffi::unboxer::unbox_any; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct TransactionInput { pub input_hash: *mut [u8; 32], pub index: u32, @@ -15,6 +16,21 @@ pub struct TransactionInput { pub signature_length: usize, pub sequence: u32, } + +impl Drop for TransactionInput { + fn drop(&mut self) { + unsafe { + unbox_any(self.input_hash); + if !self.script.is_null() && self.script_length > 0 { + unbox_any(slice_from_raw_parts_mut(self.script, self.script_length)); + } + if !self.signature.is_null() && self.signature_length > 0 { + unbox_any(slice_from_raw_parts_mut(self.signature, self.signature_length)); + } + } + } +} + impl<'a> TryRead<'a, Endian> for TransactionInput { fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { let offset = &mut 0; diff --git a/dash-spv-masternode-processor/src/types/transaction_output.rs b/dash-spv-masternode-processor/src/types/transaction_output.rs index f29f13de..4de75ff1 100644 --- a/dash-spv-masternode-processor/src/types/transaction_output.rs +++ b/dash-spv-masternode-processor/src/types/transaction_output.rs @@ -1,11 +1,12 @@ use byte::ctx::Endian; use byte::{BytesExt, TryRead, LE}; -use std::ptr::null_mut; +use std::ptr::{null_mut, slice_from_raw_parts_mut}; use crate::crypto::VarBytes; use crate::ffi::boxer::boxed_vec; +use crate::ffi::unboxer::unbox_any; #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct TransactionOutput { pub amount: u64, pub script: *mut u8, @@ -13,6 +14,20 @@ pub struct TransactionOutput { pub address: *mut u8, pub address_length: usize, } + +impl Drop for TransactionOutput { + fn drop(&mut self) { + unsafe { + if !self.script.is_null() && self.script_length > 0 { + unbox_any(slice_from_raw_parts_mut(self.script, self.script_length)); + } + if !self.address.is_null() && self.address_length > 0 { + unbox_any(slice_from_raw_parts_mut(self.address, self.address_length)); + } + } + } +} + impl<'a> TryRead<'a, Endian> for TransactionOutput { fn try_read(bytes: &'a [u8], _endian: Endian) -> byte::Result<(Self, usize)> { let offset = &mut 0; diff --git a/dash-spv-masternode-processor/src/util/java.rs b/dash-spv-masternode-processor/src/util/java.rs index 9c4d641f..45918481 100644 --- a/dash-spv-masternode-processor/src/util/java.rs +++ b/dash-spv-masternode-processor/src/util/java.rs @@ -5,9 +5,9 @@ use hashes::hex::ToHex; use secp256k1::rand::{Rng, thread_rng}; use crate::chain::common::chain_type::DevnetType; use crate::common::{ChainType, LLMQType}; -use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256}; +use crate::crypto::{byte_util::{Reversable, Zeroable}, UInt256, UInt768}; use crate::ffi::from::FromFFI; -use crate::models::{LLMQEntry, LLMQSnapshot, MasternodeEntry}; +use crate::models::{LLMQEntry, LLMQSnapshot, MasternodeEntry, QuorumsCLSigsObject}; use crate::{models, types}; use crate::util::file::save_java_class; use crate::util::save_json_file; @@ -345,6 +345,12 @@ pub fn save_snapshot_to_json(snapshot: &LLMQSnapshot, block_height: u32) { .expect("Can't save snapshot"); } +pub fn save_cl_signature_to_json(cl_signature: &UInt768, block_height: u32) { + let file_name = format!("cl_signature_{}.json", block_height); + save_json_file(file_name.as_str(), cl_signature) + .expect("Can't save snapshot"); +} + pub fn save_masternode_list_to_json(masternode_list: &models::MasternodeList, block_height: u32) { let masternodes = serde_json::to_value(masternode_list.masternodes.values().collect::>()).unwrap(); let file_name = format!("masternodes_{}.json", block_height);