Skip to content

Commit

Permalink
Merge pull request #92 from sammy007/logfix
Browse files Browse the repository at this point in the history
Swap out glog to log15
  • Loading branch information
karalabe authored Feb 24, 2017
2 parents 214d4c0 + 548c022 commit dd61087
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/pow"
)

Expand Down Expand Up @@ -89,14 +88,14 @@ func (cache *cache) generate() {
cache.gen.Do(func() {
started := time.Now()
seedHash := makeSeedHash(cache.epoch)
glog.V(logger.Debug).Infof("Generating cache for epoch %d (%x)", cache.epoch, seedHash)
log.Debug(fmt.Sprintf("Generating cache for epoch %d (%x)", cache.epoch, seedHash))
size := C.ethash_get_cachesize(C.uint64_t(cache.epoch * epochLength))
if cache.test {
size = cacheSizeForTesting
}
cache.ptr = C.ethash_light_new_internal(size, (*C.ethash_h256_t)(unsafe.Pointer(&seedHash[0])))
runtime.SetFinalizer(cache, freeCache)
glog.V(logger.Debug).Infof("Done generating cache for epoch %d, it took %v", cache.epoch, time.Since(started))
log.Debug(fmt.Sprintf("Done generating cache for epoch %d, it took %v", cache.epoch, time.Since(started)))
})
}

Expand Down Expand Up @@ -132,7 +131,7 @@ func (l *Light) Verify(block pow.Block) bool {
// to prevent DOS attacks.
blockNum := block.NumberU64()
if blockNum >= epochLength*2048 {
glog.V(logger.Debug).Infof("block number %d too high, limit is %d", epochLength*2048)
log.Debug(fmt.Sprintf("block number %d too high, limit is %d", epochLength*2048))
return false
}

Expand All @@ -143,7 +142,7 @@ func (l *Light) Verify(block pow.Block) bool {
Ethereum protocol consensus rules here which are not in scope of Ethash
*/
if difficulty.Cmp(common.Big0) == 0 {
glog.V(logger.Debug).Infof("invalid block difficulty")
log.Debug("invalid block difficulty")
return false
}

Expand Down Expand Up @@ -198,22 +197,22 @@ func (l *Light) getCache(blockNum uint64) *cache {
evict = cache
}
}
glog.V(logger.Debug).Infof("Evicting DAG for epoch %d in favour of epoch %d", evict.epoch, epoch)
log.Debug(fmt.Sprintf("Evicting DAG for epoch %d in favour of epoch %d", evict.epoch, epoch))
delete(l.caches, evict.epoch)
}
// If we have the new DAG pre-generated, use that, otherwise create a new one
if l.future != nil && l.future.epoch == epoch {
glog.V(logger.Debug).Infof("Using pre-generated DAG for epoch %d", epoch)
log.Debug(fmt.Sprintf("Using pre-generated DAG for epoch %d", epoch))
c, l.future = l.future, nil
} else {
glog.V(logger.Debug).Infof("No pre-generated DAG available, creating new for epoch %d", epoch)
log.Debug(fmt.Sprintf("No pre-generated DAG available, creating new for epoch %d", epoch))
c = &cache{epoch: epoch, test: l.test}
}
l.caches[epoch] = c

// If we just used up the future cache, or need a refresh, regenerate
if l.future == nil || l.future.epoch <= epoch {
glog.V(logger.Debug).Infof("Pre-generating DAG for epoch %d", epoch+1)
log.Debug(fmt.Sprintf("Pre-generating DAG for epoch %d", epoch+1))
l.future = &cache{epoch: epoch + 1, test: l.test}
go l.future.generate()
}
Expand Down Expand Up @@ -256,7 +255,7 @@ func (d *dag) generate() {
if d.dir == "" {
d.dir = DefaultDir
}
glog.V(logger.Info).Infof("Generating DAG for epoch %d (size %d) (%x)", d.epoch, dagSize, seedHash)
log.Info(fmt.Sprintf("Generating DAG for epoch %d (size %d) (%x)", d.epoch, dagSize, seedHash))
// Generate a temporary cache.
// TODO: this could share the cache with Light
cache := C.ethash_light_new_internal(cacheSize, (*C.ethash_h256_t)(unsafe.Pointer(&seedHash[0])))
Expand All @@ -273,7 +272,7 @@ func (d *dag) generate() {
panic("ethash_full_new IO or memory error")
}
runtime.SetFinalizer(d, freeDAG)
glog.V(logger.Info).Infof("Done generating DAG for epoch %d, it took %v", d.epoch, time.Since(started))
log.Info(fmt.Sprintf("Done generating DAG for epoch %d, it took %v", d.epoch, time.Since(started)))
})
}

Expand All @@ -288,7 +287,7 @@ func (d *dag) Ptr() unsafe.Pointer {

//export ethashGoCallback
func ethashGoCallback(percent C.unsigned) C.int {
glog.V(logger.Info).Infof("Generating DAG: %d%%", percent)
log.Info(fmt.Sprintf("Generating DAG: %d%%", percent))
return 0
}

Expand Down

0 comments on commit dd61087

Please sign in to comment.