Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove tari script serialization fix migration #4874

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base_layer/core/src/chain_storage/lmdb_db/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ pub fn lmdb_clear(txn: &WriteTransaction<'_>, db: &Database) -> Result<usize, Ch
Ok(num_deleted)
}

/// Used for migrations, you probably dont want to use this.
/// Used for migrations, you probably dont want to use this as it loops though the entire database.
#[allow(dead_code)]
pub(super) fn lmdb_map_inplace<F, V, R>(
txn: &WriteTransaction<'_>,
db: &Database,
Expand Down
77 changes: 1 addition & 76 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ fn run_migrations(db: &LMDBDatabase) -> Result<(), ChainStorageError> {
drop(txn);

if n < MIGRATION_VERSION {
tari_script_execution_stack_bug_migration::migrate(db)?;
// Add migrations here
info!(target: LOG_TARGET, "Migrated database to version {}", MIGRATION_VERSION);
let txn = db.write_transaction()?;
lmdb_replace(
Expand All @@ -2617,78 +2617,3 @@ fn run_migrations(db: &LMDBDatabase) -> Result<(), ChainStorageError> {

Ok(())
}

// TODO: this is a temporary fix, remove
mod tari_script_execution_stack_bug_migration {
use serde::{Deserialize, Serialize};
use tari_common_types::types::{ComSignature, PublicKey};
use tari_crypto::ristretto::{pedersen::PedersenCommitment, RistrettoPublicKey, RistrettoSchnorr};
use tari_script::{ExecutionStack, HashValue, ScalarValue, StackItem};

use super::*;
use crate::{
chain_storage::lmdb_db::lmdb::lmdb_map_inplace,
transactions::transaction_components::{SpentOutput, TransactionInputVersion},
};

pub fn migrate(db: &LMDBDatabase) -> Result<(), ChainStorageError> {
{
let txn = db.read_transaction()?;
// Only perform migration if necessary
if lmdb_len(&txn, &db.inputs_db)? == 0 {
return Ok(());
}
}
unsafe {
LMDBStore::resize(&db.env, &LMDBConfig::new(0, 1024 * 1024 * 1024, 0))?;
}
let txn = db.write_transaction()?;
lmdb_map_inplace(&txn, &db.inputs_db, |mut v: TransactionInputRowDataV0| {
let mut items = Vec::with_capacity(v.input.input_data.items.len());
while let Some(item) = v.input.input_data.items.pop() {
if let StackItemV0::Commitment(ref commitment) = item {
let pk = PublicKey::from_bytes(commitment.as_bytes()).unwrap();
items.push(StackItem::PublicKey(pk));
} else {
items.push(unsafe { mem::transmute(item) });
}
}
let mut v = unsafe { mem::transmute::<_, TransactionInputRowData>(v) };
v.input.input_data = ExecutionStack::new(items);
Some(v)
})?;
txn.commit()?;
Ok(())
}

#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct TransactionInputRowDataV0 {
pub input: TransactionInputV0,
pub header_hash: HashOutput,
pub mmr_position: u32,
pub hash: HashOutput,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TransactionInputV0 {
version: TransactionInputVersion,
spent_output: SpentOutput,
input_data: ExecutionStackV0,
script_signature: ComSignature,
}

#[derive(Debug, Serialize, Deserialize)]
struct ExecutionStackV0 {
items: Vec<StackItemV0>,
}

#[derive(Debug, Serialize, Deserialize)]
enum StackItemV0 {
Number(i64),
Hash(HashValue),
Scalar(ScalarValue),
Commitment(PedersenCommitment),
PublicKey(RistrettoPublicKey),
Signature(RistrettoSchnorr),
}
}