Merge pull request #693 from nuttycom/wallet/skip_unmined_tx_in_migrations
Fix a bug in migrations when transaction block height is unknown.
This commit is contained in:
commit
c0abaa4727
|
@ -39,8 +39,6 @@ pub(super) fn all_migrations<P: consensus::Parameters + 'static>(
|
||||||
_params: params.clone(),
|
_params: params.clone(),
|
||||||
}),
|
}),
|
||||||
Box::new(sent_notes_to_internal::Migration {}),
|
Box::new(sent_notes_to_internal::Migration {}),
|
||||||
Box::new(add_transaction_views::Migration {
|
Box::new(add_transaction_views::Migration),
|
||||||
params: params.clone(),
|
|
||||||
}),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use schemer_rusqlite::RusqliteMigration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
consensus::{self, BlockHeight, BranchId},
|
consensus::BranchId,
|
||||||
transaction::{
|
transaction::{
|
||||||
components::amount::{Amount, BalanceError},
|
components::amount::{Amount, BalanceError},
|
||||||
Transaction,
|
Transaction,
|
||||||
|
@ -24,11 +24,9 @@ pub(super) const MIGRATION_ID: Uuid = Uuid::from_fields(
|
||||||
b"\x8b\xed\x71\x82\x13\x20\x90\x9f",
|
b"\x8b\xed\x71\x82\x13\x20\x90\x9f",
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) struct Migration<P> {
|
pub(crate) struct Migration;
|
||||||
pub(super) params: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> schemer::Migration for Migration<P> {
|
impl schemer::Migration for Migration {
|
||||||
fn id(&self) -> Uuid {
|
fn id(&self) -> Uuid {
|
||||||
MIGRATION_ID
|
MIGRATION_ID
|
||||||
}
|
}
|
||||||
|
@ -47,7 +45,7 @@ impl<P> schemer::Migration for Migration<P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
|
impl RusqliteMigration for Migration {
|
||||||
type Error = WalletMigrationError;
|
type Error = WalletMigrationError;
|
||||||
|
|
||||||
fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
|
fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
|
||||||
|
@ -72,8 +70,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
|
||||||
|
|
||||||
transaction.execute_batch("ALTER TABLE transactions ADD COLUMN fee INTEGER;")?;
|
transaction.execute_batch("ALTER TABLE transactions ADD COLUMN fee INTEGER;")?;
|
||||||
|
|
||||||
let mut stmt_list_txs =
|
let mut stmt_list_txs = transaction.prepare("SELECT id_tx, raw FROM transactions")?;
|
||||||
transaction.prepare("SELECT id_tx, raw, block FROM transactions")?;
|
|
||||||
|
|
||||||
let mut stmt_set_fee =
|
let mut stmt_set_fee =
|
||||||
transaction.prepare("UPDATE transactions SET fee = ? WHERE id_tx = ?")?;
|
transaction.prepare("UPDATE transactions SET fee = ? WHERE id_tx = ?")?;
|
||||||
|
@ -85,20 +82,23 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
|
||||||
while let Some(row) = tx_rows.next()? {
|
while let Some(row) = tx_rows.next()? {
|
||||||
let id_tx: i64 = row.get(0)?;
|
let id_tx: i64 = row.get(0)?;
|
||||||
let tx_bytes: Option<Vec<u8>> = row.get(1)?;
|
let tx_bytes: Option<Vec<u8>> = row.get(1)?;
|
||||||
let h: u32 = row.get(2)?;
|
|
||||||
let block_height = BlockHeight::from(h);
|
|
||||||
|
|
||||||
// If only transaction metadata has been stored, and not transaction data, the fee
|
// If only transaction metadata has been stored, and not transaction data, the fee
|
||||||
// information will eventually be set when the full transaction data is inserted.
|
// information will eventually be set when the full transaction data is inserted.
|
||||||
if let Some(b) = tx_bytes {
|
if let Some(tx_bytes) = tx_bytes {
|
||||||
let tx =
|
let tx = Transaction::read(
|
||||||
Transaction::read(&b[..], BranchId::for_height(&self.params, block_height))
|
&tx_bytes[..],
|
||||||
.map_err(|e| {
|
// The consensus branch ID is unused in determining the fee paid, so
|
||||||
WalletMigrationError::CorruptedData(format!(
|
// just pass Nu5 as a dummy value since we know that parsing both v4
|
||||||
"Parsing failed for transaction {:?}: {:?}",
|
// and v5 transactions is supported during the Nu5 epoch.
|
||||||
id_tx, e
|
BranchId::Nu5,
|
||||||
))
|
)
|
||||||
})?;
|
.map_err(|e| {
|
||||||
|
WalletMigrationError::CorruptedData(format!(
|
||||||
|
"Parsing failed for transaction {:?}: {:?}",
|
||||||
|
id_tx, e
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
let fee_paid = tx.fee_paid(|op| {
|
let fee_paid = tx.fee_paid(|op| {
|
||||||
let op_amount = stmt_find_utxo_value
|
let op_amount = stmt_find_utxo_value
|
||||||
|
|
Loading…
Reference in New Issue