4

I would like to pick a random node, call getNodeInfo and see it's latest milestone.

Then I'd like to walk the graph (depth first search? breadth first search?) backwards to the start and map the entire graph.

I.e. this is the "sync" operation a wallet would do when it first starts up and has zero stored transactions.

I've looked at the IRI java code but I'm missing the simple logic to take the milestone value from a node, and call GetTrytes to turn that into a full 2673 length tx, then take the Bundle, and/or TrunkTransaction, BranchTransaction, Address and get the next hop, and the next hop, etc.

When I try to write this logic myself I get a few hops, but then I quickly reached the end of some path and don't walk the entire tangle.

Does anyone have simple Pseudocode to walk the entire tangle?

3
  • Haven't you reached your goal then? Having walked back to the start? Or is your goal to map the entire graph?
    – Helmar
    Dec 20, 2017 at 17:58
  • map the entire graph. but I see what you are saying. I'm not adding the right stuff to a list and then going back to that list in true breadth first graph walking style. Dec 20, 2017 at 18:09
  • Exactly you'll need to take all the open tips and follow both source transactions to the source—or to an already mapped transaction.
    – Helmar
    Dec 20, 2017 at 18:31

2 Answers 2

6

Basic recursion for every open tip should do it. Just follow everything back to the origin or until you hit something you mapped already. I know that those object notations are very pseudo ;)

foreach(tangle_node open_tip)
{
  follow(parent_a);
  follow(parent_b);
}

follow(tangle_node x)
{     
  add_node_to_map(x); 
  if(root OR (x already_mapped))break;
  follow(x's_parent_a);
  follow(x's_parent_b);
}
1
  • this is working better for me. hasn't stopped yet. Dec 21, 2017 at 16:16
2

I would use a list of "seen" and "unseen" transactions (essentially being a breadth-first search). Don't care about the bundle hashes or address hashes, they will only point you to transactions that are in the tangle elsewhere. The ones you have to follow are trunk transaction hash and branch transaction hash. The very first milestone will have a trunk transaction hash and branch transaction hash of 9999⋯9 (so all zero trytes), so if you treat that one as "seen", your algorithm will terminate eventually.

When confirmed transactions are all you need, start with the latest solid subtangle milestone hash; else you'd also have to query for tips (but I think the node will not give you the full list but only a selection) and add those too.

So in pseudocode:

seen = [999⋯9]
unseen = [latest_solid_subtangle_milestone_hash]
while (unseen is not empty) {
  tofetch = get_and_remove_first(unseen)
  tx = fetch(tofetch)
  process(tx)
  seen.add(tofetch)
  if (not seen.contains(tx.trunk) and not unseen.contains(tx.trunk))
    unseen.add(tx.trunk)
  if (not seen.contains(tx.branch) and not unseen.contains(tx.branch))
    unseen.add(tx.branch)
}
5
  • i tried this logic and got back to 2017-10-24 22:36:48 and about 15,000 transactions but then it stopped. Dec 21, 2017 at 16:15
  • @AndrewArrow That was about the time of the last snapshot. You won't get any more recent transactions from online nodes. Have a look at these (and probably import them into the corresponding old iri versions) if you need more history: store.alon-e.com/IOTA_DBs
    – mihi
    Dec 21, 2017 at 18:12
  • so online nodes never have the full history or this was a 1 time event back in Nov 23 2017? Dec 21, 2017 at 18:51
  • i.e. going forward will online nodes provide full history or that was never the idea? Dec 21, 2017 at 18:51
  • It is a design decision that full nodes will not provide full history (as it will grow big and for most practical needs it is enough to keep the nonzero balances in the snapshot). This information should be provided by "permanodes" later (see also iota.stackexchange.com/questions/782/full-node-vs-permanode), who may charge for this service, but currently there is no finished software to host one, you'd have to import old iri dbs yourself (like iotawayback does).
    – mihi
    Dec 21, 2017 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.