Skip to content

Commit

Permalink
Merge branch 'patch-v5-2-0' into cumulative-tx-amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianna Fitz Wren committed Jan 28, 2025
2 parents 5877022 + 1229154 commit 6f5e105
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 120 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
232 changes: 120 additions & 112 deletions src/json_rescue_v5_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ 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

wtxs.block_timestamp = timestamp;

// 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 => {}
};
Expand All @@ -95,7 +95,7 @@ pub fn decode_transaction_dataview_v5(
_ => {}
}
}

dbg!(&tx_vec);
Ok((tx_vec, event_vec, unique_functions))
}

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/schema_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -48,7 +49,7 @@ impl RelationLabel {

pub fn get_recipient(&self) -> Option<AccountAddress> {
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),
Expand Down
1 change: 1 addition & 0 deletions tests/test_json_rescue_v5_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_json_rescue_v5_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 6f5e105

Please sign in to comment.