made claims never expire
This commit is contained in:
parent
b87ee2b51e
commit
45e6adbe46
4 changed files with 56 additions and 19 deletions
|
@ -54,12 +54,6 @@ func (nm *BaseManager) NodeAt(height int32, name []byte) (*Node, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
// Node returns a node at the current height.
|
||||
// The returned node may have pending changes.
|
||||
func (nm *BaseManager) node(name []byte) (*Node, error) {
|
||||
return nm.NodeAt(nm.height, name)
|
||||
}
|
||||
|
||||
// newNodeFromChanges returns a new Node constructed from the changes.
|
||||
// The changes must preserve their order received.
|
||||
func (nm *BaseManager) newNodeFromChanges(changes []change.Change, height int32) (*Node, error) {
|
||||
|
@ -356,17 +350,17 @@ func (nm *BaseManager) IterateNames(predicate func(name []byte) bool) {
|
|||
|
||||
func (nm *BaseManager) Hash(name []byte) (*chainhash.Hash, int32) {
|
||||
|
||||
n, err := nm.node(name)
|
||||
n, err := nm.NodeAt(nm.height, name)
|
||||
if err != nil || n == nil {
|
||||
return nil, 0
|
||||
}
|
||||
if len(n.Claims) > 0 {
|
||||
if n.BestClaim != nil && n.BestClaim.Status == Activated {
|
||||
h := calculateNodeHash(n.BestClaim.OutPoint, n.TakenOverAt)
|
||||
return h, n.NextUpdate()
|
||||
return h, n.NextUpdate(nm.height)
|
||||
}
|
||||
}
|
||||
return nil, n.NextUpdate()
|
||||
return nil, n.NextUpdate(nm.height)
|
||||
}
|
||||
|
||||
func (nm *BaseManager) Flush() error {
|
||||
|
|
|
@ -67,25 +67,25 @@ func TestSimpleAddClaim(t *testing.T) {
|
|||
_, err = m.IncrementHeightTo(12)
|
||||
r.NoError(err)
|
||||
|
||||
n1, err := m.node(name1)
|
||||
n1, err := m.NodeAt(m.height, name1)
|
||||
r.NoError(err)
|
||||
r.Equal(1, len(n1.Claims))
|
||||
r.NotNil(n1.Claims.find(byOut(*out1)))
|
||||
|
||||
n2, err := m.node(name2)
|
||||
n2, err := m.NodeAt(m.height, name2)
|
||||
r.NoError(err)
|
||||
r.Equal(1, len(n2.Claims))
|
||||
r.NotNil(n2.Claims.find(byOut(*out2)))
|
||||
|
||||
err = m.DecrementHeightTo([][]byte{name2}, 11)
|
||||
r.NoError(err)
|
||||
n2, err = m.node(name2)
|
||||
n2, err = m.NodeAt(m.height, name2)
|
||||
r.NoError(err)
|
||||
r.Nil(n2)
|
||||
|
||||
err = m.DecrementHeightTo([][]byte{name1}, 1)
|
||||
r.NoError(err)
|
||||
n2, err = m.node(name1)
|
||||
n2, err = m.NodeAt(m.height, name1)
|
||||
r.NoError(err)
|
||||
r.Nil(n2)
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func TestSupportAmounts(t *testing.T) {
|
|||
_, err = m.IncrementHeightTo(20)
|
||||
r.NoError(err)
|
||||
|
||||
n1, err := m.node(name1)
|
||||
n1, err := m.NodeAt(m.height, name1)
|
||||
r.NoError(err)
|
||||
r.Equal(2, len(n1.Claims))
|
||||
r.Equal(int64(5), n1.BestClaim.Amount+n1.SupportSums[n1.BestClaim.ClaimID.Key()])
|
||||
|
@ -248,3 +248,35 @@ func TestCollectChildren(t *testing.T) {
|
|||
|
||||
r.Len(c[7].SpentChildren, 0)
|
||||
}
|
||||
|
||||
func TestEndOfExpiration(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
param.SetNetwork(wire.TestNet)
|
||||
repo, err := noderepo.NewPebble(t.TempDir())
|
||||
r.NoError(err)
|
||||
|
||||
m, err := NewBaseManager(repo)
|
||||
r.NoError(err)
|
||||
defer m.Close()
|
||||
|
||||
et := param.ActiveParams.ExtendedClaimExpirationForkHeight
|
||||
gf := param.ActiveParams.GrandForkHeight
|
||||
|
||||
chg := change.NewChange(change.AddClaim).SetName(name1).SetOutPoint(out1).SetHeight(et).SetAmount(2)
|
||||
chg.ClaimID = change.NewClaimID(*out1)
|
||||
m.AppendChange(chg)
|
||||
|
||||
_, err = m.IncrementHeightTo(et)
|
||||
r.NoError(err)
|
||||
n, err := m.NodeAt(m.height, name1)
|
||||
r.NoError(err)
|
||||
r.Equal(m.height + param.ActiveParams.ExtendedClaimExpirationTime, n.NextUpdate(m.height))
|
||||
|
||||
_, err = m.IncrementHeightTo(gf)
|
||||
r.NoError(err)
|
||||
|
||||
n, err = m.NodeAt(m.height, name1)
|
||||
r.NoError(err)
|
||||
r.Equal(int32(0), n.NextUpdate(m.height))
|
||||
}
|
|
@ -114,7 +114,10 @@ func (n *Node) AdjustTo(height, maxHeight int32, name []byte) *Node {
|
|||
changed := n.handleExpiredAndActivated(height) > 0
|
||||
n.updateTakeoverHeight(height, name, changed)
|
||||
if maxHeight > height {
|
||||
for h := n.NextUpdate(); h <= maxHeight; h = n.NextUpdate() {
|
||||
for h := n.NextUpdate(height); h <= maxHeight; h = n.NextUpdate(height) {
|
||||
if h <= 0 {
|
||||
break
|
||||
}
|
||||
changed = n.handleExpiredAndActivated(h) > 0
|
||||
n.updateTakeoverHeight(h, name, changed)
|
||||
height = h
|
||||
|
@ -167,7 +170,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 || (height < param.ActiveParams.GrandForkHeight && c.ExpireAt() <= height) {
|
||||
if i < len(items)-1 {
|
||||
items[i] = items[len(items)-1]
|
||||
i--
|
||||
|
@ -188,12 +191,12 @@ func (n *Node) handleExpiredAndActivated(height int32) int {
|
|||
|
||||
// NextUpdate returns the nearest height in the future that the node should
|
||||
// be refreshed due to changes of claims or supports.
|
||||
func (n Node) NextUpdate() int32 {
|
||||
func (n Node) NextUpdate(height int32) int32 {
|
||||
|
||||
next := int32(math.MaxInt32)
|
||||
|
||||
for _, c := range n.Claims {
|
||||
if c.ExpireAt() < next {
|
||||
if height < param.ActiveParams.GrandForkHeight && c.ExpireAt() < next {
|
||||
next = c.ExpireAt()
|
||||
}
|
||||
// if we're not active, we need to go to activeAt unless we're still invisible there
|
||||
|
@ -209,7 +212,7 @@ func (n Node) NextUpdate() int32 {
|
|||
}
|
||||
|
||||
for _, s := range n.Supports {
|
||||
if s.ExpireAt() < next {
|
||||
if height < param.ActiveParams.GrandForkHeight && s.ExpireAt() < next {
|
||||
next = s.ExpireAt()
|
||||
}
|
||||
if s.Status == Accepted {
|
||||
|
@ -223,6 +226,10 @@ func (n Node) NextUpdate() int32 {
|
|||
}
|
||||
}
|
||||
|
||||
if next == int32(math.MaxInt32) || next <= height {
|
||||
return 0
|
||||
}
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ type ClaimTrieParams struct {
|
|||
|
||||
NormalizedNameForkHeight int32
|
||||
AllClaimsInMerkleForkHeight int32
|
||||
GrandForkHeight int32
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -32,6 +33,7 @@ var (
|
|||
MaxRemovalWorkaroundHeight: 658300,
|
||||
NormalizedNameForkHeight: 539940, // targeting 21 March 2019}, https://lbry.com/news/hf1903
|
||||
AllClaimsInMerkleForkHeight: 658309, // targeting 30 Oct 2019}, https://lbry.com/news/hf1910
|
||||
GrandForkHeight: 1200000,
|
||||
}
|
||||
|
||||
TestNet = ClaimTrieParams{
|
||||
|
@ -45,6 +47,7 @@ var (
|
|||
MaxRemovalWorkaroundHeight: 1, // if you get a hash mismatch, come back to this
|
||||
NormalizedNameForkHeight: 993380,
|
||||
AllClaimsInMerkleForkHeight: 1198559,
|
||||
GrandForkHeight: 1200000,
|
||||
}
|
||||
|
||||
Regtest = ClaimTrieParams{
|
||||
|
@ -58,6 +61,7 @@ var (
|
|||
MaxRemovalWorkaroundHeight: -1,
|
||||
NormalizedNameForkHeight: 250,
|
||||
AllClaimsInMerkleForkHeight: 349,
|
||||
GrandForkHeight: 850,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue