From c565a7cb78442d59912cf04d2da452f9bbd0d680 Mon Sep 17 00:00:00 2001 From: kanishka Date: Tue, 20 Jun 2023 23:46:11 +0530 Subject: [PATCH] add disputes coordinator --- dot/parachain/dispute/coordinator.go | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 dot/parachain/dispute/coordinator.go diff --git a/dot/parachain/dispute/coordinator.go b/dot/parachain/dispute/coordinator.go new file mode 100644 index 0000000000..994801957e --- /dev/null +++ b/dot/parachain/dispute/coordinator.go @@ -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(), + } +}