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

feat(lib/parachain): Implement request and response message for /req_collation/1 protocol #3356

Merged
merged 27 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a556c9e
feat/scale: add `BitVec` (#3253)
kanishkatn May 29, 2023
78b00f9
Merge branch 'development' into feat/parachain
kanishkatn May 30, 2023
9898735
Merge branch 'development' into feat/parachain
kanishkatn Jun 5, 2023
2d57d59
Merge branch 'development' into feat/parachain
kanishkatn Jun 7, 2023
1782a1b
feat(erasure_coding): introduce erasure coding for PoV Distributor (#…
edwardmack Jun 8, 2023
05160a2
chore(deps): bump github.com/go-playground/validator/v10 from 10.14.0…
dependabot[bot] Jun 7, 2023
17a0168
chore(lib/runtime): revise `lib/runtime` interfaces (#3290)
timwu20 Jun 7, 2023
5c5720c
chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4 (#3…
dependabot[bot] Jun 7, 2023
fba1036
feat(lib/blocktree): reduce the entries in the runtimes mapping (#3151)
EclesioMeloJunior Jun 7, 2023
8e67ce5
Merge branch 'development' into feat/parachain
kanishkatn Jun 9, 2023
26770e7
Fix(lint): fixes a lint issue in bitvec-test (#3306)
kanishkatn Jun 9, 2023
9a7b632
feat(parachain): add types (#3297)
kanishkatn Jun 15, 2023
1f4b871
feat(parachain): Add StatementDistributionMessage varingDataType (#3316)
axaysagathiya Jun 20, 2023
d18af54
update `feat/parachain` with `development` (#3345)
kishansagathiya Jun 20, 2023
f7820dd
feat/runtime: Add few parachain runtime calls (#3241)
kanishkatn Jun 21, 2023
6a6480e
feat(parachain): Create struct for Approval Distribution Message (#3326)
edwardmack Jun 21, 2023
bff52ae
chore(parachain): improve comments of statement and statement distrib…
axaysagathiya Jun 23, 2023
c3bd831
feat(parachain): Add CollationProtocol VaryingDataType (#3337)
axaysagathiya Jun 26, 2023
d756253
implement req-res message for req_collation protoc
axaysagathiya Jun 26, 2023
60d7df5
change the type of PoV
axaysagathiya Jun 27, 2023
b6f1f34
clean up
axaysagathiya Jun 28, 2023
199ea26
update type of Collation.PoV
axaysagathiya Jun 28, 2023
6acf32a
Merge branch 'feat/parachain' into issue-3339
axaysagathiya Jul 5, 2023
7f0e2bc
resolve merge conflict issue
axaysagathiya Jul 5, 2023
adcbd11
use realistic hash values
axaysagathiya Jul 5, 2023
018c780
Merge branch 'feat/parachain' into issue-3339
axaysagathiya Jul 6, 2023
6f333c4
clean up after pull latest feat/parachain
axaysagathiya Jul 6, 2023
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
4 changes: 4 additions & 0 deletions dot/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/ChainSafe/gossamer/lib/transaction"
)

type BlockImportDigestHandler interface {
Handle(*types.Header) error
}

// BlockState interface for block state methods
type BlockState interface {
BestBlockHash() common.Hash
Expand Down
9 changes: 9 additions & 0 deletions dot/core/messages_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func TestService_HandleBlockProduced(t *testing.T) {
Body: *types.NewBody([]types.Extrinsic{}),
}

onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&newBlock.Header).Return(nil)

s.onBlockImport = onBlockImportHandlerMock

expected := &network.BlockAnnounceMessage{
ParentHash: newBlock.Header.ParentHash,
Number: newBlock.Header.Number,
Expand Down Expand Up @@ -172,6 +177,10 @@ func TestService_HandleTransactionMessage(t *testing.T) {
currentSlot := currentTimestamp / babeConfig.SlotDuration

block := buildTestBlockWithoutExtrinsics(t, rt, genHeader, currentSlot, currentTimestamp)
onBlockImportDigestHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportDigestHandlerMock.EXPECT().Handle(&block.Header).Return(nil)

s.onBlockImport = onBlockImportDigestHandlerMock

err = s.handleBlock(block, ts)
require.NoError(t, err)
Expand Down
122 changes: 122 additions & 0 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.

2 changes: 1 addition & 1 deletion dot/core/mocks_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

package core

//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,CodeSubstitutedState,Telemetry
//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,CodeSubstitutedState,Telemetry,BlockImportDigestHandler
//go:generate mockgen -destination=mock_runtime_instance_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/lib/runtime Instance
39 changes: 38 additions & 1 deletion dot/core/mocks_test.go

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

10 changes: 9 additions & 1 deletion dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type Service struct {
codeSubstitutedState CodeSubstitutedState

// Keystore
keys *keystore.GlobalKeystore
keys *keystore.GlobalKeystore
onBlockImport BlockImportDigestHandler
}

// Config holds the configuration for the core Service.
Expand All @@ -68,6 +69,7 @@ type Config struct {

CodeSubstitutes map[common.Hash]string
CodeSubstitutedState CodeSubstitutedState
OnBlockImport BlockImportDigestHandler
}

// NewService returns a new core service that connects the runtime, BABE
Expand All @@ -89,6 +91,7 @@ func NewService(cfg *Config) (*Service, error) {
blockAddCh: blockAddCh,
codeSubstitute: cfg.CodeSubstitutes,
codeSubstitutedState: cfg.CodeSubstitutedState,
onBlockImport: cfg.OnBlockImport,
}

return srv, nil
Expand Down Expand Up @@ -209,6 +212,11 @@ func (s *Service) handleBlock(block *types.Block, state *rtstorage.TrieState) er
}
}

err = s.onBlockImport.Handle(&block.Header)
if err != nil {
return fmt.Errorf("on block import handle: %w", err)
}

logger.Debugf("imported block %s and stored state trie with root %s",
block.Header.Hash(), state.MustRoot())

Expand Down
8 changes: 8 additions & 0 deletions dot/core/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func TestAnnounceBlock(t *testing.T) {
Body: *types.NewBody([]types.Extrinsic{}),
}

onBlockImportHandleMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandleMock.EXPECT().Handle(&newBlock.Header).Return(nil)
s.onBlockImport = onBlockImportHandleMock

expected := &network.BlockAnnounceMessage{
ParentHash: newBlock.Header.ParentHash,
Number: newBlock.Header.Number,
Expand Down Expand Up @@ -481,6 +485,10 @@ func TestService_HandleSubmittedExtrinsic(t *testing.T) {

block := buildTestBlockWithoutExtrinsics(t, rt, genHeader, currentSlotNumber, currentTimestamp)

onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&block.Header).Return(nil)
s.onBlockImport = onBlockImportHandlerMock

err = s.handleBlock(block, ts)
require.NoError(t, err)

Expand Down
36 changes: 25 additions & 11 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,13 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().AddBlock(&block).Return(blocktree.ErrBlockExists)
mockBlockState.EXPECT().GetRuntime(block.Header.ParentHash).Return(nil, errTestDummyError)

onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&block.Header).Return(nil)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
storageState: mockStorageState,
blockState: mockBlockState,
onBlockImport: onBlockImportHandlerMock,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -448,9 +452,13 @@ func Test_Service_handleBlock(t *testing.T) {
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).
Return(errTestDummyError)

onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&block.Header).Return(nil)

service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
storageState: mockStorageState,
blockState: mockBlockState,
onBlockImport: onBlockImportHandlerMock,
}
execTest(t, service, &block, trieState, errTestDummyError)
})
Expand All @@ -472,10 +480,13 @@ 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(nil)

onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&block.Header).Return(nil)
service := &Service{
storageState: mockStorageState,
blockState: mockBlockState,
ctx: context.Background(),
storageState: mockStorageState,
blockState: mockBlockState,
ctx: context.Background(),
onBlockImport: onBlockImportHandlerMock,
}
execTest(t, service, &block, trieState, nil)
})
Expand Down Expand Up @@ -531,12 +542,15 @@ func Test_Service_HandleBlockProduced(t *testing.T) {
mockBlockState.EXPECT().HandleRuntimeChanges(trieState, runtimeMock, block.Header.Hash()).Return(nil)
mockNetwork := NewMockNetwork(ctrl)
mockNetwork.EXPECT().GossipMessage(msg)
onBlockImportHandlerMock := NewMockBlockImportDigestHandler(ctrl)
onBlockImportHandlerMock.EXPECT().Handle(&block.Header).Return(nil)

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