Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Sep 12, 2024
1 parent 5dbd59b commit 935c070
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 129 deletions.
248 changes: 124 additions & 124 deletions dot/parachain/collator-protocol/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestHandleCollationMessageAdvertiseCollation(t *testing.T) {

peerID := peer.ID("testPeerID")
testRelayParent := getDummyHash(5)
// testParaID := parachaintypes.ParaID(5)
testParaID := parachaintypes.ParaID(5)

testCases := []struct {
description string
Expand All @@ -432,129 +432,129 @@ func TestHandleCollationMessageAdvertiseCollation(t *testing.T) {
},
errString: ErrRelayParentUnknown.Error(),
},
// {
// description: "fail with unknown peer if peer is not tracked in our list of active collators",
// advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
// perRelayParent: map[common.Hash]PerRelayParent{
// testRelayParent: {},
// },
// errString: ErrUnknownPeer.Error(),
// },
// {
// description: "fail with undeclared para if peer has not declared its para id" +
// " and report the peer",
// advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
// perRelayParent: map[common.Hash]PerRelayParent{
// testRelayParent: {},
// },
// peerData: map[peer.ID]PeerData{
// peerID: {
// view: View{},
// state: PeerStateInfo{
// PeerState: Connected,
// },
// },
// },
// expectedMessage: networkbridgemessages.ReportPeer{
// PeerID: peerID,
// ReputationChange: peerset.ReputationChange{
// Value: peerset.UnexpectedMessageValue,
// Reason: peerset.UnexpectedMessageReason,
// },
// },
// errString: ErrUndeclaredPara.Error(),
// },
// {
// description: "fail with invalid assignment if para id is not currently" +
// " assigned to us for this relay parent and report the peer",
// advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
// perRelayParent: map[common.Hash]PerRelayParent{
// testRelayParent: {
// assignment: &testParaID,
// },
// },
// peerData: map[peer.ID]PeerData{
// peerID: {
// view: View{},
// state: PeerStateInfo{
// PeerState: Collating,
// CollatingPeerState: CollatingPeerState{
// ParaID: parachaintypes.ParaID(6),
// },
// },
// },
// },
// expectedMessage: networkbridgemessages.ReportPeer{
// PeerID: peerID,
// ReputationChange: peerset.ReputationChange{
// Value: peerset.WrongParaValue,
// Reason: peerset.WrongParaReason,
// },
// },
// errString: ErrInvalidAssignment.Error(),
// },
// {
// // NOTE: prospective parachain mode and prospective candidates were added in V2,
// // In V1, prospective parachain mode is disabled by and prospective candidates is nil
// // In V2, prospective parachain mode is enabled by and prospective candidates is not nil
// description: "fail with protocol mismatch is prospective parachain mode in" +
// " enable but with got a nil value for prospective candidate",
// advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
// perRelayParent: map[common.Hash]PerRelayParent{
// testRelayParent: {
// assignment: &testParaID,
// prospectiveParachainMode: parachaintypes.ProspectiveParachainsMode{
// IsEnabled: true,
// },
// },
// },
// peerData: map[peer.ID]PeerData{
// peerID: {
// view: View{},
// state: PeerStateInfo{
// PeerState: Collating,
// CollatingPeerState: CollatingPeerState{
// ParaID: testParaID,
// },
// },
// },
// },
// errString: ErrProtocolMismatch.Error(),
// },
// {
// description: "fail if para reached a limit of seconded candidates for this relay parent",
// advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
// perRelayParent: map[common.Hash]PerRelayParent{
// testRelayParent: {
// assignment: &testParaID,
// collations: Collations{
// // For Collator Protocol v1, we can only second one candidate
// // at a time, so seconded limit would be 1
// secondedCount: 1,
// },
// },
// },
// peerData: map[peer.ID]PeerData{
// peerID: {
// view: View{},
// state: PeerStateInfo{
// PeerState: Collating,
// CollatingPeerState: CollatingPeerState{
// ParaID: testParaID,
// },
// },
// },
// },
// expectedMessage: networkbridgemessages.ReportPeer{
// PeerID: peerID,
// ReputationChange: peerset.ReputationChange{
// Value: peerset.UnexpectedMessageValue,
// Reason: peerset.UnexpectedMessageReason,
// },
// },
// activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{},
// errString: ErrSecondedLimitReached.Error(),
// },
{
description: "fail with unknown peer if peer is not tracked in our list of active collators",
advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {},
},
errString: ErrUnknownPeer.Error(),
},
{
description: "fail with undeclared para if peer has not declared its para id" +
" and report the peer",
advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {},
},
peerData: map[peer.ID]PeerData{
peerID: {
view: View{},
state: PeerStateInfo{
PeerState: Connected,
},
},
},
expectedMessage: networkbridgemessages.ReportPeer{
PeerID: peerID,
ReputationChange: peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
},
},
errString: ErrUndeclaredPara.Error(),
},
{
description: "fail with invalid assignment if para id is not currently" +
" assigned to us for this relay parent and report the peer",
advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {
assignment: &testParaID,
},
},
peerData: map[peer.ID]PeerData{
peerID: {
view: View{},
state: PeerStateInfo{
PeerState: Collating,
CollatingPeerState: CollatingPeerState{
ParaID: parachaintypes.ParaID(6),
},
},
},
},
expectedMessage: networkbridgemessages.ReportPeer{
PeerID: peerID,
ReputationChange: peerset.ReputationChange{
Value: peerset.WrongParaValue,
Reason: peerset.WrongParaReason,
},
},
errString: ErrInvalidAssignment.Error(),
},
{
// NOTE: prospective parachain mode and prospective candidates were added in V2,
// In V1, prospective parachain mode is disabled by and prospective candidates is nil
// In V2, prospective parachain mode is enabled by and prospective candidates is not nil
description: "fail with protocol mismatch is prospective parachain mode in" +
" enable but with got a nil value for prospective candidate",
advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {
assignment: &testParaID,
prospectiveParachainMode: parachaintypes.ProspectiveParachainsMode{
IsEnabled: true,
},
},
},
peerData: map[peer.ID]PeerData{
peerID: {
view: View{},
state: PeerStateInfo{
PeerState: Collating,
CollatingPeerState: CollatingPeerState{
ParaID: testParaID,
},
},
},
},
errString: ErrProtocolMismatch.Error(),
},
{
description: "fail if para reached a limit of seconded candidates for this relay parent",
advertiseCollation: collatorprotocolmessages.AdvertiseCollation(testRelayParent),
perRelayParent: map[common.Hash]PerRelayParent{
testRelayParent: {
assignment: &testParaID,
collations: Collations{
// For Collator Protocol v1, we can only second one candidate
// at a time, so seconded limit would be 1
secondedCount: 1,
},
},
},
peerData: map[peer.ID]PeerData{
peerID: {
view: View{},
state: PeerStateInfo{
PeerState: Collating,
CollatingPeerState: CollatingPeerState{
ParaID: testParaID,
},
},
},
},
expectedMessage: networkbridgemessages.ReportPeer{
PeerID: peerID,
ReputationChange: peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
},
},
activeLeaves: map[common.Hash]parachaintypes.ProspectiveParachainsMode{},
errString: ErrSecondedLimitReached.Error(),
},
}
for _, c := range testCases {
c := c
Expand Down
4 changes: 1 addition & 3 deletions dot/parachain/collator-protocol/validator_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ type CollatorProtocolValidatorSide struct {
Keystore keystore.Keystore

SubSystemToOverseer chan<- any
OverseerToSubSystem <-chan any

unfetchedCollation chan UnfetchedCollation
unfetchedCollation chan UnfetchedCollation

collationFetchingReqResProtocol *network.RequestResponseProtocol

Expand Down
4 changes: 2 additions & 2 deletions dot/parachain/collator-protocol/validator_side_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ func TestProcessBackedOverseerMessage(t *testing.T) {

cpvs.BlockedAdvertisements = c.blockedAdvertisements

cpvs.OverseerToSubSystem = overseer.RegisterSubsystem(cpvs)
overseer.RegisterSubsystem(cpvs)

err := overseer.Start()
require.NoError(t, err)

defer overseer.Stop()

overseer.ReceiveMessage(c.msg)
// overseer.ReceiveMessage(c.msg)
overseer.ExpectActions(c.expectedActions...)

time.Sleep(1 * time.Second)
Expand Down

0 comments on commit 935c070

Please sign in to comment.