Skip to content

Commit

Permalink
fix(dot/digest): BABE NextEpochData and NextConfigData should be set …
Browse files Browse the repository at this point in the history
…on finalization (#2339)

* feat: include substrate docker image

* chore: add substrate docker images

* chore: formatting and add depends on yaml key

* chore: add datadog stuff again

* chore: use alice peer id

* chore: split substrate docker compose services into another file

* chore: enable prometheus external and add datadog

* chore: keep substrate ports same as gossamer node ports

* chore: expose rpc and ws calls in substrate docker file

* chore: use same dns name and p2p id

* chore: use same key for both alice gossamer and substrate nodes

* chore: fix dd golang cmd

chore: keep both cross-client and gssmr chain genesis raw

chore: mistakes

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: update `substrate_alice` readme info

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: add `/tcp` to expose ports

* chore: adjust args and envs

* chore: pin prometheus version, add read only volume and add trailing new line

* chore: improve README.md

* chore: add port 7001 explicitly

* chore: remove prometheus `--config.file` flag

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: use env to chain

This is needed since ARG cannot be used inside ENTRYPOINT

* update substrate_bob.Dockerfile

* chore: add datadog-agent start to gssmr alice node

* chore: add comment about different but same node keys

* chore: IncrementSetID to return the nextSetID

* chore: digest HandleDigests check !ok first

* feat: store babe next epoch data only at finalised blocks

* feat: include substrate docker image

* chore: add substrate docker images

* chore: formatting and add depends on yaml key

* chore: add datadog stuff again

* chore: use alice peer id

* chore: split substrate docker compose services into another file

* chore: enable prometheus external and add datadog

* chore: keep substrate ports same as gossamer node ports

* chore: expose rpc and ws calls in substrate docker file

* chore: use same dns name and p2p id

* chore: use same key for both alice gossamer and substrate nodes

* chore: fix dd golang cmd

chore: keep both cross-client and gssmr chain genesis raw

chore: mistakes

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: update `substrate_alice` readme info

* chore: add `/tcp` to expose ports

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: adjust args and envs

* chore: pin prometheus version, add read only volume and add trailing new line

* chore: improve README.md

* chore: add port 7001 explicitly

* chore: add datadog-agent start to gssmr alice node

* chore: remove prometheus `--config.file` flag

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: use env to chain

This is needed since ARG cannot be used inside ENTRYPOINT

* update substrate_bob.Dockerfile

* chore: add comment about different but same node keys

* chore: IncrementSetID to return the nextSetID

* chore: digest HandleDigests check !ok first

* feat: store babe next epoch data only at finalised blocks

* chore: resolve conflicts

* chore: remove unused

* chore: rename function and change log message

* chore: fix babe next epoch data/config while not finalized chain

* chore: allow forks validate blocks using the right epoch data

* chore: add exported comments and improve VerifyBlock comment

* chore: fix lint, removing shadowing

* chore: promising integration test to cover babe digest handler

* chore: integration test added to babe verify block

* chore: needs improvent at chain finalization

* chore: integration test done!

* chore: fix lint

* chore: addressing comments at digest pkg

* chore: wrap errors at granpda pkg and fix lll at verify_integration_test

* chore: improve comments

* chore: improving state/epoch tests

* chore: return wrapped error at `babe digest finalization`

* chore: improve testing

* chore: improve exported comment

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: improve exported comment

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: improve error decription

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: improve error description

* chore: reorg `HasConfigData` and `HasEpochData`

* chore: add two mutexes for protect `nextEpoch` and `nextConfig`

* chore: improve exported comment

* chore: change `GetEpochData` to check in the memory if database doesnt return

* chore: scope specific variables

* unneeded `\n`

* chore: fix unit tests

* chore: git add fix exported func name

* chore: fix tests

* chore: remove DigestHandler from core pkg

* chore: get current epoch at next epoch data and next config data

* chore: check `err != nil` before check `err is not ErrKeyNotFound`

* chore: rename error var name

* chore: flip babe digest finalization

* chore: improve exported comment

* chore: separate not related conditions

* chore: remove DigestHandler from `dot/core` pkg

* chore: changing `String()` method owner

* chore: change function name to `persistBABEDigestsForNextEpoch`

* chore: fix typo

* chore: remove `nilnil` lint warn

* chore: remove unused core.DigestHandler mocks

* chore: fix

* chore: unexport functions

* chore: fix integration tests

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
  • Loading branch information
EclesioMeloJunior and qdm12 committed Apr 1, 2022
1 parent ce3c10c commit e991cc8
Show file tree
Hide file tree
Showing 34 changed files with 1,202 additions and 293 deletions.
3 changes: 0 additions & 3 deletions dot/core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ var (
// ErrEmptyRuntimeCode is returned when the storage :code is empty
ErrEmptyRuntimeCode = errors.New("new :code is empty")

// ErrNilDigestHandler is returned when the DigestHandler interface is nil
ErrNilDigestHandler = errors.New("cannot have nil DigestHandler")

errNilCodeSubstitutedState = errors.New("cannot have nil CodeSubstitutedStat")
)

Expand Down
5 changes: 0 additions & 5 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"
"testing"

"github.com/ChainSafe/gossamer/dot/digest"
"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/internal/log"
Expand All @@ -32,10 +31,6 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
cfg = &Config{}
}

if cfg.DigestHandler == nil {
cfg.DigestHandler = &digest.Handler{} // only for nil check in NewService
}

if cfg.Keystore == nil {
cfg.Keystore = keystore.NewGlobalKeystore()
kp, err := sr25519.GenerateKeypair()
Expand Down
7 changes: 1 addition & 6 deletions dot/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/ChainSafe/gossamer/lib/transaction"
)

