Skip to content

Commit 8100cbe

Browse files
committed
change order of checks and run gofmt
Signed-off-by: Hagar Meir <[email protected]>
1 parent 83aa522 commit 8100cbe

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

internal/bft/controller.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ type Future interface {
7878

7979
type Controller struct {
8080
// configuration
81-
ID uint64
82-
N uint64
83-
RequestPool RequestPool
84-
Batcher Batcher
85-
Verifier Verifier
86-
Logger Logger
87-
Assembler Assembler
88-
Application Application
89-
FailureDetector FailureDetector
90-
Synchronizer Synchronizer
91-
Comm Comm
92-
Signer Signer
81+
ID uint64
82+
N uint64
83+
RequestPool RequestPool
84+
Batcher Batcher
85+
Verifier Verifier
86+
Logger Logger
87+
Assembler Assembler
88+
Application Application
89+
FailureDetector FailureDetector
90+
Synchronizer Synchronizer
91+
Comm Comm
92+
Signer Signer
9393
RequestInspector RequestInspector
9494

9595
quorum int

internal/bft/requestpool.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func (rp *RequestPool) Submit(request []byte) error {
5454
}
5555
rp.lock.Lock()
5656
defer rp.lock.Unlock()
57-
existStr := fmt.Sprintf("%v~%v",reqInfo.ClientID, reqInfo.ID)
58-
if _, exist := rp.existMap[existStr] ; exist{
57+
existStr := fmt.Sprintf("%v~%v", reqInfo.ClientID, reqInfo.ID)
58+
if _, exist := rp.existMap[existStr]; exist {
5959
rp.semaphore.Release(1)
6060
err := fmt.Sprintf("a request with ID %v and client ID %v already exists in the pool", reqInfo.ID, reqInfo.ClientID)
6161
rp.Log.Errorf(err)
@@ -80,20 +80,21 @@ func (rp *RequestPool) NextRequests(n int) []Request {
8080
func (rp *RequestPool) RemoveRequest(request Request) error {
8181
rp.lock.Lock()
8282
defer rp.lock.Unlock()
83-
existStr := fmt.Sprintf("%v~%v",request.ClientID, request.ID)
84-
if _, exist := rp.existMap[existStr] ; exist {
85-
for i, existingReq := range rp.queue {
86-
if existingReq.ClientID == request.ClientID && existingReq.ID == request.ID {
87-
rp.Log.Infof("Removed request %v from request pool", request)
88-
rp.queue = append(rp.queue[:i], rp.queue[i+1:]...)
89-
delete(rp.existMap, existStr)
90-
rp.semaphore.Release(1)
91-
return nil
92-
}
83+
existStr := fmt.Sprintf("%v~%v", request.ClientID, request.ID)
84+
if _, exist := rp.existMap[existStr]; !exist {
85+
err := fmt.Sprintf("Request %v is not in the pool at remove time", request)
86+
rp.Log.Warnf(err)
87+
return fmt.Errorf(err)
88+
}
89+
for i, existingReq := range rp.queue {
90+
if existingReq.ClientID != request.ClientID || existingReq.ID != request.ID {
91+
continue
9392
}
93+
rp.Log.Infof("Removed request %v from request pool", request)
94+
rp.queue = append(rp.queue[:i], rp.queue[i+1:]...)
95+
delete(rp.existMap, existStr)
96+
rp.semaphore.Release(1)
97+
return nil
9498
}
95-
err := fmt.Sprintf("Request %v is not in the pool at remove time", request)
96-
rp.Log.Warnf(err)
97-
return fmt.Errorf(err)
98-
99+
panic("RemoveRequest should have returned earlier")
99100
}

0 commit comments

Comments
 (0)