Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation #1

Merged
merged 61 commits into from
Oct 1, 2024
Merged

Implementation #1

merged 61 commits into from
Oct 1, 2024

Conversation

juliangruber
Copy link
Member

@juliangruber juliangruber commented Aug 27, 2024

This implements revision D of https://spacemeridian.notion.site/Meridian-Off-chain-scheduled-rewards-f9480ef009464ecfaf02a4f752cc4d70.

I decided to use Redis as the data store, because:

  • It's easy to install and run
  • Fly supports it out of the box
  • It is less complex than postgres
  • Redis data structures made this straight forward
  • This service will be deprecated asap

@bajtos
Copy link
Member

bajtos commented Aug 29, 2024

I see you made changes while I was reviewing the PR, I will review them after posting this comment.

The change was just setting SENTRY_ENVIROMENT for Fly.io, that part LGTM.

@juliangruber juliangruber requested a review from bajtos August 29, 2024 11:52
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!

Do you have any concerns about the the growing storage requirements for logs? I did a quick calculation, we will produce ~60MB per day if we have 5k participants.

Redis supports TTL-based expiration. Can we use it for log entries? I think TTL of 30 days is more than enough for what we need.

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
bin/spark-rewards.js Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test.js Outdated
address: '0x000000000000000000000000000000000000dEaD',
scheduledRewards: '-9132'
address: '0x000000000000000000000000000000000000dEa2',
scheduledRewardsDelta: '-9132'
}
])
}
})
await t.test('validate signatures', async t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't node:test provide an API for grouping tests to test suites? I know they provide both describe and it, what is the counterpart for describe? Maybe suite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow, isn't t.test() grouping tests as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the tap way of defining a subtest

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in node:test, describe() is an alias of suite(): https://nodejs.org/api/test.html#describe-and-it-aliases.

I'm not sure when to use suite() vs test(), do you know how it could improve this test suite?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use suite for grouping related tests and test for individual tests, that's how I am using describe and it.

Basically, only suites are allowed to contain nested things (tests or suites).

suite('scheduled rewards', () => {
  test('empty scheduled rewards', async t => {
    // ...
  })

  test('ignore burner address', async t => {
    // ...
  })

  // etc.
})

This way, you also do not need to await t.test.

See the example code snippet provided in Snapshot Testing:

// test.js
suite('suite of snapshot tests', () => {
  test('snapshot test', (t) => {
    t.assert.snapshot({ value1: 1, value2: 2 });
    t.assert.snapshot(5);
  });
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, thank you, but why is it better?

I assume it's better because you can filter tests better? I never use this functionality so I don't mind. Would you like me to rework this using suite()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, only suites are allowed to contain nested things (tests or suites).

Please see https://nodejs.org/api/test.html#contexttestname-options-fn, node test doesn't have this limitation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to suites in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, thank you, but why is it better?

I find the test code easier to read this way because it's clear to me which parts define the structure and which parts are actually executed as tests.

I assume it's better because you can filter tests better?

That's very likely! I don't have any experience with your style of structuring tests, so I cannot tell how it affects test filtering.

I never use this functionality so I don't mind. Would you like me to rework this using suite()?

That would be great, thank you! 🙏🏻

Switched to suites

😍

@juliangruber
Copy link
Member Author

Almost there!

Do you have any concerns about the the growing storage requirements for logs? I did a quick calculation, we will produce ~60MB per day if we have 5k participants.

Redis supports TTL-based expiration. Can we use it for log entries? I think TTL of 30 days is more than enough for what we need.

Good point, I've limited logs to ~30 days.

Redis doesn't (easily) support expiration of list entries, therefore I'm capping the list based on an estimation of how many entries we have after 30 days:

3 rounds per hour * 24 hours * 30 days * 5000 participants

@juliangruber juliangruber requested a review from bajtos September 30, 2024 13:42
@juliangruber juliangruber merged commit ea65dee into main Oct 1, 2024
6 checks passed
@juliangruber juliangruber deleted the add/implementation branch October 1, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants