-
Notifications
You must be signed in to change notification settings - Fork 132
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(parachain): availability distribution skeleton #4591
Open
haikoschol
wants to merge
3
commits into
feat/parachain
Choose a base branch
from
haiko/availability-distribution/skeleton
base: feat/parachain
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
dot/parachain/availability-distribution/availability_distribution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2025 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package availabilitydistribution | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ChainSafe/gossamer/dot/network" | ||
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" | ||
"github.com/ChainSafe/gossamer/dot/types" | ||
"github.com/ChainSafe/gossamer/internal/log" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
"github.com/ChainSafe/gossamer/lib/runtime" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/libp2p/go-libp2p/core/protocol" | ||
) | ||
|
||
var logger = log.NewFromGlobal(log.AddContext("pkg", "parachain-availability-distribution")) | ||
|
||
type AvailabilityDistribution struct { | ||
subSystemToOverseer chan<- any | ||
net Network | ||
blockState BlockState | ||
} | ||
|
||
var _ parachaintypes.Subsystem = (*AvailabilityDistribution)(nil) | ||
|
||
type Network interface { | ||
RegisterRequestHandler(subprotocolID protocol.ID, handler network.RequestHandler) | ||
} | ||
|
||
type BlockState interface { | ||
GetHeader(hash common.Hash) (*types.Header, error) | ||
GetRuntime(hash common.Hash) (instance runtime.Instance, err error) | ||
} | ||
|
||
// NewAvailabilityDistribution creates a new AvailabilityDistribution subsystem | ||
func NewAvailabilityDistribution( | ||
overseerChan chan<- any, | ||
net Network, | ||
blockState BlockState, | ||
) *AvailabilityDistribution { | ||
return &AvailabilityDistribution{ | ||
subSystemToOverseer: overseerChan, | ||
net: net, | ||
blockState: blockState, | ||
} | ||
} | ||
|
||
// Run starts the AvailabilityDistribution subsystem | ||
func (ad *AvailabilityDistribution) Run(ctx context.Context, overseerToSubSystem <-chan any) { | ||
for { | ||
select { | ||
case msg := <-overseerToSubSystem: | ||
err := ad.processMessage(msg) | ||
if err != nil { | ||
logger.Errorf("processing message: %s", err.Error()) | ||
} | ||
case <-ctx.Done(): | ||
if err := ctx.Err(); err != nil && !errors.Is(err, context.Canceled) { | ||
logger.Errorf("ctx error: %s\n", err) | ||
} | ||
return | ||
} | ||
} | ||
} | ||
|
||
func (ad *AvailabilityDistribution) Stop() { | ||
logger.Tracef("Stopping %s subsystem", ad.Name()) | ||
} | ||
|
||
// Name returns the name of the subsystem | ||
func (ad *AvailabilityDistribution) Name() parachaintypes.SubSystemName { | ||
return parachaintypes.AvailabilityDistribution | ||
} | ||
|
||
// processMessage processes messages sent to the AvailabilityDistribution subsystem | ||
func (ad *AvailabilityDistribution) processMessage(msg any) error { | ||
switch msg := msg.(type) { | ||
case parachaintypes.ActiveLeavesUpdateSignal: | ||
err := ad.ProcessActiveLeavesUpdateSignal(msg) | ||
if err != nil { | ||
return fmt.Errorf("processing active leaves update signal: %w", err) | ||
} | ||
case parachaintypes.BlockFinalizedSignal: | ||
return ad.ProcessBlockFinalizedSignal(msg) | ||
case parachaintypes.AvailabilityDistributionMessageFetchPoV: | ||
return ad.processAvailabilityDistributionMessageFetchPoV(msg) | ||
default: | ||
return fmt.Errorf("%w: %T", parachaintypes.ErrUnknownOverseerMessage, msg) | ||
} | ||
return nil | ||
} | ||
|
||
// ProcessActiveLeavesUpdateSignal processes active leaves update signal | ||
func (ad *AvailabilityDistribution) ProcessActiveLeavesUpdateSignal( | ||
signal parachaintypes.ActiveLeavesUpdateSignal, | ||
) error { | ||
return nil // TODO: implement | ||
} | ||
|
||
// ProcessBlockFinalizedSignal processes block finalized signal | ||
func (ad *AvailabilityDistribution) ProcessBlockFinalizedSignal(msg parachaintypes.BlockFinalizedSignal) error { | ||
return nil // nothing to do | ||
} | ||
|
||
func (ad *AvailabilityDistribution) processAvailabilityDistributionMessageFetchPoV( | ||
msg parachaintypes.AvailabilityDistributionMessageFetchPoV, | ||
) error { | ||
return nil // TODO: implement | ||
} | ||
|
||
//nolint:unused | ||
func (ad *AvailabilityDistribution) handleChunkFetchingRequest( | ||
who peer.ID, | ||
payload []byte, | ||
) (network.ResponseMessage, error) { | ||
return nil, nil // TODO: implement | ||
} | ||
|
||
//nolint:unused | ||
func (ad *AvailabilityDistribution) handlePoVFetchingRequest( | ||
who peer.ID, | ||
payload []byte, | ||
) (network.ResponseMessage, error) { | ||
return nil, nil // TODO: implement | ||
} |
23 changes: 23 additions & 0 deletions
23
dot/parachain/availability-distribution/availability_distribution_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2025 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package availabilitydistribution | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestNewAvailabilityDistribution(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
netMock := NewMockNetwork(ctrl) | ||
blockStateMock := NewMockBlockState(ctrl) | ||
|
||
overseerCh := make(chan any) | ||
|
||
ad := NewAvailabilityDistribution(overseerCh, netMock, blockStateMock) | ||
|
||
assert.NotNil(t, ad) | ||
} |
73 changes: 73 additions & 0 deletions
73
dot/parachain/availability-distribution/mocks_blockstate_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
dot/parachain/availability-distribution/mocks_generate_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2025 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package availabilitydistribution | ||
|
||
//go:generate mockgen -destination=mocks_network_test.go -package=$GOPACKAGE . Network | ||
//go:generate mockgen -destination=mocks_blockstate_test.go -package=$GOPACKAGE . BlockState |
54 changes: 54 additions & 0 deletions
54
dot/parachain/availability-distribution/mocks_network_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something, but why can the subsystem register a handler? I mean, in what specific case the subsystem will register a request handler for a specific network protocol id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The availability distribution subsystem is responsible for fetching erasure chunks and PoVs as well as responding to those requests from other nodes.
So on startup the subsystem will register handlers for
req_chunk/1
(and/orreq_chunk/2
) andreq_pov/1
.