diff --git a/Cargo.lock b/Cargo.lock index 17ba92b..92db919 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,9 +114,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.6.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" +checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c" dependencies = [ "memchr", "regex-automata", @@ -146,41 +146,37 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.9.9" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa0f00717c71b8e9ee4c090b4880ec2418c8506bb6828a2c72df72d3896e905d" +checksum = "a2525ab7a58543c132da8c780abe3aa1ba394ddcc1888a4ad2ba4f5100906ebe" dependencies = [ "anyhow", "binread", "byteorder", "candid_derive", - "codespan-reporting", - "crc32fast", - "data-encoding", "hex", + "ic_principal", "leb128", "num-bigint", "num-traits", - "num_enum", "paste", "pretty", "serde", "serde_bytes", - "sha2", "stacker", "thiserror", ] [[package]] name = "candid_derive" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158403ea38fab5904ae47a5d67eb7047650a91681407f5ccbcbcabc4f4ffb489" +checksum = "970c220da8aa2fa6f7ef5dbbf3ea5b620a59eb3ac107cfb95ae8c6eebdfb7a08" dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -201,9 +197,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.6" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" dependencies = [ "clap_builder", "clap_derive", @@ -211,9 +207,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" dependencies = [ "anstream", "anstyle", @@ -223,21 +219,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "codespan-reporting" @@ -257,9 +253,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] @@ -285,9 +281,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.107" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe98ba1789d56fb3db3bee5e032774d4f421b685de7ba703643584ba24effbe" +checksum = "7129e341034ecb940c9072817cd9007974ea696844fc4dd582dc1653a7fbe2e8" dependencies = [ "cc", "cxxbridge-flags", @@ -297,9 +293,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.107" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ce20f6b8433da4841b1dadfb9468709868022d829d5ca1f2ffbda928455ea3" +checksum = "a2a24f3f5f8eed71936f21e570436f024f5c2e25628f7496aa7ccd03b90109d5" dependencies = [ "cc", "codespan-reporting", @@ -307,31 +303,31 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] name = "cxxbridge-flags" -version = "1.0.107" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20888d9e1d2298e2ff473cee30efe7d5036e437857ab68bbfea84c74dba91da2" +checksum = "06fdd177fc61050d63f67f5bd6351fac6ab5526694ea8e359cd9cd3b75857f44" [[package]] name = "cxxbridge-macro" -version = "1.0.107" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fa16a70dd58129e4dfffdff535fb1bce66673f7bbeec4a5a1765a504e1ccd84" +checksum = "587663dd5fb3d10932c8aecfe7c844db1bcf0aee93eeab08fac13dc1212c2e7f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "difflib" @@ -361,33 +357,16 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - [[package]] name = "errno" -version = "0.3.4" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" 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 = "fallible-iterator" version = "0.2.0" @@ -417,7 +396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", - "indexmap 1.9.3", + "indexmap", "stable_deref_trait", ] @@ -427,12 +406,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - [[package]] name = "heck" version = "0.3.3" @@ -456,7 +429,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "ic-wasm" -version = "0.6.0" +version = "0.7.0" dependencies = [ "anyhow", "assert_cmd", @@ -471,6 +444,21 @@ dependencies = [ "wasm-opt", ] +[[package]] +name = "ic_principal" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899a4e8ddada85b91a2fe32b4dc6c0d475ef7bfef3f51cf2aecb26ee4ac4724f" +dependencies = [ + "crc32fast", + "data-encoding", + "hex", + "serde", + "serde_bytes", + "sha2", + "thiserror", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -484,17 +472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown 0.14.1", + "hashbrown", ] [[package]] @@ -514,9 +492,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -535,9 +513,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "link-cplusplus" @@ -550,9 +528,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "log" @@ -590,34 +568,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -669,21 +626,11 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - [[package]] name = "proc-macro2" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -708,18 +655,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "regex-automata" -version = "0.3.9" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" [[package]] name = "rustc-demangle" @@ -729,11 +676,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.19" +version = "0.38.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -760,9 +707,9 @@ checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] @@ -778,13 +725,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -866,9 +813,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -877,9 +824,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand", @@ -890,9 +837,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" dependencies = [ "winapi-util", ] @@ -905,39 +852,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", -] - -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.0.2", - "toml_datetime", - "winnow", + "syn 2.0.39", ] [[package]] @@ -993,9 +923,9 @@ dependencies = [ [[package]] name = "walrus" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc27d837c587f863d99515dc8cae7cef1098bd1d99fa29373e3660c12766265e" +checksum = "0a7b95ecf5892b48104914fa021721699bb8149ae754cff50a22daeb7df0928f" dependencies = [ "anyhow", "gimli", @@ -1170,12 +1100,3 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winnow" -version = "0.5.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" -dependencies = [ - "memchr", -] diff --git a/Cargo.toml b/Cargo.toml index fcdbf42..72468ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ic-wasm" -version = "0.6.1" +version = "0.7.0" authors = ["DFINITY Stiftung"] edition = "2021" description = "A library for performing Wasm transformations specific to canisters running on the Internet Computer" @@ -19,7 +19,7 @@ required-features = ["exe"] [dependencies] walrus = "0.20.1" -candid = "0.9.9" +candid = "0.10" rustc-demangle = "0.1" thiserror = "1.0.35" @@ -31,7 +31,7 @@ serde = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true } [features] -default = ["anyhow", "clap", "wasm-opt"] +default = ["exe", "wasm-opt"] exe = ["anyhow", "clap", "serde"] wasm-opt = ["dep:wasm-opt", "tempfile"] serde = ["dep:serde", "dep:serde_json"] diff --git a/src/bin/main.rs b/src/bin/main.rs index 0494eb9..61a8a3e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -80,9 +80,6 @@ enum SubCommand { /// The number of pages of the preallocated stable memory #[clap(short, long, requires("start_page"))] page_limit: Option, - /// Use the new metering cost, default to false. This flag will eventually be removed and set to true after the mainnet has adapted the new metering. - #[clap(short, long)] - use_new_metering: bool, }, } @@ -126,14 +123,12 @@ fn main() -> anyhow::Result<()> { trace_only, start_page, page_limit, - use_new_metering, } => { use ic_wasm::instrumentation::{instrument, Config}; let config = Config { trace_only_funcs: trace_only.clone().unwrap_or(vec![]), start_address: start_page.map(|page| page * 65536), page_limit: *page_limit, - use_new_metering: *use_new_metering, }; instrument(&mut m, config).map_err(|e| anyhow::anyhow!("{e}"))?; } diff --git a/src/instrumentation.rs b/src/instrumentation.rs index 569a033..a803cbc 100644 --- a/src/instrumentation.rs +++ b/src/instrumentation.rs @@ -38,7 +38,6 @@ pub struct Config { pub trace_only_funcs: Vec, pub start_address: Option, pub page_limit: Option, - pub use_new_metering: bool, } impl Config { pub fn is_preallocated(&self) -> bool { @@ -69,7 +68,7 @@ pub fn instrument(m: &mut Module, config: Config) -> Result<(), String> { trace_only_ids.insert(id); } let is_partial_tracing = !trace_only_ids.is_empty(); - let func_cost = FunctionCost::new(m, config.use_new_metering); + let func_cost = FunctionCost::new(m); let total_counter = m .globals .add_local(ValType::I64, true, InitExpr::Value(Value::I64(0))); @@ -110,7 +109,6 @@ pub fn instrument(m: &mut Module, config: Config) -> Result<(), String> { &vars, &func_cost, is_partial_tracing, - config.use_new_metering, ); } } @@ -151,7 +149,6 @@ fn inject_metering( vars: &Variables, func_cost: &FunctionCost, is_partial_tracing: bool, - use_new_metering: bool, ) { use InjectionKind::*; let mut stack = vec![start]; @@ -161,7 +158,7 @@ fn inject_metering( let mut injection_points = vec![]; let mut curr = InjectionPoint::new(); // each function has at least a unit cost - if seq_id == start && use_new_metering { + if seq_id == start { curr.cost += 1; } for (pos, (instr, _)) in seq.instrs.iter().enumerate() { @@ -169,9 +166,7 @@ fn inject_metering( match instr { Instr::Block(Block { seq }) | Instr::Loop(Loop { seq }) => { match func.block(*seq).ty { - InstrSeqType::Simple(Some(_)) => { - curr.cost += instr_cost(instr, use_new_metering) - } + InstrSeqType::Simple(Some(_)) => curr.cost += instr_cost(instr), InstrSeqType::Simple(None) => (), InstrSeqType::MultiValue(_) => unreachable!("Multivalue not supported"), } @@ -183,7 +178,7 @@ fn inject_metering( consequent, alternative, }) => { - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); stack.push(*consequent); stack.push(*alternative); injection_points.push(curr); @@ -191,17 +186,17 @@ fn inject_metering( } Instr::Br(_) | Instr::BrIf(_) | Instr::BrTable(_) => { // br always points to a block, so we don't need to push the br block to stack for traversal - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); injection_points.push(curr); curr = InjectionPoint::new(); } Instr::Return(_) | Instr::Unreachable(_) => { - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); injection_points.push(curr); curr = InjectionPoint::new(); } Instr::Call(Call { func }) => { - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); match func_cost.get_cost(*func) { Some((cost, InjectionKind::Static)) => curr.cost += cost, Some((cost, kind @ InjectionKind::Dynamic)) @@ -222,7 +217,7 @@ fn inject_metering( | Instr::MemoryInit(_) | Instr::TableCopy(_) | Instr::TableInit(_) => { - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); let dynamic = InjectionPoint { position: pos, cost: 0, @@ -231,7 +226,7 @@ fn inject_metering( injection_points.push(dynamic); } _ => { - curr.cost += instr_cost(instr, use_new_metering); + curr.cost += instr_cost(instr); } } } diff --git a/src/utils.rs b/src/utils.rs index db88e3f..64d6605 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,7 +32,7 @@ pub(crate) enum InjectionKind { pub(crate) struct FunctionCost(HashMap); impl FunctionCost { - pub fn new(m: &Module, use_new_metering: bool) -> Self { + pub fn new(m: &Module) -> Self { let mut res = HashMap::new(); for (method, func) in m.imports.iter().filter_map(|i| { if let ImportKind::Function(func) = i.kind { @@ -47,70 +47,48 @@ impl FunctionCost { }) { use InjectionKind::*; // System API cost taken from https://github.com/dfinity/ic/blob/master/rs/embedders/src/wasmtime_embedder/system_api_complexity.rs - let cost = if use_new_metering { - match method { - "accept_message" => (500, Static), - "call_cycles_add" | "call_cycles_add128" => (500, Static), - "call_data_append" => (500, Dynamic), - "call_new" => (1500, Static), - "call_on_cleanup" => (500, Static), - "call_perform" => (5000, Static), - "canister_cycle_balance" | "canister_cycle_balance128" => (500, Static), - "canister_self_copy" => (500, Dynamic), - "canister_self_size" => (500, Static), - "canister_status" | "canister_version" => (500, Static), - "certified_data_set" => (500, Dynamic), - "data_certificate_copy" => (500, Dynamic), - "data_certificate_present" | "data_certificate_size" => (500, Static), - "debug_print" => (100, Dynamic), - "global_timer_set" => (500, Static), - "is_controller" => (1000, Dynamic), - "msg_arg_data_copy" => (500, Dynamic), - "msg_arg_data_size" => (500, Static), - "msg_caller_copy" => (500, Dynamic), - "msg_caller_size" => (500, Static), - "msg_cycles_accept" | "msg_cycles_accept128" => (500, Static), - "msg_cycles_available" | "msg_cycles_available128" => (500, Static), - "msg_cycles_refunded" | "msg_cycles_refunded128" => (500, Static), - "cycles_burn128" => (100, Static), - "msg_method_name_copy" => (500, Dynamic), - "msg_method_name_size" => (500, Static), - "msg_reject_code" | "msg_reject_msg_size" => (500, Static), - "msg_reject_msg_copy" => (500, Dynamic), - "msg_reject" => (500, Dynamic), - "msg_reply_data_append" => (500, Dynamic), - "msg_reply" => (500, Static), - "performance_counter" => (200, Static), - "stable_grow" | "stable64_grow" => (100, Static), - "stable_size" | "stable64_size" => (20, Static), - "stable_read" => (20, Dynamic), - "stable_write" => (20, Dynamic), - "stable64_read" => (20, Dynamic64), - "stable64_write" => (20, Dynamic64), - "trap" => (500, Dynamic), - "time" => (500, Static), - _ => (20, Static), - } - } else { - match method { - "msg_arg_data_copy" => (20, Dynamic), - "msg_method_name_copy" => (20, Dynamic), - "msg_reply_data_append" => (20, Dynamic), - "msg_reject" => (20, Dynamic), - "msg_reject_msg_copy" => (20, Dynamic), - "debug_print" => (100, Dynamic), - "is_controller" => (1000, Dynamic), - "trap" => (20, Dynamic), - "call_new" => (0, Static), - "call_data_append" => (20, Dynamic), - "call_perform" => (0, Static), - "stable_read" => (20, Dynamic), - "stable_write" => (20, Dynamic), - "stable64_read" => (20, Dynamic64), - "stable64_write" => (20, Dynamic64), - "performance_counter" => (200, Static), - _ => (0, Static), - } + let cost = match method { + "accept_message" => (500, Static), + "call_cycles_add" | "call_cycles_add128" => (500, Static), + "call_data_append" => (500, Dynamic), + "call_new" => (1500, Static), + "call_on_cleanup" => (500, Static), + "call_perform" => (5000, Static), + "canister_cycle_balance" | "canister_cycle_balance128" => (500, Static), + "canister_self_copy" => (500, Dynamic), + "canister_self_size" => (500, Static), + "canister_status" | "canister_version" => (500, Static), + "certified_data_set" => (500, Dynamic), + "data_certificate_copy" => (500, Dynamic), + "data_certificate_present" | "data_certificate_size" => (500, Static), + "debug_print" => (100, Dynamic), + "global_timer_set" => (500, Static), + "is_controller" => (1000, Dynamic), + "msg_arg_data_copy" => (500, Dynamic), + "msg_arg_data_size" => (500, Static), + "msg_caller_copy" => (500, Dynamic), + "msg_caller_size" => (500, Static), + "msg_cycles_accept" | "msg_cycles_accept128" => (500, Static), + "msg_cycles_available" | "msg_cycles_available128" => (500, Static), + "msg_cycles_refunded" | "msg_cycles_refunded128" => (500, Static), + "cycles_burn128" => (100, Static), + "msg_method_name_copy" => (500, Dynamic), + "msg_method_name_size" => (500, Static), + "msg_reject_code" | "msg_reject_msg_size" => (500, Static), + "msg_reject_msg_copy" => (500, Dynamic), + "msg_reject" => (500, Dynamic), + "msg_reply_data_append" => (500, Dynamic), + "msg_reply" => (500, Static), + "performance_counter" => (200, Static), + "stable_grow" | "stable64_grow" => (100, Static), + "stable_size" | "stable64_size" => (20, Static), + "stable_read" => (20, Dynamic), + "stable_write" => (20, Dynamic), + "stable64_read" => (20, Dynamic64), + "stable64_write" => (20, Dynamic64), + "trap" => (500, Dynamic), + "time" => (500, Static), + _ => (20, Static), }; res.insert(func, cost); } @@ -120,13 +98,10 @@ impl FunctionCost { self.0.get(&id).copied() } } -pub(crate) fn instr_cost(i: &ir::Instr, use_new_metering: bool) -> i64 { +pub(crate) fn instr_cost(i: &ir::Instr) -> i64 { use ir::*; use BinaryOp::*; use UnaryOp::*; - if !use_new_metering { - return 1; - } // Cost taken from https://github.com/dfinity/ic/blob/master/rs/embedders/src/wasm_utils/instrumentation.rs match i { Instr::Block(..) | Instr::Loop(..) => 0, diff --git a/tests/deployable.ic-repl.sh b/tests/deployable.ic-repl.sh index 6c6dab8..a2c9e84 100644 --- a/tests/deployable.ic-repl.sh +++ b/tests/deployable.ic-repl.sh @@ -98,33 +98,33 @@ function check_profiling(S, cycles, len) { }; let S = counter(file("ok/motoko-instrument.wasm")); -check_profiling(S, 9397, 78); +check_profiling(S, 21571, 78); let S = counter(file("ok/motoko-gc-instrument.wasm")); -check_profiling(S, 250, 4); +check_profiling(S, 595, 4); let wasm = file("ok/motoko-region-instrument.wasm"); let S = counter(wasm); -check_profiling(S, 463666, 78); +check_profiling(S, 478652, 78); upgrade(S, wasm); call S.get(); assert _ == (45 : nat); -check_profiling(S, 474294, 460); +check_profiling(S, 494682, 460); counter(file("ok/motoko-shrink.wasm")); counter(file("ok/motoko-limit.wasm")); let S = counter(file("ok/rust-instrument.wasm")); -check_profiling(S, 53149, 576); +check_profiling(S, 75279, 576); let wasm = file("ok/rust-region-instrument.wasm"); let S = counter(wasm); -check_profiling(S, 126136, 574); +check_profiling(S, 152042, 574); upgrade(S, wasm); call S.get(); assert _ == (45 : nat); -check_profiling(S, 911310, 2344); +check_profiling(S, 1023168, 2344); counter(file("ok/rust-shrink.wasm")); counter(file("ok/rust-limit.wasm")); let S = wat(file("ok/wat-instrument.wasm")); -check_profiling(S, 189, 2); +check_profiling(S, 5656, 2); wat(file("ok/wat-shrink.wasm")); wat(file("ok/wat-limit.wasm")); diff --git a/tests/ok/motoko-gc-instrument.wasm b/tests/ok/motoko-gc-instrument.wasm index 6c1f349..f1476cc 100644 Binary files a/tests/ok/motoko-gc-instrument.wasm and b/tests/ok/motoko-gc-instrument.wasm differ diff --git a/tests/ok/motoko-instrument.wasm b/tests/ok/motoko-instrument.wasm index e0cec5a..de41072 100644 Binary files a/tests/ok/motoko-instrument.wasm and b/tests/ok/motoko-instrument.wasm differ diff --git a/tests/ok/motoko-region-instrument.wasm b/tests/ok/motoko-region-instrument.wasm index 18f61ce..d1a8bab 100644 Binary files a/tests/ok/motoko-region-instrument.wasm and b/tests/ok/motoko-region-instrument.wasm differ diff --git a/tests/ok/rust-instrument.wasm b/tests/ok/rust-instrument.wasm index a6a9319..e1b5ee5 100644 Binary files a/tests/ok/rust-instrument.wasm and b/tests/ok/rust-instrument.wasm differ diff --git a/tests/ok/rust-region-instrument.wasm b/tests/ok/rust-region-instrument.wasm index 7ab7b60..f5f8f3d 100644 Binary files a/tests/ok/rust-region-instrument.wasm and b/tests/ok/rust-region-instrument.wasm differ diff --git a/tests/ok/wat-instrument.wasm b/tests/ok/wat-instrument.wasm index 5212e23..2c21354 100644 Binary files a/tests/ok/wat-instrument.wasm and b/tests/ok/wat-instrument.wasm differ