Skip to content

Commit

Permalink
remove ProspectiveParachainsMode type
Browse files Browse the repository at this point in the history
Removed ProspectiveParachainsMode defined in collatorprotocol package and used the same
type defined in parachaintypes package.
  • Loading branch information
axaysagathiya committed Jan 5, 2024
1 parent 09e3a14 commit e8abb02
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
6 changes: 3 additions & 3 deletions dot/parachain/collator-protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (cpvs CollatorProtocolValidatorSide) enqueueCollation(
logger.Error("candidate relay parent went out of view for valid advertisement")
return ErrRelayParentUnknown
}
if perRelayParent.prospectiveParachainMode.isEnabled {
if perRelayParent.prospectiveParachainMode.IsEnabled {
return cpvs.fetchCollation(pendingCollation)
} else {
logger.Debug("a collation has already been seconded")
Expand Down Expand Up @@ -334,7 +334,7 @@ func (cpvs *CollatorProtocolValidatorSide) handleAdvertisement(relayParent commo
}

// Note: Prospective Parachain mode would be set or edited when the view gets updated.
if perRelayParent.prospectiveParachainMode.isEnabled && prospectiveCandidate == nil {
if perRelayParent.prospectiveParachainMode.IsEnabled && prospectiveCandidate == nil {
// Expected v2 advertisement.
return ErrProtocolMismatch
}
Expand Down Expand Up @@ -366,7 +366,7 @@ func (cpvs *CollatorProtocolValidatorSide) handleAdvertisement(relayParent commo
}

/*NOTE:---------------------------------------Matters only in V2----------------------------------------------*/
isSecondingAllowed := !perRelayParent.prospectiveParachainMode.isEnabled || cpvs.canSecond(
isSecondingAllowed := !perRelayParent.prospectiveParachainMode.IsEnabled || cpvs.canSecond(
collatorParaID,
relayParent,
prospectiveCandidate.CandidateHash,
Expand Down
28 changes: 14 additions & 14 deletions dot/parachain/collator-protocol/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func TestHandleCollationMessageAdvertiseCollation(t *testing.T) {
peerData map[peer.ID]PeerData
perRelayParent map[common.Hash]PerRelayParent
net Network
activeLeaves map[common.Hash]ProspectiveParachainsMode
activeLeaves map[common.Hash]parachaintypes.ProspectiveParachainsMode
errString string
}{
{
Expand Down Expand Up @@ -509,8 +509,8 @@ func TestHandleCollationMessageAdvertiseCollation(t *testing.T) {
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {
assignment: &testParaID,
prospectiveParachainMode: ProspectiveParachainsMode{
isEnabled: true,
prospectiveParachainMode: parachaintypes.ProspectiveParachainsMode{
IsEnabled: true,
},
},
},
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestHandleCollationMessageAdvertiseCollation(t *testing.T) {
}, peerID)
return net
}(),
activeLeaves: map[common.Hash]ProspectiveParachainsMode{},
activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{},
errString: ErrSecondedLimitReached.Error(),
},
}
Expand Down Expand Up @@ -608,10 +608,10 @@ func TestInsertAdvertisement(t *testing.T) {
testCases := []struct {
description string
peerData PeerData
relayParentMode ProspectiveParachainsMode
relayParentMode parachaintypes.ProspectiveParachainsMode
candidateHash *parachaintypes.CandidateHash
implicitView ImplicitView
activeLeaves map[common.Hash]ProspectiveParachainsMode
activeLeaves map[common.Hash]parachaintypes.ProspectiveParachainsMode
err error
}{
{
Expand All @@ -632,9 +632,9 @@ func TestInsertAdvertisement(t *testing.T) {
PeerState: Collating,
},
},
relayParentMode: ProspectiveParachainsMode{},
relayParentMode: parachaintypes.ProspectiveParachainsMode{},
candidateHash: nil,
activeLeaves: map[common.Hash]ProspectiveParachainsMode{},
activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{},
err: ErrOutOfView,
},
{
Expand All @@ -651,11 +651,11 @@ func TestInsertAdvertisement(t *testing.T) {
},
},
},
relayParentMode: ProspectiveParachainsMode{},
relayParentMode: parachaintypes.ProspectiveParachainsMode{},
candidateHash: nil,
activeLeaves: map[common.Hash]ProspectiveParachainsMode{
activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{
relayParent: {
isEnabled: false,
IsEnabled: false,
},
},
err: ErrDuplicateAdvertisement,
Expand All @@ -672,11 +672,11 @@ func TestInsertAdvertisement(t *testing.T) {
},
},
},
relayParentMode: ProspectiveParachainsMode{},
relayParentMode: parachaintypes.ProspectiveParachainsMode{},
candidateHash: &candidateHash,
activeLeaves: map[common.Hash]ProspectiveParachainsMode{
activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{
relayParent: {
isEnabled: false,
IsEnabled: false,
},
},
},
Expand Down
41 changes: 13 additions & 28 deletions dot/parachain/collator-protocol/validator_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ func (peerData *PeerData) SetCollating(collatorID parachaintypes.CollatorID, par

func IsRelayParentInImplicitView(
relayParent common.Hash,
relayParentMode ProspectiveParachainsMode,
relayParentMode parachaintypes.ProspectiveParachainsMode,
implicitView ImplicitView,
activeLeaves map[common.Hash]ProspectiveParachainsMode,
activeLeaves map[common.Hash]parachaintypes.ProspectiveParachainsMode,
paraID parachaintypes.ParaID,
) bool {
if !relayParentMode.isEnabled {
if !relayParentMode.IsEnabled {
_, ok := activeLeaves[relayParent]
return ok
}

for hash, mode := range activeLeaves {
knownAllowedRelayParent := implicitView.KnownAllowedRelayParentsUnder(hash, paraID)
if mode.isEnabled && knownAllowedRelayParent.String() == relayParent.String() {
if mode.IsEnabled && knownAllowedRelayParent.String() == relayParent.String() {
return true
}
}
Expand All @@ -198,10 +198,10 @@ func IsRelayParentInImplicitView(
// declared itself a collator.
func (peerData *PeerData) InsertAdvertisement(
onRelayParent common.Hash,
relayParentMode ProspectiveParachainsMode,
relayParentMode parachaintypes.ProspectiveParachainsMode,
candidateHash *parachaintypes.CandidateHash,
implicitView ImplicitView,
activeLeaves map[common.Hash]ProspectiveParachainsMode,
activeLeaves map[common.Hash]parachaintypes.ProspectiveParachainsMode,
) (isAdvertisementInvalid bool, err error) {
switch peerData.state.PeerState {
case Connected:
Expand All @@ -212,14 +212,14 @@ func (peerData *PeerData) InsertAdvertisement(
return false, ErrOutOfView
}

if relayParentMode.isEnabled {
if relayParentMode.IsEnabled {
// relayParentMode.maxCandidateDepth
candidates, ok := peerData.state.CollatingPeerState.advertisements[onRelayParent]
if ok && slices.Contains[[]parachaintypes.CandidateHash](candidates, *candidateHash) {
return false, ErrDuplicateAdvertisement
}

if len(candidates) > int(relayParentMode.maxCandidateDepth) {
if len(candidates) > int(relayParentMode.MaxCandidateDepth) {
return false, ErrPeerLimitReached
}
candidates = append(candidates, *candidateHash)
Expand Down Expand Up @@ -331,7 +331,7 @@ type CollatorProtocolValidatorSide struct {
/// support prospective parachains. This mapping works as a replacement for
/// [`polkadot_node_network_protocol::View`] and can be dropped once the transition
/// to asynchronous backing is done.
activeLeaves map[common.Hash]ProspectiveParachainsMode
activeLeaves map[common.Hash]parachaintypes.ProspectiveParachainsMode

// Collations that we have successfully requested from peers and waiting
// on validation.
Expand All @@ -353,23 +353,8 @@ func (f fetchedCollationInfo) String() string {
f.relayParent.String(), f.paraID, f.candidateHash.Value.String(), f.collatorID)
}

// Prospective parachains mode of a relay parent. Defined by
// the Runtime API version.
//
// Needed for the period of transition to asynchronous backing.
type ProspectiveParachainsMode struct {
// if disabled, there are no prospective parachains. Runtime API does not have support for `async_backing_params`
isEnabled bool

// these values would be present only if `isEnabled` is true

// The maximum number of para blocks between the para head in a relay parent and a new candidate.
// Restricts nodes from building arbitrary long chains and spamming other validators.
maxCandidateDepth uint
}

type PerRelayParent struct {
prospectiveParachainMode ProspectiveParachainsMode
prospectiveParachainMode parachaintypes.ProspectiveParachainsMode
assignment *parachaintypes.ParaID
collations Collations
}
Expand All @@ -384,10 +369,10 @@ type Collations struct {
}

// IsSecondedLimitReached check the limit of seconded candidates for a given para has been reached.
func (collations Collations) IsSecondedLimitReached(relayParentMode ProspectiveParachainsMode) bool {
func (collations Collations) IsSecondedLimitReached(relayParentMode parachaintypes.ProspectiveParachainsMode) bool {
var secondedLimit uint
if relayParentMode.isEnabled {
secondedLimit = relayParentMode.maxCandidateDepth + 1
if relayParentMode.IsEnabled {
secondedLimit = relayParentMode.MaxCandidateDepth + 1
} else {
secondedLimit = 1
}
Expand Down

0 comments on commit e8abb02

Please sign in to comment.