Skip to content

Commit 3302cd5

Browse files
chore: add comments and check ancestry first
1 parent 82adadb commit 3302cd5

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

dot/state/grandpa_changes.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ type pendingChangeNode struct {
137137
nodes []*pendingChangeNode
138138
}
139139

140+
// importNode method is called recursivelly until we found a node that import the pending change as one of
141+
// its children. The node which should import the pending change must be a ancestor with a
142+
// lower block number than the pending change.
140143
func (c *pendingChangeNode) importNode(blockHash common.Hash, blockNumber uint, pendingChange *pendingChange,
141144
isDescendantOf isDescendantOfFunc) (imported bool, err error) {
142145
announcingHash := c.change.announcingHeader.Hash()
@@ -145,6 +148,15 @@ func (c *pendingChangeNode) importNode(blockHash common.Hash, blockNumber uint,
145148
return false, fmt.Errorf("%w: %s", errDuplicateHashes, blockHash)
146149
}
147150

151+
isDescendant, err := isDescendantOf(announcingHash, blockHash)
152+
if err != nil {
153+
return false, fmt.Errorf("cannot check ancestry: %w", err)
154+
}
155+
156+
if !isDescendant {
157+
return false, nil
158+
}
159+
148160
if blockNumber <= c.change.announcingHeader.Number {
149161
return false, nil
150162
}
@@ -160,15 +172,6 @@ func (c *pendingChangeNode) importNode(blockHash common.Hash, blockNumber uint,
160172
}
161173
}
162174

163-
isDescendant, err := isDescendantOf(announcingHash, blockHash)
164-
if err != nil {
165-
return false, fmt.Errorf("cannot check ancestry: %w", err)
166-
}
167-
168-
if !isDescendant {
169-
return false, nil
170-
}
171-
172175
childrenNode := &pendingChangeNode{change: pendingChange}
173176
c.nodes = append(c.nodes, childrenNode)
174177
return true, nil

0 commit comments

Comments
 (0)