Skip to content

Commit

Permalink
statement distribution skeleton (#4169)
Browse files Browse the repository at this point in the history
Statement Distribution subsystem is responsible for distributing signed statements that we have generated and forwarding statements generated by our peers. 
This commit just introduces a skeleton for it.
- implements the subsystem interface
- registers the subsystem with overseer
- add the processMessage method with messages to be handled

Issue #3583
  • Loading branch information
kishansagathiya authored Oct 2, 2024
1 parent a2450fe commit a6d5321
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 23 deletions.
3 changes: 2 additions & 1 deletion dot/parachain/backing/candidate_backing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
availabilitystore "github.com/ChainSafe/gossamer/dot/parachain/availability-store"
candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation"
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
statementdistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
Expand Down Expand Up @@ -83,7 +84,7 @@ func mockOverseer(t *testing.T, subsystemToOverseer chan any) {
parachaintypes.ProvisionerMessageProvisionableData,
parachaintypes.ProspectiveParachainsMessageCandidateBacked,
collatorprotocolmessages.Backed,
parachaintypes.StatementDistributionMessageBacked:
statementdistributionmessages.Backed:
continue
default:
t.Errorf("unknown type: %T\n", data)
Expand Down
11 changes: 6 additions & 5 deletions dot/parachain/backing/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation"
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
"github.com/ChainSafe/gossamer/dot/parachain/overseer"
statementedistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto"
Expand Down Expand Up @@ -396,7 +397,7 @@ func TestSecondsValidCandidate(t *testing.T) {

distribute := func(msg any) bool {
// we have seconded a candidate and shared the statement to peers
share, ok := msg.(parachaintypes.StatementDistributionMessageShare)
share, ok := msg.(statementedistributionmessages.Share)
if !ok {
return false
}
Expand Down Expand Up @@ -539,7 +540,7 @@ func TestCandidateReachesQuorum(t *testing.T) {
validate := validResponseForValidateFromExhaustive(headData, pvd)

distribute := func(msg any) bool {
_, ok := msg.(parachaintypes.StatementDistributionMessageShare)
_, ok := msg.(statementedistributionmessages.Share)
return ok
}

Expand Down Expand Up @@ -844,7 +845,7 @@ func TestCanNotSecondMultipleCandidatesPerRelayParent(t *testing.T) {

distribute := func(msg any) bool {
// we have seconded a candidate and shared the statement to peers
share, ok := msg.(parachaintypes.StatementDistributionMessageShare)
share, ok := msg.(statementedistributionmessages.Share)
if !ok {
return false
}
Expand Down Expand Up @@ -996,7 +997,7 @@ func TestNewLeafDoesNotClobberOld(t *testing.T) {

distribute := func(msg any) bool {
// we have seconded a candidate and shared the statement to peers
share, ok := msg.(parachaintypes.StatementDistributionMessageShare)
share, ok := msg.(statementedistributionmessages.Share)
if !ok {
return false
}
Expand Down Expand Up @@ -1137,7 +1138,7 @@ func TestConflictingStatementIsMisbehavior(t *testing.T) {
validate := validResponseForValidateFromExhaustive(headData, pvd)

distribute := func(msg any) bool {
_, ok := msg.(parachaintypes.StatementDistributionMessageShare)
_, ok := msg.(statementedistributionmessages.Share)
return ok
}

Expand Down
3 changes: 2 additions & 1 deletion dot/parachain/backing/per_relay_parent_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
availabilitystore "github.com/ChainSafe/gossamer/dot/parachain/availability-store"
candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation"
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
statementedistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/runtime"
wazero_runtime "github.com/ChainSafe/gossamer/lib/runtime/wazero"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan
}

// Notify statement distribution of backed candidate.
subSystemToOverseer <- parachaintypes.StatementDistributionMessageBacked(candidateHash)
subSystemToOverseer <- statementedistributionmessages.Backed(candidateHash)

} else {
// TODO: figure out what this comment means by 'avoid cycles'.
Expand Down
3 changes: 2 additions & 1 deletion dot/parachain/backing/validated_candidate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
statementedistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/keystore"
Expand Down Expand Up @@ -345,7 +346,7 @@ func signImportAndDistributeStatement(
}

// `Share` must always be sent before `Backed`. We send the latter in `postImportStatement` below.
subSystemToOverseer <- parachaintypes.StatementDistributionMessageShare{
subSystemToOverseer <- statementedistributionmessages.Share{
RelayParent: rpState.relayParent,
SignedFullStatementWithPVD: signedStatementWithPVD,
}
Expand Down
4 changes: 4 additions & 0 deletions dot/parachain/overseer/overseer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
networkbridgemessages "github.com/ChainSafe/gossamer/dot/parachain/network-bridge/messages"
parachain "github.com/ChainSafe/gossamer/dot/parachain/runtime"
statementedistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/dot/parachain/util"
"github.com/ChainSafe/gossamer/dot/types"
Expand Down Expand Up @@ -142,6 +143,9 @@ func (o *OverseerSystem) processMessages() {

subsystem = o.nameToSubsystem[parachaintypes.AvailabilityStore]

case statementedistributionmessages.Share, statementedistributionmessages.Backed:
subsystem = o.nameToSubsystem[parachaintypes.StatementDistribution]

case chainapi.ChainAPIMessage[util.Ancestors], chainapi.ChainAPIMessage[chainapi.BlockHeader]:
subsystem = o.nameToSubsystem[parachaintypes.ChainAPI]

Expand Down
21 changes: 21 additions & 0 deletions dot/parachain/statement-distribution/messages/messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package messages

import (
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/common"
)

// Backed is a statement distribution message.
// it represents a message indicating that a candidate has received sufficient
// validity votes from the backing group. If backed as a result of a local statement,
// it must be preceded by a `Share` message for that statement to ensure awareness of
// full candidates before the `Backed` notification, even in groups of size 1.
type Backed parachaintypes.CandidateHash

// Share is a statement distribution message.
// It is a signed statement in the context of
// given relay-parent hash and it should be distributed to other validators.
type Share struct {
RelayParent common.Hash
SignedFullStatementWithPVD parachaintypes.SignedFullStatementWithPVD
}
71 changes: 71 additions & 0 deletions dot/parachain/statement-distribution/statement_distribution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package statementdistribution

import (
"context"

"github.com/ChainSafe/gossamer/internal/log"

statementedistributionmessages "github.com/ChainSafe/gossamer/dot/parachain/statement-distribution/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
)

var logger = log.NewFromGlobal(log.AddContext("pkg", "statement-distribution"))

type StatementDistribution struct {
}

func (s StatementDistribution) Run(ctx context.Context, overseerToSubSystem <-chan any) {
for {
select {
case msg, ok := <-overseerToSubSystem:
if !ok {
return
}
err := s.processMessage(msg)
if err != nil {
logger.Errorf("processing overseer message: %w", err)
}
case <-ctx.Done():
if err := ctx.Err(); err != nil {
logger.Errorf("ctx error: %v\n", err)
}
}
}
}

func (s StatementDistribution) processMessage(msg any) error {

switch msg := msg.(type) {
case statementedistributionmessages.Backed:
// TODO #4171
case statementedistributionmessages.Share:
// TODO #4170
// case statementedistributionmessages.NetworkBridgeUpdate
// TODO #4172 this above case would need to wait until network bridge receiver side is merged
case parachaintypes.ActiveLeavesUpdateSignal:
return s.ProcessActiveLeavesUpdateSignal(msg)
case parachaintypes.BlockFinalizedSignal:
return s.ProcessBlockFinalizedSignal(msg)

default:
return parachaintypes.ErrUnknownOverseerMessage
}

return nil
}

func (s StatementDistribution) Name() parachaintypes.SubSystemName {
return parachaintypes.StatementDistribution
}

func (s StatementDistribution) ProcessActiveLeavesUpdateSignal(signal parachaintypes.ActiveLeavesUpdateSignal) error {
// TODO #4173
return nil
}

func (s StatementDistribution) ProcessBlockFinalizedSignal(signal parachaintypes.BlockFinalizedSignal) error {
// nothing to do here
return nil
}

func (s StatementDistribution) Stop() {}
15 changes: 0 additions & 15 deletions dot/parachain/types/overseer_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ type ProvisionableDataMisbehaviorReport struct {

func (ProvisionableDataMisbehaviorReport) IsProvisionableData() {}

// StatementDistributionMessageBacked is a statement distribution message.
// it represents a message indicating that a candidate has received sufficient
// validity votes from the backing group. If backed as a result of a local statement,
// it must be preceded by a `Share` message for that statement to ensure awareness of
// full candidates before the `Backed` notification, even in groups of size 1.
type StatementDistributionMessageBacked CandidateHash

// StatementDistributionMessageShare is a statement distribution message.
// It is a signed statement in the context of
// given relay-parent hash and it should be distributed to other validators.
type StatementDistributionMessageShare struct {
RelayParent common.Hash
SignedFullStatementWithPVD SignedFullStatementWithPVD
}

// ProspectiveParachainsMessageGetTreeMembership is a prospective parachains message.
// It is intended for retrieving the membership of a candidate in all fragment trees
type ProspectiveParachainsMessageGetTreeMembership struct {
Expand Down
1 change: 1 addition & 0 deletions dot/parachain/types/subsystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
NetworkBridgeReceiver SubSystemName = "NetworkBridgeReceiver"
ChainAPI SubSystemName = "ChainAPI"
CandidateValidation SubSystemName = "CandidateValidation"
StatementDistribution SubSystemName = "StatementDistribution"
)

var SubsystemRequestTimeout = 1 * time.Second
Expand Down

0 comments on commit a6d5321

Please sign in to comment.