Skip to content

Commit

Permalink
Add stack trace implementation to track the current Hub
Browse files Browse the repository at this point in the history
  • Loading branch information
dmigwi committed Jan 1, 2019
1 parent ef1af31 commit 3e85db8
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions analytics/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ func ChainDiscovery(client *rpcclient.Client, txHash string) ([]*Hub, error) {
// back in time when the source for each path can be identified.
var hubsChain []*Hub

var depth = 3
var depth = 2

for _, val := range tx.Outpoints {
var setCount, hubCount, newDepth int
for _, val := range tx.Outpoints[3:] {
var setCount, hubCount int
var stackTrace []*Hub
count := 1

entry := &Hub{
Expand All @@ -67,9 +68,9 @@ func ChainDiscovery(client *rpcclient.Client, txHash string) ([]*Hub, error) {
}

hubCopy := entry
origHub := entry
// origHub := entry

err = handleDepths(entry, hubCopy, origHub, client, count, depth, setCount, newDepth, hubCount)
err = handleDepths(entry, hubCopy, stackTrace, client, count, depth, setCount, hubCount)
if err != nil {
return nil, err
}
Expand All @@ -82,32 +83,43 @@ func ChainDiscovery(client *rpcclient.Client, txHash string) ([]*Hub, error) {
return hubsChain, nil
}

func handleDepths(prevHub, curHub, origHub *Hub, client *rpcclient.Client, count, depth, setCount, newDepth, hubCount int) error {
err := curHub.getDepth(client)
if err != nil || count == depth {
return err
}
func handleDepths(curHub, prevHub *Hub, stack []*Hub, client *rpcclient.Client, count, depth, setCount, hubCount int) error {
// Adds items to the stack.
stack = append(stack, curHub)

if hubCount == len(prevHub.Matched[setCount].Inputs) {
hubCount = 0
count++
if count == depth || curHub.TxHash == "" {
// backtrack till we find an unvisited Hub.
for {
if len(stack) == 0 {
return nil
}

if setCount+1 < len(prevHub.Matched) {
setCount++
} else {
setCount = 0
prevHub = origHub.Matched[setCount].Inputs[hubCount]
}
curHub = stack[len(stack)-1]

}
if hubCount+1 < len(prevHub.Matched[setCount].Inputs) {
hubCount++
count--
break
} else if setCount+1 < len(prevHub.Matched) && hubCount == len(prevHub.Matched[setCount].Inputs) {
setCount++
count--
hubCount = 0
break
}

curHub = prevHub.Matched[setCount].Inputs[hubCount]
stack = stack[len(stack)-1:]
}
}

if len(prevHub.Matched) > 0 && hubCount < len(prevHub.Matched[setCount].Inputs) {
hubCount++
err := curHub.getDepth(client)
if err != nil {
return err
}

return handleDepths(prevHub, curHub, origHub, client, count, depth, setCount, newDepth, hubCount)
fmt.Printf(" >>>>>> setCount %v, len %v >>>>> hubCount %v, len %v \n", setCount, len(curHub.Matched), hubCount, len(curHub.Matched[setCount].Inputs))
curHub = curHub.Matched[setCount].Inputs[hubCount]

return handleDepths(curHub, prevHub, stack, client, count+1, depth, setCount, hubCount)
}

// getDepth appends all the sets linked to a given output after a given amount
Expand Down

0 comments on commit 3e85db8

Please sign in to comment.