-
Notifications
You must be signed in to change notification settings - Fork 375
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
Optimized Attestation view calls and removal of the reveal TX #1578
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1578 +/- ##
=========================================
Coverage ? 73.78%
=========================================
Files ? 279
Lines ? 7606
Branches ? 657
=========================================
Hits ? 5612
Misses ? 1881
Partials ? 113
Continue to review full report at Codecov.
|
packages/utils/src/collections.ts
Outdated
@@ -18,6 +18,16 @@ export function zip3<A, B, C>(as: A[], bs: B[], cs: C[]) { | |||
return res | |||
} | |||
|
|||
export function compact<A>(as: Array<A | null>): A[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this could be done with .filter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, originally filter didn't properly get rid of the type, but i can use the custom defined type guard below
} | ||
} catch (error) { | ||
console.error(error) | ||
return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider allowing the error to propagate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about it, but it seemed to me that a validator not or incorrectly registering an attestation service url should not result in an error for a client who just wants to complete attestations. Thus, I favored returning the attestations that are completable, by intent of the function.
this.contract.methods.reveal( | ||
PhoneNumberUtils.getPhoneHash(phoneNumber), | ||
encryptedPhone, | ||
async requestAttestationFromIssuer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reveal
is a better name here? or something else. I find this is confusing given that requesting an attestation is already a step in the verification process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always open to naming advice, I opted for requestFromIssuer
because that's what it represents imo (vs. requesting from the smart contract). reveal
made more sense when it was on-chain as we encrypted the number to the validator, but now we are explicitly requesting from a validator's service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to two "request"s being confusing. In some sense, we are revealing our phone number here to the issuer. Alternatively, maybe the original request is more of a commitment to request attestations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like commit a lot, but many related structs and events do make more sense as request
for that transaction. Here are the steps currently:
- request - "commits" to a number of attestations, we have that commitment as an "unselected request" right now
- selectIssuers - "selects" on an "unselected request", and persists the actual attestations with their corresponding issuers
- requestFromIssuer - advances an attestation by "revealing" the phone number to an issuer, prompting an issuer to send the SMS
- complete - completes the attestation by posting the signed message from the SMS.
I still don't quite like reveal
but given my lack of alternative suggestions, I'll move it to reveal
Do you have any information on whether or not this actually makes things faster? |
AttestedAddress storage state = identifiers[identifier].attestations[account]; | ||
address[] storage issuers = state.selectedIssuers; | ||
|
||
uint num = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256 everywhere
* @param account Address of the account. | ||
* @return ( blockNumbers[] - Block number of request/completion the attestation, | ||
* issuers[] - Address of the issuer, | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
@@ -238,46 +230,6 @@ contract Attestations is | |||
delete state.unselectedRequests[msg.sender]; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document this in the PR desrcriptinn. If anything, maybe this should be the title of the PR
view | ||
returns (uint[] memory, bytes memory) | ||
{ | ||
uint totalSize = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256
Do you have any information on whether or not this actually makes things faster? Also please be sure to follow the style guide. |
We have no concrete information on whether this makes things actually faster or not. However theoretically, we move from 2*N + 1 view calls to 1 view call (where N = 3). It might be a negligent number once we improve light client performance, but in the meantime this seems like an easy win. My bad on |
@@ -0,0 +1,21 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't review this
@@ -179,50 +176,50 @@ export class AttestationsWrapper extends BaseWrapper<Attestations> { | |||
} | |||
|
|||
/** | |||
* Returns an array of attestations that can be completed, along with the issuers public key | |||
* Returns an array of attestations that can be completed, along with the issuers attestation service url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: issuer's
.then(parseAttestationInfo) | ||
) | ||
|
||
const result = await this.contract.methods.getCompletableAttestations(phoneHash, account).call() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define a helper method that parses this into a more readable object
this.contract.methods.reveal( | ||
PhoneNumberUtils.getPhoneHash(phoneNumber), | ||
encryptedPhone, | ||
async requestAttestationFromIssuer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to two "request"s being confusing. In some sense, we are revealing our phone number here to the issuer. Alternatively, maybe the original request is more of a commitment to request attestations?
* @param issuer The issuer of the attestation. | ||
* @param sendSms Whether or not to send an SMS. For testing purposes. | ||
*/ | ||
function reveal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕺
uint256[] memory sizes = new uint256[](accountsToQuery.length); | ||
for (uint256 i = 0; i < accountsToQuery.length; i++) { | ||
sizes[i] = bytes(accounts[accountsToQuery[i]].metadataURL).length; | ||
totalSize += sizes[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
safemath everywhere
@@ -1,29 +1,26 @@ | |||
pragma solidity ^0.5.3; | |||
|
|||
import "openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol"; | |||
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | |||
import 'openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we went with double quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with an upstream merge
* master: (56 commits) Adjust e2e transfer and governance tests to match new fee distribution and eliminate ProposerFraction (#1585) [Wallet] Add more local currencies (#1698) Switch to correct cluster when fauceting (#1687) [Wallet] Use the country of the phone number for determining the default local currency (#1684) [Wallet] Limit QR code scanner to 1 code per second (#1676) Update Dark backgrounds text color (#1677) Remove integration sync test Minor attestation service fixes (#1680) [wallet] Fixed Native phone picker Use native API instead (#1669) Fix token addresses for notification service (#1674) Add golang to setup docs [wallet] Hide invite education copy after invite was redeemed (#1670) [Wallet] Add spinner, timer, and tip text to Verification input screen (#1656) [Wallet] Fix app deprecation check mechanism (#1358) Point end-to-end governance test back to master (#1665) Add EpochRewards smart contract to calculate epoch rewards and payments (#1558) Optimized Attestation view calls and removal of the reveal TX (#1578) Support claim signatures and support Keybase claims (#1575) [Wallet] Add timestamp to top banner messages (#1657) Export geth metrics on VM testnet (#1351) ... # Conflicts: # yarn.lock
Description
This PR tries to reduce the number of view calls a client has to make to receive attestations. It does so by introducing two view calls:
Attestations#getCompletableAttestationStates
It directly returns the attestation issuers for which a user can complete attestations for (instead of having to iterate over all selected issuers themselves)
Accounts#batchGetMetadataURL
Fetches the metdata URLs for a set of accounts (instead of having to do N view calls)
This PR also removes any mention of the
reveal
transactionTested
namoffchainreveal
Related issues