Skip to content

Commit 10046a5

Browse files
committed
ignore empty claims in the hash computation
1 parent 269403d commit 10046a5

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

claimtrie/claimtrie.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func New(cfg config.Config) (*ClaimTrie, error) {
8989
return nil, errors.Wrap(err, "creating node base manager")
9090
}
9191
normalizingManager := node.NewNormalizingManager(baseManager)
92-
nodeManager := &node.HashV2Manager{Manager: normalizingManager}
92+
hashV2Manager := &node.HashV2Manager{Manager: normalizingManager}
93+
nodeManager := &node.HashV3Manager{Manager: hashV2Manager}
94+
9395
cleanups = append(cleanups, nodeManager.Close)
9496

9597
var trie merkletrie.MerkleTrie

claimtrie/node/hash_manager.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package node
2+
3+
import (
4+
"github.com/btcsuite/btcd/chaincfg/chainhash"
5+
"github.com/lbryio/chain/claimtrie/change"
6+
"github.com/lbryio/chain/claimtrie/param"
7+
)
8+
9+
type HashV2Manager struct {
10+
Manager
11+
}
12+
13+
type HashV3Manager struct {
14+
Manager
15+
}
16+
17+
func (nm *HashV2Manager) claimHashes(name []byte) (*chainhash.Hash, int32) {
18+
19+
n, err := nm.NodeAt(nm.Height(), name)
20+
if err != nil || n == nil {
21+
return nil, 0
22+
}
23+
24+
n.SortClaimsByBid()
25+
claimHashes := make([]*chainhash.Hash, 0, len(n.Claims))
26+
for _, c := range n.Claims {
27+
if c.Status == Activated { // TODO: unit test this line
28+
claimHashes = append(claimHashes, calculateNodeHash(c.OutPoint, n.TakenOverAt))
29+
}
30+
}
31+
if len(claimHashes) > 0 {
32+
return ComputeMerkleRoot(claimHashes), n.NextUpdate(nm.Height())
33+
}
34+
return nil, n.NextUpdate(nm.Height())
35+
}
36+
37+
func (nm *HashV2Manager) Hash(name []byte) (*chainhash.Hash, int32) {
38+
39+
if nm.Height() >= param.ActiveParams.AllClaimsInMerkleForkHeight {
40+
return nm.claimHashes(name)
41+
}
42+
43+
return nm.Manager.Hash(name)
44+
}
45+
46+
func (nm *HashV3Manager) AppendChange(chg change.Change) {
47+
if nm.Height() >= param.ActiveParams.GrandForkHeight && len(chg.Name) == 0 {
48+
return
49+
}
50+
nm.Manager.AppendChange(chg)
51+
}
52+
53+
func (nm *HashV3Manager) Hash(name []byte) (*chainhash.Hash, int32) {
54+
55+
if nm.Height() >= param.ActiveParams.GrandForkHeight {
56+
if len(name) == 0 {
57+
return nil, 0 // empty name's claims are not included in the hash
58+
}
59+
// return nm.detailHash()
60+
}
61+
62+
return nm.Manager.Hash(name)
63+
}

claimtrie/node/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (nm *BaseManager) IncrementHeightTo(height int32) ([][]byte, error) {
186186
panic("invalid height")
187187
}
188188

189-
if height >= param.ActiveParams.MaxRemovalWorkaroundHeight {
189+
if height >= param.ActiveParams.MaxRemovalWorkaroundHeight && height < param.ActiveParams.GrandForkHeight {
190190
// not technically needed until block 884430, but to be true to the arbitrary rollback length...
191191
collectChildNames(nm.changes)
192192
}

claimtrie/node/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ func TestEndOfExpiration(t *testing.T) {
270270
r.NoError(err)
271271
n, err := m.NodeAt(m.height, name1)
272272
r.NoError(err)
273-
r.Equal(m.height + param.ActiveParams.ExtendedClaimExpirationTime, n.NextUpdate(m.height))
273+
r.Equal(m.height+param.ActiveParams.ExtendedClaimExpirationTime, n.NextUpdate(m.height))
274274

275275
_, err = m.IncrementHeightTo(gf)
276276
r.NoError(err)
277277

278278
n, err = m.NodeAt(m.height, name1)
279279
r.NoError(err)
280280
r.Equal(int32(0), n.NextUpdate(m.height))
281-
}
281+
}

0 commit comments

Comments
 (0)