Skip to content

Commit

Permalink
Fix: 'Invalid Transaction data' error (Zondax#130)
Browse files Browse the repository at this point in the history
We have an error when trying to get the data in some cases of bridge
transactions. We will not try to decode it anymore to avoid raising the
error and just save the encoded data.
  • Loading branch information
rllola authored Feb 14, 2024
1 parent 3ec0b29 commit 17523c9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 74 deletions.
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/bin/indexer.rs"
[dependencies]
getrandom = { version = "0.2" }
async-trait = "0.1.51"
namada_sdk = { git = "https://github.com/anoma/namada", rev = "v0.31.0" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "v0.31.4" }
rand = { version = "0.8", default-features = false }
rand_core = { version = "0.6", default-features = false }
tokio = { version = "1.26.0", features = ["rt-multi-thread"] }
Expand Down
76 changes: 39 additions & 37 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use namada_sdk::{
},
types::{
address::Address,
eth_bridge_pool::PendingTransfer,
// key::PublicKey,
token,
},
Expand Down Expand Up @@ -165,7 +164,7 @@ impl Database {

/// Inner implementation that uses a postgres-transaction
/// to ensure database coherence.
#[instrument(skip(block, checksums_map, sqlx_tx))]
#[instrument(skip(block, block_results, checksums_map, sqlx_tx))]
async fn save_block_impl<'a>(
block: &Block,
block_results: &block_results::Response,
Expand Down Expand Up @@ -275,7 +274,7 @@ impl Database {
}

/// Save a block and commit database
#[instrument(skip(self, block, checksums_map))]
#[instrument(skip(self, block, block_results, checksums_map))]
pub async fn save_block(
&self,
block: &Block,
Expand Down Expand Up @@ -423,7 +422,7 @@ impl Database {
/// It is up to the caller to commit the operation.
/// this method is meant to be used when caller is saving
/// many blocks, and can commit after it.
#[instrument(skip(block, checksums_map, sqlx_tx, network))]
#[instrument(skip(block, block_results, checksums_map, sqlx_tx, network))]
pub async fn save_block_tx<'a>(
block: &Block,
block_results: &block_results::Response,
Expand Down Expand Up @@ -543,7 +542,7 @@ impl Database {
/// Save all the transactions in txs, it is up to the caller to
/// call sqlx_tx.commit().await?; for the changes to take place in
/// database.
#[instrument(skip(txs, block_id, sqlx_tx, checksums_map, network))]
#[instrument(skip(txs, block_id, sqlx_tx, checksums_map, block_results, network))]
async fn save_transactions<'a>(
txs: &[Vec<u8>],
block_id: &[u8],
Expand Down Expand Up @@ -646,10 +645,13 @@ impl Database {
.ok_or(Error::InvalidTxData)?;

let code_hex = hex::encode(code.as_slice());

let unknown_type = "unknown".to_string();
let type_tx = checksums_map.get(&code_hex).unwrap_or(&unknown_type);
let data = tx.data().ok_or(Error::InvalidTxData)?;
let mut data: Vec<u8> = vec![];
if type_tx != "tx_bridge_pool" {
// "tx_bridge_pool" doesn't have their data in the data section anymore ?
data = tx.data().ok_or(Error::InvalidTxData)?;
}

info!("Saving {} transaction", type_tx);

Expand Down Expand Up @@ -740,36 +742,36 @@ impl Database {
query.execute(&mut *sqlx_tx).await?;
}
// this is an ethereum transaction
"tx_bridge_pool" => {
// Only TransferToEthereum type is supported at the moment by namada and us.
let tx_bridge = PendingTransfer::try_from_slice(&data[..])?;

let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
"INSERT INTO {}.tx_bridge_pool(
tx_id,
asset,
recipient,
sender,
amount,
gas_amount,
payer
)",
network
));

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(&hash_id)
.push_bind(tx_bridge.transfer.asset.to_string())
.push_bind(tx_bridge.transfer.recipient.to_string())
.push_bind(tx_bridge.transfer.sender.to_string())
.push_bind(tx_bridge.transfer.amount.to_string_native())
.push_bind(tx_bridge.gas_fee.amount.to_string_native())
.push_bind(tx_bridge.gas_fee.payer.to_string());
})
.build();
query.execute(&mut *sqlx_tx).await?;
}
// "tx_bridge_pool" => {
// // Only TransferToEthereum type is supported at the moment by namada and us.
// let tx_bridge = PendingTransfer::try_from_slice(&data[..])?;

// let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
// "INSERT INTO {}.tx_bridge_pool(
// tx_id,
// asset,
// recipient,
// sender,
// amount,
// gas_amount,
// payer
// )",
// network
// ));

// let query = query_builder
// .push_values(std::iter::once(0), |mut b, _| {
// b.push_bind(&hash_id)
// .push_bind(tx_bridge.transfer.asset.to_string())
// .push_bind(tx_bridge.transfer.recipient.to_string())
// .push_bind(tx_bridge.transfer.sender.to_string())
// .push_bind(tx_bridge.transfer.amount.to_string_native())
// .push_bind(tx_bridge.gas_fee.amount.to_string_native())
// .push_bind(tx_bridge.gas_fee.payer.to_string());
// })
// .build();
// query.execute(&mut *sqlx_tx).await?;
// }
"tx_vote_proposal" => {
let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
"INSERT INTO {}.vote_proposal(
Expand Down

0 comments on commit 17523c9

Please sign in to comment.