@@ -129,9 +129,7 @@ func newGrandpaBlockImport[
129129 setID := hardFork .SetID
130130 if setID == SetID (sharedAuthoritySet .SetID ()) {
131131 authoritySet , unlock := sharedAuthoritySet .inner .DataMut ()
132- // authoritySet.mtx.Lock()
133132 authoritySet .CurrentAuthorities = hardFork .PendingChange .NextAuthorities
134- // authoritySet.mtx.Unlock()
135133 unlock ()
136134 }
137135 }
@@ -183,7 +181,7 @@ func FindScheduledChange[
183181 id := runtime .OpaqueDigestItemIDConsensus (grandpa .GrandpaEngineID )
184182
185183 filterLog := func (log grandpa.ConsensusLog ) * grandpa.ScheduledChange [N ] {
186- scheduledChange , ok := log .(grandpa.ConensusLogScheduledChange [N ])
184+ scheduledChange , ok := log .(grandpa.ConsensusLogScheduledChange [N ])
187185 if ! ok {
188186 return nil
189187 }
@@ -405,10 +403,7 @@ func (gbi *GrandpaBlockImport[H, N, Hasher, Header, E]) makeAuthoritiesChanges(
405403 // with. we use the minimum between the median and the local
406404 // best finalized block.
407405 bestFinalizedNumber := gbi .inner .Info ().FinalizedNumber
408- canonNumber := bestFinalizedNumber
409- if medianLastFinalizedNumber < bestFinalizedNumber {
410- canonNumber = medianLastFinalizedNumber
411- }
406+ canonNumber := min (medianLastFinalizedNumber , bestFinalizedNumber )
412407 canonHash , err := gbi .inner .Hash (canonNumber )
413408 if err != nil {
414409 return nil , err
@@ -536,69 +531,66 @@ func (gbi *GrandpaBlockImport[H, N, Hasher, Header, E]) importState(
536531 // Force imported state finality.
537532 block .Finalized = true
538533 importResult , err := gbi .inner .ImportBlock (block )
539- if err == nil {
540- switch importResult := importResult .(type ) {
541- case client_common.ImportResultImported :
542- aux := client_common .ImportedAux (importResult )
543- // We've just imported a new state. We trust the sync module has verified
544- // finality proofs and that the state is correct and final.
545- // So we can read the authority list and set id from the state.
546- gbi .authoritySetHardForksMtx .Lock ()
547- gbi .authoritySetHardForks = make (map [H ]PendingChange [H , N ])
548- gbi .authoritySetHardForksMtx .Unlock ()
549- authorities , err := gbi .inner .RuntimeAPI ().GrandpaAuthorities (hash )
550- if err != nil {
551- return nil , err
552- }
553- setID , err := gbi .currentSetID (hash )
554- if err != nil {
555- return nil , err
556- }
557- authoritySet , err := NewAuthoritySet [H , N ](
558- authorities ,
559- uint64 (setID ),
560- forktree .NewForkTree [H , N , PendingChange [H , N ]](),
561- []PendingChange [H , N ]{},
562- AuthoritySetChanges [N ]{},
563- )
564- if err != nil {
565- return nil , err
566- }
534+ if err != nil {
535+ return nil , err
536+ }
537+ switch importResult := importResult .(type ) {
538+ case client_common.ImportResultImported :
539+ aux := client_common .ImportedAux (importResult )
540+ // We've just imported a new state. We trust the sync module has verified
541+ // finality proofs and that the state is correct and final.
542+ // So we can read the authority list and set id from the state.
543+ gbi .authoritySetHardForksMtx .Lock ()
544+ gbi .authoritySetHardForks = make (map [H ]PendingChange [H , N ])
545+ gbi .authoritySetHardForksMtx .Unlock ()
546+ authorities , err := gbi .inner .RuntimeAPI ().GrandpaAuthorities (hash )
547+ if err != nil {
548+ return nil , err
549+ }
550+ setID , err := gbi .currentSetID (hash )
551+ if err != nil {
552+ return nil , err
553+ }
554+ authoritySet , err := NewAuthoritySet [H , N ](
555+ authorities ,
556+ uint64 (setID ),
557+ forktree .NewForkTree [H , N , PendingChange [H , N ]](),
558+ []PendingChange [H , N ]{},
559+ AuthoritySetChanges [N ]{},
560+ )
561+ if err != nil {
562+ return nil , err
563+ }
567564
568- locked := gbi .authoritySet .inner .Locked ()
569- * locked .MutRef () = authoritySet .Clone ()
570- defer locked .Unlock ()
565+ locked := gbi .authoritySet .inner .Locked ()
566+ * locked .MutRef () = authoritySet .Clone ()
567+ defer locked .Unlock ()
571568
572- err = updateAuthoritySet (
573- locked .Data (),
574- nil ,
575- func (insertions []api.KeyValue ) error {
576- return gbi .inner .InsertAux (insertions , nil )
577- },
578- )
579- if err != nil {
580- return nil , err
581- }
582- newSet := newAuthoritySet [H , N ]{
583- CanonNumber : number ,
584- CanonHash : hash ,
585- SetID : setID ,
586- Authorities : authorities ,
587- }
588- gbi .sendVoterCommands <- voterCommandChangeAuthorities [H , N ](newSet )
589- return client_common .ImportResultImported (aux ), nil
590- case client_common.ImportResultAlreadyInChain ,
591- client_common.ImportResultKnownBad ,
592- client_common.ImportResultMissingState ,
593- client_common.ImportResultUnknownParent :
594- // Ok(r) => Ok(r),
595- return importResult , nil
596- default :
597- panic ("unreachable" )
569+ err = updateAuthoritySet (
570+ locked .Data (),
571+ nil ,
572+ func (insertions []api.KeyValue ) error {
573+ return gbi .inner .InsertAux (insertions , nil )
574+ },
575+ )
576+ if err != nil {
577+ return nil , err
598578 }
599-
600- } else {
601- return nil , err
579+ newSet := newAuthoritySet [H , N ]{
580+ CanonNumber : number ,
581+ CanonHash : hash ,
582+ SetID : setID ,
583+ Authorities : authorities ,
584+ }
585+ gbi .sendVoterCommands <- voterCommandChangeAuthorities [H , N ](newSet )
586+ return client_common .ImportResultImported (aux ), nil
587+ case client_common.ImportResultAlreadyInChain ,
588+ client_common.ImportResultKnownBad ,
589+ client_common.ImportResultMissingState ,
590+ client_common.ImportResultUnknownParent :
591+ return importResult , nil
592+ default :
593+ panic ("unreachable" )
602594 }
603595}
604596
@@ -712,7 +704,6 @@ func (gbi *GrandpaBlockImport[H, N, Hasher, Header, E]) ImportBlock(
712704 importedAux .ClearJustificationRequests = true
713705
714706 case importAppliedChangesStandard :
715- // this is a standard change, we don't apply it yet, but we will send a
716707 // we can't apply this change yet since there are other dependent changes that we
717708 // need to apply first, drop any justification that might have been provided with
718709 // the block to make sure we request them from `sync` which will ensure they'll be
0 commit comments