Page MenuHomePhabricator

[alias-server] Handle startup case with its own callback in parseWebsocketMessage
ClosedPublic

Authored by bytesofman on Apr 6 2023, 03:30.

Details

Summary

T3060

parseWebsocketMessage is the main function that updates valid alias registrations. If the server has been shutdown, it is called immediately on app startup to bring the server to the latest chain state.

Otherwise it is always called on receiving a websocket message from chronik. Instead of shimming the special startup case into the BlockConnected callback, define its own callback.

Add TODOs for future functions and logic.

Test Plan

npm test

Diff Detail

Event Timeline

OK I see that you tried to reuse the suggestions from the previous diffs reviews. However there is a simpler and better solution: create a startup function.

Now that the message parsing has been emptied, the logic for block connection can be moved into its own function (say handleBlockConnected(hash, height).

Then your startup function can look like so:

function startup() {
    console.log('App startup, catching up to the current tip');

    {tipHash, tipHeight} = someWayToGatherTheHashAndHeight();

    handleBlockConnected(tipHash, tipHeight);
}

Improving logic with new event handler functions

However there is a simpler and better solution: create a startup function.

Good point.

I've created stub methods for these functions. Unit tests for the app startup function will be added when the function does something.

removing obsolete 'StartUp' switch type

Fabien requested changes to this revision.Apr 6 2023, 12:59
Fabien added inline comments.
apps/alias-server/src/events.js
52 ↗(On Diff #39339)

This block is misplaced, see below

apps/alias-server/src/websocket.js
48 ↗(On Diff #39339)

The new block found log belongs here

This revision now requires changes to proceed.Apr 6 2023, 12:59
bytesofman marked 2 inline comments as done.

block found log belongs in switch statement

remove unused var and replace with commented todo to pass lint

This revision is now accepted and ready to land.Apr 6 2023, 13:52