Page MenuHomePhabricator

[alias-server] Add avalancheCheckWaitInterval as a parameter to prevent 10s delays in unit tests
ClosedPublic

Authored by bytesofman on Apr 8 2023, 13:48.

Details

Summary

T3060

Depends on D13631

App should wait ~10s before checking if a found block is avalanche finalized. We don't want to do this in unit tests.

So, make this a parameter and pass to all required functions.

Test Plan

npm test
npm test

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bytesofman updated this revision to Diff 39433.

Using param in function

Fabien requested changes to this revision.Apr 9 2023, 09:05
Fabien added a subscriber: Fabien.
Fabien added inline comments.
apps/alias-server/config.js
8 ↗(On Diff #39433)
apps/alias-server/index.js
84 ↗(On Diff #39433)

You might as well just pass config to main and all the way down, and avoid adding more and more options over time

apps/alias-server/src/events.js
91 ↗(On Diff #39433)

This is not an efficient strategy, you should rather retry in a loop with a small delay, up to a timeout. Pseudo code:

var timeout = 10000;
while (!avalanche_finalized(blockhash) && timeout >= 0) {
    wait(500);
    timeout -= 500;
}
92 ↗(On Diff #39433)

No blocker, but it would be easier to read if that was a made a generic function, like waitAsync(delay) or something like that

This revision now requires changes to proceed.Apr 9 2023, 09:05

updating todo, putting wait method into more readable utils function

apps/alias-server/index.js
84 ↗(On Diff #39433)

Yes. I think its best done after this stack though, so that there are existing unit tests on main()

apps/alias-server/src/events.js
93 ↗(On Diff #39471)

this is more readable. i'm not sure how to unit test the function, it's just a JS primitive

91 ↗(On Diff #39433)

ok, but this should be done in the function that checks for isFinalBlock, as the value is needed for this loop

in this diff we only introduce the parameter.

Updated the todo

apps/alias-server/src/events.js
91 ↗(On Diff #39433)

While this approach is better, imo this is another feature that may not be needed and is not relevant to this stack

The right way to fix this is to have chronik send block connected msgs on avalanche finalized blocks, obviating the need for rpc entirely.

This type of "keep checking for avalanche status" functionality can be added as an optimization if we are seeing this issue in prod.

Fabien requested changes to this revision.Apr 10 2023, 19:09
Fabien added inline comments.
apps/alias-server/src/events.js
93 ↗(On Diff #39471)

You don't need to unit test this function, there is no logic there

91 ↗(On Diff #39433)

this should be done in the function that checks for isFinalBlock

Agreed.

91 ↗(On Diff #39433)

I disagree. It's not another way to do it, it's the proper way to do it.
Chronik will still send you connected block message before they are avalanche finalized and that's normal, it would be a bad indexer if it wasn't doing it. But it will provide you an endpoint to check for finalization so you won't have to use an RPC.

Look at it from another angle: you stacked a diff to bypass this delay during the tests. With the suggested method, you don't need it at all. That's an immediate win.

This revision now requires changes to proceed.Apr 10 2023, 19:09
bytesofman marked an inline comment as done.

Add logic to check isFinalBlock at set intervals

see D13634 for implementation with isFinalBlock

apps/alias-server/src/events.js
94 ↗(On Diff #39518)

Note: testing this over 20 blocks

Max time to avalanche final block: 41 seconds
Min time: 24 seconds
Avg: 29.1 seconds

So -- even with a high-ish resolution of "check every half second" -- we should probably wait 20s before checks begin.

apps/alias-server/src/events.js
95 ↗(On Diff #39518)

Check first, then wait only if needed. Even if that's never reached in real world that's what you want for the tests.

Fabien added inline comments.
apps/alias-server/src/events.js
95–96 ↗(On Diff #39540)
This revision is now accepted and ready to land.Apr 11 2023, 14:19