Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeerAuthenticationResolver #3749

Merged
merged 7 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dataRetriever/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,12 @@ var ErrNilHeartbeatPool = errors.New("nil heartbeat pool")

// ErrNotFound signals that a data is missing
var ErrNotFound = errors.New("data not found")

// ErrNilNodesCoordinator signals a nil nodes coordinator has been provided
var ErrNilNodesCoordinator = errors.New("nil nodes coordinator")

// InvalidChunkIndex signals that an invalid chunk was provided
var InvalidChunkIndex = errors.New("invalid chunk index")

// ErrInvalidNumOfPeerAuthentication signals that an invalid number of peer authentication was provided
var ErrInvalidNumOfPeerAuthentication = errors.New("invalid num of peer authentication")
7 changes: 7 additions & 0 deletions dataRetriever/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type MiniBlocksResolver interface {
// PeerAuthenticationResolver defines what a peer authentication resolver should do
type PeerAuthenticationResolver interface {
Resolver
RequestDataFromChunk(chunkIndex uint32, epoch uint32) error
RequestDataFromHashArray(hashes [][]byte, epoch uint32) error
}

Expand Down Expand Up @@ -420,3 +421,9 @@ type SelfShardIDProvider interface {
SelfId() uint32
IsInterfaceNil() bool
}

// NodesCoordinator provides Validator methods needed for the peer processing
type NodesCoordinator interface {
GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
IsInterfaceNil() bool
}
20 changes: 20 additions & 0 deletions dataRetriever/mock/nodesCoordinatorStub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mock

// NodesCoordinatorStub -
type NodesCoordinatorStub struct {
GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error)
}

// GetAllEligibleValidatorsPublicKeys -
func (nc *NodesCoordinatorStub) GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) {
if nc.GetAllEligibleValidatorsPublicKeysCalled != nil {
return nc.GetAllEligibleValidatorsPublicKeysCalled(epoch)
}

return nil, nil
}

// IsInterfaceNil -
func (nc *NodesCoordinatorStub) IsInterfaceNil() bool {
return nc == nil
}
50 changes: 27 additions & 23 deletions dataRetriever/requestData.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dataRetriever/requestData.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum RequestDataType {
NonceType = 3;
// EpochType indicates that the request data object is of type epoch
EpochType = 4;
// ChunkType indicates that the request data object is of type chunk
ChunkType = 5;
}

// RequestData holds the requested data
Expand Down
11 changes: 11 additions & 0 deletions dataRetriever/resolvers/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ func createRequestMsg(dataType dataRetriever.RequestDataType, val []byte) p2p.Me
buff, _ := marshalizer.Marshal(&dataRetriever.RequestData{Type: dataType, Value: val})
return &mock.P2PMessageMock{DataField: buff}
}

func createRequestMsgWithChunkIndex(dataType dataRetriever.RequestDataType, val []byte, epoch uint32, chunkIndex uint32) p2p.MessageP2P {
marshalizer := &mock.MarshalizerMock{}
buff, _ := marshalizer.Marshal(&dataRetriever.RequestData{
Type: dataType,
Value: val,
Epoch: epoch,
ChunkIndex: chunkIndex,
})
return &mock.P2PMessageMock{DataField: buff}
}
Loading