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

feat: optimize transaction validation for wallet #3537

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul

output_mmr.compress();

// TODO: #testnetreset clean up this code
// TODO: #testnet_reset clean up this code
let input_mr = if header.version == 1 {
MutableMmr::<HashDigest, _>::new(input_mmr.get_pruned_hash_set()?, Bitmap::create())?.get_merkle_root()?
} else {
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/transactions/aggregated_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl AggregateBody {
}
self.inputs.sort();
self.outputs.sort();
// TODO: #testnetreset clean up this code
// TODO: #testnet_reset clean up this code
if version <= 1 {
self.kernels.sort_by(|a, b| a.deprecated_cmp(b));
} else {
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/transactions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ impl TransactionOutput {
Challenge::new()
.chain(public_commitment_nonce.as_bytes())
.chain(script.as_bytes())
// TODO: Use consensus encoded bytes #testnet reset
// TODO: Use consensus encoded bytes #testnet_reset
.chain(features.to_v1_bytes())
.chain(sender_offset_public_key.as_bytes())
.chain(commitment.as_bytes())
Expand Down Expand Up @@ -887,7 +887,7 @@ impl TransactionOutput {
impl Hashable for TransactionOutput {
fn hash(&self) -> Vec<u8> {
HashDigest::new()
// TODO: use consensus encoding #testnetreset
// TODO: use consensus encoding #testnet_reset
.chain(self.features.to_v1_bytes())
.chain(self.commitment.as_bytes())
// .chain(range proof) // See docs as to why we exclude this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
PRAGMA foreign_keys=OFF;
ALTER TABLE completed_transactions
RENAME TO completed_transactions_old;
CREATE TABLE completed_transactions (
tx_id INTEGER PRIMARY KEY NOT NULL,
source_public_key BLOB NOT NULL,
destination_public_key BLOB NOT NULL,
amount INTEGER NOT NULL,
fee INTEGER NOT NULL,
transaction_protocol TEXT NOT NULL,
status INTEGER NOT NULL,
message TEXT NOT NULL,
timestamp DATETIME NOT NULL,
cancelled INTEGER NOT NULL DEFAULT 0,
direction INTEGER NULL DEFAULT NULL,
coinbase_block_height INTEGER NULL DEFAULT NULL,
send_count INTEGER NOT NULL DEFAULT 0,
last_send_timestamp DATETIME NULL DEFAULT NULL,
valid INTEGER NOT NULL DEFAULT 0,
confirmations INTEGER NULL DEFAULT NULL,
mined_height BIGINT NULL DEFAULT NULL,
mined_in_block BLOB NULL DEFAULT NULL

);
INSERT INTO completed_transactions (tx_id, source_public_key, destination_public_key, amount, fee, transaction_protocol,
status, message, timestamp, cancelled, direction, coinbase_block_height, send_count,
last_send_timestamp, valid, confirmations)
SELECT tx_id,
source_public_key,
destination_public_key,
amount,
fee,
transaction_protocol,
status,
message,
timestamp,
cancelled,
direction,
coinbase_block_height,
send_count,
last_send_timestamp,
valid,
confirmations,
mined_height,
mined_in_block
FROM completed_transactions_old;
DROP TABLE completed_transactions_old;
PRAGMA foreign_keys=ON;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE completed_transactions
ADD transaction_signature_nonce BLOB NOT NULL DEFAULT 0;

ALTER TABLE completed_transactions
ADD transaction_signature_key BLOB NOT NULL DEFAULT 0;
2 changes: 2 additions & 0 deletions base_layer/wallet/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ table! {
confirmations -> Nullable<BigInt>,
mined_height -> Nullable<BigInt>,
mined_in_block -> Nullable<Binary>,
transaction_signature_nonce -> Binary,
transaction_signature_key -> Binary,
}
}

Expand Down
4 changes: 4 additions & 0 deletions base_layer/wallet/src/transaction_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ pub enum TransactionKeyError {
Source(ByteArrayError),
#[error("Invalid destination PublicKey")]
Destination(ByteArrayError),
#[error("Invalid transaction signature nonce")]
SignatureNonce(ByteArrayError),
#[error("Invalid transaction signature key")]
SignatureKey(ByteArrayError),
}

#[derive(Debug, Error)]
Expand Down