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

Add contributors to seed function; add bulk node retrieval; and some small optimizations #51

Merged
merged 4 commits into from
Jul 18, 2024

Conversation

jagerman
Copy link
Member

  • The seed function was only taking pubkeys and leaving operator and contributors empty, thus any seeded SNs would not be unlockable. This adds a huge, slow test for seeding 2000 service nodes to get an idea of how long it will take: with randomly generated 1-4 contributors in each, this ends up being approximately 600 million gas.

  • Adds a pair of methods for retrieving all unique ids + all bls pks, and for retrieving all bls pks without needing to walk the linked list.

  • Adds a few small optimizations that slightly reduce gas costs.

  • don't use the (expensive) serviceNodesLength(), but use totalNodes instead.

I'm not sure whether it's worth keeping serviceNodesLength() and updateServiceNodesLength(): they only seem to be there for a "what if something goes horribly wrong in the contract" case (i.e. totalNodes gets out of sync with the actual number of nodes we have), but I left them in (though now unused) for now.

serviceNodeLengths() is relatively expensive in that it has to walk the
entire linked list (which involves a lot of storage accesses), and so we
shouldn't be using it in general when the much cheaper totalNodes is
available to us.

It isn't entirely clear that the serviceNodesLength and
updateServiceNodesLength have a useful purpose (totalNodes should always
be maintained at the correct value anyway), but they are perhaps useful
backup functionality for a serious contract mishap, and leaving them
doesn't *hurt* anything.
- Replace multiple repeated map lookups with a pointer.
- return storage pointer from serviceNodeAdd so that the caller can also
  avoid needing to look it up again.
- Don't pass amounts to seed list, since it will always be the staking
  amount.
- increment is cheaper than += 1
- reading "prev" into a local variable is cheaper than trying to access
  it via storage memory multiple times
oxend needs these to be able to efficiently retrieve this without having
to make an infeasible number of individual requests to walk the linked
list.
The seed function was only taking pubkeys and leaving operator and
contributors empty, thus any seeded SNs would not be unlockable.

This adds a huge, slow test for seeding 2000 service nodes to get an
idea of how long it will take: with randomly generated 1-4 contributors
in each, this ends up being approximately 600 million gas.
@jagerman jagerman merged commit c132787 into oxen-io:integration Jul 18, 2024
0 of 2 checks passed
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.

1 participant