diff --git a/Cargo.lock b/Cargo.lock index 5c7c99a783..41f3d14257 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -978,7 +978,7 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecode-interpreter-crypto" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "curve25519-dalek-fiat", @@ -2117,6 +2117,7 @@ dependencies = [ "anyhow", "atomic-counter", "bcs-ext", + "chrono", "clap 3.2.23", "csv", "futures 0.3.26", @@ -2129,6 +2130,7 @@ dependencies = [ "rayon", "serde 1.0.152", "serde_json", + "starcoin-abi-decoder", "starcoin-account-api", "starcoin-accumulator", "starcoin-chain", @@ -5016,7 +5018,7 @@ checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" [[package]] name = "move-abigen" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5033,7 +5035,7 @@ dependencies = [ [[package]] name = "move-binary-format" version = "0.0.3" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "arbitrary", @@ -5049,12 +5051,12 @@ dependencies = [ [[package]] name = "move-borrow-graph" version = "0.0.1" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" [[package]] name = "move-bytecode-source-map" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5069,7 +5071,7 @@ dependencies = [ [[package]] name = "move-bytecode-utils" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-binary-format", @@ -5081,7 +5083,7 @@ dependencies = [ [[package]] name = "move-bytecode-verifier" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "fail", @@ -5094,7 +5096,7 @@ dependencies = [ [[package]] name = "move-bytecode-viewer" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "clap 3.2.23", @@ -5111,7 +5113,7 @@ dependencies = [ [[package]] name = "move-cli" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5157,7 +5159,7 @@ dependencies = [ [[package]] name = "move-command-line-common" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "difference", @@ -5174,7 +5176,7 @@ dependencies = [ [[package]] name = "move-compiler" version = "0.0.1" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5203,7 +5205,7 @@ dependencies = [ [[package]] name = "move-core-types" version = "0.0.4" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "arbitrary", @@ -5227,7 +5229,7 @@ dependencies = [ [[package]] name = "move-coverage" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5264,7 +5266,7 @@ dependencies = [ [[package]] name = "move-disassembler" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "clap 3.2.23", @@ -5282,7 +5284,7 @@ dependencies = [ [[package]] name = "move-docgen" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "codespan 0.11.1", @@ -5300,7 +5302,7 @@ dependencies = [ [[package]] name = "move-errmapgen" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5314,7 +5316,7 @@ dependencies = [ [[package]] name = "move-ir-compiler" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5333,7 +5335,7 @@ dependencies = [ [[package]] name = "move-ir-to-bytecode" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "codespan-reporting", @@ -5352,7 +5354,7 @@ dependencies = [ [[package]] name = "move-ir-to-bytecode-syntax" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "hex", @@ -5365,7 +5367,7 @@ dependencies = [ [[package]] name = "move-ir-types" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "hex", @@ -5379,7 +5381,7 @@ dependencies = [ [[package]] name = "move-model" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "codespan 0.11.1", @@ -5405,7 +5407,7 @@ dependencies = [ [[package]] name = "move-package" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5489,7 +5491,7 @@ dependencies = [ [[package]] name = "move-prover" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "async-trait", @@ -5526,7 +5528,7 @@ dependencies = [ [[package]] name = "move-prover-boogie-backend" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "async-trait", @@ -5554,7 +5556,7 @@ dependencies = [ [[package]] name = "move-prover-test-utils" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-command-line-common", @@ -5565,7 +5567,7 @@ dependencies = [ [[package]] name = "move-read-write-set-types" version = "0.0.3" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-binary-format", @@ -5576,7 +5578,7 @@ dependencies = [ [[package]] name = "move-resource-viewer" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5591,7 +5593,7 @@ dependencies = [ [[package]] name = "move-stackless-bytecode" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "codespan 0.11.1", "codespan-reporting", @@ -5618,7 +5620,7 @@ dependencies = [ [[package]] name = "move-stackless-bytecode-interpreter" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bytecode-interpreter-crypto", @@ -5636,7 +5638,7 @@ dependencies = [ [[package]] name = "move-stdlib" version = "0.1.1" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "hex", @@ -5659,7 +5661,7 @@ dependencies = [ [[package]] name = "move-symbol-pool" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "once_cell", "serde 1.0.152", @@ -5668,7 +5670,7 @@ dependencies = [ [[package]] name = "move-table-extension" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "bcs", @@ -5685,7 +5687,7 @@ dependencies = [ [[package]] name = "move-transactional-test-runner" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "clap 3.2.23", @@ -5720,7 +5722,7 @@ dependencies = [ [[package]] name = "move-unit-test" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "better_any", @@ -5751,7 +5753,7 @@ dependencies = [ [[package]] name = "move-vm-runtime" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "better_any", "fail", @@ -5768,7 +5770,7 @@ dependencies = [ [[package]] name = "move-vm-test-utils" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-binary-format", @@ -5782,7 +5784,7 @@ dependencies = [ [[package]] name = "move-vm-types" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "bcs", "move-binary-format", @@ -7812,7 +7814,7 @@ dependencies = [ [[package]] name = "read-write-set" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-binary-format", @@ -7827,7 +7829,7 @@ dependencies = [ [[package]] name = "read-write-set-dynamic" version = "0.1.0" -source = "git+https://github.com/starcoinorg/move?rev=127584f4cb1e2b4cd650f1e6c317250f5fccca49#127584f4cb1e2b4cd650f1e6c317250f5fccca49" +source = "git+https://github.com/starcoinorg/move?rev=13bd7a8a279f1aecb4dc1e9c94e42da512320249#13bd7a8a279f1aecb4dc1e9c94e42da512320249" dependencies = [ "anyhow", "move-binary-format", diff --git a/Cargo.toml b/Cargo.toml index 7d299ec4b8..74c80bea16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -333,31 +333,31 @@ log4rs = { version = "1.2.0", features = ["background_rotation", "gzip"] } lru = "0.7.8" merkletree = { version = "0.22.1" } mirai-annotations = "1.10.1" -move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-bytecode-source-map = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-cli = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-compiler = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-core-types = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-coverage = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-disassembler = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-docgen = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-ir-compiler = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-ir-types = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-model = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-package = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-prover = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-prover-test-utils = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-resource-viewer = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-stdlib = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-transactional-test-runner = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49", features = ["table-extension"] } -move-vm-runtime = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-vm-types = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-table-extension = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49" } -move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49", features = ["table-extension"] } +move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-bytecode-source-map = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-cli = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-compiler = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-core-types = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-coverage = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-disassembler = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-docgen = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-ir-compiler = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-ir-types = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-model = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-package = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-prover = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-prover-test-utils = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-resource-viewer = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-stdlib = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-transactional-test-runner = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249", features = ["table-extension"] } +move-vm-runtime = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-vm-types = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-table-extension = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249" } +move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249", features = ["table-extension"] } names = { version = "0.14.0", default-features = false } network-api = { path = "network/api", package = "network-api" } @@ -522,7 +522,7 @@ unsigned-varint = { version = "0.6.0", features = [ "futures", "asynchronous_codec", ] } -vm = { package = "move-binary-format", git = "https://github.com/starcoinorg/move", rev = "127584f4cb1e2b4cd650f1e6c317250f5fccca49", features = [ +vm = { package = "move-binary-format", git = "https://github.com/starcoinorg/move", rev = "13bd7a8a279f1aecb4dc1e9c94e42da512320249", features = [ "fuzzing", ] } vm-status-translator = { path = "vm/vm-status-translator" } diff --git a/cmd/db-exporter/Cargo.toml b/cmd/db-exporter/Cargo.toml index ee4b2dfb82..3b676ae918 100644 --- a/cmd/db-exporter/Cargo.toml +++ b/cmd/db-exporter/Cargo.toml @@ -32,9 +32,11 @@ starcoin-transaction-builder = { workspace = true } starcoin-types = { workspace = true } starcoin-vm-types = { workspace = true } starcoin-vm-runtime = { workspace = true } +starcoin-abi-decoder = { workspace = true } futures = { workspace = true } rayon = { workspace = true } num_cpus = { workspace = true } +chrono = { workspace = true } [package] authors = { workspace = true } diff --git a/cmd/db-exporter/src/cmd_batch_execution.rs b/cmd/db-exporter/src/cmd_batch_execution.rs deleted file mode 100644 index 7bb4c27a67..0000000000 --- a/cmd/db-exporter/src/cmd_batch_execution.rs +++ /dev/null @@ -1,119 +0,0 @@ -use anyhow::bail; -use indicatif::{ProgressBar, ProgressStyle}; -use rayon::prelude::*; -use std::{ - fs::File, - io::{BufRead, BufReader}, - path::PathBuf, - time::SystemTime, -}; - -pub struct CmdBatchExecution { - name: String, - file_path: PathBuf, - batch_size: usize, -} - -struct ExecutionResult { - succeed: usize, - failed: usize, -} - -impl ExecutionResult { - pub fn new(succeed: usize, failed: usize) -> ExecutionResult { - ExecutionResult { succeed, failed } - } -} - -impl CmdBatchExecution { - pub fn new(name: String, file_path: PathBuf, batch_size: usize) -> CmdBatchExecution { - Self { - file_path, - name, - batch_size, - } - } - - pub fn progress(self) -> anyhow::Result<()> - where - BodyT: BatchCmdExec - + Send - + Sync - + Clone - + serde::Serialize - + for<'a> serde::Deserialize<'a> - + 'static, - { - println!("Start progress task, batch_size: {:?}", self.batch_size); - - let mut start_time = SystemTime::now(); - let file_name = self.file_path.display().to_string(); - let reader = BufReader::new(File::open(file_name)?); - println!( - "Reading file process expire mini seconds time: {:?}", - SystemTime::now().duration_since(start_time)?.as_micros() - ); - - start_time = SystemTime::now(); - let lines = reader.lines().collect::, _>>()?; - - let all_items = lines - .par_iter() - .map(|line| Ok(serde_json::from_str::(line.as_str()))?) - .collect::, _>>()?; - - let progress_bar = ProgressBar::new(all_items.len() as u64).with_style( - ProgressStyle::default_bar() - .template("[{elapsed_precise}] {bar:100.cyan/blue} {percent}% {msg}"), - ); - - println!( - "Reading lines from file expire time: {:?}", - SystemTime::now().duration_since(start_time)?.as_secs() - ); - - // It is necessary to divide all rows into subsets - // when reading them, - // so that they can be divided into several threads for the following operations - start_time = SystemTime::now(); - - let excution_result = all_items - .into_par_iter() - .chunks(self.batch_size) - .map(|item_vec| { - item_vec - .into_iter() - .map(|item| { - let (succeed, failed) = item.execute(); - progress_bar.inc(1); - ExecutionResult::new(succeed, failed.len()) - }) - .collect::>() - }) - .collect::>>(); - - let result = excution_result.into_iter().flatten().fold( - ExecutionResult { - succeed: 0, - failed: 0, - }, - |acc, result| ExecutionResult { - succeed: acc.succeed + result.succeed, - failed: acc.failed + result.failed, - }, - ); - - progress_bar.finish(); - - println!("verify {:?}, use time: {:?}, success modules: {}, error modules: {}, total modules: {}", - self.name, SystemTime::now().duration_since(start_time)?.as_secs(), result.succeed, result.failed, result.succeed + result.failed); - if result.failed > 0 { - bail!("verify block modules error"); - } - Ok(()) - } -} - -pub trait BatchCmdExec { - fn execute(&self) -> (usize, Vec); -} diff --git a/cmd/db-exporter/src/command_progress.rs b/cmd/db-exporter/src/command_progress.rs new file mode 100644 index 0000000000..f5487ea513 --- /dev/null +++ b/cmd/db-exporter/src/command_progress.rs @@ -0,0 +1,409 @@ +use anyhow::{bail, Result}; +use indicatif::{ProgressBar, ProgressStyle}; +use rayon::prelude::*; +use starcoin_chain::{BlockChain, ChainReader}; +use starcoin_config::ChainNetwork; +use starcoin_crypto::HashValue; +use starcoin_genesis::Genesis; +use starcoin_storage::cache_storage::CacheStorage; +use starcoin_storage::db_storage::DBStorage; +use starcoin_storage::storage::StorageInstance; +use starcoin_storage::{Storage, StorageVersion}; +use starcoin_types::block::{Block, BlockNumber}; +use starcoin_vm_types::language_storage::TypeTag; +use starcoin_vm_types::vm_status::KeptVMStatus; +use std::io::{Seek, SeekFrom}; +use std::sync::Arc; +use std::{ + fs::File, + io::{BufRead, BufReader}, + path::PathBuf, + time::SystemTime, +}; + +struct CommandResult { + succeed: usize, + failed: usize, +} + +impl CommandResult { + pub fn new(succeed: usize, failed: usize) -> CommandResult { + CommandResult { succeed, failed } + } +} + +pub struct ParallelCommandFilter { + signer: Option, + func_name: Option, + // function name for filter, none for all + ty_args: Option>, + // template parameter for filter, none for all + args: Option>, // arguments type for filter, none for all +} + +impl ParallelCommandFilter { + pub fn new( + signer: &Option, + func_name: &Option, + ty_args: &Option>, + args: &Option>, + ) -> Option { + if signer.is_some() || func_name.is_some() || ty_args.is_some() || args.is_some() { + Some(ParallelCommandFilter { + signer: signer.clone(), + func_name: func_name.clone(), + ty_args: ty_args.clone(), + args: args.clone(), + }) + } else { + None + } + } + + pub fn match_signer(&self, signer: &str) -> bool { + if self.signer.is_none() { + return true; + } + self.signer.clone().unwrap() == signer + } + + pub fn match_func_name(&self, func_name: &str) -> bool { + if self.func_name.is_none() { + return true; + } + self.func_name.clone().unwrap() == func_name + } + + pub fn match_ty_args(&self, _ty_args: &[TypeTag]) -> bool { + if self.ty_args.is_some() { + print!("match_ty_args | {:?}", self.ty_args); + // TODO(Bob): To Compare + } + true + } + + pub fn match_args(&self, _args: &[Vec]) -> bool { + if self.args.is_some() { + print!("match_args | {:?}", self.args); + // TODO(Bob): To Compare + } + true + } +} + +pub struct ParallelCommandReadBodyFromExportLine { + file: File, + line_count: u64, +} + +impl ParallelCommandReadBodyFromExportLine { + fn count_lines(reader: &mut BufReader) -> Result { + let line_count = reader.lines().count(); + reader.seek(SeekFrom::Start(0))?; + Ok(line_count as u64) + } + + pub fn new(input_path: PathBuf) -> Result { + let file = File::open(input_path.display().to_string())?; + let line_count = ParallelCommandReadBodyFromExportLine::count_lines(&mut BufReader::new( + file.try_clone()?, + ))?; + Ok(Self { file, line_count }) + } +} + +impl ParallelCommandBlockReader for ParallelCommandReadBodyFromExportLine { + fn get_progress_interval(&self) -> u64 { + self.line_count + } + + fn read(&self, load_bar: &ProgressBar) -> Result> { + let reader = BufReader::new(self.file.try_clone()?); + let lines = reader.lines().collect::, _>>()?; + Ok(lines + .par_iter() + .map(|line| { + let ret = serde_json::from_str::(line.as_str()); + load_bar.inc(1); + Ok(ret)? + }) + .collect::, _>>()?) + } + + fn query_txn_exec_state(&self, _txn_hash: HashValue) -> String { + "OK".to_string() + } +} + +fn start_end_check(start: u64, end: u64, cur_num: u64) -> (u64, u64) { + if start == 0 && end == 0 { + (0, cur_num) + } else { + assert!(start < end, "End must bigger than Start"); + assert!(end <= cur_num, "End number should less than Head num"); + (start, end) + } +} + +#[test] +fn test_start_end_check() { + let (start, end) = start_end_check(0, 100, 100); + assert_eq!(start, 0); + assert_eq!(end, 100); + + let (start, end) = start_end_check(0, 0, 100); + assert_eq!(start, 0); + assert_eq!(end, 100); +} + +#[test] +#[should_panic = "End must bigger than Start"] +fn test_start_end_check_panic_invalid() { + start_end_check(100, 1, 100); +} + +#[test] +#[should_panic = "End must bigger than Start"] +fn test_start_end_check_panic_invalid2() { + start_end_check(100, 100, 100); +} + +#[test] +#[should_panic = "End number should less than Head num"] +fn test_start_end_check_panic_overflow() { + start_end_check(100, 500, 100); +} + +pub struct ParallelCommandReadBlockFromDB { + start_num: u64, + end_num: u64, + chain: Arc, + skip_empty_block: bool, +} + +impl ParallelCommandReadBlockFromDB { + pub fn new( + input_path: PathBuf, + net: ChainNetwork, + start: u64, + end: u64, + skip_empty_block: bool, + ) -> Result<(Self, Arc)> { + let storage = Self::init_db_obj(input_path.clone()).expect("Failed to initialize db"); + let (chain_info, _) = + Genesis::init_and_check_storage(&net, storage.clone(), input_path.as_ref()) + .expect("Failed init_and_check_storage"); + let chain = BlockChain::new( + net.time_service(), + chain_info.head().id(), + storage.clone(), + None, + ) + .expect("Failed to initialize block chain"); + + let (start_num, end_num) = start_end_check(start, end, chain.status().head().number()); + Ok(( + Self { + start_num, + end_num, + chain: Arc::new(chain), + skip_empty_block, + }, + storage, + )) + } + fn init_db_obj(db_path: PathBuf) -> Result> { + let db_storage = DBStorage::open_with_cfs( + db_path.join("starcoindb/db/starcoindb"), + StorageVersion::current_version() + .get_column_family_names() + .to_vec(), + true, + Default::default(), + None, + )?; + Ok(Arc::new(Storage::new( + StorageInstance::new_cache_and_db_instance(CacheStorage::new(None), db_storage), + )?)) + } +} + +impl ParallelCommandBlockReader for ParallelCommandReadBlockFromDB { + fn get_progress_interval(&self) -> u64 { + self.end_num - self.start_num + } + + fn read(&self, load_bar: &ProgressBar) -> Result> { + println!( + "ParallelCommandBlockReader::read | read range: {}, {}, skip empty block: {}", + self.start_num, self.end_num, self.skip_empty_block + ); + + Ok((self.start_num..=self.end_num) + .collect::>() + .par_iter() + .filter_map(|num| { + load_bar.inc(1); + if self.skip_empty_block { + self.chain + .get_block_by_number(*num) + .ok() + .flatten() + .filter(|block| !block.transactions().is_empty()) + } else { + self.chain.get_block_by_number(*num).ok().flatten() + } + }) + .collect::>()) + } + + fn query_txn_exec_state(&self, txn_hash: HashValue) -> String { + let txn = self + .chain + .get_transaction_info(txn_hash) + .expect("Query failed!"); + match txn { + Some(info) => match info.status { + KeptVMStatus::Executed => "OK".to_string(), + _ => "FALIED".to_string(), + }, + None => "CANT_FOUND_TXN".to_string(), + } + } +} + +pub struct ParallelCommandProgress { + name: String, + parallel_level: usize, + block_reader: Arc, + filter: Option, + obs: Option>, +} + +impl ParallelCommandProgress { + pub fn new( + name: String, + parallel_level: usize, + reader: Arc, + filter: Option, + obs: Option>, + ) -> ParallelCommandProgress { + Self { + name, + block_reader: reader.clone(), + parallel_level, + filter, + obs, + } + } + + pub fn progress(self, command: &CommandT) -> Result<()> + where + Block: ParallelCommand, + { + println!("Start progress task, batch_size: {:?}", self.parallel_level); + + let mut start_time = SystemTime::now(); + //let file_name = self.file_path.display().to_string(); + //let reader = BufReader::new(File::open(file_name)?); + println!( + "Reading file process expire mini seconds time: {:?}", + SystemTime::now().duration_since(start_time)?.as_micros() + ); + + start_time = SystemTime::now(); + + if let Some(observer) = &self.obs { + observer.before_progress()?; + } + + let load_interval_count = self.block_reader.get_progress_interval(); + let load_bar = ProgressBar::new(load_interval_count).with_style( + ProgressStyle::default_bar() + .template("loading [{elapsed_precise}] {bar:100.cyan/blue} {percent}% {msg}"), + ); + + let mut all_items = self.block_reader.read(&load_bar)?; + load_bar.finish(); + + let all_item_size = all_items.len(); + all_items.retain(|b| (*b).matched(&self.filter)); + let filtered_item_size = all_items.len(); + + println!( + "Reading lines from file expire time: {:?}, get interval: {:?}, actual return item size: {:?}, filtered item size:{:?}", + SystemTime::now().duration_since(start_time)?.as_secs(), + load_interval_count, + all_item_size, + filtered_item_size, + ); + + // It is necessary to divide all rows into subsets + // when reading them, + // so that they can be divided into several threads for the following operations + start_time = SystemTime::now(); + + let progress_bar = ProgressBar::new(all_items.len() as u64).with_style( + ProgressStyle::default_bar() + .template("processing [{elapsed_precise}] {bar:100.cyan/blue} {percent}% {msg}"), + ); + let excution_result = all_items + .into_par_iter() + .chunks(self.parallel_level) + .map(|item_vec| { + item_vec + .into_iter() + .map(|item| { + let (succeed, failed) = item.execute(self.block_reader.as_ref(), command); + progress_bar.inc(1); + CommandResult::new(succeed, failed.len()) + }) + .collect::>() + }) + .collect::>>(); + + let result = excution_result.into_iter().flatten().fold( + CommandResult { + succeed: 0, + failed: 0, + }, + |acc, result| CommandResult { + succeed: acc.succeed + result.succeed, + failed: acc.failed + result.failed, + }, + ); + progress_bar.finish(); + + println!("Running ParallelCommand {:?}, use time: {:?}, success modules: {}, error modules: {}, total modules: {}", + self.name, SystemTime::now().duration_since(start_time)?.as_secs(), result.succeed, result.failed, result.succeed + result.failed); + if result.failed > 0 { + bail!("verify block modules error"); + } + if let Some(observer) = &self.obs { + observer.after_progress()?; + } + + Ok(()) + } +} + +pub trait ParallelCommand { + fn execute( + &self, + block_reader: &dyn ParallelCommandBlockReader, + cmd: &CommandT, + ) -> (usize, Vec); + + fn matched(&self, filter: &Option) -> bool; +} + +pub trait ParallelCommandObserver { + fn before_progress(&self) -> Result<()>; + fn after_progress(&self) -> Result<()>; +} + +pub trait ParallelCommandBlockReader: Sync + Send { + fn get_progress_interval(&self) -> u64; + fn read(&self, load_bar: &ProgressBar) -> Result>; + fn query_txn_exec_state(&self, txn_hash: HashValue) -> String; +} diff --git a/cmd/db-exporter/src/commands/decode_payload.rs b/cmd/db-exporter/src/commands/decode_payload.rs new file mode 100644 index 0000000000..cb0ea7c67e --- /dev/null +++ b/cmd/db-exporter/src/commands/decode_payload.rs @@ -0,0 +1,338 @@ +// Copyright (c) The Starcoin Core Contributors +// SPDX-License-Identifier: Apache-2.0 + +use crate::command_progress::{ + ParallelCommand, ParallelCommandBlockReader, ParallelCommandFilter, ParallelCommandObserver, + ParallelCommandProgress, ParallelCommandReadBlockFromDB, +}; +use anyhow::Result; +use chrono::{DateTime, Utc}; +use clap::Parser; +use csv::{Writer, WriterBuilder}; +use serde::Serialize; +use starcoin_abi_decoder; +use starcoin_abi_decoder::DecodedTransactionPayload; +use starcoin_config::{BuiltinNetworkID, ChainNetwork}; +use starcoin_crypto::{hash::CryptoHash, HashValue}; +use starcoin_statedb::ChainStateDB; +use starcoin_storage::Storage; +use starcoin_types::{block::Block, block::BlockNumber, transaction::TransactionPayload}; +use starcoin_vm_types::errors::VMError; +use std::fs::File; +use std::sync::{Arc, Mutex}; +use std::time::{Duration, UNIX_EPOCH}; +use std::{fmt::Debug, path::PathBuf}; + +const DECODE_PAYLOAD_COMMAND_NAME: &str = "decode_payload_command"; + +#[derive(Debug, Parser)] +#[clap( + name = "decode-payload", + about = "Decode payload for given parameter and function name" +)] +pub struct DecodePayloadCommandOptions { + #[clap(long, short = 'n')] + /// Chain Network, like main, proxima + pub net: BuiltinNetworkID, + + #[clap(long, short = 'o', parse(from_os_str))] + /// output dir, like ~/, output filename like ~/block_start_end.csv + pub output: PathBuf, + + #[clap(long, short = 'i', parse(from_os_str))] + /// starcoin node db path. like ~/.starcoin/main + pub db_path: PathBuf, + + #[clap(long, short = 's')] + pub start: Option, + + #[clap(long, short = 'e')] + pub end: Option, + + #[clap(long, short = 'c')] + /// Signer filter + pub signer: Option, + + #[clap(long, short = 'f')] + /// function name for filter + pub func_name: Option, + + #[clap(long = "arg", multiple_values = true, number_of_values = 1)] + /// List of arguments for filter + pub args: Option>, + + #[clap(long, short = 't', multiple_values = true, number_of_values = 1)] + /// List of template arguments for filter + pub ty_args: Option>, +} + +#[derive(Debug)] +pub struct DecodePayloadCommandError { + pub block_number: u64, + pub txn_hash: HashValue, + pub error: VMError, +} + +// impl DecodePayloadCommandError { +// fn new_from_vm_error(error: VMError, block_number: u64, txn_hash: &HashValue) -> Self { +// DecodePayloadCommandError { +// block_number, +// txn_hash: txn_hash.clone(), +// error, +// } +// } +// +// fn new_from_partial_vm_error( +// error: PartialVMError, +// block_number: u64, +// txn_hash: &HashValue, +// ) -> Self { +// DecodePayloadCommandError { +// block_number, +// txn_hash: txn_hash.clone(), +// error: error.finish(Location::Undefined), +// } +// } +// } + +#[derive(Serialize)] +pub struct CSVHeaders { + block_num: String, + txn_hash: String, + signer: String, + txn_type: String, + func_name: String, + ty_args: String, + args: String, + execute_result: String, + timestamp: u64, + date_time: String, +} + +pub struct CommandDecodePayload { + writer_mutex: Mutex>, + storage: Arc, +} + +impl ParallelCommandObserver for CommandDecodePayload { + fn before_progress(&self) -> Result<()> { + Ok(()) + } + + fn after_progress(&self) -> Result<()> { + let mut writer = self.writer_mutex.lock().unwrap(); + writer.flush()?; + Ok(()) + } +} + +fn timestamp_to_datetime(timestamp: u64) -> String { + // Creates a new SystemTime from the specified number of whole seconds + let d = UNIX_EPOCH + Duration::from_secs(timestamp); + // Create DateTime from SystemTime + let datetime = DateTime::::from(d); + // Formats the combined date and time with the specified format string. + datetime.format("%Y-%m-%d %H:%M:%S.%f").to_string() +} + +impl ParallelCommand for Block { + fn execute( + &self, + block_reader: &dyn ParallelCommandBlockReader, + command: &CommandDecodePayload, + ) -> (usize, Vec) { + // let errors = vec![]; + // let mut success_module_size = 0; + + let timestamp = self.header.timestamp() / 1000; + let formatted_date = timestamp_to_datetime(timestamp); + + let root = self.header.state_root(); + let statedb = ChainStateDB::new(command.storage.clone(), Some(root)); + let block_num = self.header.number().to_string(); + + for txn in self.transactions() { + let signer = txn.sender().to_string(); + let decoded_txn_payload = + starcoin_abi_decoder::decode_txn_payload(&statedb, txn.payload()) + .expect("Decode transaction payload failed!"); + + let execute_result = block_reader.query_txn_exec_state(txn.hash()); + + let mut writer = command.writer_mutex.lock().unwrap(); + match decoded_txn_payload { + DecodedTransactionPayload::ScriptFunction(payload) => writer + .serialize(CSVHeaders { + block_num: block_num.clone(), + txn_hash: txn.hash().to_string(), + txn_type: String::from("ScriptFunction"), + signer, + func_name: format!("{}::{}", payload.module, payload.function), + ty_args: payload + .ty_args + .iter() + .map(|a| a.to_string().trim_matches('"').to_string()) + .collect::>() + .join("|"), + args: payload + .args + .iter() + .map(|a| a.0.to_string().trim_matches('"').to_string()) + .collect::>() + .join("|"), + timestamp, + execute_result, + date_time: formatted_date.clone(), + }) + .expect("Write into CSV failed!"), + DecodedTransactionPayload::Script(script) => writer + .serialize(CSVHeaders { + block_num: block_num.clone(), + txn_hash: txn.hash().to_string(), + txn_type: String::from("Script"), + signer, + func_name: String::from(""), + ty_args: script + .ty_args + .iter() + .map(|a| a.to_string()) + .collect::>() + .join("|"), + args: script + .args + .iter() + .map(|a| a.0.to_string().trim_matches('"').to_string()) + .collect::>() + .join("|"), + timestamp, + execute_result, + date_time: formatted_date.clone(), + }) + .expect("Write into CSV failed!"), + DecodedTransactionPayload::Package(_) => writer + .serialize(CSVHeaders { + block_num: block_num.clone(), + txn_hash: txn.hash().to_string(), + txn_type: String::from("Package"), + signer, + func_name: "".to_string(), + ty_args: "".to_string(), + args: "".to_string(), + timestamp, + execute_result, + date_time: formatted_date.clone(), + }) + .expect("Write into CSV failed!"), + } + } + //(success_module_size, errors) + (0, vec![]) + } + + /// + /// Check whether the conditions are met from the list of all transactions in a block, + /// and return false if any condition is met. + /// + fn matched(&self, filters: &Option) -> bool { + if self.transactions().is_empty() { + return true; + }; + + match filters { + Some(filter) => self.transactions().iter().any(|txn| match txn.payload() { + TransactionPayload::ScriptFunction(payload) => { + filter.match_signer(&txn.sender().to_string()) + && filter.match_func_name(payload.function().as_str()) + && filter.match_ty_args(payload.ty_args()) + && filter.match_args(payload.args()) + } + TransactionPayload::Script(_) | TransactionPayload::Package(_) => { + filter.match_signer(&txn.sender().to_string()) + } + }), + None => true, + } + } +} + +pub fn do_decode_payload_command(option: &DecodePayloadCommandOptions) -> Result<()> { + do_decode_payload( + option.net, + option.db_path.clone(), + option.output.clone(), + option.start, + option.end, + ParallelCommandFilter::new( + &option.signer, + &option.func_name, + &option.ty_args, + &option.args, + ), + ) +} + +pub fn do_decode_payload( + net: BuiltinNetworkID, + input_path: PathBuf, + out_path: PathBuf, + start_height: Option, + end_height: Option, + filter: Option, +) -> Result<()> { + let file = WriterBuilder::new().from_path(out_path)?; + let writer_mutex = Mutex::new(file); + + let (dbreader, storage) = ParallelCommandReadBlockFromDB::new( + input_path, + ChainNetwork::from(net), + start_height.unwrap_or(0), + end_height.unwrap_or(0), + true, + )?; + let command = Arc::new(CommandDecodePayload { + writer_mutex, + storage, + }); + + ParallelCommandProgress::new( + String::from(DECODE_PAYLOAD_COMMAND_NAME), + num_cpus::get(), + Arc::new(dbreader), + filter, + Some(command.clone() as Arc), + ) + .progress::(&command) +} + +#[test] +pub fn test_decode_payload() -> Result<()> { + let input = PathBuf::from("/Users/bobong/.starcoin/main"); + let output = PathBuf::from("/Users/bobong/Downloads/unit-output.csv"); + + // do_decode_payload(Main, input.clone(), output.clone(), None, None, None)?; + + // do_decode_payload( + // Main, + // input.clone(), + // output.clone(), + // Some(0), + // Some(100), + // None, + // )?; + // + do_decode_payload( + BuiltinNetworkID::Main, + input, + output, + None, + None, + ParallelCommandFilter::new( + &Some("0x45b467f509bb82f8bcbd7b01170a22d0".to_string()), + &None, + &None, + &None, + ), + )?; + + Ok(()) +} diff --git a/cmd/db-exporter/src/commands/mod.rs b/cmd/db-exporter/src/commands/mod.rs new file mode 100644 index 0000000000..411723f565 --- /dev/null +++ b/cmd/db-exporter/src/commands/mod.rs @@ -0,0 +1,3 @@ +pub mod decode_payload; +pub mod verify_header; +pub mod verify_module; diff --git a/cmd/db-exporter/src/verify_header.rs b/cmd/db-exporter/src/commands/verify_header.rs similarity index 60% rename from cmd/db-exporter/src/verify_header.rs rename to cmd/db-exporter/src/commands/verify_header.rs index b49baffcdc..c781eb7c61 100644 --- a/cmd/db-exporter/src/verify_header.rs +++ b/cmd/db-exporter/src/commands/verify_header.rs @@ -4,8 +4,12 @@ use clap::Parser; use starcoin_consensus::{Consensus, G_CRYPTONIGHT}; use std::path::PathBuf; +use std::sync::Arc; -use crate::cmd_batch_execution::{BatchCmdExec, CmdBatchExecution}; +use crate::command_progress::{ + ParallelCommand, ParallelCommandBlockReader, ParallelCommandFilter, ParallelCommandProgress, + ParallelCommandReadBodyFromExportLine, +}; use starcoin_types::block::Block; #[derive(Debug, Parser)] @@ -28,12 +32,22 @@ pub struct VerifyHeaderError { pub struct VerifyHeaderCmdType; pub fn verify_header_via_export_file(path: PathBuf, batch_size: usize) -> anyhow::Result<()> { - let batch_cmd = CmdBatchExecution::new(String::from("verify_block_header"), path, batch_size); - batch_cmd.progress::() + let batch_cmd = ParallelCommandProgress::new( + String::from("verify_block_header"), + batch_size, + Arc::new(ParallelCommandReadBodyFromExportLine::new(path)?), + None, + None, + ); + batch_cmd.progress::(&VerifyHeaderCmdType {}) } -impl BatchCmdExec for Block { - fn execute(&self) -> (usize, Vec) { +impl ParallelCommand for Block { + fn execute( + &self, + _reader: &dyn ParallelCommandBlockReader, + _cmd: &VerifyHeaderCmdType, + ) -> (usize, Vec) { let ret = G_CRYPTONIGHT.verify_header_difficulty(self.header.difficulty(), &self.header); match ret { Ok(_) => (1, vec![]), @@ -48,4 +62,8 @@ impl BatchCmdExec for Block { } } } + + fn matched(&self, _filter: &Option) -> bool { + true + } } diff --git a/cmd/db-exporter/src/verify_module.rs b/cmd/db-exporter/src/commands/verify_module.rs similarity index 89% rename from cmd/db-exporter/src/verify_module.rs rename to cmd/db-exporter/src/commands/verify_module.rs index 687cb74bbb..2e20c6369e 100644 --- a/cmd/db-exporter/src/verify_module.rs +++ b/cmd/db-exporter/src/commands/verify_module.rs @@ -1,11 +1,14 @@ +use crate::command_progress::{ + ParallelCommand, ParallelCommandBlockReader, ParallelCommandFilter, ParallelCommandProgress, + ParallelCommandReadBodyFromExportLine, +}; use clap::Parser; use move_binary_format::errors::Location; use starcoin_crypto::HashValue; use starcoin_types::{block::Block, transaction::TransactionPayload}; use starcoin_vm_types::{errors::VMError, file_format::CompiledModule}; +use std::sync::Arc; use std::{fmt::Debug, path::PathBuf}; -//use starcoin_accumulator::node::AccumulatorStoreType::Block; -use crate::cmd_batch_execution::{BatchCmdExec, CmdBatchExecution}; #[derive(Debug, Parser)] #[clap( @@ -27,8 +30,12 @@ pub struct VerifyModuleError { pub struct VerifyModulesType; -impl BatchCmdExec for Block { - fn execute(&self) -> (usize, Vec) { +impl ParallelCommand for Block { + fn execute( + &self, + _reader: &dyn ParallelCommandBlockReader, + _cmd: &VerifyModulesType, + ) -> (usize, Vec) { let mut errors = vec![]; let mut success_modules = 0; let block = self; @@ -72,6 +79,10 @@ impl BatchCmdExec for Block { } (success_modules, errors) } + + fn matched(&self, _filter: &Option) -> bool { + true + } } // fn verify_block_modules(block: Block) -> (usize, Vec) { @@ -119,8 +130,14 @@ impl BatchCmdExec for Block { // } pub fn verify_modules_via_export_file(input_path: PathBuf) -> anyhow::Result<()> { - let batch_cmd = CmdBatchExecution::new(String::from("verify_module"), input_path, 10); - batch_cmd.progress::() + let batch_cmd = ParallelCommandProgress::new( + String::from("verify_module"), + num_cpus::get(), + Arc::new(ParallelCommandReadBodyFromExportLine::new(input_path)?), + None, + None, + ); + batch_cmd.progress::(&VerifyModulesType {}) // let start_time = SystemTime::now(); // let file_name = input_path.display().to_string(); // let reader = BufReader::new(File::open(input_path)?); diff --git a/cmd/db-exporter/src/lib.rs b/cmd/db-exporter/src/lib.rs index 99e57915f1..170251ca05 100644 --- a/cmd/db-exporter/src/lib.rs +++ b/cmd/db-exporter/src/lib.rs @@ -1,6 +1,5 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -pub mod cmd_batch_execution; -pub mod verify_header; -pub mod verify_module; +pub mod command_progress; +pub mod commands; diff --git a/cmd/db-exporter/src/main.rs b/cmd/db-exporter/src/main.rs index 98b9d02f2c..dd4f7aff22 100644 --- a/cmd/db-exporter/src/main.rs +++ b/cmd/db-exporter/src/main.rs @@ -5,10 +5,11 @@ use anyhow::{bail, format_err, Result}; use bcs_ext::{BCSCodec, Sample}; use clap::{IntoApp, Parser}; use csv::Writer; -use db_exporter::{ - verify_header::{verify_header_via_export_file, VerifyHeaderOptions}, - verify_module::{verify_modules_via_export_file, VerifyModuleOptions}, -}; +// use db_exporter::{ +// decode_payload::{do_decode_payload_command, DecodePayloadCommandOptions}, +// verify_header::{verify_header_via_export_file, VerifyHeaderOptions}, +// verify_module::{verify_modules_via_export_file, VerifyModuleOptions}, +// }; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use serde::{ser::SerializeMap, Serialize, Serializer}; use starcoin_account_api::AccountInfo; @@ -69,6 +70,12 @@ use std::{ time::SystemTime, }; +use db_exporter::commands::{ + decode_payload::{do_decode_payload_command, DecodePayloadCommandOptions}, + verify_header::{verify_header_via_export_file, VerifyHeaderOptions}, + verify_module::{verify_modules_via_export_file, VerifyModuleOptions}, +}; + const BLOCK_GAP: u64 = 1000; const BACK_SIZE: u64 = 10000; const SNAP_GAP: u64 = 128; @@ -235,6 +242,7 @@ enum Cmd { VerifyHeader(VerifyHeaderOptions), GenTurboSTMTransactions(GenTurboSTMTransactionsOptions), ApplyTurboSTMBlock(ApplyTurboSTMBlockOptions), + DecodePayload(DecodePayloadCommandOptions), } #[derive(Debug, Clone, Parser)] @@ -259,7 +267,7 @@ pub struct CheckKeyOptions { /// starcoin node db path. like ~/.starcoin/barnard/starcoindb/db/starcoindb pub db_path: PathBuf, #[clap(long, short = 'n', - possible_values=&["block", "block_header"],)] + possible_values = & ["block", "block_header"],)] pub cf_name: String, #[clap(long, short = 'b')] pub block_hash: HashValue, @@ -350,7 +358,7 @@ pub struct GenBlockTransactionsOptions { pub block_num: Option, #[clap(long, short = 't')] pub trans_num: Option, - #[clap(long, short = 'p', possible_values=&["CreateAccount", "FixAccount", "EmptyTxn"],)] + #[clap(long, short = 'p', possible_values = & ["CreateAccount", "FixAccount", "EmptyTxn"],)] /// txn type pub txn_type: Txntype, } @@ -404,9 +412,9 @@ pub struct ExportResourceOptions { pub block_hash: HashValue, #[clap( - short='r', - default_value = "0x1::Account::Balance<0x1::STC::STC>", - parse(try_from_str=parse_struct_tag) + short = 'r', + default_value = "0x1::Account::Balance<0x1::STC::STC>", + parse(try_from_str = parse_struct_tag) )] /// resource struct tag. resource_type: StructTag, @@ -607,6 +615,9 @@ async fn main() -> anyhow::Result<()> { apply_turbo_stm_block(option.to_path, option.turbo_stm_to_path, option.input_path); return result; } + Cmd::DecodePayload(option) => { + return do_decode_payload_command(&option); + } } Ok(()) } @@ -856,6 +867,7 @@ pub fn gen_block_transactions( } } } + /// Returns a transaction to create a new account with the given arguments. pub fn create_account_txn_sent_as_association( new_account: &Account, @@ -1881,6 +1893,7 @@ pub fn export_resource( let now2 = Instant::now(); for (k, v) in resource_set.iter() { let struct_tag = StructTag::decode(k.as_slice())?; + println!("struct_tag: {:?}", struct_tag.to_string()); if struct_tag == resource_struct_tag { let annotated_struct = value_annotator.view_struct(resource_struct_tag.clone(), v.as_slice())?;