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
1b98cbbf
Commit
1b98cbbf
authored
Dec 10, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved pow
parent
4082c8b6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
91 deletions
+120
-91
block_manager.go
core/block_manager.go
+5
-3
dagger.go
core/dagger.go
+0
-85
simple_pow.go
core/simple_pow.go
+1
-0
block.go
core/types/block.go
+3
-0
miner.go
miner/miner.go
+5
-3
block.go
pow/block.go
+9
-0
pow.go
pow/ezp/pow.go
+89
-0
pow.go
pow/pow.go
+8
-0
No files found.
core/block_manager.go
View file @
1b98cbbf
...
@@ -14,6 +14,8 @@ import (
...
@@ -14,6 +14,8 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/pow/ezp"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
"github.com/ethereum/go-ethereum/wire"
)
)
...
@@ -55,7 +57,7 @@ type BlockManager struct {
...
@@ -55,7 +57,7 @@ type BlockManager struct {
// non-persistent key/value memory storage
// non-persistent key/value memory storage
mem
map
[
string
]
*
big
.
Int
mem
map
[
string
]
*
big
.
Int
// Proof of work used for validating
// Proof of work used for validating
Pow
PoW
Pow
pow
.
PoW
// The ethereum manager interface
// The ethereum manager interface
eth
EthManager
eth
EthManager
// The managed states
// The managed states
...
@@ -78,7 +80,7 @@ type BlockManager struct {
...
@@ -78,7 +80,7 @@ type BlockManager struct {
func
NewBlockManager
(
ethereum
EthManager
)
*
BlockManager
{
func
NewBlockManager
(
ethereum
EthManager
)
*
BlockManager
{
sm
:=
&
BlockManager
{
sm
:=
&
BlockManager
{
mem
:
make
(
map
[
string
]
*
big
.
Int
),
mem
:
make
(
map
[
string
]
*
big
.
Int
),
Pow
:
&
EasyPow
{}
,
Pow
:
ezp
.
New
()
,
eth
:
ethereum
,
eth
:
ethereum
,
bc
:
ethereum
.
ChainManager
(),
bc
:
ethereum
.
ChainManager
(),
}
}
...
@@ -327,7 +329,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
...
@@ -327,7 +329,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
*/
*/
// Verify the nonce of the block. Return an error if it's not valid
// Verify the nonce of the block. Return an error if it's not valid
if
!
sm
.
Pow
.
Verify
(
block
.
HashNoNonce
(),
block
.
Difficulty
,
block
.
Nonce
)
{
if
!
sm
.
Pow
.
Verify
(
block
/*block.HashNoNonce(), block.Difficulty, block.Nonce*/
)
{
return
ValidationError
(
"Block's nonce is invalid (= %v)"
,
ethutil
.
Bytes2Hex
(
block
.
Nonce
))
return
ValidationError
(
"Block's nonce is invalid (= %v)"
,
ethutil
.
Bytes2Hex
(
block
.
Nonce
))
}
}
...
...
core/dagger.go
View file @
1b98cbbf
...
@@ -6,8 +6,6 @@ import (
...
@@ -6,8 +6,6 @@ import (
"math/rand"
"math/rand"
"time"
"time"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/obscuren/sha3"
"github.com/obscuren/sha3"
...
@@ -15,89 +13,6 @@ import (
...
@@ -15,89 +13,6 @@ import (
var
powlogger
=
logger
.
NewLogger
(
"POW"
)
var
powlogger
=
logger
.
NewLogger
(
"POW"
)
type
PoW
interface
{
Search
(
block
*
types
.
Block
,
stop
<-
chan
struct
{})
[]
byte
Verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
[]
byte
)
bool
GetHashrate
()
int64
Turbo
(
bool
)
}
type
EasyPow
struct
{
hash
*
big
.
Int
HashRate
int64
turbo
bool
}
func
(
pow
*
EasyPow
)
GetHashrate
()
int64
{
return
pow
.
HashRate
}
func
(
pow
*
EasyPow
)
Turbo
(
on
bool
)
{
pow
.
turbo
=
on
}
func
(
pow
*
EasyPow
)
Search
(
block
*
types
.
Block
,
stop
<-
chan
struct
{})
[]
byte
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
hash
:=
block
.
HashNoNonce
()
diff
:=
block
.
Difficulty
i
:=
int64
(
0
)
start
:=
time
.
Now
()
.
UnixNano
()
t
:=
time
.
Now
()
for
{
select
{
case
<-
stop
:
powlogger
.
Infoln
(
"Breaking from mining"
)
pow
.
HashRate
=
0
return
nil
default
:
i
++
if
time
.
Since
(
t
)
>
(
1
*
time
.
Second
)
{
elapsed
:=
time
.
Now
()
.
UnixNano
()
-
start
hashes
:=
((
float64
(
1e9
)
/
float64
(
elapsed
))
*
float64
(
i
))
/
1000
pow
.
HashRate
=
int64
(
hashes
)
powlogger
.
Infoln
(
"Hashing @"
,
pow
.
HashRate
,
"khash"
)
t
=
time
.
Now
()
}
sha
:=
crypto
.
Sha3
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
if
pow
.
Verify
(
hash
,
diff
,
sha
)
{
return
sha
}
}
if
!
pow
.
turbo
{
time
.
Sleep
(
20
*
time
.
Microsecond
)
}
}
return
nil
}
func
(
pow
*
EasyPow
)
Verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
[]
byte
)
bool
{
sha
:=
sha3
.
NewKeccak256
()
d
:=
append
(
hash
,
nonce
...
)
sha
.
Write
(
d
)
verification
:=
new
(
big
.
Int
)
.
Div
(
ethutil
.
BigPow
(
2
,
256
),
diff
)
res
:=
ethutil
.
U256
(
ethutil
.
BigD
(
sha
.
Sum
(
nil
)))
/*
fmt.Printf("hash w/o nonce %x\n", hash)
fmt.Printf("2**256 / %v = %v\n", diff, verification)
fmt.Printf("%v <= %v\n", res, verification)
fmt.Printf("vlen: %d rlen: %d\n", len(verification.Bytes()), len(res.Bytes()))
*/
return
res
.
Cmp
(
verification
)
<=
0
}
func
(
pow
*
EasyPow
)
SetHash
(
hash
*
big
.
Int
)
{
}
type
Dagger
struct
{
type
Dagger
struct
{
hash
*
big
.
Int
hash
*
big
.
Int
xn
*
big
.
Int
xn
*
big
.
Int
...
...
core/simple_pow.go
0 → 100644
View file @
1b98cbbf
package
core
core/types/block.go
View file @
1b98cbbf
...
@@ -411,3 +411,6 @@ func (self *Block) Size() ethutil.StorageSize {
...
@@ -411,3 +411,6 @@ func (self *Block) Size() ethutil.StorageSize {
func
(
self
*
Block
)
RlpData
()
interface
{}
{
func
(
self
*
Block
)
RlpData
()
interface
{}
{
return
self
.
Value
()
.
Val
return
self
.
Value
()
.
Val
}
}
// Implement pow.Block
func
(
self
*
Block
)
N
()
[]
byte
{
return
self
.
Nonce
}
miner/miner.go
View file @
1b98cbbf
...
@@ -29,6 +29,8 @@ import (
...
@@ -29,6 +29,8 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/pow/ezp"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -59,7 +61,7 @@ type Miner struct {
...
@@ -59,7 +61,7 @@ type Miner struct {
localTxs
map
[
int
]
*
LocalTx
localTxs
map
[
int
]
*
LocalTx
localTxId
int
localTxId
int
pow
core
.
PoW
pow
pow
.
PoW
quitCh
chan
struct
{}
quitCh
chan
struct
{}
powQuitCh
chan
struct
{}
powQuitCh
chan
struct
{}
...
@@ -74,7 +76,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner {
...
@@ -74,7 +76,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner {
return
&
Miner
{
return
&
Miner
{
eth
:
eth
,
eth
:
eth
,
powQuitCh
:
make
(
chan
struct
{}),
powQuitCh
:
make
(
chan
struct
{}),
pow
:
&
core
.
EasyPow
{}
,
pow
:
ezp
.
New
()
,
mining
:
false
,
mining
:
false
,
localTxs
:
make
(
map
[
int
]
*
LocalTx
),
localTxs
:
make
(
map
[
int
]
*
LocalTx
),
MinAcceptedGasPrice
:
big
.
NewInt
(
10000000000000
),
MinAcceptedGasPrice
:
big
.
NewInt
(
10000000000000
),
...
@@ -82,7 +84,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner {
...
@@ -82,7 +84,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner {
}
}
}
}
func
(
self
*
Miner
)
GetPow
()
core
.
PoW
{
func
(
self
*
Miner
)
GetPow
()
pow
.
PoW
{
return
self
.
pow
return
self
.
pow
}
}
...
...
pow/block.go
0 → 100644
View file @
1b98cbbf
package
pow
import
"math/big"
type
Block
interface
{
Diff
()
*
big
.
Int
HashNoNonce
()
[]
byte
N
()
[]
byte
}
pow/ezp/pow.go
0 → 100644
View file @
1b98cbbf
package
ezp
import
(
"math/big"
"math/rand"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/pow"
"github.com/obscuren/sha3"
)
var
powlogger
=
logger
.
NewLogger
(
"POW"
)
type
EasyPow
struct
{
hash
*
big
.
Int
HashRate
int64
turbo
bool
}
func
New
()
*
EasyPow
{
return
&
EasyPow
{}
}
func
(
pow
*
EasyPow
)
GetHashrate
()
int64
{
return
pow
.
HashRate
}
func
(
pow
*
EasyPow
)
Turbo
(
on
bool
)
{
pow
.
turbo
=
on
}
func
(
pow
*
EasyPow
)
Search
(
block
pow
.
Block
,
stop
<-
chan
struct
{})
[]
byte
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
hash
:=
block
.
HashNoNonce
()
diff
:=
block
.
Diff
()
i
:=
int64
(
0
)
start
:=
time
.
Now
()
.
UnixNano
()
t
:=
time
.
Now
()
for
{
select
{
case
<-
stop
:
powlogger
.
Infoln
(
"Breaking from mining"
)
pow
.
HashRate
=
0
return
nil
default
:
i
++
if
time
.
Since
(
t
)
>
(
1
*
time
.
Second
)
{
elapsed
:=
time
.
Now
()
.
UnixNano
()
-
start
hashes
:=
((
float64
(
1e9
)
/
float64
(
elapsed
))
*
float64
(
i
))
/
1000
pow
.
HashRate
=
int64
(
hashes
)
powlogger
.
Infoln
(
"Hashing @"
,
pow
.
HashRate
,
"khash"
)
t
=
time
.
Now
()
}
sha
:=
crypto
.
Sha3
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
if
pow
.
verify
(
hash
,
diff
,
sha
)
{
return
sha
}
}
if
!
pow
.
turbo
{
time
.
Sleep
(
20
*
time
.
Microsecond
)
}
}
return
nil
}
func
(
pow
*
EasyPow
)
verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
[]
byte
)
bool
{
sha
:=
sha3
.
NewKeccak256
()
d
:=
append
(
hash
,
nonce
...
)
sha
.
Write
(
d
)
verification
:=
new
(
big
.
Int
)
.
Div
(
ethutil
.
BigPow
(
2
,
256
),
diff
)
res
:=
ethutil
.
U256
(
ethutil
.
BigD
(
sha
.
Sum
(
nil
)))
return
res
.
Cmp
(
verification
)
<=
0
}
func
(
pow
*
EasyPow
)
Verify
(
block
pow
.
Block
)
bool
{
return
pow
.
verify
(
block
.
HashNoNonce
(),
block
.
Diff
(),
block
.
N
())
}
pow/pow.go
0 → 100644
View file @
1b98cbbf
package
pow
type
PoW
interface
{
Search
(
block
Block
,
stop
<-
chan
struct
{})
[]
byte
Verify
(
block
Block
)
bool
GetHashrate
()
int64
Turbo
(
bool
)
}
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