Skip to content

Instantly share code, notes, and snippets.

@sherry-x
Created July 27, 2021 18:43
Show Gist options
  • Save sherry-x/51fb5e29028dbc4ff0683fc1b93b0474 to your computer and use it in GitHub Desktop.
Save sherry-x/51fb5e29028dbc4ff0683fc1b93b0474 to your computer and use it in GitHub Desktop.
diff --git a/Cargo.lock b/Cargo.lock
index 17a3c9b7a7..d22721fd05 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2506,6 +2506,7 @@ dependencies = [
"diem-workspace-hack",
"diemdb",
"handlebars",
+ "hex",
"move-core-types",
"move-lang",
"move-vm-runtime",
diff --git a/language/diem-tools/transaction-replay/src/main.rs b/language/diem-tools/transaction-replay/src/main.rs
index 5877e45eff..0f06cf8c9c 100644
--- a/language/diem-tools/transaction-replay/src/main.rs
+++ b/language/diem-tools/transaction-replay/src/main.rs
@@ -3,7 +3,7 @@
use anyhow::Result;
use diem_transaction_replay::DiemDebugger;
-use diem_types::{account_address::AccountAddress, transaction::Version};
+use diem_types::{account_address::AccountAddress, transaction::{Version, TransactionPayload}};
use difference::Changeset;
use move_core_types::effects::ChangeSet;
use std::{fs, path::PathBuf};
@@ -122,7 +122,10 @@ fn main() -> Result<()> {
write_set_blob_path: path,
version,
} => {
- let writeset_payload = bcs::from_bytes(&fs::read(path.as_path())?)?;
+ let writeset_payload = match bcs::from_bytes(&fs::read(path.as_path())?)? {
+ TransactionPayload::WriteSet(ws) => ws,
+ _ => panic!("Invalid writeset payload encountered"),
+ };
println!(
"{:?}",
debugger.execute_writeset_at_version(
diff --git a/language/diem-tools/writeset-transaction-generator/Cargo.toml b/language/diem-tools/writeset-transaction-generator/Cargo.toml
index 99cf55e67d..8077df2a86 100644
--- a/language/diem-tools/writeset-transaction-generator/Cargo.toml
+++ b/language/diem-tools/writeset-transaction-generator/Cargo.toml
@@ -19,6 +19,7 @@ handlebars = "3.5.3"
serde = { version = "1.0.124", default-features = false }
serde_json = "1.0.64"
once_cell = "1.7.2"
+hex = "0.4.3"
diem-workspace-hack = { path = "../../../common/workspace-hack" }
diem-crypto-derive = { path = "../../../crypto/crypto-derive" }
diff --git a/language/diem-tools/writeset-transaction-generator/src/main.rs b/language/diem-tools/writeset-transaction-generator/src/main.rs
index 4c8bc8c2af..fe57447ed4 100644
--- a/language/diem-tools/writeset-transaction-generator/src/main.rs
+++ b/language/diem-tools/writeset-transaction-generator/src/main.rs
@@ -7,6 +7,8 @@ use diem_types::{
chain_id::ChainId,
transaction::{Transaction, TransactionPayload, WriteSetPayload},
};
+use std::hash::{Hash, Hasher};
+use std::collections::hash_map::DefaultHasher;
use diem_writeset_generator::{
create_release, encode_custom_script, encode_halt_network_payload,
@@ -73,7 +75,16 @@ enum Command {
},
}
+
+fn calculate_hash(writeset_payload: &[u8]) -> u64 {
+ let mut hasher = DefaultHasher::new();
+ hex::encode(writeset_payload).hash(&mut hasher);
+ hasher.finish()
+}
+
fn save_bytes(bytes: Vec<u8>, path: PathBuf) -> Result<()> {
+ println!("Hash of bytes being saved to file: {:?} is: {}", path, calculate_hash(bytes.as_slice()));
+ println!("Hex bytes: {}", hex::encode(bytes.as_slice()));
std::fs::write(path.as_path(), bytes.as_slice())
.map_err(|_| format_err!("Unable to write to path"))
}
diff --git a/language/diem-tools/writeset-transaction-generator/templates/halt_scripts.move b/language/diem-tools/writeset-transaction-generator/templates/halt_scripts.move
new file mode 100644
index 0000000000..cc499f0ca1
--- /dev/null
+++ b/language/diem-tools/writeset-transaction-generator/templates/halt_scripts.move
@@ -0,0 +1,6 @@
+script {
+ use 0x1::DiemTransactionPublishingOption;
+ fun main(dr_signer: signer, _unused_dr_signer: signer) {
+ DiemTransactionPublishingOption::halt_all_transactions(&dr_signer)
+ }
+}
diff --git a/language/diem-tools/writeset-transaction-generator/templates/resume_scripts.move b/language/diem-tools/writeset-transaction-generator/templates/resume_scripts.move
new file mode 100644
index 0000000000..a438ff1ece
--- /dev/null
+++ b/language/diem-tools/writeset-transaction-generator/templates/resume_scripts.move
@@ -0,0 +1,6 @@
+script {
+ use 0x1::DiemTransactionPublishingOption;
+ fun main(dr_signer: signer, _unused_dr_signer: signer) {
+ DiemTransactionPublishingOption::resume_transactions(&dr_signer)
+ }
+}
diff --git a/language/generate_and_check.sh b/language/generate_and_check.sh
new file mode 100755
index 0000000000..6fde7d40a2
--- /dev/null
+++ b/language/generate_and_check.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+cargo run --bin diem-writeset-generator -- -o halt_scripts.payload --output-payload build-custom-script halt_scripts.move "{}"
+cargo run --bin diem-writeset-generator -- -o resume_scripts.payload --output-payload build-custom-script resume_scripts.move "{}"
diff --git a/language/halt_scripts.payload b/language/halt_scripts.payload
new file mode 100644
index 0000000000000000000000000000000000000000..7f221452030809ab154c29582350f75a54a48faa
GIT binary patch
literal 138
zcmZQzWIzI3p*#|$3uRt&GXVuz85x+EnOIrb+1dHbI9vpPLX1p6F&-WUMm8RKm(0}M
zkfOxA;>6^V%>2B7(xjZs;*89^bpHYnUo;~zrzAcxCnvrHp{N+iE)WxFIU_S4gCGOY
FJ^&_)8BzcM
literal 0
HcmV?d00001
diff --git a/language/resume_scripts.payload b/language/resume_scripts.payload
new file mode 100644
index 0000000000000000000000000000000000000000..25ea4f2eccdbbda6558ff4b628df83742f28e43e
GIT binary patch
literal 136
zcmZQzWIzI3p*#}B3uRt&GXVuz85x+EnOIrb+1dF_IGhB4LX1p6F&-WUMm8RKm(0}M
zkfOxA;>6^V%>2B7(xjZs;*89^bpHYnU$`i>xHLC4z67D97|A9O6KFLfGarK>1JE`A
D;lvo4
literal 0
HcmV?d00001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment