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
26de12d9
Commit
26de12d9
authored
10 years ago
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed nonce to a uint64
parent
e9f1e868
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
30 additions
and
25 deletions
+30
-25
block_processor.go
core/block_processor.go
+2
-2
chain_makers.go
core/chain_makers.go
+3
-3
chain_manager.go
core/chain_manager.go
+1
-1
genesis.go
core/genesis.go
+1
-1
block.go
core/types/block.go
+5
-5
agent.go
miner/agent.go
+1
-1
worker.go
miner/worker.go
+3
-3
block.go
pow/block.go
+3
-2
pow.go
pow/ezp/pow.go
+10
-6
pow.go
pow/pow.go
+1
-1
No files found.
core/block_processor.go
View file @
26de12d9
...
...
@@ -277,7 +277,7 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
// Verify the nonce of the block. Return an error if it's not valid
if
!
sm
.
Pow
.
Verify
(
block
)
{
return
ValidationError
(
"Block's nonce is invalid (= %
v)"
,
ethutil
.
Bytes2Hex
(
block
.
Header
()
.
Nonce
)
)
return
ValidationError
(
"Block's nonce is invalid (= %
x)"
,
block
.
Header
()
.
Nonce
)
}
return
nil
...
...
@@ -305,7 +305,7 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
}
if
!
sm
.
Pow
.
Verify
(
types
.
NewBlockWithHeader
(
uncle
))
{
return
ValidationError
(
"Uncle's nonce is invalid (= %
v)"
,
ethutil
.
Bytes2Hex
(
uncle
.
Nonce
)
)
return
ValidationError
(
"Uncle's nonce is invalid (= %
x)"
,
uncle
.
Nonce
)
}
r
:=
new
(
big
.
Int
)
...
...
This diff is collapsed.
Click to expand it.
core/chain_makers.go
View file @
26de12d9
...
...
@@ -14,8 +14,8 @@ import (
// So we can generate blocks easily
type
FakePow
struct
{}
func
(
f
FakePow
)
Search
(
block
pow
.
Block
,
stop
<-
chan
struct
{})
(
[]
byte
,
[]
byte
,
[]
byte
)
{
return
nil
,
nil
,
nil
func
(
f
FakePow
)
Search
(
block
pow
.
Block
,
stop
<-
chan
struct
{})
(
uint64
,
[]
byte
,
[]
byte
)
{
return
0
,
nil
,
nil
}
func
(
f
FakePow
)
Verify
(
block
pow
.
Block
)
bool
{
return
true
}
func
(
f
FakePow
)
GetHashrate
()
int64
{
return
0
}
...
...
@@ -55,7 +55,7 @@ func NewCanonical(n int, db ethutil.Database) (*BlockProcessor, error) {
// block time is fixed at 10 seconds
func
newBlockFromParent
(
addr
[]
byte
,
parent
*
types
.
Block
)
*
types
.
Block
{
block
:=
types
.
NewBlock
(
parent
.
Hash
(),
addr
,
parent
.
Root
(),
ethutil
.
BigPow
(
2
,
32
),
nil
,
""
)
block
:=
types
.
NewBlock
(
parent
.
Hash
(),
addr
,
parent
.
Root
(),
ethutil
.
BigPow
(
2
,
32
),
0
,
""
)
block
.
SetUncles
(
nil
)
block
.
SetTransactions
(
nil
)
block
.
SetReceipts
(
nil
)
...
...
This diff is collapsed.
Click to expand it.
core/chain_manager.go
View file @
26de12d9
...
...
@@ -197,7 +197,7 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
coinbase
,
root
,
ethutil
.
BigPow
(
2
,
32
),
nil
,
0
,
""
)
block
.
SetUncles
(
nil
)
block
.
SetTransactions
(
nil
)
...
...
This diff is collapsed.
Click to expand it.
core/genesis.go
View file @
26de12d9
...
...
@@ -23,7 +23,7 @@ var EmptyShaList = crypto.Sha3(ethutil.Encode([]interface{}{}))
var
EmptyListRoot
=
crypto
.
Sha3
(
ethutil
.
Encode
(
""
))
func
GenesisBlock
(
db
ethutil
.
Database
)
*
types
.
Block
{
genesis
:=
types
.
NewBlock
(
ZeroHash256
,
ZeroHash160
,
nil
,
big
.
NewInt
(
131072
),
crypto
.
Sha3
(
big
.
NewInt
(
42
)
.
Bytes
())
,
""
)
genesis
:=
types
.
NewBlock
(
ZeroHash256
,
ZeroHash160
,
nil
,
big
.
NewInt
(
131072
),
42
,
""
)
genesis
.
Header
()
.
Number
=
ethutil
.
Big0
genesis
.
Header
()
.
GasLimit
=
big
.
NewInt
(
1000000
)
genesis
.
Header
()
.
GasUsed
=
ethutil
.
Big0
...
...
This diff is collapsed.
Click to expand it.
core/types/block.go
View file @
26de12d9
...
...
@@ -39,8 +39,8 @@ type Header struct {
Time
uint64
// Extra data
Extra
string
//
Block Nonce for verification
Nonce
ethutil
.
Bytes
//
Nonce
Nonce
uint64
// Mix digest for quick checking to prevent DOS
MixDigest
ethutil
.
Bytes
// SeedHash used for light client verification
...
...
@@ -94,7 +94,7 @@ type Block struct {
Reward
*
big
.
Int
}
func
NewBlock
(
parentHash
[]
byte
,
coinbase
[]
byte
,
root
[]
byte
,
difficulty
*
big
.
Int
,
nonce
[]
byte
,
extra
string
)
*
Block
{
func
NewBlock
(
parentHash
[]
byte
,
coinbase
[]
byte
,
root
[]
byte
,
difficulty
*
big
.
Int
,
nonce
uint64
,
extra
string
)
*
Block
{
header
:=
&
Header
{
Root
:
root
,
ParentHash
:
parentHash
,
...
...
@@ -195,7 +195,7 @@ func (self *Block) Number() *big.Int { return self.header.Number }
func
(
self
*
Block
)
NumberU64
()
uint64
{
return
self
.
header
.
Number
.
Uint64
()
}
func
(
self
*
Block
)
MixDigest
()
[]
byte
{
return
self
.
header
.
MixDigest
}
func
(
self
*
Block
)
SeedHash
()
[]
byte
{
return
self
.
header
.
SeedHash
}
func
(
self
*
Block
)
Nonce
()
[]
byte
{
return
self
.
header
.
Nonce
}
func
(
self
*
Block
)
Nonce
()
uint64
{
return
self
.
header
.
Nonce
}
func
(
self
*
Block
)
Bloom
()
[]
byte
{
return
self
.
header
.
Bloom
}
func
(
self
*
Block
)
Coinbase
()
[]
byte
{
return
self
.
header
.
Coinbase
}
func
(
self
*
Block
)
Time
()
int64
{
return
int64
(
self
.
header
.
Time
)
}
...
...
@@ -267,7 +267,7 @@ func (self *Header) String() string {
GasUsed: %v
Time: %v
Extra: %v
Nonce: %
x
Nonce: %
d
MixDigest: %x
SeedHash: %x
...
...
This diff is collapsed.
Click to expand it.
miner/agent.go
View file @
26de12d9
...
...
@@ -75,7 +75,7 @@ done:
func
(
self
*
CpuMiner
)
mine
(
block
*
types
.
Block
)
{
minerlogger
.
Infof
(
"(re)started agent[%d]. mining...
\n
"
,
self
.
index
)
nonce
,
mixDigest
,
seedHash
:=
self
.
pow
.
Search
(
block
,
self
.
quitCurrentOp
)
if
nonce
!=
nil
{
if
nonce
!=
0
{
self
.
returnCh
<-
Work
{
block
.
Number
()
.
Uint64
(),
nonce
,
mixDigest
,
seedHash
}
}
}
This diff is collapsed.
Click to expand it.
miner/worker.go
View file @
26de12d9
...
...
@@ -47,7 +47,7 @@ func env(block *types.Block, eth core.Backend) *environment {
type
Work
struct
{
Number
uint64
Nonce
[]
byte
Nonce
uint64
MixDigest
[]
byte
SeedHash
[]
byte
}
...
...
@@ -150,7 +150,7 @@ func (self *worker) wait() {
for
work
:=
range
self
.
recv
{
// Someone Successfully Mined!
block
:=
self
.
current
.
block
if
block
.
Number
()
.
Uint64
()
==
work
.
Number
&&
block
.
Nonce
()
==
nil
{
if
block
.
Number
()
.
Uint64
()
==
work
.
Number
&&
block
.
Nonce
()
==
0
{
self
.
current
.
block
.
Header
()
.
Nonce
=
work
.
Nonce
self
.
current
.
block
.
Header
()
.
MixDigest
=
work
.
MixDigest
self
.
current
.
block
.
Header
()
.
SeedHash
=
work
.
SeedHash
...
...
@@ -242,7 +242,7 @@ func (self *worker) commitUncle(uncle *types.Header) error {
}
if
!
self
.
pow
.
Verify
(
types
.
NewBlockWithHeader
(
uncle
))
{
return
core
.
ValidationError
(
"Uncle's nonce is invalid (= %
v)"
,
ethutil
.
Bytes2Hex
(
uncle
.
Nonce
)
)
return
core
.
ValidationError
(
"Uncle's nonce is invalid (= %
x)"
,
uncle
.
Nonce
)
}
uncleAccount
:=
self
.
current
.
state
.
GetAccount
(
uncle
.
Coinbase
)
...
...
This diff is collapsed.
Click to expand it.
pow/block.go
View file @
26de12d9
package
pow
import
(
"github.com/ethereum/go-ethereum/core/types"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
)
type
Block
interface
{
Difficulty
()
*
big
.
Int
HashNoNonce
()
[]
byte
Nonce
()
[]
byte
Nonce
()
uint64
MixDigest
()
[]
byte
SeedHash
()
[]
byte
NumberU64
()
uint64
...
...
This diff is collapsed.
Click to expand it.
pow/ezp/pow.go
View file @
26de12d9
package
ezp
import
(
"encoding/binary"
"math/big"
"math/rand"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
...
...
@@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) {
pow
.
turbo
=
on
}
func
(
pow
*
EasyPow
)
Search
(
block
pow
.
Block
,
stop
<-
chan
struct
{})
(
[]
byte
,
[]
byte
,
[]
byte
)
{
func
(
pow
*
EasyPow
)
Search
(
block
pow
.
Block
,
stop
<-
chan
struct
{})
(
uint64
,
[]
byte
,
[]
byte
)
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
hash
:=
block
.
HashNoNonce
()
diff
:=
block
.
Difficulty
()
...
...
@@ -57,7 +57,7 @@ empty:
for
{
select
{
case
<-
stop
:
return
nil
,
nil
,
nil
return
0
,
nil
,
nil
default
:
i
++
...
...
@@ -65,7 +65,7 @@ empty:
hashes
:=
((
float64
(
1e9
)
/
float64
(
elapsed
))
*
float64
(
i
-
starti
))
/
1000
pow
.
HashRate
=
int64
(
hashes
)
sha
:=
crypto
.
Sha3
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
sha
:=
uint64
(
r
.
Int63
())
if
verify
(
hash
,
diff
,
sha
)
{
return
sha
,
nil
,
nil
}
...
...
@@ -75,16 +75,20 @@ empty:
time
.
Sleep
(
20
*
time
.
Microsecond
)
}
}
return
0
,
nil
,
nil
}
func
(
pow
*
EasyPow
)
Verify
(
block
pow
.
Block
)
bool
{
return
Verify
(
block
)
}
func
verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
[]
byte
)
bool
{
func
verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
uint64
)
bool
{
sha
:=
sha3
.
NewKeccak256
()
d
:=
append
(
hash
,
nonce
...
)
n
:=
make
([]
byte
,
8
)
binary
.
PutUvarint
(
n
,
nonce
)
d
:=
append
(
hash
,
n
...
)
sha
.
Write
(
d
)
verification
:=
new
(
big
.
Int
)
.
Div
(
ethutil
.
BigPow
(
2
,
256
),
diff
)
...
...
This diff is collapsed.
Click to expand it.
pow/pow.go
View file @
26de12d9
package
pow
type
PoW
interface
{
Search
(
block
Block
,
stop
<-
chan
struct
{})
(
[]
byte
,
[]
byte
,
[]
byte
)
Search
(
block
Block
,
stop
<-
chan
struct
{})
(
uint64
,
[]
byte
,
[]
byte
)
Verify
(
block
Block
)
bool
GetHashrate
()
int64
Turbo
(
bool
)
...
...
This diff is collapsed.
Click to expand it.
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