Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
32c7ebc5
Commit
32c7ebc5
authored
Feb 14, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed mining & limited hash power
parent
65159d65
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
22 deletions
+44
-22
block.go
core/types/block.go
+2
-1
receipt.go
core/types/receipt.go
+1
-1
agent.go
miner/agent.go
+11
-8
worker.go
miner/worker.go
+29
-11
pow.go
pow/ezp/pow.go
+1
-1
No files found.
core/types/block.go
View file @
32c7ebc5
...
@@ -209,6 +209,7 @@ func (self *Block) ParentHash() []byte {
...
@@ -209,6 +209,7 @@ func (self *Block) ParentHash() []byte {
func
(
self
*
Block
)
String
()
string
{
func
(
self
*
Block
)
String
()
string
{
return
fmt
.
Sprintf
(
`BLOCK(%x): Size: %v TD: %v {
return
fmt
.
Sprintf
(
`BLOCK(%x): Size: %v TD: %v {
NoNonce: %x
Header:
Header:
[
[
%v
%v
...
@@ -218,7 +219,7 @@ Transactions:
...
@@ -218,7 +219,7 @@ Transactions:
Uncles:
Uncles:
%v
%v
}
}
`
,
self
.
header
.
Hash
(),
self
.
Size
(),
self
.
Td
,
self
.
header
,
self
.
transactions
,
self
.
uncles
)
`
,
self
.
header
.
Hash
(),
self
.
Size
(),
self
.
Td
,
self
.
header
.
HashNoNonce
(),
self
.
header
,
self
.
transactions
,
self
.
uncles
)
}
}
func
(
self
*
Header
)
String
()
string
{
func
(
self
*
Header
)
String
()
string
{
...
...
core/types/receipt.go
View file @
32c7ebc5
...
@@ -17,7 +17,7 @@ type Receipt struct {
...
@@ -17,7 +17,7 @@ type Receipt struct {
}
}
func
NewReceipt
(
root
[]
byte
,
cumalativeGasUsed
*
big
.
Int
)
*
Receipt
{
func
NewReceipt
(
root
[]
byte
,
cumalativeGasUsed
*
big
.
Int
)
*
Receipt
{
return
&
Receipt
{
PostState
:
ethutil
.
CopyBytes
(
root
),
CumulativeGasUsed
:
cumalativeGasUsed
}
return
&
Receipt
{
PostState
:
ethutil
.
CopyBytes
(
root
),
CumulativeGasUsed
:
new
(
big
.
Int
)
.
Set
(
cumalativeGasUsed
)
}
}
}
func
NewRecieptFromValue
(
val
*
ethutil
.
Value
)
*
Receipt
{
func
NewRecieptFromValue
(
val
*
ethutil
.
Value
)
*
Receipt
{
...
...
miner/agent.go
View file @
32c7ebc5
...
@@ -17,32 +17,35 @@ type CpuMiner struct {
...
@@ -17,32 +17,35 @@ type CpuMiner struct {
func
NewCpuMiner
(
index
int
,
pow
pow
.
PoW
)
*
CpuMiner
{
func
NewCpuMiner
(
index
int
,
pow
pow
.
PoW
)
*
CpuMiner
{
miner
:=
&
CpuMiner
{
miner
:=
&
CpuMiner
{
c
:
make
(
chan
*
types
.
Block
,
1
),
pow
:
pow
,
quit
:
make
(
chan
struct
{}),
index
:
index
,
quitCurrentOp
:
make
(
chan
struct
{},
1
),
pow
:
pow
,
index
:
index
,
}
}
go
miner
.
update
()
return
miner
return
miner
}
}
func
(
self
*
CpuMiner
)
Work
()
chan
<-
*
types
.
Block
{
return
self
.
c
}
func
(
self
*
CpuMiner
)
Work
()
chan
<-
*
types
.
Block
{
return
self
.
c
}
func
(
self
*
CpuMiner
)
Pow
()
pow
.
PoW
{
return
self
.
pow
}
func
(
self
*
CpuMiner
)
Pow
()
pow
.
PoW
{
return
self
.
pow
}
func
(
self
*
CpuMiner
)
Set
NonceCh
(
ch
chan
<-
Work
)
{
self
.
returnCh
=
ch
}
func
(
self
*
CpuMiner
)
Set
WorkCh
(
ch
chan
<-
Work
)
{
self
.
returnCh
=
ch
}
func
(
self
*
CpuMiner
)
Stop
()
{
func
(
self
*
CpuMiner
)
Stop
()
{
close
(
self
.
quit
)
close
(
self
.
quit
)
close
(
self
.
quitCurrentOp
)
close
(
self
.
quitCurrentOp
)
}
}
func
(
self
*
CpuMiner
)
Start
()
{
self
.
quit
=
make
(
chan
struct
{})
self
.
quitCurrentOp
=
make
(
chan
struct
{},
1
)
self
.
c
=
make
(
chan
*
types
.
Block
,
1
)
go
self
.
update
()
}
func
(
self
*
CpuMiner
)
update
()
{
func
(
self
*
CpuMiner
)
update
()
{
out
:
out
:
for
{
for
{
select
{
select
{
case
block
:=
<-
self
.
c
:
case
block
:=
<-
self
.
c
:
// make sure it's open
self
.
quitCurrentOp
<-
struct
{}{}
self
.
quitCurrentOp
<-
struct
{}{}
go
self
.
mine
(
block
)
go
self
.
mine
(
block
)
...
...
miner/worker.go
View file @
32c7ebc5
...
@@ -48,8 +48,9 @@ type Work struct {
...
@@ -48,8 +48,9 @@ type Work struct {
type
Agent
interface
{
type
Agent
interface
{
Work
()
chan
<-
*
types
.
Block
Work
()
chan
<-
*
types
.
Block
Set
Nonce
Ch
(
chan
<-
Work
)
Set
Work
Ch
(
chan
<-
Work
)
Stop
()
Stop
()
Start
()
Pow
()
pow
.
PoW
Pow
()
pow
.
PoW
}
}
...
@@ -86,6 +87,11 @@ func (self *worker) start() {
...
@@ -86,6 +87,11 @@ func (self *worker) start() {
self
.
quit
=
make
(
chan
struct
{})
self
.
quit
=
make
(
chan
struct
{})
// spin up agents
for
_
,
agent
:=
range
self
.
agents
{
agent
.
Start
()
}
go
self
.
update
()
go
self
.
update
()
go
self
.
wait
()
go
self
.
wait
()
}
}
...
@@ -98,7 +104,7 @@ func (self *worker) stop() {
...
@@ -98,7 +104,7 @@ func (self *worker) stop() {
func
(
self
*
worker
)
register
(
agent
Agent
)
{
func
(
self
*
worker
)
register
(
agent
Agent
)
{
self
.
agents
=
append
(
self
.
agents
,
agent
)
self
.
agents
=
append
(
self
.
agents
,
agent
)
agent
.
Set
Nonce
Ch
(
self
.
recv
)
agent
.
Set
Work
Ch
(
self
.
recv
)
}
}
func
(
self
*
worker
)
update
()
{
func
(
self
*
worker
)
update
()
{
...
@@ -108,15 +114,17 @@ out:
...
@@ -108,15 +114,17 @@ out:
for
{
for
{
select
{
select
{
case
event
:=
<-
events
.
Chan
()
:
case
event
:=
<-
events
.
Chan
()
:
switch
event
:=
event
.
(
type
)
{
switch
event
.
(
type
)
{
case
core
.
ChainEvent
:
case
core
.
ChainEvent
:
self
.
commitNewWork
()
self
.
commitNewWork
()
case
core
.
TxPreEvent
:
case
core
.
TxPreEvent
:
if
err
:=
self
.
commitTransaction
(
event
.
Tx
);
err
!=
nil
{
self
.
commitNewWork
()
self
.
push
()
}
}
}
case
<-
self
.
quit
:
case
<-
self
.
quit
:
// stop all agents
for
_
,
agent
:=
range
self
.
agents
{
agent
.
Stop
()
}
break
out
break
out
}
}
}
}
...
@@ -131,8 +139,11 @@ func (self *worker) wait() {
...
@@ -131,8 +139,11 @@ func (self *worker) wait() {
if
block
.
Number
()
.
Uint64
()
==
work
.
Number
&&
block
.
Nonce
()
==
nil
{
if
block
.
Number
()
.
Uint64
()
==
work
.
Number
&&
block
.
Nonce
()
==
nil
{
self
.
current
.
block
.
Header
()
.
Nonce
=
work
.
Nonce
self
.
current
.
block
.
Header
()
.
Nonce
=
work
.
Nonce
self
.
chain
.
InsertChain
(
types
.
Blocks
{
self
.
current
.
block
})
if
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
self
.
current
.
block
});
err
==
nil
{
self
.
mux
.
Post
(
core
.
NewMinedBlockEvent
{
self
.
current
.
block
})
self
.
mux
.
Post
(
core
.
NewMinedBlockEvent
{
self
.
current
.
block
})
}
else
{
self
.
commitNewWork
()
}
}
}
break
break
}
}
...
@@ -141,9 +152,10 @@ func (self *worker) wait() {
...
@@ -141,9 +152,10 @@ func (self *worker) wait() {
func
(
self
*
worker
)
push
()
{
func
(
self
*
worker
)
push
()
{
if
self
.
mining
{
if
self
.
mining
{
self
.
current
.
state
.
Update
(
ethutil
.
Big0
)
self
.
current
.
block
.
Header
()
.
GasUsed
=
self
.
current
.
totalUsedGas
self
.
current
.
block
.
SetRoot
(
self
.
current
.
state
.
Root
())
self
.
current
.
block
.
SetRoot
(
self
.
current
.
state
.
Root
())
// push new work to agents
for
_
,
agent
:=
range
self
.
agents
{
for
_
,
agent
:=
range
self
.
agents
{
agent
.
Work
()
<-
self
.
current
.
block
agent
.
Work
()
<-
self
.
current
.
block
}
}
...
@@ -169,14 +181,18 @@ func (self *worker) commitNewWork() {
...
@@ -169,14 +181,18 @@ func (self *worker) commitNewWork() {
// Break on gas limit
// Break on gas limit
break
break
default
:
default
:
minerlogger
.
Infoln
(
err
)
remove
=
append
(
remove
,
tx
)
remove
=
append
(
remove
,
tx
)
}
}
if
err
!=
nil
{
minerlogger
.
Infoln
(
err
)
}
}
}
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
self
.
current
.
coinbase
.
AddAmount
(
core
.
BlockReward
)
self
.
current
.
coinbase
.
AddAmount
(
core
.
BlockReward
)
self
.
current
.
state
.
Update
(
ethutil
.
Big0
)
self
.
push
()
self
.
push
()
}
}
...
@@ -213,7 +229,9 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
...
@@ -213,7 +229,9 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
snapshot
:=
self
.
current
.
state
.
Copy
()
snapshot
:=
self
.
current
.
state
.
Copy
()
receipt
,
txGas
,
err
:=
self
.
proc
.
ApplyTransaction
(
self
.
current
.
coinbase
,
self
.
current
.
state
,
self
.
current
.
block
,
tx
,
self
.
current
.
totalUsedGas
,
true
)
receipt
,
txGas
,
err
:=
self
.
proc
.
ApplyTransaction
(
self
.
current
.
coinbase
,
self
.
current
.
state
,
self
.
current
.
block
,
tx
,
self
.
current
.
totalUsedGas
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
self
.
current
.
state
.
Set
(
snapshot
)
if
core
.
IsNonceErr
(
err
)
||
core
.
IsGasLimitErr
(
err
)
{
self
.
current
.
state
.
Set
(
snapshot
)
}
return
err
return
err
}
}
...
...
pow/ezp/pow.go
View file @
32c7ebc5
...
@@ -21,7 +21,7 @@ type EasyPow struct {
...
@@ -21,7 +21,7 @@ type EasyPow struct {
}
}
func
New
()
*
EasyPow
{
func
New
()
*
EasyPow
{
return
&
EasyPow
{
turbo
:
tru
e
}
return
&
EasyPow
{
turbo
:
fals
e
}
}
}
func
(
pow
*
EasyPow
)
GetHashrate
()
int64
{
func
(
pow
*
EasyPow
)
GetHashrate
()
int64
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment