Skip to content

Commit 73eb836

Browse files
committed
update source code
1 parent b17e938 commit 73eb836

25 files changed

+262
-600
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ name = "hypercube-keygen"
5858
path = "src/bin/keygen.rs"
5959

6060
[[bin]]
61-
name = "hypercube-wallet"
62-
path = "src/bin/wallet.rs"
61+
name = "hypercube-qtc"
62+
path = "src/bin/qtc.rs"
6363

6464
[badges]
6565
codecov = { repository = "hypercube-labs/hypercube", branch = "master", service = "github" }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The XPZ (full name HyperCube) public chain supports large-scale, multi-threaded,
5858

5959
* Athena SDK can provide fast casting NFT, low-cost digital art creation
6060

61-
* Anonymous social + OTC + wallet, XPZ wallet supports anonymous social, OTC and token storage, facilitating quick realization of NFT creators, and supporting the issuance of social tokens and personal NFT works
61+
* Anonymous social + OTC + qtc, XPZ qtc supports anonymous social, OTC and token storage, facilitating quick realization of NFT creators, and supporting the issuance of social tokens and personal NFT works
6262

6363
* XPZ supports a hybrid on-chain transaction engine based on order books and automated market makers, which can help DeFi to be implemented on a large scale
6464

@@ -132,7 +132,7 @@ U.S. export controls and sanctions law. This risk applies to
132132
individuals, organizations, and other ecosystem participants that
133133
deploy, integrate, or use the HyperCube blockchain protocol code directly
134134
(e.g., as a node operator), and individuals that transact on the HyperCube
135-
blockchain through light clients, third party interfaces, and/or wallet
135+
blockchain through light clients, third party interfaces, and/or qtc
136136
software.
137137

138138

src/bin/bench-tps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hypercube::builtin_tansaction::SystemTransaction;
2323
use hypercube::thin_client::{poll_gossip_for_leader, ThinClient};
2424
use hypercube::timing::{duration_as_ms, duration_as_s};
2525
use hypercube::transaction::Transaction;
26-
use hypercube::wallet::request_airdrop;
26+
use hypercube::qtc::request_airdrop;
2727
use hypercube::window::default_window;
2828
use std::collections::VecDeque;
2929
use std::net::SocketAddr;

src/bin/fullnode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use hypercube::logger;
1616
use hypercube::metrics::set_panic_hook;
1717
use hypercube::signature::{Keypair, KeypairUtil};
1818
use hypercube::thin_client::poll_gossip_for_leader;
19-
use hypercube::wallet::request_airdrop;
19+
use hypercube::qtc::request_airdrop;
2020
use std::fs::File;
2121
use std::net::{Ipv4Addr, SocketAddr};
2222
use std::process::exit;

src/bin/keygen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate serde_json;
66
extern crate hypercube;
77

88
use clap::{App, Arg};
9-
use hypercube::wallet::gen_keypair_file;
9+
use hypercube::qtc::gen_keypair_file;
1010
use std::error;
1111

