Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2 #8

Closed
wants to merge 18 commits into from
2 changes: 1 addition & 1 deletion algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package etchash
package etchashNH

import (
"encoding/binary"
Expand Down
2 changes: 1 addition & 1 deletion compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package etchash
package etchashNH

import (
"math/big"
Expand Down
44 changes: 30 additions & 14 deletions etchash.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package etchash
package etchashNH

import (
"encoding/binary"
Expand Down Expand Up @@ -259,7 +259,7 @@ func (lru *lru) get(epoch uint64, epochLength uint64, ecip1099FBlock *uint64) (i
}

// Update the 'future item' if epoch is larger than previously seen.
if epoch < maxEpoch-1 && lru.future < nextEpoch {
if epoch < maxEpoch-1 && lru.future != nextEpoch {
log.Trace("Requiring new future etchash "+lru.what, "epoch", nextEpoch)
future = lru.new(nextEpoch, nextEpochLength)
lru.future = nextEpoch
Expand Down Expand Up @@ -462,14 +462,14 @@ func (l *Light) Verify(block Block) bool {
}

// compute() to get mixhash and result
func (l *Light) Compute(blockNum uint64, hashNoNonce common.Hash, nonce uint64) (mixDigest common.Hash, result common.Hash) {
epochLength := calcEpochLength(blockNum, l.ecip1099FBlock)
epoch := calcEpoch(blockNum, epochLength)

cache := l.getCache(blockNum)
dagSize := datasetSize(epoch)
return cache.compute(uint64(dagSize), hashNoNonce, nonce)
}
// func (l *Light) Compute(blockNum uint64, hashNoNonce common.Hash, nonce uint64) (mixDigest common.Hash, result common.Hash) {
// epochLength := calcEpochLength(blockNum, l.ecip1099FBlock)
// epoch := calcEpoch(blockNum, epochLength)
//
// cache := l.getCache(blockNum)
// dagSize := datasetSize(epoch)
// return cache.compute(uint64(dagSize), hashNoNonce, nonce)
// }

func (l *Light) getCache(blockNum uint64) *cache {
var c *cache
Expand Down Expand Up @@ -510,9 +510,12 @@ func (l *Light) getCache(blockNum uint64) *cache {
var nextEpoch = epoch + 1
var nextEpochLength = epochLength
var nextEpochBlock = nextEpoch * epochLength
if nextEpochBlock == *l.ecip1099FBlock && epochLength == epochLengthDefault {
nextEpoch = nextEpoch / 2
nextEpochLength = epochLengthECIP1099

if l.ecip1099FBlock != nil {
if nextEpochBlock == *l.ecip1099FBlock && epochLength == epochLengthDefault {
nextEpoch = nextEpoch / 2
nextEpochLength = epochLengthECIP1099
}
}

// If we just used up the future cache, or need a refresh, regenerate
Expand All @@ -530,7 +533,7 @@ func (l *Light) getCache(blockNum uint64) *cache {
return c
}

/// dataset wraps an etchash dataset with some metadata to allow easier concurrent use.
// dataset wraps an etchash dataset with some metadata to allow easier concurrent use.
type dataset struct {
epoch uint64 // Epoch for which this cache is relevant
epochLength uint64 // Epoch length (ECIP-1099)
Expand Down Expand Up @@ -768,3 +771,16 @@ func NewForTesting(ecip1099FBlock *uint64, uip1FEpoch *uint64) (*Etchash, error)
}
return &Etchash{&Light{test: true}, &Full{Dir: dir, test: true}}, nil
}

// added for NiceHash GetShareDiff
func (l *Light) computeMixDigest(blockNum uint64, hashNoNonce common.Hash, nonce uint64) (mixDigest common.Hash, result common.Hash) {
epochLength := calcEpochLength(blockNum, l.ecip1099FBlock)
epoch := calcEpoch(blockNum, epochLength)
cache := l.getCache(blockNum)
dagSize := datasetSize(epoch)
return cache.compute(uint64(dagSize), hashNoNonce, nonce)
}

func (l *Light) Compute(blockNum uint64, headerHash common.Hash, nonce uint64) (mixDigest common.Hash, result common.Hash) {
return l.computeMixDigest(blockNum, headerHash, nonce)
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/etclabscore/go-etchash
module github.com/karpusa/go-etchash

go 1.15

require (
github.com/edsrzf/mmap-go v1.0.0
github.com/ethereum/go-ethereum v1.9.24
github.com/hashicorp/golang-lru v0.5.4
golang.org/x/crypto v0.0.0-20201116153603-4be66e5b6582
github.com/ethereum/go-ethereum v1.10.3
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
)
Loading