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

Update signer to support multiple stacks node urls #382

Merged
merged 5 commits into from
Aug 11, 2024

Conversation

xoloki
Copy link
Contributor

@xoloki xoloki commented Aug 1, 2024

Description

Update code and config to support multiple stacks urls.

Closes: #225

Changes

Config and stacks api now store multiple endpoints. Stacks api also keeps an index for the current endpoint. This index is incremented on network failure.

Testing Information

Existing tests have been updated to check previous and new functionality.

Checklist:

  • I have performed a self-review of my code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@xoloki xoloki changed the title Update deserializer for vec of urls Update signer to support multiple stacks node urls Aug 2, 2024
@xoloki xoloki marked this pull request as ready for review August 3, 2024 19:24
@xoloki xoloki requested a review from djordon August 3, 2024 19:24
Copy link
Contributor

@djordon djordon left a comment

Choose a reason for hiding this comment

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

This looks okay, but I think we inadvertently introduced some behavior that we don't want. I think I see one main issue, and another "stylistic issue":

  1. We switch to another stacks node even when the current stacks node that we were using was perfectly fine. For example, Stacks nodes return an error when they don't have enough data to estimate fees, the node could be perfectly fine. With these changes, we'd change node endpoints in that example, but I think it would be better to change node endpoints only when we suspect that the node is down.
  2. We switch to a new node within the endpoint functions when we it feels more natural to switch outside of them. To me, it feels better to have a simple endpoint function that wraps the API call, and another that uses the simple endpoint function and rotates the node endpoint if it gets connectivity error (or a similar error) from the simple function. This other function could also retry the call after switching nodes (but we can save that part for another day). So I wouldn't change the endpoint functions here, probably just the trait functions.

Anyway, let me know if you think that these suggestions make sense.

signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/config.rs Show resolved Hide resolved
@xoloki
Copy link
Contributor Author

xoloki commented Aug 5, 2024

  1. Totally agree. Earlier versions of this PR only rotated urls on connection errors or if the response didn’t complete. But once I realized I could put a closure in map_err, I just did them all 😂
  2. Disagree on this. What you’ve described sounds much more complicated, and other than saving a few mutables doesn’t seem to gain us anything. Logically the API should know the URLs, and it knows when connection errors happen, so it should be the one to rotate the URLs.

Forgot return

Deserializer return vec needs to be mutable

Store full endpoint array from config; keep an index into endpoints and use it to get current url

Fix missing endpoints updates

Fix config tests for multiple endpoints

Fix tests in api.rs for multiple endpoints

Fix remaining test

Update default config

Stacks node not API uses multiple endpoints

Fix environment variables in config tests

Test multiple endpoints via environment

Increment index on network error

Specify result return

Specify request::Error

Try making self mutable so we can increment the index

Need semicolon since we’re returning a value

Make stacks client mutable

Keep going down the mutable rabbit hole

More mutable

Moar mutable

Need moar mutable

Use ephemeral stacks clients

Fix usage of stacks client

Remove mutable since stacks client is now ephemeral

Try again to fix mutable issue

Handle connection errors on all functions

Add mutable and fix response types

Trait functions need to be mutable

Need to clone before moving into closure; trait needs to be mutable

Remove closure

Fix braces

Return on error from dummy tx

Fix warnings

Stacks client ref needs to be mut

Remove unused imports; mutability fixes

Take mutable reference

Stacks client needs to be mutable

Moar mutability fixes

Keep going down mutability rabbit hole

Trait functions need mutable self

Fix final trait

Handle response failure in get account

Return Err not just error

Handler response errors in submit tx

Handle response errors in get fee estimate

Try again with match not if let else

Try closure map_err for get block

Add next _endpoint fn; use only closure map err in get block

Add doc comment for next endpoint fn

Handle rest of response errors

Convert everything to map err

Moar map err

map_err for get_account

Remove unneeded question mark

check for network errors in trait not api functions themselves; unwind as much of the mutable changes as possible
@xoloki xoloki force-pushed the 225-multiple-stacks-endpoints branch from 5c53151 to 992fd78 Compare August 8, 2024 23:04
@xoloki
Copy link
Contributor Author

xoloki commented Aug 8, 2024

Ok @djordon I've addressed all review comments, rebased on main, and squashed the bulk of the commits to make the PR less verbose. lmk what you think.

@xoloki xoloki requested a review from djordon August 8, 2024 23:16
Copy link
Contributor

@djordon djordon left a comment

Choose a reason for hiding this comment

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

Great, I think this feels better. My main comments are around factoring out the identical logic into a function and matching on fewer error variants.

signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
signer/src/block_observer.rs Outdated Show resolved Hide resolved
signer/src/stacks/api.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@djordon djordon left a comment

Choose a reason for hiding this comment

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

Looks good ✅

signer/src/block_observer.rs Outdated Show resolved Hide resolved
@xoloki xoloki merged commit 8cacd72 into main Aug 11, 2024
3 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.

[Feature]: Support multiple Stacks node URLs
2 participants