Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ece598pv-sp2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ttang13
ece598pv-sp2020
Commits
6b6e1375
Commit
6b6e1375
authored
4 years ago
by
Cardy Tang
Browse files
Options
Downloads
Patches
Plain Diff
still buggy
parent
057d2c93
Branches
master
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/generator.rs
+5
-3
5 additions, 3 deletions
src/generator.rs
src/miner.rs
+20
-3
20 additions, 3 deletions
src/miner.rs
src/network/worker.rs
+4
-2
4 additions, 2 deletions
src/network/worker.rs
with
29 additions
and
8 deletions
src/generator.rs
+
5
−
3
View file @
6b6e1375
...
...
@@ -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
()]));
}
...
...
This diff is collapsed.
Click to expand it.
src/miner.rs
+
20
−
3
View file @
6b6e1375
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
src/network/worker.rs
+
4
−
2
View file @
6b6e1375
...
...
@@ -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: {:?}
\n
curr 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)");
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment