From 50d678b007e484ef6b972ebdcba9c2b33afdbeef Mon Sep 17 00:00:00 2001 From: Brannon King Date: Mon, 27 Dec 2021 17:17:44 -0500 Subject: [PATCH] [lbry] claimtrie: try to make ExpiresAt inlinable --- claimtrie/node/claim.go | 10 ---------- claimtrie/node/node.go | 32 +++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/claimtrie/node/claim.go b/claimtrie/node/claim.go index 8f385913..09a7ed08 100644 --- a/claimtrie/node/claim.go +++ b/claimtrie/node/claim.go @@ -7,7 +7,6 @@ import ( "github.com/lbryio/lbcd/chaincfg/chainhash" "github.com/lbryio/lbcd/claimtrie/change" - "github.com/lbryio/lbcd/claimtrie/param" "github.com/lbryio/lbcd/wire" ) @@ -58,15 +57,6 @@ func (c *Claim) setStatus(status Status) *Claim { return c } -func (c *Claim) ExpireAt() int32 { - - if c.AcceptedAt+param.ActiveParams.OriginalClaimExpirationTime > param.ActiveParams.ExtendedClaimExpirationForkHeight { - return c.AcceptedAt + param.ActiveParams.ExtendedClaimExpirationTime - } - - return c.AcceptedAt + param.ActiveParams.OriginalClaimExpirationTime -} - func OutPointLess(a, b wire.OutPoint) bool { switch cmp := bytes.Compare(a.Hash[:], b.Hash[:]); { diff --git a/claimtrie/node/node.go b/claimtrie/node/node.go index f9a466be..fe6db947 100644 --- a/claimtrie/node/node.go +++ b/claimtrie/node/node.go @@ -156,6 +156,16 @@ func (n *Node) updateTakeoverHeight(height int32, name []byte, refindBest bool) func (n *Node) handleExpiredAndActivated(height int32) int { + ot := param.ActiveParams.OriginalClaimExpirationTime + et := param.ActiveParams.ExtendedClaimExpirationTime + fk := param.ActiveParams.ExtendedClaimExpirationForkHeight + expiresAt := func(c *Claim) int32 { + if c.AcceptedAt+ot > fk { + return c.AcceptedAt + et + } + return c.AcceptedAt + ot + } + changes := 0 update := func(items ClaimList, sums map[string]int64) ClaimList { for i := 0; i < len(items); i++ { @@ -167,7 +177,7 @@ func (n *Node) handleExpiredAndActivated(height int32) int { sums[c.ClaimID.Key()] += c.Amount } } - if c.ExpireAt() <= height || c.Status == Deactivated { + if c.Status == Deactivated || expiresAt(c) <= height { if i < len(items)-1 { items[i] = items[len(items)-1] i-- @@ -190,11 +200,22 @@ func (n *Node) handleExpiredAndActivated(height int32) int { // be refreshed due to changes of claims or supports. func (n Node) NextUpdate() int32 { + ot := param.ActiveParams.OriginalClaimExpirationTime + et := param.ActiveParams.ExtendedClaimExpirationTime + fk := param.ActiveParams.ExtendedClaimExpirationForkHeight + expiresAt := func(c *Claim) int32 { + if c.AcceptedAt+ot > fk { + return c.AcceptedAt + et + } + return c.AcceptedAt + ot + } + next := int32(math.MaxInt32) for _, c := range n.Claims { - if c.ExpireAt() < next { - next = c.ExpireAt() + ea := expiresAt(c) + if ea < next { + next = ea } // if we're not active, we need to go to activeAt unless we're still invisible there if c.Status == Accepted { @@ -209,8 +230,9 @@ func (n Node) NextUpdate() int32 { } for _, s := range n.Supports { - if s.ExpireAt() < next { - next = s.ExpireAt() + es := expiresAt(s) + if es < next { + next = es } if s.Status == Accepted { min := s.ActiveAt