From 8d51d4f2bac85a578217d5cb660fcf58d0c21566 Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Sharma Date: Tue, 9 Apr 2024 14:37:37 +0530 Subject: [PATCH 1/2] add solana compute budget substream --- .../solana-compute-budget/Cargo.lock | 819 ++++++++++++++++++ .../solana-compute-budget/Cargo.toml | 25 + .../solana-compute-budget/Makefile | 17 + .../solana-compute-budget/proto/main.proto | 22 + .../solana-compute-budget/src/constants.rs | 1 + .../solana-compute-budget/src/instruction.rs | 80 ++ .../solana-compute-budget/src/lib.rs | 128 +++ .../solana-compute-budget/src/pb/mod.rs | 16 + .../sf.solana.programs.compute.budget.v1.rs | 36 + .../solana-compute-budget/src/utils.rs | 9 + .../solana-compute-budget/substreams.yaml | 24 + 11 files changed, 1177 insertions(+) create mode 100644 solana-program-library/solana-compute-budget/Cargo.lock create mode 100644 solana-program-library/solana-compute-budget/Cargo.toml create mode 100644 solana-program-library/solana-compute-budget/Makefile create mode 100644 solana-program-library/solana-compute-budget/proto/main.proto create mode 100644 solana-program-library/solana-compute-budget/src/constants.rs create mode 100644 solana-program-library/solana-compute-budget/src/instruction.rs create mode 100644 solana-program-library/solana-compute-budget/src/lib.rs create mode 100644 solana-program-library/solana-compute-budget/src/pb/mod.rs create mode 100644 solana-program-library/solana-compute-budget/src/pb/sf.solana.programs.compute.budget.v1.rs create mode 100644 solana-program-library/solana-compute-budget/src/utils.rs create mode 100644 solana-program-library/solana-compute-budget/substreams.yaml diff --git a/solana-program-library/solana-compute-budget/Cargo.lock b/solana-program-library/solana-compute-budget/Cargo.lock new file mode 100644 index 0000000..609d689 --- /dev/null +++ b/solana-program-library/solana-compute-budget/Cargo.lock @@ -0,0 +1,819 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bigdecimal" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "borsh" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +dependencies = [ + "borsh-derive", + "hashbrown 0.13.2", +] + +[[package]] +name = "borsh-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "borsh-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[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.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pad" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "petgraph" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 1.0.109", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "substreams" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3520661f782c338f0e3c6cfc001ac790ed5e68d8f28515139e2aa674f8bb54da" +dependencies = [ + "anyhow", + "bigdecimal", + "hex", + "hex-literal", + "num-bigint", + "num-integer", + "num-traits", + "pad", + "prost", + "prost-build", + "prost-types", + "substreams-macro", + "thiserror", +] + +[[package]] +name = "substreams-macro" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c15595ceab80fece579e462d4823048fe85d67922584c681f5e94305727ad9ee" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "thiserror", +] + +[[package]] +name = "substreams-solana" +version = "0.11.1" +source = "git+https://github.com/streamingfast/substreams-solana?branch=master#1f66cc3081f61ad1189dc814cb82096ae5ac4b3b" +dependencies = [ + "anyhow", + "num_enum", + "substreams", + "substreams-solana-core", + "substreams-solana-macro", +] + +[[package]] +name = "substreams-solana-core" +version = "0.11.1" +source = "git+https://github.com/streamingfast/substreams-solana?branch=master#1f66cc3081f61ad1189dc814cb82096ae5ac4b3b" +dependencies = [ + "bs58 0.4.0", + "prost", + "prost-build", + "prost-types", +] + +[[package]] +name = "substreams-solana-macro" +version = "0.11.1" +source = "git+https://github.com/streamingfast/substreams-solana?branch=master#1f66cc3081f61ad1189dc814cb82096ae5ac4b3b" +dependencies = [ + "bs58 0.4.0", +] + +[[package]] +name = "substreams-solana-program-instructions" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2d2eac3fee28a079bd3af5573bb6d43cf9667d89ce577fc7dd40113bb31e9e1" +dependencies = [ + "anyhow", + "num_enum", + "substreams", +] + +[[package]] +name = "substreams-solana-programs-compute-budget" +version = "1.0.0" +dependencies = [ + "base64", + "borsh", + "bs58 0.5.1", + "bytes", + "chrono", + "num-bigint", + "prost", + "substreams", + "substreams-solana", + "substreams-solana-program-instructions", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] diff --git a/solana-program-library/solana-compute-budget/Cargo.toml b/solana-program-library/solana-compute-budget/Cargo.toml new file mode 100644 index 0000000..5abe4b3 --- /dev/null +++ b/solana-program-library/solana-compute-budget/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "substreams-solana-programs-compute-budget" +version = "1.0.0" +edition = "2021" + +[lib] +name = "substreams" +crate-type = ["cdylib"] + +[dependencies] +substreams = "^0.5.0" +substreams-solana = { git = "https://github.com/streamingfast/substreams-solana", branch = "master" } +substreams-solana-program-instructions = "0.1" +bytes = "1.1.0" +prost = "0.11" +num-bigint = "0.4" +bs58 = "0.5.0" +base64 = "0.21.5" +borsh = { version = "0.10.3"} +chrono = { version = "0.4", features = [ "std" ], default-features = false } + +[profile.release] +lto = true +opt-level = 's' +strip = "debuginfo" \ No newline at end of file diff --git a/solana-program-library/solana-compute-budget/Makefile b/solana-program-library/solana-compute-budget/Makefile new file mode 100644 index 0000000..dd8f032 --- /dev/null +++ b/solana-program-library/solana-compute-budget/Makefile @@ -0,0 +1,17 @@ +ENDPOINT ?= mainnet.sol.streamingfast.io:443 + +.PHONY: build +build: + LDFLAGS="-Wl,-no_compact_unwind" cargo build --target wasm32-unknown-unknown --release + +.PHONY: stream +stream: build + substreams run -e $(ENDPOINT) substreams.yaml map_block -s 251293572 -t +1 + +.PHONY: protogen +protogen: + substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google" + +.PHONY: package +package: + substreams pack ./substreams.yaml \ No newline at end of file diff --git a/solana-program-library/solana-compute-budget/proto/main.proto b/solana-program-library/solana-compute-budget/proto/main.proto new file mode 100644 index 0000000..0c97323 --- /dev/null +++ b/solana-program-library/solana-compute-budget/proto/main.proto @@ -0,0 +1,22 @@ +syntax = "proto2"; + +package sf.solana.programs.compute.budget.v1; + +message ComputeBudgetMeta { + required string block_date = 1; + required int64 block_time = 2; + required string tx_id = 3; + required string dapp = 4; + required uint64 block_slot = 5; + required uint32 instruction_index = 7; + required bool is_inner_instruction = 8; + required uint32 inner_instruction_index = 9; + required string instruction_type = 10; + optional uint32 bytes = 11; + optional uint32 units = 12; + optional uint64 micro_lamports = 13; +} + +message Output { + repeated ComputeBudgetMeta data = 1; +} \ No newline at end of file diff --git a/solana-program-library/solana-compute-budget/src/constants.rs b/solana-program-library/solana-compute-budget/src/constants.rs new file mode 100644 index 0000000..4b5a0e0 --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/constants.rs @@ -0,0 +1 @@ +pub const PROGRAM_ADDRESS: &str = "ComputeBudget111111111111111111111111111111"; diff --git a/solana-program-library/solana-compute-budget/src/instruction.rs b/solana-program-library/solana-compute-budget/src/instruction.rs new file mode 100644 index 0000000..9ee1fec --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/instruction.rs @@ -0,0 +1,80 @@ +use borsh::{BorshDeserialize, BorshSerialize}; + +#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Default)] +pub struct RequestHeapFrameLayout { + pub bytes: u32, +} + +#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Default)] +pub struct SetComputeUnitLimitLayout { + pub units: u32, +} + +#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Default)] +pub struct SetComputeUnitPriceLayout { + pub micro_lamports: u64, +} + +#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Default)] +pub struct SetLoadedAccountsDataSizeLimitLayout { + pub bytes: u32, +} + +#[derive(Debug)] +pub struct Instruction { + pub name: String, + pub requestHeapFrameArg: RequestHeapFrameLayout, + pub setComputeUnitLimitArg: SetComputeUnitLimitLayout, + pub setComputeUnitPriceArg: SetComputeUnitPriceLayout, + pub setLoadedAccountsDataSizeLimitArg: SetLoadedAccountsDataSizeLimitLayout, +} + +pub fn parse_instruction(bytes_stream: Vec) -> Instruction { + let mut instruction_name = String::default(); + + let mut requestHeapFrameArg: RequestHeapFrameLayout = RequestHeapFrameLayout::default(); + let mut setComputeUnitLimitArg: SetComputeUnitLimitLayout = + SetComputeUnitLimitLayout::default(); + let mut setComputeUnitPriceArg: SetComputeUnitPriceLayout = + SetComputeUnitPriceLayout::default(); + let mut setLoadedAccountsDataSizeLimitArg: SetLoadedAccountsDataSizeLimitLayout = + SetLoadedAccountsDataSizeLimitLayout::default(); + + let (disc_bytes, rest) = bytes_stream.split_at(1); + let discriminator: u8 = u8::try_from_slice(disc_bytes).unwrap(); + let rest_bytes = &mut rest.clone(); + + match discriminator { + 0 => { + instruction_name = String::from("Unused"); + } + 1 => { + instruction_name = String::from("RequestHeapFrame"); + requestHeapFrameArg = RequestHeapFrameLayout::deserialize(rest_bytes).unwrap(); + } + 2 => { + instruction_name = String::from("SetComputeUnitLimit"); + setComputeUnitLimitArg = SetComputeUnitLimitLayout::deserialize(rest_bytes).unwrap(); + } + 3 => { + instruction_name = String::from("SetComputeUnitPrice"); + setComputeUnitPriceArg = SetComputeUnitPriceLayout::deserialize(rest_bytes).unwrap(); + } + 4 => { + instruction_name = String::from("SetLoadedAccountsDataSizeLimit"); + setLoadedAccountsDataSizeLimitArg = + SetLoadedAccountsDataSizeLimitLayout::deserialize(rest_bytes).unwrap(); + } + _ => {} + } + + let result: Instruction = Instruction { + name: instruction_name, + requestHeapFrameArg: requestHeapFrameArg, + setComputeUnitLimitArg: setComputeUnitLimitArg, + setComputeUnitPriceArg: setComputeUnitPriceArg, + setLoadedAccountsDataSizeLimitArg: setLoadedAccountsDataSizeLimitArg, + }; + + return result; +} diff --git a/solana-program-library/solana-compute-budget/src/lib.rs b/solana-program-library/solana-compute-budget/src/lib.rs new file mode 100644 index 0000000..ad35ba6 --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/lib.rs @@ -0,0 +1,128 @@ +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(non_snake_case)] + +mod constants; +mod instruction; +mod pb; +mod utils; + +use instruction::{parse_instruction, Instruction}; +use pb::sf::solana::programs::compute::budget::v1::{ComputeBudgetMeta, Output}; +use substreams::log; +use substreams_solana::pb::sf::solana::r#type::v1::Block; +use utils::convert_to_date; + +#[substreams::handlers::map] +fn map_block(block: Block) -> Result { + let slot = block.slot; + let parent_slot = block.parent_slot; + let timestamp = block.block_time.as_ref().unwrap().timestamp; + + let mut data: Vec = vec![]; + + for trx in block.transactions_owned() { + let accounts = trx.resolved_accounts_as_strings(); + if let Some(transaction) = trx.transaction { + let meta = trx.meta.unwrap(); + let msg = transaction.message.unwrap(); + + for (idx, inst) in msg.instructions.into_iter().enumerate() { + let program = &accounts[inst.program_id_index as usize]; + + let tx_id: String = bs58::encode(&transaction.signatures[0]).into_string(); + if program == constants::PROGRAM_ADDRESS { + let meta: ComputeBudgetMeta = get_meta( + timestamp, + tx_id.clone(), + parent_slot, + inst.program_id_index, + false, + 0, + inst.data.clone(), + ); + data.push(meta); + } + + meta.inner_instructions + .iter() + .filter(|inner_instruction| inner_instruction.index == idx as u32) + .for_each(|inner_instruction| { + inner_instruction + .instructions + .iter() + .for_each(|inner_inst| { + let program = &accounts[inner_inst.program_id_index as usize]; + if program == constants::PROGRAM_ADDRESS { + let meta: ComputeBudgetMeta = get_meta( + timestamp, + tx_id.clone(), + parent_slot, + inst.program_id_index, + true, + inner_inst.program_id_index, + inner_inst.data.clone(), + ); + data.push(meta); + } + }) + }); + } + } + } + + // TODO: remove + log::info!("{:#?}", slot); + log::info!("{:#?}", data.len()); + + Ok(Output { data }) +} + +fn get_meta( + timestamp: i64, + tx_id: String, + slot: u64, + ix_index: u32, + is_inner_instruction: bool, + inner_ix_index: u32, + instruction_data: Vec, +) -> ComputeBudgetMeta { + let mut meta: ComputeBudgetMeta = ComputeBudgetMeta::default(); + let instruction: Instruction = parse_instruction(instruction_data); + + meta.block_date = convert_to_date(timestamp); + meta.block_time = timestamp; + meta.tx_id = tx_id; + meta.dapp = constants::PROGRAM_ADDRESS.to_string(); + meta.block_slot = slot; + meta.instruction_index = ix_index; + meta.is_inner_instruction = is_inner_instruction.clone(); + meta.inner_instruction_index = inner_ix_index.clone(); + + match instruction.name.as_str() { + "Unused" => { + meta.instruction_type = "Unused".to_string(); + } + "RequestHeapFrame" => { + meta.instruction_type = "RequestHeapFrame".to_string(); + meta.bytes = Some(instruction.requestHeapFrameArg.bytes); + } + "SetComputeUnitLimit" => { + meta.instruction_type = "SetComputeUnitLimit".to_string(); + meta.units = Some(instruction.setComputeUnitLimitArg.units); + } + "SetComputeUnitPrice" => { + meta.instruction_type = "SetComputeUnitPrice".to_string(); + meta.micro_lamports = Some(instruction.setComputeUnitPriceArg.micro_lamports); + } + "SetLoadedAccountsDataSizeLimit" => { + meta.instruction_type = "SetLoadedAccountsDataSizeLimit".to_string(); + meta.bytes = Some(instruction.setLoadedAccountsDataSizeLimitArg.bytes); + } + _ => { + meta.instruction_type = String::from("Unknown Instruction"); + } + } + + return meta; +} diff --git a/solana-program-library/solana-compute-budget/src/pb/mod.rs b/solana-program-library/solana-compute-budget/src/pb/mod.rs new file mode 100644 index 0000000..b64c754 --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/pb/mod.rs @@ -0,0 +1,16 @@ +// @generated +pub mod sf { + pub mod solana { + pub mod programs { + pub mod compute { + pub mod budget { + // @@protoc_insertion_point(attribute:sf.solana.programs.compute.budget.v1) + pub mod v1 { + include!("sf.solana.programs.compute.budget.v1.rs"); + // @@protoc_insertion_point(sf.solana.programs.compute.budget.v1) + } + } + } + } + } +} diff --git a/solana-program-library/solana-compute-budget/src/pb/sf.solana.programs.compute.budget.v1.rs b/solana-program-library/solana-compute-budget/src/pb/sf.solana.programs.compute.budget.v1.rs new file mode 100644 index 0000000..5663bf8 --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/pb/sf.solana.programs.compute.budget.v1.rs @@ -0,0 +1,36 @@ +// @generated +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ComputeBudgetMeta { + #[prost(string, required, tag="1")] + pub block_date: ::prost::alloc::string::String, + #[prost(int64, required, tag="2")] + pub block_time: i64, + #[prost(string, required, tag="3")] + pub tx_id: ::prost::alloc::string::String, + #[prost(string, required, tag="4")] + pub dapp: ::prost::alloc::string::String, + #[prost(uint64, required, tag="5")] + pub block_slot: u64, + #[prost(uint32, required, tag="7")] + pub instruction_index: u32, + #[prost(bool, required, tag="8")] + pub is_inner_instruction: bool, + #[prost(uint32, required, tag="9")] + pub inner_instruction_index: u32, + #[prost(string, required, tag="10")] + pub instruction_type: ::prost::alloc::string::String, + #[prost(uint32, optional, tag="11")] + pub bytes: ::core::option::Option, + #[prost(uint32, optional, tag="12")] + pub units: ::core::option::Option, + #[prost(uint64, optional, tag="13")] + pub micro_lamports: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Output { + #[prost(message, repeated, tag="1")] + pub data: ::prost::alloc::vec::Vec, +} +// @@protoc_insertion_point(module) diff --git a/solana-program-library/solana-compute-budget/src/utils.rs b/solana-program-library/solana-compute-budget/src/utils.rs new file mode 100644 index 0000000..362701b --- /dev/null +++ b/solana-program-library/solana-compute-budget/src/utils.rs @@ -0,0 +1,9 @@ +extern crate chrono; +use chrono::prelude::*; + +pub fn convert_to_date(ts: i64) -> String { + let nt = NaiveDateTime::from_timestamp_opt(ts, 0); + let dt: DateTime = DateTime::from_utc(nt.unwrap(), Utc); + let res = dt.format("%Y-%m-%d"); + return res.to_string(); +} \ No newline at end of file diff --git a/solana-program-library/solana-compute-budget/substreams.yaml b/solana-program-library/solana-compute-budget/substreams.yaml new file mode 100644 index 0000000..468bdd9 --- /dev/null +++ b/solana-program-library/solana-compute-budget/substreams.yaml @@ -0,0 +1,24 @@ +specVersion: v0.1.0 +package: + name: 'tl_solana_programs_compute_budget' + version: v1.0.0 + +protobuf: + files: + - main.proto + importPaths: + - ./proto + + +binaries: + default: + type: wasm/rust-v1 + file: target/wasm32-unknown-unknown/release/substreams.wasm + +modules: + - name: map_block + kind: map + inputs: + - source: sf.solana.type.v1.Block + output: + type: proto:sf.solana.programs.compute.budget.v1.Output \ No newline at end of file From 4b4195fac9f22dfcf26b575409dbc13a42a4a161 Mon Sep 17 00:00:00 2001 From: dkdocs Date: Thu, 11 Apr 2024 02:24:45 +0530 Subject: [PATCH 2/2] fixes invalid length of input error --- solana-program-library/solana-compute-budget/Makefile | 7 +++++-- .../solana-compute-budget/src/instruction.rs | 7 ++++++- .../solana-compute-budget/substreams.yaml | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/solana-program-library/solana-compute-budget/Makefile b/solana-program-library/solana-compute-budget/Makefile index dd8f032..ae190b9 100644 --- a/solana-program-library/solana-compute-budget/Makefile +++ b/solana-program-library/solana-compute-budget/Makefile @@ -6,7 +6,7 @@ build: .PHONY: stream stream: build - substreams run -e $(ENDPOINT) substreams.yaml map_block -s 251293572 -t +1 + substreams run -e $(ENDPOINT) substreams.yaml map_block -s 252842623 -t +1 .PHONY: protogen protogen: @@ -14,4 +14,7 @@ protogen: .PHONY: package package: - substreams pack ./substreams.yaml \ No newline at end of file + substreams pack ./substreams.yaml + + +# 2024-04-10T20:36:00.696Z ERRO (cli) application shutdown unexpectedly, quitting: stream invalid: rpc error: code = InvalidArgument desc = rpc error: code = InvalidArgument desc = step new irr: handler step new: execute modules: applying executor results "map_block": execute: maps wasm call: block 252842623: module "map_block": general wasm execution panicked: wasm execution failed deterministically: panic in the wasm: "called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidInput, error: \"Unexpected length of input\" }" at src/instruction.rs:61:89 \ No newline at end of file diff --git a/solana-program-library/solana-compute-budget/src/instruction.rs b/solana-program-library/solana-compute-budget/src/instruction.rs index 9ee1fec..4aa8d37 100644 --- a/solana-program-library/solana-compute-budget/src/instruction.rs +++ b/solana-program-library/solana-compute-budget/src/instruction.rs @@ -1,4 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; +use substreams::log; #[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Default)] pub struct RequestHeapFrameLayout { @@ -58,7 +59,11 @@ pub fn parse_instruction(bytes_stream: Vec) -> Instruction { } 3 => { instruction_name = String::from("SetComputeUnitPrice"); - setComputeUnitPriceArg = SetComputeUnitPriceLayout::deserialize(rest_bytes).unwrap(); + log::info!("{:?}", rest_bytes); + if rest_bytes.len() > 7 { + setComputeUnitPriceArg = SetComputeUnitPriceLayout::deserialize(rest_bytes).unwrap(); + } + } 4 => { instruction_name = String::from("SetLoadedAccountsDataSizeLimit"); diff --git a/solana-program-library/solana-compute-budget/substreams.yaml b/solana-program-library/solana-compute-budget/substreams.yaml index 468bdd9..519faad 100644 --- a/solana-program-library/solana-compute-budget/substreams.yaml +++ b/solana-program-library/solana-compute-budget/substreams.yaml @@ -1,7 +1,7 @@ specVersion: v0.1.0 package: name: 'tl_solana_programs_compute_budget' - version: v1.0.0 + version: v1.0.1 protobuf: files: