Skip to content

Commit

Permalink
add disputes coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed Jun 21, 2023
1 parent c0a2f9c commit 081b1b7
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions dot/parachain/dispute/coordinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package dispute

import (
"fmt"
"github.com/google/btree"
"time"
)

type DisputeCoordinatorSubsystem interface {
Run() error
}

type disputeCoordinator struct {
db Backend
}

func (d *disputeCoordinator) Run() error {
if err := d.initialize(); err != nil {
return fmt.Errorf("initialize dispute coordinator: %w", err)
}

// TODO: run the subsystem

return nil
}

func (d *disputeCoordinator) initialize() error {
// TODO: wait for the first leaf

if err := d.handleStartup(); err != nil {
return fmt.Errorf("handle startup: %w", err)
}

// TODO: update db on disk

//TODO implement me
panic("implement me")
}

func (d *disputeCoordinator) handleStartup() error {
var now = time.Now().Unix()
activeDisputes, err := d.db.GetActiveDisputes(now)
if err != nil {
return fmt.Errorf("get active disputes: %w", err)
}

// TODO: get highest session

// TODO: check if there is a gap in cache

// TODO: prune obsolete disputes

// TODO: for every dispute in activeDisputes
// get candidate votes
// check if it is a potential spam
// participate if needed, if not distribute the own vote
activeDisputes.Descend(func(i btree.Item) bool {
return true
})

return nil
}

func NewDisputeCoordinator() DisputeCoordinatorSubsystem {
return &disputeCoordinator{
db: NewBackend(),
}
}

0 comments on commit 081b1b7

Please sign in to comment.