Repository navigation
bft: enqueue a decision when its view is aborted #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ package bft | |
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/hyperledger/SmartBFT/pkg/types" | ||
| protos "github.com/hyperledger/SmartBFT/smartbftprotos" | ||
|
|
@@ -48,6 +49,49 @@ func TestControllerDecideViewBookkeeping(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| // TestDecideDoesNotDropDecisionOnAbortedView covers the hand-off between the view | ||
| // and the controller: a view that is being aborted must not stay blocked on a full | ||
| // decision channel, but the committed decision must still reach the controller. | ||
| func TestDecideDoesNotDropDecisionOnAbortedView(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(Written by Claude Code.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| view := &View{abortChan: make(chan struct{})} | ||
| controller := &Controller{ | ||
| currView: view, | ||
| decisionChan: make(chan decision, 1), | ||
| stopChan: make(chan struct{}), | ||
| } | ||
| controller.decisionChan <- decision{proposal: types.Proposal{Payload: []byte("queued")}} | ||
|
|
||
| decided := make(chan struct{}) | ||
| go func() { | ||
| controller.Decide(types.Proposal{Payload: []byte("committed")}, nil, nil) | ||
| close(decided) | ||
| }() | ||
|
|
||
| select { | ||
| case <-decided: | ||
| t.Fatal("Decide returned before the view was aborted") | ||
| case <-time.After(50 * time.Millisecond): | ||
| } | ||
|
|
||
| view.stop() | ||
|
|
||
| select { | ||
| case <-decided: | ||
| case <-time.After(time.Second): | ||
| t.Fatal("Decide did not return after the view was aborted") | ||
| } | ||
|
|
||
| queued := <-controller.decisionChan | ||
| require.Equal(t, []byte("queued"), queued.proposal.Payload) | ||
|
|
||
| select { | ||
| case committed := <-controller.decisionChan: | ||
| require.Equal(t, []byte("committed"), committed.proposal.Payload) | ||
| case <-time.After(time.Second): | ||
| t.Fatal("the committed decision was dropped") | ||
| } | ||
| } | ||
|
|
||
| // newDecidingController returns a controller whose current view is the given view, | ||
| // and whose own ID is the leader of the current view, so that a delivered decision | ||
| // would normally acquire the leader token. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing: the deadlock in the description is the controller loop sitting in
abortViewwaiting for this view, not a long sync or delivery. Could the comment say that? Otherwise someone might think this case only matters for slow syncs.(Written by Claude Code.)