Skip to content

Commit

Permalink
Always store and update kernel excess (mimblewimble#231)
Browse files Browse the repository at this point in the history
* always store and update kernel excess

* fix to parent key id on update as caught by testing

* save kernel excess for transaction recipients and coinbase outputs

* rustfmt

* logic cleanup, cargo.lock

* update to use node beta.3 release

* fix to doctests

* check result of calc offset before using

* rustfmt
  • Loading branch information
yeastplume authored Oct 3, 2019
1 parent e403db0 commit 2b7c2a2
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 88 deletions.
106 changes: 53 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ pub trait OwnerRpc: Sync + Send {
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 0,
"kernel_excess": null,
"kernel_lookup_min_height": null,
"kernel_excess": "0838e19c490038b10f051c9c190a9b1f96d59bbd242f5d3143f50630deb74342ed",
"kernel_lookup_min_height": 1,
"messages": null,
"num_inputs": 0,
"num_outputs": 1,
Expand All @@ -250,8 +250,8 @@ pub trait OwnerRpc: Sync + Send {
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 1,
"kernel_excess": null,
"kernel_lookup_min_height": null,
"kernel_excess": "08cd9d890c0b6a004f700aa5939a1ce0488fe2a11fa33cf096b50732ceab0be1df",
"kernel_lookup_min_height": 2,
"messages": null,
"num_inputs": 0,
"num_outputs": 1,
Expand Down Expand Up @@ -1025,7 +1025,9 @@ pub trait OwnerRpc: Sync + Send {
"parent_key_id": "0200000000000000000000000000000000",
"stored_tx": "0436430c-2b02-624c-2032-570501212b00.grintx",
"tx_slate_id": "0436430c-2b02-624c-2032-570501212b00",
"tx_type": "TxSent"
"tx_type": "TxSent",
"kernel_excess": null,
"kernel_lookup_min_height": null
}
]
}
Expand Down
12 changes: 7 additions & 5 deletions api/src/owner_rpc_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ pub trait OwnerRpcS {
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 0,
"kernel_excess": null,
"kernel_lookup_min_height": null,
"kernel_excess": "0838e19c490038b10f051c9c190a9b1f96d59bbd242f5d3143f50630deb74342ed",
"kernel_lookup_min_height": 1,
"messages": null,
"num_inputs": 0,
"num_outputs": 1,
Expand All @@ -273,8 +273,8 @@ pub trait OwnerRpcS {
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 1,
"kernel_excess": null,
"kernel_lookup_min_height": null,
"kernel_excess": "08cd9d890c0b6a004f700aa5939a1ce0488fe2a11fa33cf096b50732ceab0be1df",
"kernel_lookup_min_height": 2,
"messages": null,
"num_inputs": 0,
"num_outputs": 1,
Expand Down Expand Up @@ -1078,7 +1078,9 @@ pub trait OwnerRpcS {
"parent_key_id": "0200000000000000000000000000000000",
"stored_tx": "0436430c-2b02-624c-2032-570501212b00.grintx",
"tx_slate_id": "0436430c-2b02-624c-2032-570501212b00",
"tx_type": "TxSent"
"tx_type": "TxSent",
"kernel_excess": null,
"kernel_lookup_min_height": null
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions controller/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub fn txs(
bMG->"Amount \nDebited",
bMG->"Fee",
bMG->"Net \nDifference",
bMG->"Kernel",
bMG->"Tx \nData",
]);

Expand Down Expand Up @@ -196,6 +197,10 @@ pub fn txs(
Some(_) => "Yes".to_owned(),
None => "None".to_owned(),
};
let kernel_excess = match t.kernel_excess {
Some(e) => util::to_hex(e.0.to_vec()),
None => "None".to_owned(),
};
if dark_background_color_scheme {
table.add_row(row![
bFC->id,
Expand All @@ -210,6 +215,7 @@ pub fn txs(
bFR->amount_debited_str,
bFR->fee,
bFY->net_diff,
bFB->kernel_excess,
bFb->tx_data,
]);
} else {
Expand All @@ -227,6 +233,7 @@ pub fn txs(
bFD->amount_debited_str,
bFD->fee,
bFG->net_diff,
bFB->kernel_excess,
bFB->tx_data,
]);
} else {
Expand All @@ -243,6 +250,7 @@ pub fn txs(
bFD->amount_debited_str,
bFD->fee,
bFG->net_diff,
bFB->kernel_excess,
bFB->tx_data,
]);
}
Expand Down
5 changes: 5 additions & 0 deletions libwallet/src/api_impl/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ where
if tx.confirmed {
continue;
}
if tx.amount_debited != 0 && tx.amount_credited != 0 {
continue;
}
if let Some(e) = tx.kernel_excess {
let res = w
.w2n_client()
Expand All @@ -585,6 +588,8 @@ where
batch.save_tx_log_entry(tx.clone(), &parent_key_id)?;
batch.commit()?;
}
} else {
warn!("Attempted to update via kernel excess for transaction {:?}, but kernel excess was not stored", tx.tx_slate_id);
}
}
Ok(true)
Expand Down
16 changes: 12 additions & 4 deletions libwallet/src/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ where
let filename = format!("{}.grintx", slate_id);
t.stored_tx = Some(filename);
t.fee = Some(slate.fee);
// TODO: Future multi-kernel considerations
if total_change == 0 {
t.kernel_excess = Some(slate.calc_excess(&keychain)?);
t.kernel_lookup_min_height = Some(slate.height);

match slate.calc_excess(&keychain) {
Ok(e) => t.kernel_excess = Some(e),
Err(_) => {}
}
t.kernel_lookup_min_height = Some(slate.height);

let mut amount_debited = 0;
t.num_inputs = lock_inputs.len();
for id in lock_inputs {
Expand Down Expand Up @@ -234,6 +236,12 @@ where
t.amount_credited = amount;
t.num_outputs = 1;
t.messages = messages;
// when invoicing, this will be invalid
match slate.calc_excess(&keychain) {
Ok(e) => t.kernel_excess = Some(e),
Err(_) => {}
}
t.kernel_lookup_min_height = Some(slate.height);
batch.save(OutputData {
root_key_id: parent_key_id.clone(),
key_id: key_id_inner.clone(),
Expand Down
Loading

0 comments on commit 2b7c2a2

Please sign in to comment.