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

grant_installation #50

Merged
merged 4 commits into from
Jan 29, 2024
Merged

Conversation

tsachiherman
Copy link
Contributor

What ?

This PR adds support for registering a new installation.

Design considerations

The xps-gateway is the executable endpoint, that manages the rpc endpoint. It will setup an rpc server that would listen for incoming requests and perform input validation. Valid requests would be forwarded to the inbox / messaging / registry crates for method-specific implementation.

Requirements

This PR followed the design details in #22; discussion in #13 and xmtp/libxmtp#274

@tsachiherman tsachiherman requested a review from insipx January 29, 2024 17:23
@tsachiherman tsachiherman self-assigned this Jan 29, 2024
@insipx
Copy link
Contributor

insipx commented Jan 29, 2024

should have an integration test in the style of revoke_installation

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (1439a2e) 77.32% compared to head (fff0803) 82.01%.
Report is 1 commits behind head on main.

Files Patch % Lines
registry/src/lib.rs 94.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #50      +/-   ##
==========================================
+ Coverage   77.32%   82.01%   +4.69%     
==========================================
  Files          10       10              
  Lines         172      228      +56     
==========================================
+ Hits          133      187      +54     
- Misses         39       41       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

gateway-types/src/lib.rs Show resolved Hide resolved
let attribute: [u8; 32] = Attribute::from(name).into();
log::debug!(
"setting attribute {:#?}",
String::from_utf8_lossy(&attribute)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember that this string will always be created, even if this log is suppressed. This may be slightly too verbose logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm perfectly fine eliminating that. it was used during my debugging, but I don't feel strongly here.

@tsachiherman
Copy link
Contributor Author

@jac18281828 question - I've calculated a validity to be one year in the future.
The issue is that it needs to be exactly the same validity for the signer and the sender.
so, taking current_block + 1 year might change. two options:

  1. add the validity to the grant_installation rpc arguments.
  2. set the validity so that it won't change between signing and sending. for example - trim it to a 1000's round a year from n ow. i.e. validity = (block_number + 1 year ) & 0xfffffff000

)
.send()
.await?
.await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

so far, we've been doing this strategy with .await?.await? which first sends the transaction, gets back a PendingTransaction, and then waits for it to be included + a specified amount of confirmations (default of 1). I like what you did below, though, but unsure what the better path would be:

Do we make the gateway wait until tx is confirmed or do we just return the tx_hash and have libxmtp/client wait?

We can instead just return the txHash from the RPC, and not wait on transaction inclusion, leaving tx confirmations up to the client. We do give up some control if something goes wrong.

Not a super important detail, but maybe worth a quick discussion WDYT @tsachiherman @jac18281828 @37ng

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that it's a very important observation, as this is a blocking operation that consumes servers memory for the entire duration of the operation.
Another point is that regardless if we make it "non-blocking" or not, we need to be able to detect a fail cases so that we can log these.

Copy link
Contributor

@insipx insipx Jan 29, 2024

Choose a reason for hiding this comment

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

That's true, IMO I think we should hand off control of the transaction to the client and just return txHash. A PendingTransaction can be easily rebuilt from libxmtp side by just providing the hash and a provider, so if anything fails they could re-submit the transaction

We could also provide an endpoint to do this for them, i.e subscribeTransaction or something along those lines

Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid waiting whenever possible in the service. We haven't spent much time optimizing the number of threads, etc., these threads will be precious.

Copy link
Contributor

Choose a reason for hiding this comment

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

made an issue for this: #52

the return of revoke_installation will have to change as well

@@ -23,16 +24,57 @@ where
Self { registry }
}

fn resolve_did_address(&self, did: String) -> Result<H160, ContactOperationError<M>> {
// for now, we will just assume the DID is a valid ethereum wallet address
// TODO: Parse or resolve the actual DID
Copy link
Contributor

Choose a reason for hiding this comment

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

Made into an issue, #51

@@ -23,16 +24,57 @@ where
Self { registry }
}

fn resolve_did_address(&self, did: String) -> Result<H160, ContactOperationError<M>> {
// for now, we will just assume the DID is a valid ethereum wallet address
// TODO: Parse or resolve the actual DID
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO: Parse or resolve the actual DID

Copy link
Contributor

@insipx insipx 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! I'm willing to approve after an integration test is added

@jac18281828
Copy link
Contributor

@jac18281828 question - I've calculated a validity to be one year in the future. The issue is that it needs to be exactly the same validity for the signer and the sender. so, taking current_block + 1 year might change. two options:

  1. add the validity to the grant_installation rpc arguments.
  2. set the validity so that it won't change between signing and sending. for example - trim it to a 1000's round a year from n ow. i.e. validity = (block_number + 1 year ) & 0xfffffff000

The validity period should be sent to the contract (how long). The contract computes the validity internally according to the EVM block timestamp and reports back the validity that it came up with. That validity should then be used in the future for all operations. The validity required for the signature will be the duration validity (one year) not the actual timestamp.

We may want to standardize on two options to begin with: does not expire, or one year

@tsachiherman
Copy link
Contributor Author

tsachiherman commented Jan 29, 2024

Looks good! I'm willing to approve after an integration test is added

see test_grant_installation()

@insipx
Copy link
Contributor

insipx commented Jan 29, 2024

We could do this in the style of the attribute, i.e an enum like

enum Validity {
    OneYear
    Forever
}

@jac18281828
Copy link
Contributor

We could do this in the style of the attribute, i.e an enum like

enum Validity {
    OneYear
    Forever
}

Yeah, my bad, I should have looked it up before I wrote my message but a validity is always required. We may want to choose either OneYear or FiveYear.

@tsachiherman
Copy link
Contributor Author

I'll merge it and keep working on the extended unit tests & validity.

@tsachiherman tsachiherman merged commit d5fc1cd into xmtp:main Jan 29, 2024
4 of 5 checks passed
@tsachiherman tsachiherman deleted the tsachi/add_installation branch January 29, 2024 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants