diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go index 3dddb69539..f6158b641c 100644 --- a/whisper/whisperv6/api.go +++ b/whisper/whisperv6/api.go @@ -118,7 +118,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32) // SetMinPow sets the minimum PoW for a message before it is accepted. func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) { - return true, api.w.SetMinimumPoW(pow) + return true, api.w.SetMinimumPoW(pow, false) } // MarkTrustedPeer marks a peer trusted. , which will allow it to send historic (expired) messages. diff --git a/whisper/whisperv6/peer_test.go b/whisper/whisperv6/peer_test.go index 39a4ab1980..d1c217da95 100644 --- a/whisper/whisperv6/peer_test.go +++ b/whisper/whisperv6/peer_test.go @@ -114,7 +114,7 @@ func initialize(t *testing.T) { for i := 0; i < NumNodes; i++ { var node TestNode node.shh = New(&DefaultConfig) - node.shh.SetMinimumPoW(0.00000001) + node.shh.SetMinimumPoW(0.00000001, true) node.shh.Start(nil) topics := make([]TopicType, 0) topics = append(topics, sharedTopic) diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index f52ee6e9ee..ad1897e802 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -181,17 +181,22 @@ func (w *Whisper) SetMaxMessageSize(size uint32) error { } // SetMinimumPoW sets the minimal PoW required by this node -func (w *Whisper) SetMinimumPoW(val float64) error { +func (w *Whisper) SetMinimumPoW(val float64, testMode bool) error { if val <= 0.0 { return fmt.Errorf("invalid PoW: %f", val) } + w.notifyPeersAboutPowRequirementChange(val) - go func() { - // allow some time before all the peers have processed the notification - time.Sleep(time.Duration(w.reactionAllowance) * time.Second) + if testMode { w.settings.Store(minPowIdx, val) - }() + } else { + go func() { + // // allow some time before all the peers have processed the notification + time.Sleep(time.Duration(w.reactionAllowance) * time.Second) + w.settings.Store(minPowIdx, val) + }() + } return nil } diff --git a/whisper/whisperv6/whisper_test.go b/whisper/whisperv6/whisper_test.go index c8f3a9ed74..009f50d3cb 100644 --- a/whisper/whisperv6/whisper_test.go +++ b/whisper/whisperv6/whisper_test.go @@ -472,8 +472,8 @@ func TestExpiry(t *testing.T) { InitSingleTest() w := New(&DefaultConfig) - w.SetMinimumPoW(0.0000001) - defer w.SetMinimumPoW(DefaultMinimumPoW) + w.SetMinimumPoW(0.0000001, true) + defer w.SetMinimumPoW(DefaultMinimumPoW, true) w.Start(nil) defer w.Stop() @@ -529,7 +529,7 @@ func TestCustomization(t *testing.T) { InitSingleTest() w := New(&DefaultConfig) - defer w.SetMinimumPoW(DefaultMinimumPoW) + defer w.SetMinimumPoW(DefaultMinimumPoW, true) defer w.SetMaxMessageSize(DefaultMaxMessageSize) w.Start(nil) defer w.Stop() @@ -563,7 +563,7 @@ func TestCustomization(t *testing.T) { t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed) } - w.SetMinimumPoW(smallPoW / 2) + w.SetMinimumPoW(smallPoW/2, true) err = w.Send(env) if err != nil { t.Fatalf("failed to send envelope with seed %d: %s.", seed, err) @@ -625,7 +625,7 @@ func TestSymmetricSendCycle(t *testing.T) { InitSingleTest() w := New(&DefaultConfig) - defer w.SetMinimumPoW(DefaultMinimumPoW) + defer w.SetMinimumPoW(DefaultMinimumPoW, true) defer w.SetMaxMessageSize(DefaultMaxMessageSize) w.Start(nil) defer w.Stop() @@ -714,7 +714,7 @@ func TestSymmetricSendWithoutAKey(t *testing.T) { InitSingleTest() w := New(&DefaultConfig) - defer w.SetMinimumPoW(DefaultMinimumPoW) + defer w.SetMinimumPoW(DefaultMinimumPoW, true) defer w.SetMaxMessageSize(DefaultMaxMessageSize) w.Start(nil) defer w.Stop() @@ -782,7 +782,7 @@ func TestSymmetricSendKeyMismatch(t *testing.T) { InitSingleTest() w := New(&DefaultConfig) - defer w.SetMinimumPoW(DefaultMinimumPoW) + defer w.SetMinimumPoW(DefaultMinimumPoW, true) defer w.SetMaxMessageSize(DefaultMaxMessageSize) w.Start(nil) defer w.Stop()