1212
fn main() -> Result<(), Box<error::Error>> {

src/bin/wallet.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use hypercube::logger;
1010
use hypercube::rpc::RPC_PORT;
1111
use hypercube::signature::{read_keypair, KeypairUtil};
1212
use hypercube::thin_client::poll_gossip_for_leader;
13-
use hypercube::wallet::{gen_keypair_file, parse_command, process_command, WalletConfig, WalletError};
13+
use hypercube::qtc::{gen_keypair_file, parse_command, process_command, QtcConfig, QtcError};
1414
use std::error;
1515
use std::net::SocketAddr;
1616

17-
pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error>> {
17+
pub fn parse_args(matches: &ArgMatches) -> Result<QtcConfig, Box<error::Error>> {
1818
let network = if let Some(addr) = matches.value_of("network") {
1919
addr.parse().or_else(|_| {
20-
Err(WalletError::BadParameter(
20+
Err(QtcError::BadParameter(
2121
"Invalid network location".to_string(),
2222
))
2323
})?
@@ -43,7 +43,7 @@ pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error
4343
path.to_str().unwrap()
4444
};
4545
let id = read_keypair(id_path).or_else(|err| {
46-
Err(WalletError::BadParameter(format!(
46+
Err(QtcError::BadParameter(format!(
4747
"{}: Unable to open keypair file: {}",
4848
err, id_path
4949
)))
@@ -69,7 +69,7 @@ pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error
6969

7070
let command = parse_command(id.pubkey(), &matches)?;
7171

72-
Ok(WalletConfig {
72+
Ok(QtcConfig {
7373
leader,
7474
id,
7575
faucet_addr, // TODO: Add an option for this.
@@ -80,7 +80,7 @@ pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error
8080

8181
fn main() -> Result<(), Box<error::Error>> {
8282
logger::setup();
83-
let matches = App::new("hypercube-wallet")
83+
let matches = App::new("hypercube-qtc")
8484
.version(crate_version!())
8585
.arg(
8686
Arg::with_name("network")

src/ledger.rs

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,14 @@ use std::path::Path;
2121
use transaction::Transaction;
2222
use window::WINDOW_SIZE;
2323

24-
//
25-
// A persistent ledger is 2 files:
26-
// ledger_path/ --+
27-
// +-- index <== an array of u64 offsets into data,
28-
// | each offset points to the first bytes
29-
// | of a u64 that contains the length of
30-
// | the entry. To make the code smaller,
31-
// | index[0] is set to 0, TODO: this field
32-
// | could later be used for other stuff...
33-
// +-- data <== concatenated instances of
34-
// u64 length
35-
// entry data
36-
//
37-
// When opening a ledger, we have the ability to "audit" it, which means we need
38-
// to pick which file to use as "truth", and correct the other file as
39-
// necessary, if possible.
40-
//
41-
// The protocol for writing the ledger is to append to the data file first, the
42-
// index file 2nd. If the writing node is interupted while appending to the
43-
// ledger, there are some possibilities we need to cover:
44-
//
45-
// 1. a partial write of data, which might be a partial write of length
46-
// or a partial write entry data
47-
// 2. a partial or missing write to index for that entry
48-
//
49-
// There is also the possibility of "unsynchronized" reading of the ledger
50-
// during transfer across nodes via rsync (or whatever). In this case, if the
51-
// transfer of the data file is done before the transfer of the index file,
52-
// it's likely that the index file will be far ahead of the data file in time.
53-
//
54-
// The quickest and most reliable strategy for recovery is therefore to treat
55-
// the data file as nearest to the "truth".
56-
//
57-
// The logic for "recovery/audit" is to open index and read backwards from the
58-
// last u64-aligned entry to get to where index and data agree (i.e. where a
59-
// successful deserialization of an entry can be performed), then truncate
60-
// both files to this syncrhonization point.
61-
//
62-
63-
// ledger window
24+
6425
#[derive(Debug)]
6526
pub struct LedgerWindow {
6627
index: BufReader<File>,
6728
data: BufReader<File>,
6829
}
6930

70-
// use a CONST because there's a cast, and we don't want "sizeof::<u64> as u64"...
31+
7132
const SIZEOF_U64: u64 = size_of::<u64>() as u64;
7233

7334
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
@@ -95,8 +56,7 @@ fn u64_at<A: Read + Seek>(file: &mut A, at: u64) -> io::Result<u64> {
9556
}
9657

9758
impl LedgerWindow {
98-
// opens a Ledger in directory, provides "infinite" window
99-
//
59+
10060
pub fn open(ledger_path: &str) -> io::Result<Self> {
10161
let ledger_path = Path::new(&ledger_path);
10262

@@ -255,19 +215,7 @@ fn recover_ledger(ledger_path: &str) -> io::Result<()> {
255215
data.sync_all()
256216
}
257217

258-
// TODO?? ... we could open the files on demand to support [], but today
259-
// LedgerWindow needs "&mut self"
260-
//
261-
//impl Index<u64> for LedgerWindow {
262-
// type Outx_creatort = io::Result<Entry>;
263-
//
264-
// fn index(&mut self, index: u64) -> &io::Result<Entry> {
265-
// match u64_at(&mut self.index, index * SIZEOF_U64) {
266-
// Ok(offset) => &entry_at(&mut self.data, offset),
267-
// Err(e) => &Err(e),
268-
// }
269-
// }
270-
//}
218+
271219

272220
#[derive(Debug)]
273221
pub struct LedgerWriter {
@@ -276,13 +224,13 @@ pub struct LedgerWriter {
276224
}
277225

278226
impl LedgerWriter {
279-
// recover and open the ledger for writing
227+
280228
pub fn recover(ledger_path: &str) -> io::Result<Self> {
281229
recover_ledger(ledger_path)?;
282230
LedgerWriter::open(ledger_path, false)
283231
}
284232

285-
// opens or creates a LedgerWriter in ledger_path directory
233+
286234
pub fn open(ledger_path: &str, create: bool) -> io::Result<Self> {
287235
let ledger_path = Path::new(&ledger_path);
288236

@@ -465,15 +413,13 @@ pub fn reconstruct_entries_from_blobs(blobs: Vec<SharedBlob>) -> Result<Vec<Entr
465413
Ok(entries)
466414
}
467415

468-
/// Creates the next entries for given transactions, outx_creatorts
469-
/// updates start_hash to id of last Entry, sets num_hashes to 0
416+
470417
pub fn next_entries_mut(
471418
start_hash: &mut Hash,
472419
num_hashes: &mut u64,
473420
transactions: Vec<Transaction>,
474421
) -> Vec<Entry> {
475-
// TODO: ?? find a number that works better than |?
476-
// V
422+
V
477423
if transactions.is_empty() || transactions.len() == 1 {
478424
vec![Entry::new_mut(start_hash, num_hashes, transactions)]
479425
} else {
@@ -486,7 +432,7 @@ pub fn next_entries_mut(
486432
let mut lower = chunk_start;
487433
let mut next = chunk_end; // be optimistic that all will fit
488434

489-
// binary search for how many transactions will fit in an Entry (i.e. a BLOB)
435+
490436
loop {
491437
debug!(
492438
"chunk_end {}, upper {} lower {} next {} transactions.len() {}",
@@ -527,7 +473,7 @@ pub fn next_entries_mut(
527473
}
528474
}
529475

530-
/// Creates the next Entries for given transactions
476+
531477
pub fn next_entries(
532478
start_hash: &Hash,
533479
num_hashes: u64,
@@ -629,16 +575,7 @@ mod tests {
629575
Utc::now(),
630576
one,
631577
);
632-
//
633-
// TODO: this magic number and the mix of transaction types
634-
// is designed to fill up a Blob more or less exactly,
635-
// to get near enough the the threshold that
636-
// deserialization falls over if it uses the wrong size()
637-
// parameter to index into blob.data()
638-
//
639-
// magic numbers -----------------+
640-
// |
641-
// V
578+
642579
let mut transactions = vec![tx0; 362];
643580
transactions.extend(vec![tx1; 100]);
644581
next_entries(&zero, 0, transactions)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub mod tx_creator;
6161
pub mod transaction;
6262
pub mod tx_signer;
6363
pub mod vote_stage;
64-
pub mod wallet;
64+
pub mod qtc;
6565
pub mod window;
6666
pub mod window_service;
6767
pub mod write_stage;

src/loopfiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
# this script loop through all files in thec
4+
35
def loopfile():
46
directory = os.getcwd()
57
for filename in os.listdir(directory):

0 commit comments

Comments
 (0)