mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
whisper: fix unit tests
This commit is contained in:
parent
21a105a38a
commit
08fc722619
1 changed files with 6 additions and 7 deletions
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/ecies"
|
"github.com/ethereum/go-ethereum/crypto/ecies"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
@ -82,7 +81,7 @@ func (e *Envelope) Seal(options *MessageParams) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var target, bestBit int
|
var target, bestLeadingZeros int
|
||||||
if options.PoW < 0 {
|
if options.PoW < 0 {
|
||||||
// target is not set - the function should run for a period
|
// target is not set - the function should run for a period
|
||||||
// of time specified in WorkTime param. Since we can predict
|
// of time specified in WorkTime param. Since we can predict
|
||||||
|
|
@ -101,10 +100,10 @@ func (e *Envelope) Seal(options *MessageParams) error {
|
||||||
for i := 0; i < 1024; i++ {
|
for i := 0; i < 1024; i++ {
|
||||||
binary.BigEndian.PutUint64(buf[56:], nonce)
|
binary.BigEndian.PutUint64(buf[56:], nonce)
|
||||||
d := new(big.Int).SetBytes(crypto.Keccak256(buf))
|
d := new(big.Int).SetBytes(crypto.Keccak256(buf))
|
||||||
firstBit := math.FirstBitSet(d)
|
leadingZeros := 256 - d.BitLen()
|
||||||
if firstBit > bestBit {
|
if leadingZeros > bestLeadingZeros {
|
||||||
e.Nonce, bestBit = nonce, firstBit
|
e.Nonce, bestLeadingZeros = nonce, leadingZeros
|
||||||
if target > 0 && bestBit >= target {
|
if target > 0 && bestLeadingZeros >= target {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +111,7 @@ func (e *Envelope) Seal(options *MessageParams) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if target > 0 && bestBit < target {
|
if target > 0 && bestLeadingZeros < target {
|
||||||
return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime)
|
return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue