berty / go-orbit-db

Go version of P2P Database on IPFS
https://berty.tech
Apache License 2.0
412 stars 56 forks source link

fix replciation when there is no direct connection betwen peers #98

Closed PGoski closed 2 years ago

PGoski commented 2 years ago

Scenario:

Problem reproduction:

  1. A creates new store and writes 1 entry
  2. C also creates store with same name and receives data from A
  3. B creates same store and doesn't receive data. (Data will be received when A adds a new entry to store and all 3 nodes are online)

After my fix B will receive data even if A went offline

PGoski commented 2 years ago

Tested again, B receive data after node restart which is better than before but not solves the problem fully.

PGoski commented 2 years ago

after more debugging I've found that there is a race condition in the original code behavior. Looks like it should be fixed somewhere else.

evidence that original code is working (sometimes):

2022-03-22T17:07:06.198Z DEBUG baseorbitdb/orbitdb.go:980 connecting to QmYCQorVqw67DUHEAmVv26K9wv5V8QrySoi89k6fUp2gxP 2022/03/22 17:07:06 end replicate event /orbitdb/bafyreic27uz6j5vaxk6g5q4f53ig3vw7cwt3zklnj74pt7ykiz2las6v4q/profile-metadata 2022-03-22T17:07:07.198Z DEBUG baseorbitdb/orbitdb.go:985 connected to QmYCQorVqw67DUHEAmVv26K9wv5V8QrySoi89k6fUp2gxP 2022-03-22T17:07:07.199Z DEBUG baseorbitdb/orbitdb.go:985 connected to QmPPG6NETmEwiSQooqMyE5GmmHZgzhxENzebaJgRhZHw3H 2022-03-22T17:07:07.199Z DEBUG baseorbitdb/orbitdb.go:1032 sending heads {"addr": "/orbitdb/bafyreigvpjkyrhfvyfwchmyez3unhaum54conaqxhgfd53aelinz2ghrbm/9902ef6b-28c6-4daf-8f0e-ff848c789717", "heads": 0, "peer": "QmYCQorVqw67DUHEAmVv26K9wv5V8QrySoi89k6fUp2gxP"} 2022-03-22T17:07:07.199Z DEBUG baseorbitdb/orbitdb.go:1032 sending heads {"addr": "/orbitdb/bafyreigvpjkyrhfvyfwchmyez3unhaum54conaqxhgfd53aelinz2ghrbm/9902ef6b-28c6-4daf-8f0e-ff848c789717", "heads": 0, "peer": "QmPPG6NETmEwiSQooqMyE5GmmHZgzhxENzebaJgRhZHw3H"} 2022-03-22T17:07:08.050Z DEBUG baseorbitdb/events_handler.go:33 QmUd9hASvtA76gS2mNZ8WAimnCAFyJps25iktkk9wgXGXq: Received 1 heads for '/orbitdb/bafyreigvpjkyrhfvyfwchmyez3unhaum54conaqxhgfd53aelinz2ghrbm/9902ef6b-28c6-4daf-8f0e-ff848c789717' from QmPPG6NETmEwiSQooqMyE5GmmHZgzhxENzebaJgRhZHw3H: