Skip to content

Commit

Permalink
Remove debugging logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will committed Oct 11, 2024
1 parent 8636f36 commit f69b93e
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions core/vm/ipgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
var (
royaltyPolicyKindLAP = big.NewInt(0)
royaltyPolicyKindLRP = big.NewInt(1)
hundredPercent = big.NewInt(100000000) // 100% in the integer format
ipGraphAddress = common.HexToAddress("0x0000000000000000000000000000000000000101")
aclAddress = common.HexToAddress("0x680E66e4c7Df9133a7AFC1ed091089B32b89C4ae")
aclSlot = "af99b37fdaacca72ee7240cb1435cc9e498aee6ef4edc19c8cc0cd787f4e6800"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (c *ipGraph) RequiredGas(input []byte) uint64 {
case bytes.Equal(selector, setRoyaltySelector):
return ipGraphWriteGas
case bytes.Equal(selector, getRoyaltySelector):
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 64, 32))
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 64+4, 32))
if royaltyPolicyKind.Cmp(royaltyPolicyKindLAP) == 0 {
return ipGraphReadGas * (averageAncestorIpCount * 3)
} else if royaltyPolicyKind.Cmp(royaltyPolicyKindLRP) == 0 {
Expand All @@ -72,7 +73,7 @@ func (c *ipGraph) RequiredGas(input []byte) uint64 {
return intrinsicGas
}
case bytes.Equal(selector, getRoyaltyStackSelector):
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 32, 32))
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 32+4, 32))
if royaltyPolicyKind.Cmp(royaltyPolicyKindLAP) == 0 {
return ipGraphReadGas * (averageParentIpCount + 1)
} else if royaltyPolicyKind.Cmp(royaltyPolicyKindLRP) == 0 {
Expand Down Expand Up @@ -410,8 +411,6 @@ func (c *ipGraph) getRoyaltyLapForAncestor(ipId, ancestorIpId common.Address, ev
}

func (c *ipGraph) getRoyaltyLrp(ipId, ancestorIpId common.Address, evm *EVM, ipGraphAddress common.Address) *big.Int {
hundredPercent := big.NewInt(100000000) // 100% in the integer format

royalty := make(map[common.Address]*big.Int)
royalty[ipId] = hundredPercent

Expand All @@ -424,36 +423,28 @@ func (c *ipGraph) getRoyaltyLrp(ipId, ancestorIpId common.Address, evm *EVM, ipG

for i := len(topoOrder) - 1; i >= 0; i-- {
node := topoOrder[i]
log.Info("getRoyaltyLrp", "Processing node", node)
// If we reached the ancestor IP, we can stop the calculation
if node == ancestorIpId {
log.Info("getRoyaltyLrp", "msg", "Ancestor IP reached, stopping royalty calculation", "ancestorIpId", ancestorIpId)
break
}

currentRoyalty, exists := royalty[node]
if !exists || currentRoyalty.Sign() == 0 {
log.Info("getRoyaltyLrp", "msg", "Skipping node with no royalty", "node", node)
continue // Skip if there's no royalty to distribute
}

parents := allParents[node]
log.Info("getRoyaltyLrp", "parents", parents)
for _, parentIpId := range parents {
royaltySlot := crypto.Keccak256Hash(node.Bytes(), parentIpId.Bytes(), royaltyPolicyKindLRP.Bytes()).Big()
royaltyHash := common.BigToHash(royaltySlot)
parentRoyalty := evm.StateDB.GetState(ipGraphAddress, royaltyHash).Big()
log.Info("getRoyaltyLrp", "parentIpId", parentIpId, "parentRoyalty", parentRoyalty)

contribution := new(big.Int).Div(new(big.Int).Mul(currentRoyalty, parentRoyalty), hundredPercent)
log.Info("getRoyaltyLrp", "contribution", contribution)

if existingRoyalty, exists := royalty[parentIpId]; exists {
royalty[parentIpId] = new(big.Int).Add(existingRoyalty, contribution)
log.Info("getRoyaltyLrp", "msg", "Updated existing royalty", "parentIpId", parentIpId, "royalty", royalty[parentIpId])
} else {
royalty[parentIpId] = contribution
log.Info("getRoyaltyLrp", "msg", "Added new royalty", "parentIpId", parentIpId, "royalty", royalty[parentIpId])
}
}
}
Expand All @@ -475,31 +466,18 @@ func (c *ipGraph) topologicalSort(ipId, ancestorIpId common.Address, evm *EVM, i
stack := []common.Address{ipId}

for len(stack) > 0 {
log.Info("topologicalSort", "stack", stack)
current := stack[len(stack)-1]
stack = stack[:len(stack)-1] // pop from stack

log.Info("topologicalSort", "pop current", current)
log.Info("topologicalSort", "after pop stack", stack)
log.Info("topologicalSort", "visited", visited)
log.Info("topologicalSort", "topoOrder", topoOrder)

if visited[current] {
log.Info("topologicalSort", "msg", "current node already visited", "current", current)
log.Info("topologicalSort", "msg", "adding to topoOrder", "current", current)
topoOrder = append(topoOrder, current)
log.Info("topologicalSort", "topoOrder", topoOrder)
log.Info("topologicalSort", "msg", "Skipping visited node", "current", current)
continue
}
visited[current] = true
log.Info("topologicalSort", "visited", visited)
stack = append(stack, current)
log.Info("topologicalSort", "stack", stack)

currentLengthHash := evm.StateDB.GetState(ipGraphAddress, common.BytesToHash(current.Bytes()))
currentLength := currentLengthHash.Big()
log.Info("topologicalSort", "parentsLength", currentLength)
for i := uint64(0); i < currentLength.Uint64(); i++ {
slot := crypto.Keccak256Hash(current.Bytes()).Big()
slot.Add(slot, new(big.Int).SetUint64(i))
Expand All @@ -508,13 +486,11 @@ func (c *ipGraph) topologicalSort(ipId, ancestorIpId common.Address, evm *EVM, i
allParents[current] = append(allParents[current], parentIpId)

if !visited[parentIpId] {
log.Info("topologicalSort", "msg", "Adding parent to stack", "parentIpId", parentIpId)
stack = append(stack, parentIpId)
}
}
}
if !visited[ancestorIpId] {
log.Info("Ancestor IP is not ancestor of child IP", "ancestorIpId", ancestorIpId, "childIpId", ipId)
return []common.Address{}, map[common.Address][]common.Address{}, nil
}
return topoOrder, allParents, nil
Expand Down

0 comments on commit f69b93e

Please sign in to comment.