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(parachain/collator): handle Seconded overseer message #3557

Merged
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
807c876
Handle Declare message received by a collator
kishansagathiya Oct 9, 2023
5d1f2c0
temp
kishansagathiya Oct 10, 2023
2242509
added tests, need to prettify a bit though
kishansagathiya Oct 11, 2023
526c657
prettified tests
kishansagathiya Oct 11, 2023
cf84289
added one more check
kishansagathiya Oct 11, 2023
5051079
Update dot/parachain/collator-protocol/message.go
kishansagathiya Oct 12, 2023
9b5a969
Update dot/parachain/collator-protocol/message.go
kishansagathiya Oct 12, 2023
f435794
fixing lint
kishansagathiya Oct 12, 2023
58fdcba
Merge branch 'kishan/feat/parachain/collator-declare' of github.com:C…
kishansagathiya Oct 12, 2023
fafbb5e
underscore to camelcase
kishansagathiya Oct 12, 2023
6a300dc
temp
kishansagathiya Oct 12, 2023
c9588eb
some progress
kishansagathiya Oct 13, 2023
a9c55fa
temp
kishansagathiya Oct 13, 2023
72a1453
more changes, some improvements in overseer
kishansagathiya Oct 18, 2023
4d4c049
more changes
kishansagathiya Oct 18, 2023
8b77ca9
more addition to collator protocol
kishansagathiya Oct 19, 2023
d1c5de8
added some tests for advertise collation
kishansagathiya Oct 19, 2023
dd0d8ca
Merge branch 'feat/parachain' into kishan/feat/parachain/collator-adv…
kishansagathiya Oct 21, 2023
db47168
wrote some tests
kishansagathiya Oct 23, 2023
3d0e782
TestInsertAdvertisement
kishansagathiya Oct 25, 2023
64846c8
added TestFetchCollation
kishansagathiya Oct 25, 2023
4ba1cf2
fixing lint
kishansagathiya Oct 25, 2023
afcc501
small fix
kishansagathiya Oct 25, 2023
36c7fda
Update dot/parachain/collator-protocol/message.go
kishansagathiya Oct 27, 2023
d04355d
Update dot/parachain/collator-protocol/message.go
kishansagathiya Oct 27, 2023
c90d6c8
more progress
kishansagathiya Oct 30, 2023
53c645f
tagged an issue
kishansagathiya Oct 30, 2023
0d3c898
Merge branch 'kishan/feat/parachain/collator-advertisements' of githu…
kishansagathiya Oct 30, 2023
f56db9c
more progress
kishansagathiya Oct 30, 2023
0d9c1bd
some more tests
kishansagathiya Oct 31, 2023
0bd5c40
more tests
kishansagathiya Oct 31, 2023
496560d
some reviews
kishansagathiya Nov 6, 2023
67ee6b1
fixed some tiny todos
kishansagathiya Nov 8, 2023
a8ce806
Merge branch 'kishan/feat/parachain/collator-advertisements' into kis…
kishansagathiya Nov 8, 2023
bd799de
fix lint
kishansagathiya Nov 8, 2023
5b3c6c2
Merge branch 'feat/parachain' into kishan/feat/parachain/collation-se…
kishansagathiya Nov 10, 2023
6f726a2
temp
kishansagathiya Nov 10, 2023
85edc4e
addressed reviews
kishansagathiya Nov 15, 2023
e921404
return err in newFetchedCollationInfo
kishansagathiya Nov 16, 2023
542fa13
Update dot/parachain/collator-protocol/validator_side.go
kishansagathiya Nov 20, 2023
21ba847
fix lint
kishansagathiya Nov 20, 2023
bc234a2
Update dot/parachain/collator-protocol/validator_side_test.go
kishansagathiya Nov 20, 2023
eee521b
Update dot/parachain/collator-protocol/validator_side_test.go
kishansagathiya Nov 20, 2023
78165ed
Update dot/parachain/collator-protocol/validator_side_test.go
kishansagathiya Nov 20, 2023
77493d8
Update dot/parachain/collator-protocol/validator_side_test.go
kishansagathiya Nov 20, 2023
c62941f
fix lint
kishansagathiya Nov 20, 2023
95a566e
Merge branch 'feat/parachain' into kishan/feat/parachain/collation-se…
kishansagathiya Nov 21, 2023
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
124 changes: 115 additions & 9 deletions dot/parachain/collator-protocol/validator_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ type CollatorProtocolValidatorSide struct {

ourView View

// Keep track of all pending candidate collations
pendingCandidates map[common.Hash]CollationEvent

// Parachains we're currently assigned to. With async backing enabled
// this includes assignments from the implicit view.
currentAssignments map[parachaintypes.ParaID]uint
Expand All @@ -335,6 +332,23 @@ type CollatorProtocolValidatorSide struct {
/// [`polkadot_node_network_protocol::View`] and can be dropped once the transition
/// to asynchronous backing is done.
activeLeaves map[common.Hash]ProspectiveParachainsMode

fetchedCandidates map[string]CollationEvent
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

// Identifier of a fetched collation
type fetchedCollationInfo struct {
// Candidate's relay parent
relayParent common.Hash
paraID parachaintypes.ParaID
candidateHash parachaintypes.CandidateHash
// Id of the collator the collation was fetched from
collatorID parachaintypes.CollatorID
}

func (f fetchedCollationInfo) String() string {
return fmt.Sprintf("relay parent: %s, para id: %d, candidate hash: %s, collator id: %+v",
f.relayParent.String(), f.paraID, f.candidateHash.Value.String(), f.collatorID)
}

// Prospective parachains mode of a relay parent. Defined by
Expand Down Expand Up @@ -403,9 +417,10 @@ type NetworkBridgeUpdate struct {
// TODO: not quite sure if we would need this or something similar to this
}

// SecondedOverseerMsg represents that the candidate we recommended to be seconded was validated successfully.
type SecondedOverseerMsg struct {
Parent common.Hash
Stmt parachaintypes.StatementVDT
Stmt parachaintypes.UncheckedSignedFullStatement
}

type Backed struct {
Expand All @@ -414,12 +429,14 @@ type Backed struct {
ParaHead common.Hash
}

// InvalidOverseerMsg represents an invalid candidata.
// We recommended a particular candidate to be seconded, but it was invalid; penalise the collator.
type InvalidOverseerMsg struct {
Parent common.Hash
CandidateReceipt parachaintypes.CandidateReceipt
}

func (cpvs CollatorProtocolValidatorSide) processMessage(msg interface{}) error {
func (cpvs CollatorProtocolValidatorSide) processMessage(msg any) error {
// run this function as a goroutine, ideally

switch msg := msg.(type) {
Expand All @@ -440,21 +457,95 @@ func (cpvs CollatorProtocolValidatorSide) processMessage(msg interface{}) error
// TODO: handle network message https://github.com/ChainSafe/gossamer/issues/3515
// https://github.com/paritytech/polkadot-sdk/blob/db3fd687262c68b115ab6724dfaa6a71d4a48a59/polkadot/node/network/collator-protocol/src/validator_side/mod.rs#L1457 //nolint
case SecondedOverseerMsg:
// TODO: handle seconded message https://github.com/ChainSafe/gossamer/issues/3516
// https://github.com/paritytech/polkadot-sdk/blob/db3fd687262c68b115ab6724dfaa6a71d4a48a59/polkadot/node/network/collator-protocol/src/validator_side/mod.rs#L1466 //nolint
statementV, err := msg.Stmt.Payload.Value()
if err != nil {
return fmt.Errorf("getting value of statement: %w", err)
}
if statementV.Index() != 1 {
return fmt.Errorf("expected a seconded statement")
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

receipt, ok := statementV.(parachaintypes.Seconded)
if !ok {
return fmt.Errorf("statement value expected: Seconded, got: %T", statementV)
}

candidateReceipt := parachaintypes.CommittedCandidateReceipt(receipt)

fetchedCollation, err := newFetchedCollationInfo(candidateReceipt.ToPlain())
if err != nil {
return fmt.Errorf("getting fetched collation info: %w", err)
}

// remove the candidate from the list of fetched candidates
collationEvent, ok := cpvs.fetchedCandidates[fetchedCollation.String()]
if !ok {
logger.Error("collation has been seconded, but the relay parent is deactivated")
return nil
}

delete(cpvs.fetchedCandidates, fetchedCollation.String())

// notify good collation
peerID, ok := cpvs.getPeerIDFromCollatorID(collationEvent.CollatorId)
if !ok {
return ErrPeerIDNotFoundForCollator
}
cpvs.net.ReportPeer(peerset.ReputationChange{
Value: peerset.BenefitNotifyGoodValue,
Reason: peerset.BenefitNotifyGoodReason,
}, peerID)

// notify collation seconded
_, ok = cpvs.peerData[peerID]
if ok {
collatorProtocolMessage := NewCollatorProtocolMessage()
err = collatorProtocolMessage.Set(CollationSeconded{
RelayParent: msg.Parent,
Statement: msg.Stmt,
})
if err != nil {
return fmt.Errorf("setting collation seconded: %w", err)
}
collationMessage := NewCollationProtocol()

err = collationMessage.Set(collatorProtocolMessage)
if err != nil {
return fmt.Errorf("setting collation message: %w", err)
}

err = cpvs.net.SendMessage(peerID, &collationMessage)
if err != nil {
return fmt.Errorf("sending collation message: %w", err)
}

perRelayParent, ok := cpvs.perRelayParent[msg.Parent]
if ok {
perRelayParent.collations.status = Seconded
perRelayParent.collations.secondedCount++
cpvs.perRelayParent[msg.Parent] = perRelayParent
}

// TODO: Few more things for async backing, but we don't have async backing yet
// https://github.com/paritytech/polkadot-sdk/blob/7035034710ecb9c6a786284e5f771364c520598d/polkadot/node/network/collator-protocol/src/validator_side/mod.rs#L1531-L1532
}
case Backed:
// TODO: handle backed message https://github.com/ChainSafe/gossamer/issues/3517
case InvalidOverseerMsg:
invalidOverseerMsg := msg

collationEvent, ok := cpvs.pendingCandidates[invalidOverseerMsg.Parent]
fetchedCollation, err := newFetchedCollationInfo(msg.CandidateReceipt)
if err != nil {
return fmt.Errorf("getting fetched collation info: %w", err)
}

collationEvent, ok := cpvs.fetchedCandidates[fetchedCollation.String()]
if !ok {
return nil
}

if *collationEvent.PendingCollation.CommitmentHash == (invalidOverseerMsg.CandidateReceipt.CommitmentsHash) {
delete(cpvs.pendingCandidates, invalidOverseerMsg.Parent)
delete(cpvs.fetchedCandidates, fetchedCollation.String())
} else {
logger.Error("reported invalid candidate for unknown `pending_candidate`")
return nil
Expand All @@ -474,3 +565,18 @@ func (cpvs CollatorProtocolValidatorSide) processMessage(msg interface{}) error

return nil
}

func newFetchedCollationInfo(candidateReceipt parachaintypes.CandidateReceipt) (*fetchedCollationInfo, error) {
candidateHash, err := candidateReceipt.Hash()
if err != nil {
return nil, fmt.Errorf("getting candidate hash: %w", err)
}
return &fetchedCollationInfo{
paraID: parachaintypes.ParaID(candidateReceipt.Descriptor.ParaID),
relayParent: candidateReceipt.Descriptor.RelayParent,
collatorID: candidateReceipt.Descriptor.Collator,
candidateHash: parachaintypes.CandidateHash{
Value: candidateHash,
},
}, nil
}
Loading
Loading