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

fix(dot/digest): verify if next epoch already contains some definition #2472

Merged
merged 22 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
18bf1d7
fix: verify if next epoch already contains some definition
EclesioMeloJunior Apr 7, 2022
5ca05d0
chore: upgrade mockery version
EclesioMeloJunior Apr 7, 2022
44c3892
chore: remove duplicated code with generics
EclesioMeloJunior Apr 7, 2022
d69c694
chore: improve test comment
EclesioMeloJunior Apr 7, 2022
27bd2e8
chore: improve test comment
EclesioMeloJunior Apr 7, 2022
bbddab4
chore: improve test comment
EclesioMeloJunior Apr 7, 2022
71309cf
chore: improve test comment
EclesioMeloJunior Apr 7, 2022
58edb99
chore: remove the go:generate from the `EpochState`'s comment
EclesioMeloJunior Apr 7, 2022
47c8836
chore: use functions to define mocks in the test cases
EclesioMeloJunior Apr 8, 2022
931e8a0
chore: split into two different functions and check for existence bef…
EclesioMeloJunior Apr 12, 2022
73e3c33
chore: fix the ci lint warns
EclesioMeloJunior Apr 12, 2022
38ddcaa
chore: use a more descriptive name
EclesioMeloJunior Apr 12, 2022
dfd06d2
chore: unexport `Data` field on epoch_test.go
EclesioMeloJunior Apr 13, 2022
89a119f
chore: addressing last nits
EclesioMeloJunior Apr 13, 2022
f4cc36a
chore: rename to a better name
EclesioMeloJunior Apr 13, 2022
71ee157
chore: fix comments
EclesioMeloJunior Apr 13, 2022
cdd29ea
chore: addressing comments
EclesioMeloJunior Apr 13, 2022
d231f5a
Merge branch 'development' into eclesio/babe-check-already-persisted
EclesioMeloJunior Apr 13, 2022
16f35dc
chore: update mockery verison
EclesioMeloJunior Apr 13, 2022
1149c1f
chore: update devnet mocks as well
EclesioMeloJunior Apr 13, 2022
ac0bdd4
chore: improve comments
EclesioMeloJunior Apr 14, 2022
1fd682d
chore: improve comments
EclesioMeloJunior Apr 14, 2022
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
2 changes: 1 addition & 1 deletion devnet/cmd/scale-down-ecs-service/mocks/ecsapi.go

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

41 changes: 7 additions & 34 deletions dot/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"

"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/services"
Expand All @@ -17,8 +16,6 @@ import (

var (
_ services.Service = &Handler{}

ErrDefineNextEpoch = errors.New("cannot define next epoch data and config")
)

// Handler is used to handle consensus messages and relevant authority updates to BABE and GRANDPA
Expand Down Expand Up @@ -242,9 +239,14 @@ func (h *Handler) handleBlockFinalisation(ctx context.Context) {
continue
}

err := h.persistBABEDigestsForNextEpoch(&info.Header)
err := h.epochState.FinalizeBABENextEpochData(&info.Header)
if err != nil {
h.logger.Errorf("failed to persist babe next epoch data: %s", err)
}

err = h.epochState.FinalizeBABENextConfigData(&info.Header)
if err != nil {
h.logger.Errorf("failed to store babe next epoch digest: %s", err)
h.logger.Errorf("failed to persist babe next epoch config: %s", err)
}

err = h.handleGrandpaChangesOnFinalization(info.Header.Number)
Expand All @@ -257,35 +259,6 @@ func (h *Handler) handleBlockFinalisation(ctx context.Context) {
}
}

// persistBABEDigestsForNextEpoch is called only when a block is finalised
// and defines the correct next epoch data and next config data.
func (h *Handler) persistBABEDigestsForNextEpoch(finalizedHeader *types.Header) error {
currEpoch, err := h.epochState.GetEpochForBlock(finalizedHeader)
if err != nil {
return fmt.Errorf("cannot get epoch for block %d (%s): %w",
finalizedHeader.Number, finalizedHeader.Hash(), err)
}

nextEpoch := currEpoch + 1
err = h.epochState.FinalizeBABENextEpochData(nextEpoch)
if err != nil && !errors.Is(err, state.ErrEpochNotInMemory) {
return fmt.Errorf("cannot finalize babe next epoch data for block number %d (%s): %w",
finalizedHeader.Number, finalizedHeader.Hash(), err)
}

err = h.epochState.FinalizeBABENextConfigData(nextEpoch)
if err == nil {
return nil
} else if errors.Is(err, state.ErrEpochNotInMemory) {
return fmt.Errorf("%w: %s", ErrDefineNextEpoch, err)
}

// the epoch state does not contains any information about the next epoch
return fmt.Errorf("cannot finalize babe next config data for block number %d (%s): %w",
finalizedHeader.Number, finalizedHeader.Hash(), err)

}

func (h *Handler) handleGrandpaChangesOnImport(num uint) error {
resume := h.grandpaResume
if resume != nil && num >= resume.atBlock {
Expand Down
6 changes: 4 additions & 2 deletions dot/digest/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type BlockState interface {
FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
}

//go:generate mockgen -destination=mock_epoch_state_test.go -package $GOPACKAGE . EpochState
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved

// EpochState is the interface for state.EpochState
type EpochState interface {
GetEpochForBlock(header *types.Header) (uint64, error)
Expand All @@ -26,8 +28,8 @@ type EpochState interface {

StoreBABENextEpochData(epoch uint64, hash common.Hash, nextEpochData types.NextEpochData)
StoreBABENextConfigData(epoch uint64, hash common.Hash, nextEpochData types.NextConfigData)
FinalizeBABENextEpochData(epoch uint64) error
FinalizeBABENextConfigData(epoch uint64) error
FinalizeBABENextEpochData(finalizedHeader *types.Header) error
FinalizeBABENextConfigData(finalizedHeader *types.Header) error
}

// GrandpaState is the interface for the state.GrandpaState
Expand Down
131 changes: 131 additions & 0 deletions dot/digest/mock_epoch_state_test.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/block_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/block_finality_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/block_producer_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/core_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/network_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/rpcapi.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/runtime_storage_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/storage_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/sync_state_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/system_api.go

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

2 changes: 1 addition & 1 deletion dot/rpc/modules/mocks/transaction_state_api.go

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

Loading