Skip to content
Snippets Groups Projects
Commit 6b6e1375 authored by Cardy Tang's avatar Cardy Tang
Browse files

still buggy

parent 057d2c93
Branches master
No related tags found
No related merge requests found
......@@ -225,13 +225,15 @@ impl Context {
let tip = self.blockchain.lock().unwrap().tip();
let interval = time::Duration::from_micros(1500000 as u64);
thread::sleep(interval);
// println!("most recent {:?} tip {:?}",most_recent_state,tip);
if most_recent_state == tip{
// println!("stay here");
self.operating_state = OperatingState::Paused;
println!("stay here");
// self.operating_state = OperatingState::Paused;
continue;
}
// println!("new transactions");
most_recent_state = tip;
// println!("Generator curr view : {:?}",self.glob_state.lock().unwrap()[&tip]);
for ((k,iter),(v,me)) in self.glob_state.lock().unwrap()[&tip].iter(){
let mut input_vec: Vec<H256> = Vec::new();
let mut idx_vec: Vec<u32> = Vec::new();
......@@ -274,7 +276,7 @@ impl Context {
transaction:trans.clone(),
sig: s.clone(),
};
debug!("Generated transactions: {:?}",trans);
// debug!("Generated transactions: {:?}",trans);
self.mempool.lock().unwrap().insert(new_trans.hash(), new_trans.clone());
self.server.broadcast(Message::NewTransactionHashes(vec![new_trans.hash()]));
}
......
......@@ -236,7 +236,7 @@ impl Context {
let mut to_remove_parent: Vec<H256> = Vec::new();
for _k in 0..lim_p{
let remove_key:H256;
let mut valid = false;
match tx_iter.next(){
Some(keys) => {
remove_key = keys.clone();
......@@ -251,8 +251,26 @@ impl Context {
continue;
}
let curr_tx_b = tx_local_lookup[&remove_key].clone();
let mut valid = true;
for curr_tx_idx in 0..curr_tx_b.content.data.len(){
let curr_tx = curr_tx_b.content.data[curr_tx_idx].clone();
for j in 0..curr_tx.transaction.input_previous.len(){
if curr_tx.transaction.input_previous[0] == H256::from([0;32]){
break;
}
let lookup_key = (curr_tx.transaction.input_previous[j],curr_tx.transaction.input_index[j]);
if !new_state.contains_key(&lookup_key){
// println!("Bad bad {:?}",lookup_key.clone());
valid = false;
break;
}
}
if !valid{
to_remove_parent.push(remove_key.clone());
break;
}
// println!("curr transaction {:?}",curr_tx);
if tx_seen.contains_key(&curr_tx.hash()){
println!("Seen!");
......@@ -273,7 +291,6 @@ impl Context {
// println!("{:?} {:?}",curr_tx,curr_tx.hash());
new_state.insert((curr_tx.hash(), j as u32),(curr_tx.transaction.output_value[j],curr_tx.transaction.output_address[j]));
}
valid = true;
}
if valid{
to_add_trans_b.push(remove_key.clone());
......@@ -343,7 +360,7 @@ impl Context {
for _k in 0..to_remove_trans.len(){
self.mempool.lock().unwrap().remove(&to_remove_trans[_k]);
}
println!("Transaction block! {:?}",new_block.hash());
println!("Transaction block! {:?} content len {:?}",new_block.hash(),new_content_t.data.len());
idx_t = idx_t+1;
}
println!("Total: {}",idx_p+idx_t);
......
......@@ -112,7 +112,7 @@ impl Context {
let txb = self.txpool.lock().unwrap()[&txb_hash].clone();
for tx in txb.content.data.clone(){
println!("Glob state: {:?}\ncurr tx: {:?}",self.glob_state.lock().unwrap()[&tip],tx.transaction);
// println!("Glob state: {:?}\ncurr tx: {:?}",self.glob_state.lock().unwrap()[&tip],tx.transaction);
//1. Check if the transactions are signed correctly by the public keys
if verify(&tx.transaction, &tx.sig.key, &tx.sig.signature) == false{
valid = false;
......@@ -197,7 +197,7 @@ impl Context {
}
//Default: Update the global state
let mut curr_state = self.glob_state.lock().unwrap()[&block_item.header.parent].clone();
// println!("State before: {:?}",curr_state);
let mut tx_seen:HashMap<H256 ,bool> = HashMap::new();
for txb_hash in block_item.content.data.clone(){
if !self.txpool.lock().unwrap().contains_key(&txb_hash){
......@@ -206,6 +206,7 @@ impl Context {
let txb = self.txpool.lock().unwrap()[&txb_hash].clone();
for transaction in txb.content.data.clone(){
if tx_seen.contains_key(&transaction.hash()){
println!("Seen!");
continue;
}
tx_seen.insert(transaction.hash(),true);
......@@ -227,6 +228,7 @@ impl Context {
self.mempool.lock().unwrap().remove(&transaction.hash());
}
}
// println!("State after: {:?}",curr_state);
self.glob_state.lock().unwrap().insert(block_item.hash(),curr_state.clone());
// for transaction in block_item.content.data.clone(){
// println!("normal transaction removed. (Not ICO tx)");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment