From cb3c834c4a5cd5cc41f6931c7c9904b2cd8dd235 Mon Sep 17 00:00:00 2001 From: kanishka Date: Mon, 19 Jun 2023 17:43:40 +0530 Subject: [PATCH] add backend --- dot/parachain/dispute/backend.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dot/parachain/dispute/backend.go b/dot/parachain/dispute/backend.go index a0bd449ab4..5652904769 100644 --- a/dot/parachain/dispute/backend.go +++ b/dot/parachain/dispute/backend.go @@ -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, } } @@ -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) @@ -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