-
Notifications
You must be signed in to change notification settings - Fork 116
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
fix(lib/grandpa): various finality fixes, improves cross-client finality #2368
Changes from 6 commits
9ccbcb5
37c3269
b9a167f
56b2c35
e6bc718
79b5749
b1c0b04
c26966b
36852ff
6ba8daa
6b2e83a
30c8bf5
1a7a620
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ package grandpa | |
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/ChainSafe/gossamer/dot/types" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
|
@@ -82,6 +83,10 @@ func (t *tracker) addCatchUpResponse(cr *CatchUpResponse) { | |
} | ||
|
||
func (t *tracker) handleBlocks() { | ||
const timeout = time.Second | ||
ticker := time.NewTicker(timeout) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case b := <-t.in: | ||
|
@@ -90,6 +95,8 @@ func (t *tracker) handleBlocks() { | |
} | ||
|
||
t.handleBlock(b) | ||
case <-ticker.C: | ||
t.handleTick() | ||
case <-t.stopped: | ||
return | ||
} | ||
|
@@ -122,3 +129,32 @@ func (t *tracker) handleBlock(b *types.Block) { | |
delete(t.commitMessages, h) | ||
} | ||
} | ||
|
||
func (t *tracker) handleTick() { | ||
t.mapLock.Lock() | ||
defer t.mapLock.Unlock() | ||
|
||
for _, vms := range t.voteMessages { | ||
for _, v := range vms { | ||
// handleMessage would never error for vote message | ||
_, err := t.handler.handleMessage(v.from, v.msg) | ||
if err != nil { | ||
logger.Debugf("failed to handle vote message %v: %s", v, err) | ||
Comment on lines
+139
to
+142
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. If this should never error, we should log it at the error level? Imo we should log at debug level if this error happens often and we don't care. 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. honestly, this will never return an error, since 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. Wellll, for now it never errors, but one could change Maybe just 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. I would suggest a |
||
} | ||
|
||
if v.msg.Round < t.handler.grandpa.state.round && v.msg.SetID == t.handler.grandpa.state.setID { | ||
delete(t.voteMessages, v.msg.Message.Hash) | ||
EclesioMeloJunior marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
for _, cm := range t.commitMessages { | ||
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. could we split these loops to run in parallel? 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. Why? Does each iteration take a significant amount of time? 🤔 |
||
_, err := t.handler.handleMessage("", cm) | ||
if err != nil { | ||
logger.Debugf("failed to handle commit message %v: %s", cm, err) | ||
continue | ||
} | ||
|
||
delete(t.commitMessages, cm.Vote.Hash) | ||
EclesioMeloJunior marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
nit: add
handleBlocksFrequency time.Duration
intracker
, and set it innewTracker
.