Introducing ethash
This commit is contained in:
12
pow/block.go
12
pow/block.go
@ -1,12 +1,20 @@
|
||||
package pow
|
||||
|
||||
import "math/big"
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type Block interface {
|
||||
Difficulty() *big.Int
|
||||
HashNoNonce() []byte
|
||||
Nonce() []byte
|
||||
Number() *big.Int
|
||||
MixDigest() []byte
|
||||
SeedHash() []byte
|
||||
NumberU64() uint64
|
||||
}
|
||||
|
||||
type ChainManager interface {
|
||||
GetBlockByNumber(uint64) *types.Block
|
||||
CurrentBlock() *types.Block
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
|
||||
resChan <- 0
|
||||
}
|
||||
|
||||
func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
|
||||
func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) {
|
||||
// TODO fix multi threading. Somehow it results in the wrong nonce
|
||||
amountOfRoutines := 1
|
||||
|
||||
@ -69,7 +69,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
|
||||
}
|
||||
}
|
||||
|
||||
return big.NewInt(res)
|
||||
return big.NewInt(res).Bytes(), nil, nil
|
||||
}
|
||||
|
||||
func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
|
||||
|
@ -1,5 +0,0 @@
|
||||
extern char *Sha3(char *, int);
|
||||
char *sha3_cgo(char *data, int l)
|
||||
{
|
||||
return Sha3(data, l);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package dash
|
||||
|
||||
/*
|
||||
char *sha3_cgo(char *, int); // Forward declaration
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
//export Sha3
|
||||
func Sha3(data []byte, l int) []byte {
|
||||
return crypto.Sha3(data)
|
||||
}
|
@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) {
|
||||
pow.turbo = on
|
||||
}
|
||||
|
||||
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
|
||||
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) ([]byte, []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
|
||||
return nil, nil, nil
|
||||
default:
|
||||
i++
|
||||
|
||||
@ -67,7 +67,7 @@ empty:
|
||||
|
||||
sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes())
|
||||
if verify(hash, diff, sha) {
|
||||
return sha
|
||||
return sha, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,8 +75,6 @@ empty:
|
||||
time.Sleep(20 * time.Microsecond)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pow *EasyPow) Verify(block pow.Block) bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package pow
|
||||
|
||||
type PoW interface {
|
||||
Search(block Block, stop <-chan struct{}) []byte
|
||||
Search(block Block, stop <-chan struct{}) ([]byte, []byte, []byte)
|
||||
Verify(block Block) bool
|
||||
GetHashrate() int64
|
||||
Turbo(bool)
|
||||
|
Reference in New Issue
Block a user