From 7bfdf68896e8d9bf15047269f31cdbe01c50f1da Mon Sep 17 00:00:00 2001 From: jimboj Date: Mon, 11 Dec 2023 13:00:23 -0700 Subject: [PATCH] revert to previous impl of AuthoritySetChangeID --- client/consensus/grandpa/authorities.go | 26 +++++++++++----------- client/consensus/grandpa/finality_proof.go | 12 +++++----- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/client/consensus/grandpa/authorities.go b/client/consensus/grandpa/authorities.go index 77ccf4d8819..f83497f9444 100644 --- a/client/consensus/grandpa/authorities.go +++ b/client/consensus/grandpa/authorities.go @@ -704,24 +704,24 @@ func (asc *AuthoritySetChanges[N]) append(setID uint64, blockNumber N) { }) } -type authoritySetChangeID any - -type authoritySetChangeIDs[N constraints.Unsigned] interface { - authoritySetChangeIDLatest | authoritySetChangeIDSet[N] | authoritySetChangeIDUnknown -} - -func newAuthoritySetID[N constraints.Unsigned, ID authoritySetChangeIDs[N]](authSetChangeID ID) authoritySetChangeID { - return authoritySetChangeID(authSetChangeID) +type authoritySetChangeID interface { + isAuthoritySetChangeID() } type authoritySetChangeIDLatest struct{} +func (authoritySetChangeIDLatest) isAuthoritySetChangeID() {} + type authoritySetChangeIDSet[N constraints.Unsigned] struct { inner setIDNumber[N] } +func (authoritySetChangeIDSet[N]) isAuthoritySetChangeID() {} + type authoritySetChangeIDUnknown struct{} +func (authoritySetChangeIDUnknown) isAuthoritySetChangeID() {} + // Three states that can be returned: Latest, Set (tuple), Unknown func (asc *AuthoritySetChanges[N]) getSetID(blockNumber N) (authoritySetChangeID, error) { if asc == nil { @@ -730,7 +730,7 @@ func (asc *AuthoritySetChanges[N]) getSetID(blockNumber N) (authoritySetChangeID authSet := *asc last := authSet[len(authSet)-1] if last.BlockNumber < blockNumber { - return newAuthoritySetID[N](authoritySetChangeIDLatest{}), nil + return authoritySetChangeIDLatest{}, nil } idx, _ := slices.BinarySearchFunc( @@ -754,15 +754,15 @@ func (asc *AuthoritySetChanges[N]) getSetID(blockNumber N) (authoritySetChangeID // if this is the first index but not the first set id then we are missing data. if idx == 0 && authChange.SetID != 0 { - return newAuthoritySetID[N](authoritySetChangeIDUnknown{}), nil + return authoritySetChangeIDUnknown{}, nil } - return newAuthoritySetID[N](authoritySetChangeIDSet[N]{ + return authoritySetChangeIDSet[N]{ authChange, - }), nil + }, nil } - return newAuthoritySetID[N](authoritySetChangeIDUnknown{}), nil + return authoritySetChangeIDUnknown{}, nil } func (asc *AuthoritySetChanges[N]) insert(blockNumber N) { diff --git a/client/consensus/grandpa/finality_proof.go b/client/consensus/grandpa/finality_proof.go index 73590367106..8a8438616cb 100644 --- a/client/consensus/grandpa/finality_proof.go +++ b/client/consensus/grandpa/finality_proof.go @@ -45,14 +45,13 @@ type FinalityProofProvider[ BE Backend[Hash, N, H, B], Hash constraints.Ordered, N constraints.Unsigned, - AuthID AuthorityID, S comparable, ID AuthorityID, H Header[Hash, N], B BlockchainBackend[Hash, N, H], ] struct { backend BE - sharedAuthoritySet *SharedAuthoritySet[Hash, N, AuthID] + sharedAuthoritySet *SharedAuthoritySet[Hash, N, ID] } // NewFinalityProofProvider Create new finality proof provider using: @@ -64,15 +63,14 @@ func NewFinalityProofProvider[ BE Backend[Hash, N, H, B], Hash constraints.Ordered, N constraints.Unsigned, - AuthID AuthorityID, S comparable, ID AuthorityID, H Header[Hash, N], B BlockchainBackend[Hash, N, H], ]( backend BE, - sharedAuthSet *SharedAuthoritySet[Hash, N, AuthID]) *FinalityProofProvider[BE, Hash, N, AuthID, S, ID, H, B] { - return &FinalityProofProvider[BE, Hash, N, AuthID, S, ID, H, B]{ + sharedAuthSet *SharedAuthoritySet[Hash, N, ID]) *FinalityProofProvider[BE, Hash, N, S, ID, H, B] { + return &FinalityProofProvider[BE, Hash, N, S, ID, H, B]{ backend: backend, sharedAuthoritySet: sharedAuthSet, } @@ -80,7 +78,7 @@ func NewFinalityProofProvider[ // ProveFinality Prove finality for the given block number by returning a Justification for the last block of // the authority set in bytes. -func (provider FinalityProofProvider[BE, H, N, AuthID, S, ID, Header, B]) ProveFinality(block N) (*[]byte, error) { +func (provider FinalityProofProvider[BE, H, N, S, ID, Header, B]) ProveFinality(block N) (*[]byte, error) { proof, err := provider.proveFinalityProof(block, true) if err != nil { return nil, err @@ -102,7 +100,7 @@ func (provider FinalityProofProvider[BE, H, N, AuthID, S, ID, Header, B]) ProveF // // If `collect_unknown_headers` is true, the finality proof will include all headers from the // requested block until the block the justification refers to. -func (provider FinalityProofProvider[BE, Hash, N, AuthID, S, ID, H, B]) proveFinalityProof( +func (provider FinalityProofProvider[BE, Hash, N, S, ID, H, B]) proveFinalityProof( block N, collectUnknownHeaders bool) (*FinalityProof[Hash, N, H], error) { if provider.sharedAuthoritySet == nil {