diff --git a/dot/parachain/dispute/participation.go b/dot/parachain/dispute/participation.go new file mode 100644 index 0000000000..45c95f5dae --- /dev/null +++ b/dot/parachain/dispute/participation.go @@ -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") +} diff --git a/dot/parachain/dispute/queues.go b/dot/parachain/dispute/queues.go index ff0e148a4b..a336d99847 100644 --- a/dot/parachain/dispute/queues.go +++ b/dot/parachain/dispute/queues.go @@ -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" @@ -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