//go:generate mockgen -destination=mock_core_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,EpochState,CodeSubstitutedState,DigestHandler
//go:generate mockgen -destination=mock_core_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,EpochState,CodeSubstitutedState

// BlockState interface for block state methods
type BlockState interface {
Expand Down Expand Up @@ -87,8 +87,3 @@ type CodeSubstitutedState interface {
LoadCodeSubstitutedBlockHash() common.Hash
StoreCodeSubstitutedBlockHash(hash common.Hash) error
}

// DigestHandler is the interface for the consensus digest handler
type DigestHandler interface {
HandleDigests(header *types.Header)
}
8 changes: 0 additions & 8 deletions dot/core/messages_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func TestService_HandleBlockProduced(t *testing.T) {
Keystore: keystore.NewGlobalKeystore(),
}

digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
cfg.DigestHandler = digestHandler

s := NewTestService(t, cfg)
err := s.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -137,9 +133,6 @@ func TestService_HandleTransactionMessage(t *testing.T) {
telemetryMock := NewMockClient(ctrl)
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()

digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))

net := NewMockNetwork(ctrl)
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage))).AnyTimes()
net.EXPECT().IsSynced().Return(true).AnyTimes()
Expand All @@ -151,7 +144,6 @@ func TestService_HandleTransactionMessage(t *testing.T) {
cfg := &Config{
Keystore: ks,
TransactionState: state.NewTransactionState(telemetryMock),
DigestHandler: digestHandler,
Network: net,
}

Expand Down
37 changes: 1 addition & 36 deletions dot/core/mock_core_test.go

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

10 changes: 0 additions & 10 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type Service struct {
storageState StorageState
transactionState TransactionState
net Network
digestHandler DigestHandler

// map of code substitutions keyed by block hash
codeSubstitute map[common.Hash]string
Expand All @@ -71,7 +70,6 @@ type Config struct {
Network Network
Keystore *keystore.GlobalKeystore
Runtime runtime.Instance
DigestHandler DigestHandler

CodeSubstitutes map[common.Hash]string
CodeSubstitutedState CodeSubstitutedState
Expand All @@ -96,10 +94,6 @@ func NewService(cfg *Config) (*Service, error) {
return nil, ErrNilNetwork
}

if cfg.DigestHandler == nil {
return nil, ErrNilDigestHandler
}

if cfg.CodeSubstitutedState == nil {
return nil, errNilCodeSubstitutedState
}
Expand All @@ -121,7 +115,6 @@ func NewService(cfg *Config) (*Service, error) {
blockAddCh: blockAddCh,
codeSubstitute: cfg.CodeSubstitutes,
codeSubstitutedState: cfg.CodeSubstitutedState,
digestHandler: cfg.DigestHandler,
}

return srv, nil
Expand Down Expand Up @@ -218,9 +211,6 @@ func (s *Service) handleBlock(block *types.Block, state *rtstorage.TrieState) er
logger.Debugf("imported block %s and stored state trie with root %s",
block.Header.Hash(), state.MustRoot())

// handle consensus digests
s.digestHandler.HandleDigests(&block.Header)

rt, err := s.blockState.GetRuntime(&block.Header.ParentHash)
if err != nil {
return err
Expand Down
7 changes: 0 additions & 7 deletions dot/core/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ func TestAnnounceBlock(t *testing.T) {
Network: net,
}

digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
cfg.DigestHandler = digestHandler

s := NewTestService(t, cfg)
err := s.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -583,9 +579,6 @@ func TestService_GetRuntimeVersion(t *testing.T) {
func TestService_HandleSubmittedExtrinsic(t *testing.T) {
cfg := &Config{}
ctrl := gomock.NewController(t)
digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
cfg.DigestHandler = digestHandler

net := NewMockNetwork(ctrl)
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage)))
Expand Down
36 changes: 13 additions & 23 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,15 @@ func Test_Service_handleCodeSubstitution(t *testing.T) {

func Test_Service_handleBlock(t *testing.T) {
t.Parallel()

execTest := func(t *testing.T, s *Service, block *types.Block, trieState *rtstorage.TrieState, expErr error) {
err := s.handleBlock(block, trieState)
assert.ErrorIs(t, err, expErr)
if expErr != nil {
assert.EqualError(t, err, expErr.Error())
}
}

t.Run("nil input", func(t *testing.T) {
t.Parallel()
service := &Service{}
Expand Down Expand Up @@ -366,13 +368,10 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(nil, errTestDummyError)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
storageState: mockStorageState,
blockState: mockBlockState,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -396,13 +395,10 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).
Return(errTestDummyError)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
storageState: mockStorageState,
blockState: mockBlockState,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -425,14 +421,11 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).Return(nil)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
ctx: context.Background(),
storageState: mockStorageState,
blockState: mockBlockState,
ctx: context.Background(),
}
execTest(t, service, &block, trieState, nil)
})
Expand Down Expand Up @@ -488,17 +481,14 @@ func Test_Service_HandleBlockProduced(t *testing.T) {
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(&block.Header.ParentHash).Return(runtimeMock, nil)
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).Return(nil)
mockDigestHandler := NewMockDigestHandler(ctrl)
mockDigestHandler.EXPECT().HandleDigests(&block.Header)
mockNetwork := NewMockNetwork(ctrl)
mockNetwork.EXPECT().GossipMessage(msg)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
digestHandler: mockDigestHandler,
net: mockNetwork,
ctx: context.Background(),
storageState: mockStorageState,
blockState: mockBlockState,
net: mockNetwork,
ctx: context.Background(),
}
execTest(t, service, &block, trieState, nil)
})
Expand Down
Loading

0 comments on commit e991cc8

Please sign in to comment.