amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.02k stars 1.16k forks source link

Data Integrity Issue, Server - Client Interaction #613

Open Dletta opened 5 years ago

Dletta commented 5 years ago

Condensed into 2 comments

Symptom

Running following code in the console, doesn't return 'undefined', but once I add data, it immediately returns the new data.

gun.get('nodes').map().once(console.log)

How to recreate

Open a client html, that creates a gun reference .

var gun = Gun('localhost:8080/gun');
//write an index you expect
var nodes = gun.get('nodes').put({label:'label'}) //when put is commented out, the error does **not** occur

Then run your server with node server.js. Even if the index existed previously with many references attached, now performing this in the client

13:23:13.688 gun.get('nodes').once(console.log) //.on does not work either in this situation
13:23:13.671 {…}
​                      _: {…}
                          "#": "nodes"
​​                          ">": Object { __type: 1537993209913, __label: 1537993209913 }
​​                                 <prototype>: Object { … }
​                      label: "label"
                      //missing references here for other nodes previously added via .set
                      <prototype>: Object { … }
                          nodes gun.js:1634:6
13:23:13.668 Object { _: {…} }
Dletta commented 5 years ago

Radata File shows clearly other data is still there, but it seems links are gone...

+0#"edges. +1#" +2#"label=""edgesIndex>+1537993209918 +2#"type=""index>+1537993209918 +1#"jmi +2#"nyb6fotDZzeg6Snip="#jminyb6fotDZzeg6Snip>+1537936952345 +2#"o7yg3OO1QWt6pJ4qv="#jmio7yg3OO1QWt6pJ4qv>+1537937402405 +0#"jmi +1#"n +2#"xo8bUGJW2Qv5VHoR. +3#" +4#"label=""Charles>+1537936922603.001 +4#"type=""node>+1537936922603.001 +3#"name=""Charles>+1537936922603.001 +3#"out="#jminzztxP4qi62wV0duo>+1537937030944 +2#"y +3#"b6fotDZzeg6Snip. +4#" +5#"label=""likes>+1537936952343.001 +5#"type=""edge>+1537936952343.001 +4#"s +5#"ince=""always>+1537936952343.001 +5#"ource="#jminxo8bUGJW2Qv5VHoR>+1537937030946 +4#"target="#jminyz8uu0NTDN6MCdrW>+1537937030947.001 +3#"z8uu0NTDN6MCdrW. +4#" +5#"label=""Ice Cream>+1537936983535 +5#"type=""node>+1537936983535 +4#"flavor=""strawberry>+1537936983535 +4#"in="#jminzzu2qXxwLfLEWZdD>+1537937030948 +2#"zz +3#"txP4qi62wV0duo.jminyb6fotDZzeg6Snip="#jminyb6fotDZzeg6Snip>+1537937030944 +3#"u2qXxwLfLEWZdD.jminyb6fotDZzeg6Snip="#jminyb6fotDZzeg6Snip>+1537937030948 +1#"o +2#"5uvs6cFNsHdpnEJL. +3#" +4#"label=""Nathan>+1537937304473 +4#"type=""node>+1537937304473 +3#"name=""Nathan Drake>+1537937304473 +3#"out="#jmio96nvh2WGTFGihIiV>+1537937459700 +2#"7yg3OO1QWt6pJ4qv. +3#" +4#"label=""type>+1537937402403.001 +4#"type=""edge>+1537937402403.001 +3#"source="#jmio5uvs6cFNsHdpnEJL>+1537937459703 +3#"target="#jmio8tamEELJcsKeFUdv>+1537937459704 +2#"8tamEELJcsKeFUdv. +3#" +4#"label=""Artist>+1537937442382.001 +4#"type=""node>+1537937442382.001 +3#"in="#jmio96o2hZt0qzelpXOW>+1537937459705.001 +3#"name=""artist>+1537937442382.001 +2#"96 +3#"nvh2WGTFGihIiV.jmio7yg3OO1QWt6pJ4qv="#jmio7yg3OO1QWt6pJ4qv>+1537937459700 +3#"o2hZt0qzelpXOW.jmio7yg3OO1QWt6pJ4qv="#jmio7yg3OO1QWt6pJ4qv>+1537937459705.001 +0#"nodes. +1#" +2#"label=""nodesIndex>+1537993209913 +2#"type=""index>+1537993209913 +1#"jmi +2#"n +3#"xo8bUGJW2Qv5VHoR="#jminxo8bUGJW2Qv5VHoR>+1537936922606 +3#"yz8uu0NTDN6MCdrW="#jminyz8uu0NTDN6MCdrW>+1537936983537 +2#"o +3#"5uvs6cFNsHdpnEJL="#jmio5uvs6cFNsHdpnEJL>+1537937304475 +3#"8tamEELJcsKeFUdv="#jmio8tamEELJcsKeFUdv>+1537937442383.001

amark commented 5 years ago

@Dletta I fixed .once in one of the more recent versions. Is this working now, can we close? :) Thanks for the report, I very much appreciate how much you help!

Dletta commented 5 years ago

@amark I ran it again. When I write following line, after data has already been added to these indices, the index looses all connections to nodes added to data underneath...

var nodes = gun.get('nodes').put({'__type':'index','__label':'nodesIndex'});

! file shows following change ocurred. Which shouldn't delete other nodes linked to from the index. When I reverse the changes, data is accessible again.

+2#"label=""nodesIndex>+1541048154860 //number changed only
+2#"type=""index>+1541048154860 //number changed only

Is this a write issue? A radix issue? Gun v 0.9.99997

amark commented 5 years ago

garrrrr.... I think this is a timing issue, and also related ot the bug I need to fix for @ThinkingJoules and quasi related to @mmalmi

Certainly need to get that fixed, but it'll definitely trash put performance for nested objects. Oh well, correctness > perf.