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:
Kris Nuttycombe 2022-11-03 19:29:03 -06:00 committed by GitHub
commit c0abaa4727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 22 deletions

View File

@ -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(),
}),
] ]
} }

View File

@ -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,14 +82,17 @@ 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[..],
// The consensus branch ID is unused in determining the fee paid, so
// just pass Nu5 as a dummy value since we know that parsing both v4
// and v5 transactions is supported during the Nu5 epoch.
BranchId::Nu5,
)
.map_err(|e| { .map_err(|e| {
WalletMigrationError::CorruptedData(format!( WalletMigrationError::CorruptedData(format!(
"Parsing failed for transaction {:?}: {:?}", "Parsing failed for transaction {:?}: {:?}",