WIP: next hard fork #5

Draft
BrannonKing wants to merge 178 commits from WIP-HF-2022 into master
4 changed files with 69 additions and 4 deletions
Showing only changes of commit 32e001c446 - Show all commits

View file

@ -89,7 +89,9 @@ func New(cfg config.Config) (*ClaimTrie, error) {
return nil, errors.Wrap(err, "creating node base manager")
}
normalizingManager := node.NewNormalizingManager(baseManager)
nodeManager := &node.HashV2Manager{Manager: normalizingManager}
hashV2Manager := &node.HashV2Manager{Manager: normalizingManager}
nodeManager := &node.HashV3Manager{Manager: hashV2Manager}
cleanups = append(cleanups, nodeManager.Close)
var trie merkletrie.MerkleTrie

View file

@ -0,0 +1,63 @@
package node
import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lbryio/chain/claimtrie/change"
"github.com/lbryio/chain/claimtrie/param"
)
type HashV2Manager struct {
Manager
}
type HashV3Manager struct {
Manager
}
func (nm *HashV2Manager) claimHashes(name []byte) (*chainhash.Hash, int32) {
n, err := nm.NodeAt(nm.Height(), name)
if err != nil || n == nil {
return nil, 0
}
n.SortClaimsByBid()
claimHashes := make([]*chainhash.Hash, 0, len(n.Claims))
for _, c := range n.Claims {
if c.Status == Activated { // TODO: unit test this line
claimHashes = append(claimHashes, calculateNodeHash(c.OutPoint, n.TakenOverAt))
}
}
if len(claimHashes) > 0 {
return ComputeMerkleRoot(claimHashes), n.NextUpdate(nm.Height())
}
return nil, n.NextUpdate(nm.Height())
}
func (nm *HashV2Manager) Hash(name []byte) (*chainhash.Hash, int32) {
if nm.Height() >= param.ActiveParams.AllClaimsInMerkleForkHeight {
return nm.claimHashes(name)
}
return nm.Manager.Hash(name)
}
func (nm *HashV3Manager) AppendChange(chg change.Change) {
if nm.Height() >= param.ActiveParams.GrandForkHeight && len(chg.Name) == 0 {
return
}
nm.Manager.AppendChange(chg)
}
func (nm *HashV3Manager) Hash(name []byte) (*chainhash.Hash, int32) {
if nm.Height() >= param.ActiveParams.GrandForkHeight {
if len(name) == 0 {
return nil, 0 // empty name's claims are not included in the hash
}
// return nm.detailHash()
}
return nm.Manager.Hash(name)
}

View file

@ -187,7 +187,7 @@ func (nm *BaseManager) IncrementHeightTo(height int32) ([][]byte, error) {
panic("invalid height")
}
if height >= param.ActiveParams.MaxRemovalWorkaroundHeight {
if height >= param.ActiveParams.MaxRemovalWorkaroundHeight && height < param.ActiveParams.GrandForkHeight {
// not technically needed until block 884430, but to be true to the arbitrary rollback length...
collectChildNames(nm.changes)
}

View file

@ -271,7 +271,7 @@ func TestEndOfExpiration(t *testing.T) {
r.NoError(err)
n, err := m.NodeAt(m.height, name1)
r.NoError(err)
r.Equal(m.height + param.ActiveParams.ExtendedClaimExpirationTime, n.NextUpdate(m.height))
r.Equal(m.height+param.ActiveParams.ExtendedClaimExpirationTime, n.NextUpdate(m.height))
_, err = m.IncrementHeightTo(gf)
r.NoError(err)
@ -279,4 +279,4 @@ func TestEndOfExpiration(t *testing.T) {
n, err = m.NodeAt(m.height, name1)
r.NoError(err)
r.Equal(int32(0), n.NextUpdate(m.height))
}
}