vegaprotocol / data-node

A rich API server for Vega Protocol
https://vega.xyz
Other
3 stars 1 forks source link

feat: handle recovery from snapshots #634

Closed ettec closed 2 years ago

ettec commented 2 years ago

closes #427 This PR completes the work to handle recovery from snapshot further to issue #498 Transactional Event Broker. On recovery the data node gets the last processed block (events for which are committed atomically) and uses this to filter out any blocks sent that have a height less than the last processed block. An additional check has been added to ensure an error is thrown if the height of the first block sent is greater than the last processed block height + 1.

ettec commented 2 years ago

The code ignores the whole block where vegaTime < time, just doing it in handle events would mean the code attempting to create an existing block, which would then require another time check, conceptually just ignoring the whole block made sense to me. I inlined a bit of the code in the processBlock as I think now its clear in that method what we do with each block, hence it bloated a bit but I think it makes the flow of events when processing a block more obvious, ie. on new block: update the time of all subscribers, open tranx, put an entry in the blocks table, process all events in block, flush subscribers, commit tranx. Before it may have looked neater but I think that was because the magic was hidden in some obscurely named methods (e.g. handleBlockEnd), which made it harder to follow the flow IMO, (having said that just made a small improvement to encapsulate a bit of logic in the processBlock)