forked from hyperledger-labs/minbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Any client application could behave improperly whether or not intended, so MinBFT cluster has to handle faulty client behaviors. But currently replica set processes a request only when the primary replica receives it, so any client can easily trigger view-change by sending request messages only to all backup replicas. This patch tries to solve the situation by introducing prepare timer, which is started when receiving a request message and broadcasts it to all other replicas when expired. Another existing timer, request timer, is adjusted to cover only the latter half of consensus process. Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
- Loading branch information
Naoya Horiguchi
committed
Nov 22, 2019
1 parent
d096bca
commit 588a5eb
Showing
14 changed files
with
368 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2019 NEC Solution Innovators, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package clientstate | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
"github.com/hyperledger-labs/minbft/core/internal/timer" | ||
) | ||
|
||
type prepareTimerState struct { | ||
sync.Mutex | ||
|
||
prepareTimer timer.Timer | ||
|
||
opts *options | ||
} | ||
|
||
func newPrepareTimeoutState(opts *options) *prepareTimerState { | ||
return &prepareTimerState{opts: opts} | ||
} | ||
|
||
func (s *prepareTimerState) StartPrepareTimer(forward func()) { | ||
s.Lock() | ||
defer s.Unlock() | ||
|
||
timerProvider := s.opts.timerProvider | ||
timeout := s.opts.prepareTimeout() | ||
|
||
if s.prepareTimer != nil { | ||
s.prepareTimer.Stop() | ||
} | ||
|
||
if timeout <= time.Duration(0) { | ||
return | ||
} | ||
|
||
fmt.Printf("start forward timer: timeout = %d\n", timeout) | ||
s.prepareTimer = timerProvider.AfterFunc(timeout, forward) | ||
} | ||
|
||
func (s *prepareTimerState) StopPrepareTimer() { | ||
s.Lock() | ||
defer s.Unlock() | ||
|
||
if s.prepareTimer != nil { | ||
s.prepareTimer.Stop() | ||
} | ||
} |
Oops, something went wrong.