diff --git a/Cargo.toml b/Cargo.toml index f9e98a5..d5404aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,10 @@ diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = env_logger = "^0.11" flate2 = "^1.0" glob = "^0.3" -libra-backwards-compatibility = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" } -libra-cached-packages = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" } -libra-storage = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" } -libra-types = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" } +libra-backwards-compatibility = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" } +libra-cached-packages = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" } +libra-storage = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" } +libra-types = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" } log = "^0.4" neo4rs = "0.8.0" once_cell = "^1.2" diff --git a/src/json_rescue_v5_extract.rs b/src/json_rescue_v5_extract.rs index 2a55a9a..5d074ef 100644 --- a/src/json_rescue_v5_extract.rs +++ b/src/json_rescue_v5_extract.rs @@ -60,8 +60,8 @@ pub fn decode_transaction_dataview_v5( unique_functions.push(wtxs.function.clone()); } - decode_entry_function_v5(&mut wtxs, &t.bytes)?; - + decode_transaction_args(&mut wtxs, &t.bytes)?; + dbg!(&wtxs); // TODO: // wtxs.events @@ -69,10 +69,10 @@ pub fn decode_transaction_dataview_v5( // TODO: create arg to exclude tx without counter party match &wtxs.relation_label { - RelationLabel::Tx => {} - RelationLabel::Transfer(_, _) => tx_vec.push(wtxs), - RelationLabel::Onboarding(_, _) => tx_vec.push(wtxs), - RelationLabel::Vouch(_) => tx_vec.push(wtxs), + RelationLabel::Unknown => {} + RelationLabel::Transfer(..) => tx_vec.push(wtxs), + RelationLabel::Onboarding(..) => tx_vec.push(wtxs), + RelationLabel::Vouch(..) => tx_vec.push(wtxs), RelationLabel::Configuration => {} RelationLabel::Miner => {} }; @@ -95,7 +95,7 @@ pub fn decode_transaction_dataview_v5( _ => {} } } - + dbg!(&tx_vec); Ok((tx_vec, event_vec, unique_functions)) } @@ -110,125 +110,133 @@ pub fn decode_entry_function_v5(wtx: &mut WarehouseTxMaster, tx_bytes: &[u8]) -> })?; if let TransactionV5::UserTransaction(u) = &t { + // check this is actually a ScriptFunction if let TransactionPayload::ScriptFunction(_) = &u.raw_txn.payload { - if let Some(sf) = &ScriptFunctionCallGenesis::decode(&u.raw_txn.payload) { + maybe_decode_v5_genesis_function(wtx, &u.raw_txn.payload)?; + // if still unknown TX try again with v5.2.0 + if let RelationLabel::Unknown = wtx.relation_label { + maybe_decode_v520_function(wtx, &u.raw_txn.payload)?; + } + } + } + Ok(()) +} + +fn maybe_decode_v5_genesis_function( + wtx: &mut WarehouseTxMaster, + payload: &TransactionPayload, +) -> Result<()> { + if let Some(sf) = &ScriptFunctionCallGenesis::decode(payload) { + dbg!(&sf); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + // TODO: some script functions have very large payloads which clog the e.g. Miner. So those are only added for the catch-all txs which don't fall into categories we are interested in. + match sf { + ScriptFunctionCallGenesis::BalanceTransfer { destination, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(destination)?); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - // TODO: some script functions have very large payloads which clog the e.g. Miner. So those are only added for the catch-all txs which don't fall into categories we are interested in. - match sf { - ScriptFunctionCallGenesis::BalanceTransfer { - destination, - unscaled_value, - } => { - wtx.relation_label = RelationLabel::Transfer( - cast_legacy_account(destination)?, - // IMPORTANT: the V5 values will be - // rebased for harmonized analytics in the - // `coins` property - // The original value can still be found in the - // tx.args which include the entry functions - *unscaled_value * LEGACY_REBASE_MULTIPLIER, - ); - - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - ScriptFunctionCallGenesis::AutopayCreateInstruction { .. } => { - wtx.relation_label = RelationLabel::Configuration; - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - ScriptFunctionCallGenesis::CreateAccUser { .. } => { - // onboards self - wtx.relation_label = RelationLabel::Onboarding(wtx.sender, 0); - } - ScriptFunctionCallGenesis::CreateAccVal { .. } => { - // onboards self - wtx.relation_label = RelationLabel::Onboarding(wtx.sender, 0); - } + } + ScriptFunctionCallGenesis::AutopayCreateInstruction { payee, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(payee)?); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + } + ScriptFunctionCallGenesis::CreateAccUser { .. } => { + // onboards self + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } + ScriptFunctionCallGenesis::CreateAccVal { .. } => { + // onboards self + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } - ScriptFunctionCallGenesis::CreateUserByCoinTx { - account, - unscaled_value, - .. - } => { - wtx.relation_label = RelationLabel::Onboarding( - cast_legacy_account(account)?, - *unscaled_value * LEGACY_REBASE_MULTIPLIER, - ); - } - ScriptFunctionCallGenesis::CreateValidatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?, 0); - } - ScriptFunctionCallGenesis::CreateValidatorOperatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?, 0); - } + ScriptFunctionCallGenesis::CreateUserByCoinTx { account, .. } => { + dbg!(&account); + wtx.relation_label = RelationLabel::Onboarding(cast_legacy_account(account)?); + } + ScriptFunctionCallGenesis::CreateValidatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallGenesis::CreateValidatorOperatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } - ScriptFunctionCallGenesis::MinerstateCommit { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - ScriptFunctionCallGenesis::MinerstateCommitByOperator { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - _ => { - wtx.relation_label = RelationLabel::Configuration; + ScriptFunctionCallGenesis::MinerstateCommit { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + ScriptFunctionCallGenesis::MinerstateCommitByOperator { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + _ => { + wtx.relation_label = RelationLabel::Unknown; - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - } + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); } + } + } + Ok(()) +} - if let Some(sf) = &ScriptFunctionCallV520::decode(&u.raw_txn.payload) { - wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); +fn maybe_decode_v520_function( + wtx: &mut WarehouseTxMaster, + payload: &TransactionPayload, +) -> Result<()> { + if let Some(sf) = &ScriptFunctionCallV520::decode(payload) { + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); + match sf { + // NOTE: This balanceTransfer likely de/encodes to the same + // bytes as v5 genesis + ScriptFunctionCallV520::BalanceTransfer { destination, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(destination)?); - match sf { - ScriptFunctionCallV520::CreateAccUser { .. } => { - wtx.relation_label = RelationLabel::Onboarding(wtx.sender, 0); - } - ScriptFunctionCallV520::CreateAccVal { .. } => { - wtx.relation_label = RelationLabel::Onboarding(wtx.sender, 0); - } + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); + } + ScriptFunctionCallV520::CreateAccUser { .. } => { + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } + ScriptFunctionCallV520::CreateAccVal { .. } => { + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } - ScriptFunctionCallV520::CreateValidatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?, 0); - } - ScriptFunctionCallV520::CreateValidatorOperatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?, 0); - } - ScriptFunctionCallV520::MinerstateCommit { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - ScriptFunctionCallV520::MinerstateCommitByOperator { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - _ => { - wtx.relation_label = RelationLabel::Configuration; - wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); - } - } + ScriptFunctionCallV520::CreateValidatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallV520::CreateValidatorOperatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallV520::MinerstateCommit { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + ScriptFunctionCallV520::MinerstateCommitByOperator { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + _ => { + wtx.relation_label = RelationLabel::Unknown; + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); } } } Ok(()) } - /// from a tgz file unwrap to temp path /// NOTE: we return the Temppath object for the directory /// for the enclosing function to handle diff --git a/src/schema_transaction.rs b/src/schema_transaction.rs index c02c622..8d73053 100644 --- a/src/schema_transaction.rs +++ b/src/schema_transaction.rs @@ -21,12 +21,13 @@ pub const COIN_DECIMAL_PRECISION: f64 = 1000000.0; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum RelationLabel { - Tx, // undefined tx + Unknown, // undefined tx // NOTE: amount u64 includes: // - legacy multiplier in v6 rebase (for all pre-v6 data) // - decimal precision scaling Transfer(AccountAddress, u64), Onboarding(AccountAddress, u64), + Vouch(AccountAddress), Configuration, Miner, @@ -37,7 +38,7 @@ pub enum RelationLabel { impl RelationLabel { pub fn to_cypher_label(&self) -> String { match self { - RelationLabel::Tx => "MiscTx".to_owned(), + RelationLabel::Unknown => "Unknown".to_owned(), RelationLabel::Transfer(..) => "Transfer".to_owned(), RelationLabel::Onboarding(..) => "Onboarding".to_owned(), RelationLabel::Vouch(..) => "Vouch".to_owned(), @@ -48,7 +49,7 @@ impl RelationLabel { pub fn get_recipient(&self) -> Option { match &self { - RelationLabel::Tx => None, + RelationLabel::Unknown => None, RelationLabel::Transfer(account_address, _) => Some(*account_address), RelationLabel::Onboarding(account_address, _) => Some(*account_address), RelationLabel::Vouch(account_address) => Some(*account_address), diff --git a/tests/test_json_rescue_v5_load.rs b/tests/test_json_rescue_v5_load.rs index 7fa7718..66661ca 100644 --- a/tests/test_json_rescue_v5_load.rs +++ b/tests/test_json_rescue_v5_load.rs @@ -67,6 +67,7 @@ async fn test_load_queue() -> anyhow::Result<()> { let path = fixtures::v5_json_tx_path(); let tx_count = json_rescue_v5_load::rip_concurrent_limited(&path, &pool, None).await?; + dbg!(&tx_count); assert!(tx_count == 13); let tx_count = json_rescue_v5_load::rip_concurrent_limited(&path, &pool, None).await?; diff --git a/tests/test_json_rescue_v5_parse.rs b/tests/test_json_rescue_v5_parse.rs index f54bf1f..f9bd952 100644 --- a/tests/test_json_rescue_v5_parse.rs +++ b/tests/test_json_rescue_v5_parse.rs @@ -71,8 +71,9 @@ fn test_json_format_example() -> anyhow::Result<()> { let p = fixtures::v5_json_tx_path().join("example_create_user.json"); let (tx, _, _) = extract_v5_json_rescue(&p)?; - let first = tx.first().unwrap(); + dbg!(&tx); + let first = tx.first().unwrap(); assert!(first.sender.to_hex_literal() == *"0xecaf65add1b785b0495e3099f4045ec0"); Ok(()) }