-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a2f9c
commit 081b1b7
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} |