aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2018-02-09 23:25:03 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-02-09 23:25:03 +0800
commitccf808353794f835422e02446384bd627f045f1a (patch)
tree100340f6779d0f6056ae64cccd16b722e22fe20c /whisper
parentc4712bf96bc1bae4a5ad4600e9719e4a74bde7d5 (diff)
downloaddexon-ccf808353794f835422e02446384bd627f045f1a.tar
dexon-ccf808353794f835422e02446384bd627f045f1a.tar.gz
dexon-ccf808353794f835422e02446384bd627f045f1a.tar.bz2
dexon-ccf808353794f835422e02446384bd627f045f1a.tar.lz
dexon-ccf808353794f835422e02446384bd627f045f1a.tar.xz
dexon-ccf808353794f835422e02446384bd627f045f1a.tar.zst
dexon-ccf808353794f835422e02446384bd627f045f1a.zip
whisper: Seal function fixed (#16048)
Diffstat (limited to 'whisper')
-rw-r--r--whisper/whisperv6/envelope.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go
index 881945e9a..c7bea2bb9 100644
--- a/whisper/whisperv6/envelope.go
+++ b/whisper/whisperv6/envelope.go
@@ -77,15 +77,19 @@ func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage) *Envelope {
// Seal closes the envelope by spending the requested amount of time as a proof
// of work on hashing the data.
func (e *Envelope) Seal(options *MessageParams) error {
- var target, bestBit int
if options.PoW == 0 {
- // adjust for the duration of Seal() execution only if execution time is predefined unconditionally
+ // PoW is not required
+ return nil
+ }
+
+ var target, bestBit int
+ if options.PoW < 0 {
+ // target is not set - the function should run for a period
+ // of time specified in WorkTime param. Since we can predict
+ // the execution time, we can also adjust Expiry.
e.Expiry += options.WorkTime
} else {
target = e.powToFirstBit(options.PoW)
- if target < 1 {
- target = 1
- }
}
buf := make([]byte, 64)
@@ -143,7 +147,11 @@ func (e *Envelope) powToFirstBit(pow float64) int {
x *= float64(e.TTL)
bits := gmath.Log2(x)
bits = gmath.Ceil(bits)
- return int(bits)
+ res := int(bits)
+ if res < 1 {
+ res = 1
+ }
+ return res
}
// Hash returns the SHA3 hash of the envelope, calculating it if not yet done.