Bonfida / agnostic-orderbook

Apache License 2.0
79 stars 33 forks source link

After upgrading: events are not processing in the same order #83

Closed 0xBraunGuy closed 2 years ago

0xBraunGuy commented 2 years ago

Repro: https://github.com/0xBraunGuy/test-aob-v4

Basically after upgrading both the client and server side of the AOB, seems events are getting out of sync when not processing them all at once.

I.e. after consuming a single event, the client shows the event was popped from the bottom of the queue. But the program registers it as being popped from the top (expected).

Could be a mismatch between versions? But not having any crates in the repo makes that harder to debug.

dr497 commented 2 years ago

Looking at your code the issue seems to be coming from how you print the event queue on the client side. Your client side implementation logEvents is not equivalent to the loop program side. The difference comes from the fact that peek_at takes into account the position of the head of the event queue. Indeed, your implementation will always print [0, nb_events] instead of [head, head + nb_events]. Adding the head offset to your for loop should solve the issue.

I also opened a PR to add a JS method equivalent to the peek_at function of the program

https://github.com/Bonfida/agnostic-orderbook/pull/85/files

0xBraunGuy commented 2 years ago

Ah that explains it! Thank you @dr497