From b92c31861fcea564716efc46f30501875d657b1d Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Fri, 30 Apr 2021 11:10:18 +0100 Subject: [PATCH] Remove check for duplicate fee address index. This check was added to InsertNewTicket pre-emptivly as a sanity check. It is not strictly required because the fee address itself is also checked, and there is no scenario where we would expect a fee address and its index not to match. Removing this check eases the route forward to improving database performance. --- database/ticket.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/database/ticket.go b/database/ticket.go index 2c2ba79..632fbd0 100644 --- a/database/ticket.go +++ b/database/ticket.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 The Decred developers +// Copyright (c) 2020-2021 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -81,6 +81,8 @@ var ( ErrNoTicketFound = errors.New("no ticket found") ) +// InsertNewTicket will insert the provided ticket into the database. Returns an +// error if either the ticket hash or fee address already exist. func (vdb *VspDatabase) InsertNewTicket(ticket Ticket) error { vdb.ticketsMtx.Lock() defer vdb.ticketsMtx.Unlock() @@ -106,10 +108,6 @@ func (vdb *VspDatabase) InsertNewTicket(ticket Ticket) error { return fmt.Errorf("ticket with fee address %s already exists", t.FeeAddress) } - if t.FeeAddressIndex == ticket.FeeAddressIndex { - return fmt.Errorf("ticket with fee address index %d already exists", t.FeeAddressIndex) - } - return nil }) if err != nil { @@ -190,6 +188,9 @@ func (vdb *VspDatabase) GetTicketByHash(ticketHash string) (Ticket, bool, error) return ticket, found, err } +// CountTickets returns the total number of voted, revoked, and currently voting +// tickets. Requires deserializing every ticket in the db so should be used +// sparingly. func (vdb *VspDatabase) CountTickets() (int64, int64, int64, error) { vdb.ticketsMtx.RLock() defer vdb.ticketsMtx.RUnlock()