Skip to content

Commit

Permalink
revert to previous impl of AuthoritySetChangeID
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Dec 11, 2023
1 parent d91434f commit 7bfdf68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
26 changes: 13 additions & 13 deletions client/consensus/grandpa/authorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
12 changes: 5 additions & 7 deletions client/consensus/grandpa/finality_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -64,23 +63,22 @@ 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,
}
}

// 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
Expand All @@ -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 {
Expand Down

0 comments on commit 7bfdf68

Please sign in to comment.