Skip to content

Commit

Permalink
move FindGuarantors to protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Mar 25, 2022
1 parent a077698 commit 3b80e9e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
3 changes: 1 addition & 2 deletions engine/access/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/onflow/flow-go/module/mempool/stdmap"
"github.com/onflow/flow-go/network"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/state/protocol/guarantor"
"github.com/onflow/flow-go/storage"
"github.com/onflow/flow-go/utils/logging"
)
Expand Down Expand Up @@ -628,7 +627,7 @@ func (e *Engine) lookupCollection(collId flow.Identifier) (bool, error) {
func (e *Engine) requestCollections(missingColls []*flow.CollectionGuarantee) {
for _, cg := range missingColls {
// TODO: move this query out of for loop?
guarantors, err := guarantor.FindGuarantors(e.state, cg)
guarantors, err := protocol.FindGuarantors(e.state, cg)
if err != nil {
e.log.Fatal().Err(err).Msgf("could not find guarantors for guarantee %v", cg.ID())
}
Expand Down
3 changes: 1 addition & 2 deletions engine/execution/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/onflow/flow-go/network"
"github.com/onflow/flow-go/state/protocol"
psEvents "github.com/onflow/flow-go/state/protocol/events"
"github.com/onflow/flow-go/state/protocol/guarantor"
"github.com/onflow/flow-go/storage"
"github.com/onflow/flow-go/utils/logging"
)
Expand Down Expand Up @@ -996,7 +995,7 @@ func (e *Engine) matchOrRequestCollections(
Hex("collection_id", logging.ID(guarantee.ID())).
Msg("requesting collection")

guarantors, err := guarantor.FindGuarantors(e.state, guarantee)
guarantors, err := protocol.FindGuarantors(e.state, guarantee)
if err != nil {
return fmt.Errorf("could not find guarantors: %w", err)
}
Expand Down
31 changes: 0 additions & 31 deletions state/protocol/guarantor/signer_indices.go

This file was deleted.

24 changes: 24 additions & 0 deletions state/protocol/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/filter"
"github.com/onflow/flow-go/module/signature"
)

// IsNodeStakedAt returns whether the node with the given ID is a valid
Expand Down Expand Up @@ -69,3 +70,26 @@ func IsSporkRootSnapshot(snapshot Snapshot) (bool, error) {
}
return true, nil
}

// FindGuarantors decodes the signer indices from the guarantee, and finds the guarantor identifiers from protocol state
func FindGuarantors(state State, guarantee *flow.CollectionGuarantee) ([]flow.Identifier, error) {
snapshot := state.AtBlockID(guarantee.ReferenceBlockID)
epochs := snapshot.Epochs()
epoch := epochs.Current()
cluster, err := epoch.ClusterByChainID(guarantee.ChainID)

if err != nil {
// protocol state must have validated the block that contains the guarantee, so the cluster
// must be found, otherwise, it's an internal error
return nil, fmt.Errorf(
"internal error retrieving collector clusters for guarantee (ReferenceBlockID: %v, ChainID: %v): %w",
guarantee.ReferenceBlockID, guarantee.ChainID, err)
}

guarantorIDs, err := signature.DecodeSignerIndicesToIdentifiers(cluster.Members().NodeIDs(), guarantee.SignerIndices)
if err != nil {
return nil, fmt.Errorf("could not decode guarantor indices: %v", err)
}

return guarantorIDs, nil
}

0 comments on commit 3b80e9e

Please sign in to comment.