Skip to content

Commit

Permalink
refactor: remove height field from outputs (#3027)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jul 4, 2021
2 parents 9b281ce + 85dea95 commit bc98c32
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 261 deletions.
3 changes: 0 additions & 3 deletions RFC/src/RFC-0201_TariScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ To summarise, the information required for one-sided transactions is as follows:
| features | \\( F_a \\) | Public |
| script | \\( \alpha_a \\) | Public |
| script input | \\( \input_a \\) | Public |
| height | \\( h_a \\) | Public |
| script signature | \\( a_{Sa},b_{Sa}, R_{Sa} \\) | Alice knows \\( k_{Sa},\\, r_{Sa} \\) and \\( k_{a},\\, v_{a} \\) of the commitment \\(C_a\\) |
| sender offset public key | \\( K_{Oa} \\) | Not used in this transaction |

Expand Down Expand Up @@ -742,7 +741,6 @@ To summarise, the information required for creating a multiparty UTXO is as foll
| features | \\( F_a \\) | Public |
| script | \\( \alpha_a \\) | Public |
| script input | \\( \input_a \\) | Public |
| height | \\( h_a \\) | Public |
| script signature | \\( (a_{Sa},b_{Sa}, R_{Sa}) \\) | Alice knows \\( k_{Sa},\\, r_{Sa} \\) and \\( k_{a},\\, v_{a} \\) of the commitment \\(C_a\\) |
| sender offset public key | \\( K_{Oa} \\) | Not used in this transaction |

Expand All @@ -765,7 +763,6 @@ When spending the multi-party input:
| features | \\( F_s \\) | Public |
| script | \\( \alpha_s \\) | Public |
| script input | \\( \input_s \\) | Public |
| height | \\( h_a \\) | Public |
| script signature | \\( (a_{Ss} ,b_{Ss} , R_{Ss}) \\) | Alice knows \\( (k_{SsA},\\, r_{SsA}) \\), Bob knows \\( (k_{SsB},\\, r_{SsB}) \\). Both parties know \\( (k_{s},\\, v_{s}) \\). Neither party knows \\( k_{Ss}\\) |
| sender offset public key | \\( K_{Os} \\) | As above, Alice and Bob each know part of the sender offset key |

Expand Down
4 changes: 0 additions & 4 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ message TransactionInput {
bytes script = 4;
// The script input data, if any
bytes input_data = 5;
// The block height that the UTXO was mined
uint64 height = 6;
// A signature with k_s, signing the script, input data, and mined height
ComSignature script_signature = 7;
// The offset public key, K_O
Expand Down Expand Up @@ -318,8 +316,6 @@ message UnblindedOutput {
bytes script = 4;
// Tari script input data for spending
bytes input_data = 5;
// The block height that the UTXO was mined
uint64 height = 6;
// Tari script private key
bytes script_private_key = 7;
// Tari script offset pubkey, K_O
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl TryFrom<grpc::TransactionInput> for TransactionInput {
commitment,
script,
input_data,
height: input.height,
script_signature,
script_offset_public_key,
})
Expand All @@ -78,7 +77,6 @@ impl From<TransactionInput> for grpc::TransactionInput {
hash,
script: input.script.as_bytes(),
input_data: input.input_data.as_bytes(),
height: input.height,
script_signature: Some(grpc::ComSignature {
public_nonce_commitment: Vec::from(input.script_signature.public_nonce().as_bytes()),
signature_u: Vec::from(input.script_signature.u().as_bytes()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl From<UnblindedOutput> for grpc::UnblindedOutput {
}),
script: output.script.as_bytes(),
input_data: output.input_data.as_bytes(),
height: output.height,
script_private_key: output.script_private_key.as_bytes().to_vec(),
script_offset_public_key: output.script_offset_public_key.as_bytes().to_vec(),
sender_metadata_signature: Some(grpc::Signature {
Expand Down Expand Up @@ -89,7 +88,6 @@ impl TryFrom<grpc::UnblindedOutput> for UnblindedOutput {
features,
script,
input_data,
height: output.height,
script_private_key,
script_offset_public_key,
sender_metadata_signature,
Expand Down
5 changes: 2 additions & 3 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,13 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
let mut csv_file = LineWriter::new(file);
writeln!(
csv_file,
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","height","script_private_key","script_offset_public_key","signature","public_nonce""##
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","script_private_key","script_offset_public_key","signature","public_nonce""##
)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
for (i, utxo) in utxos.iter().enumerate() {
writeln!(
csv_file,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}","{}","{}""##,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}","{}""##,
i + 1,
utxo.value.0,
utxo.spending_key.to_hex(),
Expand All @@ -660,7 +660,6 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
utxo.features.maturity,
utxo.script.to_hex(),
utxo.input_data.to_hex(),
utxo.height,
utxo.script_private_key.to_hex(),
utxo.script_offset_public_key.to_hex(),
utxo.sender_metadata_signature.get_signature().to_hex(),
Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ message TransactionInput {
bytes script = 3;
// The script input data, if any
bytes input_data = 4;
// The block height that the UTXO was mined
uint64 height = 5;
// A signature with k_s, signing the script, input data, and mined height
ComSignature script_signature = 6;
// The offset pubkey, K_O
Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/proto/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl TryFrom<proto::types::TransactionInput> for TransactionInput {
commitment,
script: TariScript::from_bytes(input.script.as_slice()).map_err(|err| format!("{:?}", err))?,
input_data: ExecutionStack::from_bytes(input.input_data.as_slice()).map_err(|err| format!("{:?}", err))?,
height: input.height,
script_signature,
script_offset_public_key,
})
Expand All @@ -135,7 +134,6 @@ impl From<TransactionInput> for proto::types::TransactionInput {
commitment: Some(input.commitment.into()),
script: input.script.as_bytes(),
input_data: input.input_data.as_bytes(),
height: input.height,
script_signature: Some(input.script_signature.into()),
script_offset_public_key: input.script_offset_public_key.as_bytes().to_vec(),
}
Expand Down
1 change: 0 additions & 1 deletion base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ impl CoinbaseBuilder {
Some(output_features),
script,
inputs!(PublicKey::from_secret_key(&script_private_key)),
height,
script_private_key,
script_offset_pub_key,
sender_sig,
Expand Down
10 changes: 2 additions & 8 deletions base_layer/core/src/transactions/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ pub fn create_unblinded_output(
Some(output_features),
script,
inputs!(PublicKey::from_secret_key(&test_params.script_private_key)),
0, // TODO: This will be removed by a later PR
test_params.script_private_key,
test_params.script_offset_pub_key,
sender_sig,
Expand Down Expand Up @@ -211,12 +210,11 @@ macro_rules! tx {
/// The output of this macro is intended to be used in [spend_utxos].
#[macro_export]
macro_rules! txn_schema {
(from: $input:expr, to: $outputs:expr, fee: $fee:expr, lock: $lock:expr, mined_height: $mined_height:expr, features: $features:expr) => {{
(from: $input:expr, to: $outputs:expr, fee: $fee:expr, lock: $lock:expr, features: $features:expr) => {{
$crate::transactions::helpers::TransactionSchema {
from: $input.clone(),
to: $outputs.clone(),
fee: $fee,
mined_height: $mined_height,
lock_height: $lock,
features: $features
}
Expand All @@ -228,7 +226,6 @@ macro_rules! txn_schema {
to:$outputs,
fee:$fee,
lock:$lock,
mined_height: 0,
features: $features
)
}};
Expand Down Expand Up @@ -259,7 +256,6 @@ macro_rules! txn_schema {
pub struct TransactionSchema {
pub from: Vec<UnblindedOutput>,
pub to: Vec<MicroTari>,
pub mined_height: u64,
pub fee: MicroTari,
pub lock_height: u64,
pub features: OutputFeatures,
Expand Down Expand Up @@ -354,8 +350,7 @@ pub fn spend_utxos(schema: TransactionSchema) -> (Transaction, Vec<UnblindedOutp
);

for tx_input in &schema.from {
let mut input = tx_input.clone();
input.height = schema.mined_height;
let input = tx_input.clone();
let utxo = input
.as_transaction_input(&factories.commitment)
.expect("Should be able to make a transaction input");
Expand Down Expand Up @@ -396,7 +391,6 @@ pub fn spend_utxos(schema: TransactionSchema) -> (Transaction, Vec<UnblindedOutp
inputs!(PublicKey::from_secret_key(
&test_params_change_and_txn.script_private_key
)),
0,
test_params_change_and_txn.script_private_key.clone(),
change_script_offset_public_key,
sender_sig,
Expand Down
10 changes: 0 additions & 10 deletions base_layer/core/src/transactions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ pub struct UnblindedOutput {
pub features: OutputFeatures,
pub script: TariScript,
pub input_data: ExecutionStack,
pub height: u64,
pub script_private_key: PrivateKey,
pub script_offset_public_key: PublicKey,
pub sender_metadata_signature: Signature,
Expand All @@ -225,7 +224,6 @@ impl UnblindedOutput {
features: Option<OutputFeatures>,
script: TariScript,
input_data: ExecutionStack,
height: u64,
script_private_key: PrivateKey,
script_offset_public_key: PublicKey,
sender_metadata_signature: Signature,
Expand All @@ -236,7 +234,6 @@ impl UnblindedOutput {
features: features.unwrap_or_default(),
script,
input_data,
height,
script_private_key,
script_offset_public_key,
sender_metadata_signature,
Expand Down Expand Up @@ -273,7 +270,6 @@ impl UnblindedOutput {
commitment,
script: self.script.clone(),
input_data: self.input_data.clone(),
height: self.height,
script_signature,
script_offset_public_key: self.script_offset_public_key.clone(),
})
Expand Down Expand Up @@ -381,8 +377,6 @@ pub struct TransactionInput {
pub script: TariScript,
/// The script input data, if any
pub input_data: ExecutionStack,
/// The block height that the UTXO was mined
pub height: u64,
/// A signature with k_s, signing the script, input data, and mined height
pub script_signature: ComSignature,
/// The offset pubkey, K_O
Expand All @@ -397,7 +391,6 @@ impl TransactionInput {
commitment: Commitment,
script: TariScript,
input_data: ExecutionStack,
height: u64,
script_signature: ComSignature,
script_offset_public_key: PublicKey,
) -> TransactionInput {
Expand All @@ -406,7 +399,6 @@ impl TransactionInput {
commitment,
script,
input_data,
height,
script_signature,
script_offset_public_key,
}
Expand Down Expand Up @@ -1366,15 +1358,13 @@ mod test {

let script = TariScript::default();
let input_data = ExecutionStack::default();
let height = 0;
let script_signature = ComSignature::default();
let offset_pub_key = PublicKey::default();
let mut input = TransactionInput::new(
OutputFeatures::default(),
c,
script,
input_data,
height,
script_signature,
offset_pub_key,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ impl SenderTransactionInitializer {
.as_ref()
.ok_or("Change script was not provided")?
.clone(),
0,
self.change_script_private_key
.as_ref()
.ok_or("Change script private key was not provided")?
Expand Down Expand Up @@ -722,7 +721,6 @@ mod test {
let factories = CryptoFactories::default();
let p = TestParams::new();
let (utxo, input) = create_test_input(MicroTari(500), 0, &factories.commitment);

let script = script!(Nop);
let output = create_unblinded_output(script.clone(), OutputFeatures::default(), p.clone(), MicroTari(400));
// Start the builder
Expand All @@ -747,7 +745,6 @@ mod test {
let factories = CryptoFactories::default();
let p = TestParams::new();
let (utxo, input) = create_test_input(MicroTari(400), 0, &factories.commitment);

let script = script!(Nop);
let output = create_unblinded_output(script.clone(), OutputFeatures::default(), p.clone(), MicroTari(400));
// Start the builder
Expand All @@ -772,7 +769,6 @@ mod test {
let factories = CryptoFactories::default();
let p = TestParams::new();
let (utxo, input) = create_test_input(MicroTari(100_000), 0, &factories.commitment);

let script = script!(Nop);
let output = create_unblinded_output(script.clone(), OutputFeatures::default(), p.clone(), MicroTari(15000));
// Start the builder
Expand Down
6 changes: 1 addition & 5 deletions base_layer/core/tests/base_node_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn test_base_node_wallet_rpc() {
from: vec![utxos1[0].clone()],
to: vec![400_000 * uT, 590_000 * uT]
)]);
let mut tx2 = (*txs2[0]).clone();
let tx2 = (*txs2[0]).clone();
let tx2_sig = tx2.first_kernel_excess_sig().unwrap().clone();

// Query Tx1
Expand Down Expand Up @@ -193,10 +193,6 @@ fn test_base_node_wallet_rpc() {
.block_on(base_node.local_nci.submit_block(block1.clone(), Broadcast::from(true)))
.is_ok());

// fix tx mined height
for input in tx2.body.inputs_mut() {
input.height = 1;
}
// Check that subitting Tx2 will now be accepted
let msg = TransactionProto::from(tx2);
let req = request_mock.request_with_context(Default::default(), msg);
Expand Down
Loading

0 comments on commit bc98c32

Please sign in to comment.