Skip to content

Commit

Permalink
add backend
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed Jun 21, 2023
1 parent 896094c commit cb3c834
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dot/parachain/dispute/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ type Dispute struct {
disputeStatus *Status
}

func NewCandidateVotes() *CandidateVotes {
return &CandidateVotes{
valid: treemap.NewWithIntComparator(),
invalid: treemap.NewWithIntComparator(),
func NewCandidateVotesFromReceipt(receipt parachain.CandidateReceipt) CandidateVotes {
return CandidateVotes{
valid: treemap.NewWithIntComparator(),
invalid: treemap.NewWithIntComparator(),
candidateReceipt: receipt,
}
}

Expand Down Expand Up @@ -133,7 +134,7 @@ type Backend interface {
GetCandidateVotes(session parachain.SessionIndex, candidateHash CandidateHash) (*CandidateVotes, error)

// GetActiveDisputes returns the active disputes, if any.
GetActiveDisputes() (*btree.BTree, error)
GetActiveDisputes(now int64) (*btree.BTree, error)

// TODO: need to explore further to see if we need these
SetEarliestSession(session parachain.SessionIndex)
Expand Down Expand Up @@ -202,13 +203,13 @@ func (b backend) SetCandidateVotes(session parachain.SessionIndex, candidateHash

const ActiveDuration = 180 * time.Second

func (b backend) GetActiveDisputes() (*btree.BTree, error) {
func (b backend) GetActiveDisputes(now int64) (*btree.BTree, error) {
activeDisputes := btree.New(32)

b.recentDisputes.Ascend(func(i btree.Item) bool {
d := i.(*Dispute)
concludedAt, err := d.disputeStatus.ConcludedAt()
if err == nil && concludedAt != nil && *concludedAt+uint64(ActiveDuration.Seconds()) > uint64(time.Now().Unix()) {
if err == nil && concludedAt != nil && *concludedAt+uint64(ActiveDuration.Seconds()) > uint64(now) {
activeDisputes.ReplaceOrInsert(d)
}
return true
Expand Down

0 comments on commit cb3c834

Please sign in to comment.