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(dot/parachain): added overseer signals #3638

Merged
merged 8 commits into from
Jan 9, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 73 additions & 42 deletions dot/parachain/availability-store/availability_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sync"

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/internal/database"
Expand All @@ -28,6 +29,10 @@ const (

// AvailabilityStoreSubsystem is the struct that holds subsystem data for the availability store
type AvailabilityStoreSubsystem struct {
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup

SubSystemToOverseer chan<- any
OverseerToSubSystem <-chan any
availabilityStore AvailabilityStore
Expand Down Expand Up @@ -170,7 +175,11 @@ func uint32ToBytes(value uint32) []byte {
// Run runs the availability store subsystem
func (av *AvailabilityStoreSubsystem) Run(ctx context.Context, OverseerToSubsystem chan any,
SubsystemToOverseer chan any) error {
av.processMessages()

av.wg.Add(2)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
go av.processMessages()
go av.ProcessOverseerSignals()
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

return nil
}

Expand All @@ -180,53 +189,70 @@ func (*AvailabilityStoreSubsystem) Name() parachaintypes.SubSystemName {
}

func (av *AvailabilityStoreSubsystem) processMessages() {
for msg := range av.OverseerToSubSystem {
logger.Debugf("received message %v", msg)
switch msg := msg.(type) {
case QueryAvailableData:
err := av.handleQueryAvailableData(msg)
if err != nil {
logger.Errorf("failed to handle available data: %w", err)
}
case QueryDataAvailability:
err := av.handleQueryDataAvailability(msg)
if err != nil {
logger.Errorf("failed to handle query data availability: %w", err)
}
case QueryChunk:
err := av.handleQueryChunk(msg)
if err != nil {
logger.Errorf("failed to handle query chunk: %w", err)
}
case QueryChunkSize:
err := av.handleQueryChunkSize(msg)
if err != nil {
logger.Errorf("failed to handle query chunk size: %w", err)
}
case QueryAllChunks:
err := av.handleQueryAllChunks(msg)
if err != nil {
logger.Errorf("failed to handle query all chunks: %w", err)
}
case QueryChunkAvailability:
err := av.handleQueryChunkAvailability(msg)
if err != nil {
logger.Errorf("failed to handle query chunk availability: %w", err)
}
case StoreChunk:
err := av.handleStoreChunk(msg)
if err != nil {
logger.Errorf("failed to handle store chunk: %w", err)
for {
select {
case msg := <-av.OverseerToSubSystem:
logger.Debugf("received message %v", msg)
switch msg := msg.(type) {
case QueryAvailableData:
err := av.handleQueryAvailableData(msg)
if err != nil {
logger.Errorf("failed to handle available data: %w", err)
}
case QueryDataAvailability:
err := av.handleQueryDataAvailability(msg)
if err != nil {
logger.Errorf("failed to handle query data availability: %w", err)
}
case QueryChunk:
err := av.handleQueryChunk(msg)
if err != nil {
logger.Errorf("failed to handle query chunk: %w", err)
}
case QueryChunkSize:
err := av.handleQueryChunkSize(msg)
if err != nil {
logger.Errorf("failed to handle query chunk size: %w", err)
}
case QueryAllChunks:
err := av.handleQueryAllChunks(msg)
if err != nil {
logger.Errorf("failed to handle query all chunks: %w", err)
}
case QueryChunkAvailability:
err := av.handleQueryChunkAvailability(msg)
if err != nil {
logger.Errorf("failed to handle query chunk availability: %w", err)
}
case StoreChunk:
err := av.handleStoreChunk(msg)
if err != nil {
logger.Errorf("failed to handle store chunk: %w", err)
}
case StoreAvailableData:
err := av.handleStoreAvailableData(msg)
if err != nil {
logger.Errorf("failed to handle store available data: %w", err)
}

}
case StoreAvailableData:
err := av.handleStoreAvailableData(msg)
if err != nil {
logger.Errorf("failed to handle store available data: %w", err)

case <-av.ctx.Done():
if err := av.ctx.Err(); err != nil {
logger.Errorf("ctx error: %v\n", err)
}
av.wg.Done()
return
}

}
}

func (av *AvailabilityStoreSubsystem) ProcessOverseerSignals() {
av.wg.Done()
// TODO: #3630
}

func (av *AvailabilityStoreSubsystem) handleQueryAvailableData(msg QueryAvailableData) error {
result, err := av.availabilityStore.loadAvailableData(msg.CandidateHash)
if err != nil {
Expand Down Expand Up @@ -333,3 +359,8 @@ func (av *AvailabilityStoreSubsystem) handleStoreAvailableData(msg StoreAvailabl
msg.Sender <- err // TODO: determine how to replicate Rust's Result type
return nil
}

func (av *AvailabilityStoreSubsystem) Stop() {
av.cancel()
av.wg.Wait()
}
3 changes: 3 additions & 0 deletions dot/parachain/availability-store/availability_store_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package availabilitystore

import (
Expand Down
63 changes: 46 additions & 17 deletions dot/parachain/backing/candidate_backing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package backing

import (
"context"
"sync"

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/internal/log"
Expand All @@ -14,6 +15,10 @@ import (
var logger = log.NewFromGlobal(log.AddContext("pkg", "parachain-candidate-backing"))

type CandidateBacking struct {
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup

SubSystemToOverseer chan<- any
OverseerToSubSystem <-chan any
}
Expand Down Expand Up @@ -72,31 +77,50 @@ func (cb *CandidateBacking) Run(ctx context.Context, overseerToSubSystem chan an
// other backing related overseer message.
// This would become more clear after we complete processMessages function. It would give us clarity
// if we need background_validation_rx or background_validation_tx, as done in rust.
cb.processMessages()

cb.wg.Add(2)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
go cb.processMessages()
go cb.ProcessOverseerSignals()

return nil
}

func (*CandidateBacking) Name() parachaintypes.SubSystemName {
return parachaintypes.CandidateBacking
}

func (cb *CandidateBacking) ProcessOverseerSignals() {
cb.wg.Done()
// TODO #3644
}

func (cb *CandidateBacking) processMessages() {
for msg := range cb.OverseerToSubSystem {
// process these received messages by referencing
// https://github.com/paritytech/polkadot-sdk/blob/769bdd3ff33a291cbc70a800a3830638467e42a2/polkadot/node/core/backing/src/lib.rs#L741
switch msg.(type) {
case ActiveLeavesUpdate:
cb.handleActiveLeavesUpdate()
case GetBackedCandidates:
cb.handleGetBackedCandidates()
case CanSecond:
cb.handleCanSecond()
case Second:
cb.handleSecond()
case Statement:
cb.handleStatement()
default:
logger.Error("unknown message type")
for {
select {
case msg := <-cb.OverseerToSubSystem:
// process these received messages by referencing
// https://github.com/paritytech/polkadot-sdk/blob/769bdd3ff33a291cbc70a800a3830638467e42a2/polkadot/node/core/backing/src/lib.rs#L741
switch msg.(type) {
case ActiveLeavesUpdate:
cb.handleActiveLeavesUpdate()
case GetBackedCandidates:
cb.handleGetBackedCandidates()
case CanSecond:
cb.handleCanSecond()
case Second:
cb.handleSecond()
case Statement:
cb.handleStatement()
default:
logger.Error("unknown message type")
}

case <-cb.ctx.Done():
if err := cb.ctx.Err(); err != nil {
logger.Errorf("ctx error: %v\n", err)
}
cb.wg.Done()
return
}
}
}
Expand All @@ -121,6 +145,11 @@ func (cb *CandidateBacking) handleStatement() {
// TODO: Implement this #3507
}

func (cb *CandidateBacking) Stop() {
cb.cancel()
cb.wg.Wait()
}

// SignedFullStatementWithPVD represents a signed full statement along with associated Persisted Validation Data (PVD).
type SignedFullStatementWithPVD struct {
SignedFullStatement parachaintypes.UncheckedSignedFullStatement
Expand Down
16 changes: 16 additions & 0 deletions dot/parachain/collator-protocol/validator_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func (cpvs CollatorProtocolValidatorSide) Run(
cpvs.fetchedCollations = append(cpvs.fetchedCollations, *collation)
}

case <-cpvs.ctx.Done():
if err := cpvs.ctx.Err(); err != nil {
logger.Errorf("ctx error: %v\n", err)
}
return nil
}
}
}
Expand All @@ -91,6 +96,14 @@ func (CollatorProtocolValidatorSide) Name() parachaintypes.SubSystemName {
return parachaintypes.CollationProtocol
}

func (cpvs CollatorProtocolValidatorSide) ProcessOverseerSignals() {
// NOTE: nothing to do here
}

func (cpvs CollatorProtocolValidatorSide) Stop() {
cpvs.cancel()
}

// requestCollation requests a collation from the network.
// This function will
// - check for duplicate requests
Expand Down Expand Up @@ -291,6 +304,9 @@ type CollationEvent struct {
}

type CollatorProtocolValidatorSide struct {
ctx context.Context
cancel context.CancelFunc

net Network

SubSystemToOverseer chan<- any
Expand Down
6 changes: 6 additions & 0 deletions dot/parachain/overseer/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package overseer

//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . BlockState
87 changes: 87 additions & 0 deletions dot/parachain/overseer/mocks_test.go

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

Loading
Loading