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

Compute shard id start in epoch false #1867

Merged
merged 12 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions epochStart/bootstrap/fromLocalStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (e *epochStartBootstrap) initializeFromLocalStorage() {
}
}

func (e *epochStartBootstrap) prepareEpochFromStorage() (Parameters, error) {
func (e *epochStartBootstrap) getShardIDForLatestEpoch() (uint32, bool, error) {
storer, err := e.storageOpenerHandler.GetMostRecentBootstrapStorageUnit()
defer func() {
if check.IfNil(storer) {
Expand All @@ -46,26 +46,35 @@ func (e *epochStartBootstrap) prepareEpochFromStorage() (Parameters, error) {
}()

if err != nil {
return Parameters{}, err
return 0, false, err
}

_, e.nodesConfig, err = e.getLastBootstrapData(storer)
if err != nil {
return Parameters{}, err
return 0, false, err
}

pubKey, err := e.publicKey.ToByteArray()
if err != nil {
return Parameters{}, err
return 0, false, err
}

e.epochStartMeta, err = e.getEpochStartMetaFromStorage(storer)
if err != nil {
return Parameters{}, err
return 0, false, err
}
e.baseData.numberOfShards = uint32(len(e.epochStartMeta.EpochStart.LastFinalizedHeaders))

newShardId, isShuffledOut := e.checkIfShuffledOut(pubKey, e.nodesConfig)
return newShardId, isShuffledOut, nil
}

func (e *epochStartBootstrap) prepareEpochFromStorage() (Parameters, error) {
newShardId, isShuffledOut, err := e.getShardIDForLatestEpoch()
if err != nil {
return Parameters{}, err
}

err = e.createTriesComponentsForShardId(newShardId)
if err != nil {
return Parameters{}, err
Expand Down
25 changes: 21 additions & 4 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,33 @@ func (e *epochStartBootstrap) Bootstrap() (Parameters, error) {
log.Warn("fast bootstrap is disabled")

e.initializeFromLocalStorage()
if !e.baseData.storageExists {
return Parameters{
Epoch: 0,
SelfShardId: e.genesisShardCoordinator.SelfId(),
NumOfShards: e.genesisShardCoordinator.NumberOfShards(),
}, nil
}

err := e.createTriesComponentsForShardId(e.genesisShardCoordinator.SelfId())
newShardId, shuffledOut, err := e.getShardIDForLatestEpoch()
if err != nil {
return Parameters{}, err
}

err = e.createTriesComponentsForShardId(newShardId)
if err != nil {
return Parameters{}, err
}

epochToStart := e.baseData.lastEpoch
if shuffledOut {
epochToStart = 0
}

return Parameters{
Epoch: e.baseData.lastEpoch,
SelfShardId: e.genesisShardCoordinator.SelfId(),
NumOfShards: e.genesisShardCoordinator.NumberOfShards(),
Epoch: epochToStart,
SelfShardId: newShardId,
NumOfShards: e.baseData.numberOfShards,
}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bootstrap

import (
"context"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -161,6 +162,12 @@ func TestIsStartInEpochZero(t *testing.T) {
func TestEpochStartBootstrap_BootstrapStartInEpochNotEnabled(t *testing.T) {
args := createMockEpochStartBootstrapArgs()

err := errors.New("localErr")
args.LatestStorageDataProvider = &mock.LatestStorageDataProviderStub{
GetCalled: func() (storage.LatestDataFromStorage, error) {
return storage.LatestDataFromStorage{}, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended? Returning both useful data and error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not useful. It is a strict not a pointer to a struct. Only error is important for this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, is not a pointer, missed that

},
}
epochStartProvider, _ := NewEpochStartBootstrap(args)

params, err := epochStartProvider.Bootstrap()
Expand Down