Skip to content

Commit

Permalink
client(consensus/grandpa): implement grandpa justification logic (#3454)
Browse files Browse the repository at this point in the history
Co-authored-by: Timothy Wu <[email protected]>
  • Loading branch information
jimjbrettj and timwu20 authored Nov 6, 2023
1 parent 8455e8d commit 3396fa8
Show file tree
Hide file tree
Showing 15 changed files with 1,398 additions and 320 deletions.
14 changes: 7 additions & 7 deletions client/consensus/grandpa/authorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type hashNumber[H, N any] struct {
number N
}

// medianAuthoritySet represents the median and new set when a forced hashNumber has occurred
type medianAuthoritySet[H comparable, N constraints.Unsigned, ID AuthorityID] struct {
// appliedChanges represents the median and new set when a forced change has occurred
type appliedChanges[H comparable, N constraints.Unsigned, ID AuthorityID] struct {
median N
set AuthoritySet[H, N, ID]
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (sas *SharedAuthoritySet[H, N, ID]) currentLimit(min N) (limit *N) { //noli
func (sas *SharedAuthoritySet[H, N, ID]) applyForcedChanges(bestHash H, //nolint //skipcq: SCC-U1000
bestNumber N,
isDescendentOf IsDescendentOf[H],
telemetry *Telemetry) (newSet *medianAuthoritySet[H, N, ID], err error) {
telemetry *Telemetry) (newSet *appliedChanges[H, N, ID], err error) {
sas.mtx.Lock()
defer sas.mtx.Unlock()
return sas.inner.applyForcedChanges(bestHash, bestNumber, isDescendentOf, telemetry)
Expand Down Expand Up @@ -481,7 +481,7 @@ func (authSet *AuthoritySet[H, N, ID]) currentLimit(min N) (limit *N) {
func (authSet *AuthoritySet[H, N, ID]) applyForcedChanges(bestHash H, //skipcq: RVV-B0001
bestNumber N,
isDescendentOf IsDescendentOf[H],
_ Telemetry) (newSet *medianAuthoritySet[H, N, ID], err error) {
_ Telemetry) (newSet *appliedChanges[H, N, ID], err error) {

for _, change := range authSet.PendingForcedChanges {
effectiveNumber := change.EffectiveNumber()
Expand Down Expand Up @@ -516,14 +516,14 @@ func (authSet *AuthoritySet[H, N, ID]) applyForcedChanges(bestHash H, //skipcq:
}
}

// apply this hashNumber: make the set canonical
logger.Infof("👴 Applying authority set hashNumber forced at block #%d", change.CanonHeight)
// apply this change: make the set canonical
logger.Infof("👴 Applying authority set change forced at block #%d", change.CanonHeight)

// TODO telemetry

authSetChanges := authSet.AuthoritySetChanges
authSetChanges.append(authSet.SetID, medianLastFinalized)
newSet = &medianAuthoritySet[H, N, ID]{
newSet = &appliedChanges[H, N, ID]{
medianLastFinalized,
AuthoritySet[H, N, ID]{
CurrentAuthorities: change.NextAuthorities,
Expand Down
Loading

0 comments on commit 3396fa8

Please sign in to comment.