Skip to content

Commit

Permalink
Feature/slate serialization (#2534)
Browse files Browse the repository at this point in the history
* - Add backwards compatability
- Add hex serialization

* rustfmt

* rustfmt

* Windows Compatibility Fixes #1 (#2535)

* initial changes for windows build and unit/integration tests

* rustfmt

* wallet+store tests

* rustfmt

* fix linux daemonize

* better encapsulate file rename

* rustfmt

* remove daemonize commands

* rustfmt

* remove server start/stop commands

* add ability to drop pmmr backend files explicitly for txhashset unzip

* rustfmt

* fix pmmr tests

* rustfmt

* Windows TUI Fix (#2555)

* switch pancurses backend to win32

* revert changes to restore test

* compatibility fix + debug messages

* rustfmt

* Add content disposition for OK responses  (#2545)

* Testing http send and fixing accordingly

* add repost method into wallet owner api (#2553)

* add repost method into wallet owner api

* rustfmt

* Add ability to compare selection strategies (#2516)

Before tx creation user can estimate fee and locked amount
with different selection strategies by providing `-e` flag for
`wallet send` command.
  • Loading branch information
svechinsky authored and yeastplume committed Feb 13, 2019
1 parent 0d36acf commit ee4eed7
Show file tree
Hide file tree
Showing 39 changed files with 2,339 additions and 1,152 deletions.
1,144 changes: 660 additions & 484 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ chrono = "0.4.4"
clap = { version = "2.31", features = ["yaml"] }
rpassword = "2.0.0"
ctrlc = { version = "3.1", features = ["termination"] }
cursive = "0.9.0"
humansize = "1.1.0"
daemonize = "0.3"
serde = "1"
serde_json = "1"
log = "0.4"
Expand All @@ -45,6 +43,14 @@ grin_servers = { path = "./servers", version = "1.0.1" }
grin_util = { path = "./util", version = "1.0.1" }
grin_wallet = { path = "./wallet", version = "1.0.1" }

[target.'cfg(windows)'.dependencies]
cursive = { version = "0.10.0", default-features = false, features = ["pancurses-backend"] }
[target.'cfg(windows)'.dependencies.pancurses]
version = "0.16.0"
features = ["win32"]
[target.'cfg(unix)'.dependencies]
cursive = "0.9.0"

[build-dependencies]
built = "0.3"
reqwest = "0.9"
Expand Down
4 changes: 2 additions & 2 deletions api/src/handlers/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct ChainValidationHandler {
impl Handler for ChainValidationHandler {
fn get(&self, _req: Request<Body>) -> ResponseFuture {
match w(&self.chain).validate(true) {
Ok(_) => response(StatusCode::OK, ""),
Ok(_) => response(StatusCode::OK, "{}"),
Err(e) => response(
StatusCode::INTERNAL_SERVER_ERROR,
format!("validate failed: {}", e),
Expand All @@ -75,7 +75,7 @@ pub struct ChainCompactHandler {
impl Handler for ChainCompactHandler {
fn post(&self, _req: Request<Body>) -> ResponseFuture {
match w(&self.chain).compact() {
Ok(_) => response(StatusCode::OK, ""),
Ok(_) => response(StatusCode::OK, "{}"),
Err(e) => response(
StatusCode::INTERNAL_SERVER_ERROR,
format!("compact failed: {}", e),
Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/peers_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ impl Handler for PeerHandler {
_ => return response(StatusCode::BAD_REQUEST, "invalid command"),
};

response(StatusCode::OK, "")
response(StatusCode::OK, "{}")
}
}
8 changes: 8 additions & 0 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,14 @@ impl Chain {
}

let header = self.get_block_header(&h)?;

{
let mut txhashset_ref = self.txhashset.write();
// Drop file handles in underlying txhashset
txhashset_ref.release_backend_files();
}

// Rewrite hashset
txhashset::zip_write(self.db_root.clone(), txhashset_data, &header)?;

let mut txhashset =
Expand Down
11 changes: 10 additions & 1 deletion chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::core::core::committed::Committed;
use crate::core::core::hash::{Hash, Hashed};
use crate::core::core::merkle_proof::MerkleProof;
use crate::core::core::pmmr::{self, ReadonlyPMMR, RewindablePMMR, PMMR};
use crate::core::core::pmmr::{self, Backend, ReadonlyPMMR, RewindablePMMR, PMMR};
use crate::core::core::{
Block, BlockHeader, Input, Output, OutputIdentifier, TxKernel, TxKernelEntry,
};
Expand Down Expand Up @@ -153,6 +153,15 @@ impl TxHashSet {
})
}

/// Close all backend file handles
pub fn release_backend_files(&mut self) {
self.header_pmmr_h.backend.release_files();
self.sync_pmmr_h.backend.release_files();
self.output_pmmr_h.backend.release_files();
self.rproof_pmmr_h.backend.release_files();
self.kernel_pmmr_h.backend.release_files();
}

/// Check if an output is unspent.
/// We look in the index to find the output MMR pos.
/// Then we check the entry in the output MMR and confirm the hash matches.
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
[dependencies]
blake2-rfc = "0.2"
byteorder = "1"
croaring = "=0.3"
croaring = "=0.3.8"
enum_primitive = "0.1"
failure = "0.1"
failure_derive = "0.1"
Expand Down
3 changes: 3 additions & 0 deletions core/src/core/pmmr/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub trait Backend<T: PMMRable> {
/// fastest way to to be able to allow direct access to the file
fn get_data_file_path(&self) -> &Path;

/// Release underlying datafiles and locks
fn release_files(&mut self);

/// Also a bit of a hack...
/// Saves a snapshot of the rewound utxo file with the block hash as
/// filename suffix. We need this when sending a txhashset zip file to a
Expand Down
22 changes: 22 additions & 0 deletions core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::core::hash::Hashed;
use crate::core::verifier_cache::VerifierCache;
use crate::core::{committed, Committed};
use crate::keychain::{self, BlindingFactor};
use crate::libtx::secp_ser;
use crate::ser::{
self, read_multi, FixedLength, PMMRable, Readable, Reader, VerifySortedAndUnique, Writeable,
Writer,
Expand Down Expand Up @@ -164,9 +165,14 @@ pub struct TxKernel {
/// Remainder of the sum of all transaction commitments. If the transaction
/// is well formed, amounts components should sum to zero and the excess
/// is hence a valid public key.
#[serde(
serialize_with = "secp_ser::as_hex",
deserialize_with = "secp_ser::commitment_from_hex"
)]
pub excess: Commitment,
/// The signature proving the excess is a valid public key, which signs
/// the transaction fee.
#[serde(with = "secp_ser::sig_serde")]
pub excess_sig: secp::Signature,
}

Expand Down Expand Up @@ -756,6 +762,10 @@ impl TransactionBody {
pub struct Transaction {
/// The kernel "offset" k2
/// excess is k1G after splitting the key k = k1 + k2
#[serde(
serialize_with = "secp_ser::as_hex",
deserialize_with = "secp_ser::blind_from_hex"
)]
pub offset: BlindingFactor,
/// The transaction body - inputs/outputs/kernels
body: TransactionBody,
Expand Down Expand Up @@ -1111,6 +1121,10 @@ pub struct Input {
/// We will check maturity for coinbase output.
pub features: OutputFeatures,
/// The commit referencing the output being spent.
#[serde(
serialize_with = "secp_ser::as_hex",
deserialize_with = "secp_ser::commitment_from_hex"
)]
pub commit: Commitment,
}

Expand Down Expand Up @@ -1214,8 +1228,16 @@ pub struct Output {
/// Options for an output's structure or use
pub features: OutputFeatures,
/// The homomorphic commitment representing the output amount
#[serde(
serialize_with = "secp_ser::as_hex",
deserialize_with = "secp_ser::commitment_from_hex"
)]
pub commit: Commitment,
/// A proof that the commitment is in the right range
#[serde(
serialize_with = "secp_ser::as_hex",
deserialize_with = "secp_ser::rangeproof_from_hex"
)]
pub proof: RangeProof,
}

Expand Down
2 changes: 2 additions & 0 deletions core/tests/vec_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ impl<T: PMMRable> Backend<T> for VecBackend<T> {
Path::new("")
}

fn release_files(&mut self) {}

fn dump_stats(&self) {}
}

Expand Down
45 changes: 45 additions & 0 deletions doc/api/wallet_owner_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
1. [POST Finalize Tx](#post-finalize-tx)
1. [POST Cancel Tx](#post-cancel-tx)
1. [POST Post Tx](#post-post-tx)
1. [POST Repost Tx](#post-repost-tx)
1. [POST Issue Burn Tx](#post-issue-burn-tx)
1. [Adding Foreign API Endpoints](#add-foreign-api-endpoints)

Expand Down Expand Up @@ -641,6 +642,50 @@ Push new transaction to the connected node transaction pool. Add `?fluff` at the
},
});
```
### POST Repost Tx
Repost a `sending` transaction to the connected node transaction pool with a given transaction id. Add `?fluff` at the end of the URL to bypass Dandelion relay . This could be used for retry posting when a `sending` transaction is created but somehow failed on posting.
* **URL**
* /v1/wallet/owner/repost?id=x
* /v1/wallet/owner/repost?tx_id=x
* /v1/wallet/owner/repost?fluff&tx_id=x
* **Method:**
`POST`
* **URL Params**
**Required:**
* `id=[number]` the transaction id
* `tx_id=[string]`the transaction slate id
* **Data Params**
None
* **Success Response:**
* **Code:** 200
* **Error Response:**
* **Code:** 400
* **Sample Call:**
```javascript
$.ajax({
url: "/v1/wallet/owner/repost?id=3",
dataType: "json",
type : "POST",
success : function(r) {
console.log(r);
}
});
```
### POST Issue Burn Tx
Expand Down
22 changes: 2 additions & 20 deletions src/bin/cmd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

/// Grin server commands processing
#[cfg(not(target_os = "windows"))]
use std::env::current_dir;
use std::process::exit;
use std::sync::atomic::{AtomicBool, Ordering};
Expand All @@ -22,7 +23,6 @@ use std::time::Duration;

use clap::ArgMatches;
use ctrlc;
use daemonize::Daemonize;

use crate::config::GlobalConfig;
use crate::core::global;
Expand All @@ -31,7 +31,7 @@ use crate::servers;
use crate::tui::ui;

/// wrap below to allow UI to clean up on stop
fn start_server(config: servers::ServerConfig) {
pub fn start_server(config: servers::ServerConfig) {
start_server_tui(config);
// Just kill process for now, otherwise the process
// hangs around until sigint because the API server
Expand Down Expand Up @@ -157,29 +157,11 @@ pub fn server_command(
});
}*/

// start the server in the different run modes (interactive or daemon)
if let Some(a) = server_args {
match a.subcommand() {
("run", _) => {
start_server(server_config);
}
("start", _) => {
let daemonize = Daemonize::new()
.pid_file("/tmp/grin.pid")
.chown_pid_file(true)
.working_directory(current_dir().unwrap())
.privileged_action(move || {
start_server(server_config.clone());
loop {
thread::sleep(Duration::from_secs(60));
}
});
match daemonize.start() {
Ok(_) => info!("Grin server successfully started."),
Err(e) => error!("Error starting: {}", e),
}
}
("stop", _) => println!("TODO. Just 'kill $pid' for now. Maybe /tmp/grin.pid is $pid"),
("", _) => {
println!("Subcommand required, use 'grin help server' for details");
}
Expand Down
22 changes: 19 additions & 3 deletions src/bin/cmd/wallet_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
// selection_strategy
let selection_strategy = parse_required(args, "selection_strategy")?;

// estimate_selection_strategies
let estimate_selection_strategies = args.is_present("estimate_selection_strategies");

// method
let method = parse_required(args, "method")?;

Expand All @@ -360,10 +363,18 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
None => "default",
}
} else {
parse_required(args, "dest")?
if !estimate_selection_strategies {
parse_required(args, "dest")?
} else {
""
}
}
};
if method == "http" && !dest.starts_with("http://") && !dest.starts_with("https://") {
if !estimate_selection_strategies
&& method == "http"
&& !dest.starts_with("http://")
&& !dest.starts_with("https://")
{
let msg = format!(
"HTTP Destination should start with http://: or https://: {}",
dest,
Expand All @@ -386,6 +397,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
message: message,
minimum_confirmations: min_c,
selection_strategy: selection_strategy.to_owned(),
estimate_selection_strategies,
method: method.to_owned(),
dest: dest.to_owned(),
change_outputs: change_outputs,
Expand Down Expand Up @@ -562,7 +574,11 @@ pub fn wallet_command(
}
("send", Some(args)) => {
let a = arg_parse!(parse_send_args(&args));
command::send(inst_wallet(), a)
command::send(
inst_wallet(),
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)
}
("receive", Some(args)) => {
let a = arg_parse!(parse_receive_args(&args));
Expand Down
8 changes: 4 additions & 4 deletions src/bin/grin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ subcommands:
subcommands:
- config:
about: Generate a configuration grin-server.toml file in the current directory
- start:
about: Start the Grin server as a daemon
- stop:
about: Stop the Grin server daemon
- run:
about: Run the Grin server in this console
- client:
Expand Down Expand Up @@ -161,6 +157,10 @@ subcommands:
- smallest
default_value: all
takes_value: true
- estimate_selection_strategies:
help: Estimates all possible Coin/Output selection strategies.
short: e
long: estimate-selection
- change_outputs:
help: Number of change outputs to generate (mainly for testing)
short: o
Expand Down
2 changes: 1 addition & 1 deletion store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"

[dependencies]
byteorder = "1"
croaring = "=0.3"
croaring = "=0.3.8"
env_logger = "0.5"
libc = "0.2"
failure = "0.1"
Expand Down
Loading

0 comments on commit ee4eed7

Please sign in to comment.