Skip to content

Commit

Permalink
feat(lib/parachain): added parachain service and registering protocols (
Browse files Browse the repository at this point in the history
#3277)

- Added parachain service
- Registered collation and validation protocol
- Confirmed that we can communicate with collators by talking to them in `run()` function
  • Loading branch information
kishansagathiya committed Sep 14, 2023
1 parent 59ff8eb commit b445405
Show file tree
Hide file tree
Showing 39 changed files with 689 additions and 184 deletions.
24 changes: 12 additions & 12 deletions dot/core/mock_runtime_instance_test.go

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

17 changes: 17 additions & 0 deletions dot/mock_node_builder_test.go

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

2 changes: 2 additions & 0 deletions dot/network/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
blockAnnounceMsgType MessageType = iota + 3
transactionMsgType
ConsensusMsgType
CollationMsgType
ValidationMsgType
)

// Message must be implemented by all network messages
Expand Down
8 changes: 8 additions & 0 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/parachain"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/services"
)
Expand Down Expand Up @@ -63,6 +64,7 @@ type nodeBuilderIface interface {
dh *digest.Handler) (*core.Service, error)
createGRANDPAService(config *cfg.Config, st *state.Service, ks KeyStore,
net *network.Service, telemetryMailer Telemetry) (*grandpa.Service, error)
createParachainHostService(net *network.Service, genesishHash common.Hash) (*parachain.Service, error)
newSyncService(config *cfg.Config, st *state.Service, finalityGadget BlockJustificationVerifier,
verifier *babe.VerificationManager, cs *core.Service, net *network.Service,
telemetryMailer Telemetry) (*dotsync.Service, error)
Expand Down Expand Up @@ -379,6 +381,12 @@ func newNode(config *cfg.Config,
}
nodeSrvcs = append(nodeSrvcs, fg)

phs, err := builder.createParachainHostService(networkSrvc, stateSrvc.Block.GenesisHash())
if err != nil {
return nil, err
}
nodeSrvcs = append(nodeSrvcs, phs)

syncer, err := builder.newSyncService(config, stateSrvc, fg, ver, coreSrvc, networkSrvc, telemetryMailer)
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/parachain"
"github.com/ChainSafe/gossamer/lib/runtime"
wazero_runtime "github.com/ChainSafe/gossamer/lib/runtime/wazero"
"github.com/ChainSafe/gossamer/lib/trie"
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestNewNode(t *testing.T) {
assert.NoError(t, err)

mockServiceRegistry := NewMockServiceRegisterer(ctrl)
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(8)
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(9)

m := NewMocknodeBuilderIface(ctrl)
m.EXPECT().isNodeInitialised(initConfig.BasePath).Return(true, nil)
Expand Down Expand Up @@ -119,6 +120,9 @@ func TestNewNode(t *testing.T) {
return stateSrvc, nil
})

phs, err := parachain.NewService(testNetworkService, common.Hash{})
require.NoError(t, err)

m.EXPECT().createRuntimeStorage(gomock.AssignableToTypeOf(&state.Service{})).Return(&runtime.
NodeStorage{}, nil)
m.EXPECT().loadRuntime(initConfig, &runtime.NodeStorage{}, gomock.AssignableToTypeOf(&state.Service{}),
Expand Down Expand Up @@ -149,6 +153,8 @@ func TestNewNode(t *testing.T) {
})
m.EXPECT().createNetworkService(initConfig, gomock.AssignableToTypeOf(&state.Service{}),
gomock.AssignableToTypeOf(&telemetry.Mailer{})).Return(testNetworkService, nil)
m.EXPECT().createParachainHostService(gomock.AssignableToTypeOf(&network.Service{}),
gomock.AssignableToTypeOf(common.Hash{})).Return(phs, nil)

got, err := newNode(initConfig, ks, m, mockServiceRegistry)
assert.NoError(t, err)
Expand Down
6 changes: 6 additions & 0 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/parachain"
"github.com/ChainSafe/gossamer/lib/runtime"
wazero_runtime "github.com/ChainSafe/gossamer/lib/runtime/wazero"
)
Expand Down Expand Up @@ -456,6 +457,11 @@ func (nodeBuilder) createGRANDPAService(config *cfg.Config, st *state.Service, k
return grandpa.NewService(gsCfg)
}

func (nodeBuilder) createParachainHostService(net *network.Service, genesisHash common.Hash) (
*parachain.Service, error) {
return parachain.NewService(net, genesisHash)
}

func (nodeBuilder) createBlockVerifier(st *state.Service) *babe.VerificationManager {
return babe.NewVerificationManager(st.Block, st.Slot, st.Epoch)
}
Expand Down
24 changes: 12 additions & 12 deletions dot/state/mocks_runtime_test.go

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

24 changes: 12 additions & 12 deletions dot/sync/mock_runtime_test.go

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

3 changes: 2 additions & 1 deletion lib/babe/inherents/parachain_inherents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/pkg/scale"
)

Expand Down Expand Up @@ -240,7 +241,7 @@ func newDisputeStatement() disputeStatement { //skipcq
}

// collatorID is the collator's relay-chain account ID
type collatorID []byte
type collatorID sr25519.PublicKey

// collatorSignature is the signature on a candidate's block data signed by a collator.
type collatorSignature signature
Expand Down
Loading

0 comments on commit b445405

Please sign in to comment.