Skip to content

Commit

Permalink
add participation
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed Jun 19, 2023
1 parent f6c2699 commit 6b71e22
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 16 deletions.
80 changes: 80 additions & 0 deletions dot/parachain/dispute/participation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dispute

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

// CandidateComparator comparator for ordering of disputes for candidate.
type CandidateComparator struct {
relayParentBlockNumber *uint32
candidateHash common.Hash
}

// ParticipationRequest a dispute participation request
type ParticipationRequest struct {
candidateHash common.Hash
candidateReceipt parachain.CandidateReceipt
session parachain.SessionIndex
//TODO: requestTimer for metrics
}

type ParticipationStatement struct{}

type Participation interface {
// Queue a dispute for the node to participate in
Queue(request ParticipationRequest, priority ParticipationPriority) error

// GetResult gets the outcome of a ... dispute?
GetResult(statement ParticipationStatement) error

// TODO: implement this once we have the message bus
// ProcessActiveLeavesUpdate processes an active leaves update
// ProcessActiveLeavesUpdate(update parachain.ActiveLeavesUpdate) error

// BumpPriority bumps the priority for the given receipts
BumpPriority(receipts []parachain.CandidateReceipt) error
}

type participation struct {
runningParticipation map[common.Hash]struct{}
queue Queue
//TODO: worker sender channel
recentBlock uint32
//TODO: metrics
}

func (p participation) Queue(request ParticipationRequest, priority ParticipationPriority) error {
if _, ok := p.runningParticipation[request.candidateHash]; ok {
return nil
}

// TODO: if we already have a recent block, participate right away

// TODO: if not, add it to the queue

return nil
}

func (p participation) GetResult(statement ParticipationStatement) error {
//TODO implement me
panic("implement me")
}

func (p participation) BumpPriority(receipts []parachain.CandidateReceipt) error {
//TODO implement me
panic("implement me")
}

func NewParticipation() Participation {
return &participation{
runningParticipation: make(map[common.Hash]struct{}),
queue: NewQueue(),
}
}

// TODO: implement this once we have the network protocols
func (p participation) participate() error {
//TODO implement me
panic("implement me")
}
16 changes: 0 additions & 16 deletions dot/parachain/dispute/queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package dispute

import (
"bytes"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/parachain"
"sync"

"github.com/google/btree"
Expand All @@ -22,20 +20,6 @@ import (
// However, I will not be implementing it right away. It will be picked up as a single task for the
// entire dispute module https://github.com/ChainSafe/gossamer/issues/3313.

// CandidateComparator comparator for ordering of disputes for candidate.
type CandidateComparator struct {
relayParentBlockNumber *uint32
candidateHash common.Hash
}

// ParticipationRequest a dispute participation request
type ParticipationRequest struct {
candidateHash common.Hash
candidateReceipt parachain.CandidateReceipt
session parachain.SessionIndex
//TODO: requestTimer for metrics
}

// queueItem implements btree.Item
// TODO: the rust implementation uses BTreeMap. We call `ReplaceOrInsert` in Queue().
// Doesn't make sense to use map[] here for now. Need to explore btree further to see if we can improve performance by
Expand Down

0 comments on commit 6b71e22

Please sign in to comment.