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

Optimized Attestation view calls and removal of the reveal TX #1578

Merged
merged 20 commits into from
Nov 11, 2019

Conversation

nambrot
Copy link
Contributor

@nambrot nambrot commented Nov 4, 2019

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 transaction

Tested

  • on namoffchainreveal
  • unit tests

Related issues

@nambrot nambrot requested review from asaj and m-chrzan as code owners November 4, 2019 23:53
@nambrot nambrot requested a review from jmrossy as a code owner November 6, 2019 03:01
@codecov
Copy link

codecov bot commented Nov 6, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@2664e2b). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1578   +/-   ##
=========================================
  Coverage          ?   73.78%           
=========================================
  Files             ?      279           
  Lines             ?     7606           
  Branches          ?      657           
=========================================
  Hits              ?     5612           
  Misses            ?     1881           
  Partials          ?      113
Flag Coverage Δ
#mobile 73.78% <ø> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2664e2b...eb9d87b. Read the comment docs.

@@ -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[] {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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

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 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(
Copy link
Contributor

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

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 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

Copy link
Contributor

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?

Copy link
Contributor Author

@nambrot nambrot Nov 7, 2019

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

@jmrossy jmrossy assigned nambrot and unassigned jmrossy Nov 6, 2019
@asaj
Copy link
Contributor

asaj commented Nov 6, 2019

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;
Copy link
Contributor

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,
*
Copy link
Contributor

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];
}

/**
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

uint256

@asaj
Copy link
Contributor

asaj commented Nov 6, 2019

Do you have any information on whether or not this actually makes things faster?

Also please be sure to follow the style guide.

@nambrot nambrot changed the title Support more efficient fetching of information in regards to attestations Optimized Attestation view calls and removal of the reveal TX Nov 6, 2019
@nambrot
Copy link
Contributor Author

nambrot commented Nov 6, 2019

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 uint vs uint256, it's been a while since I've been allowed to use all 256 bits :)

@@ -0,0 +1,21 @@
{
Copy link
Contributor

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
Copy link
Contributor

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()
Copy link
Contributor

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(
Copy link
Contributor

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(
Copy link
Contributor

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];
Copy link
Contributor

Choose a reason for hiding this comment

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

safemath everywhere

@asaj asaj removed their assignment Nov 6, 2019
@nambrot nambrot assigned asaj and unassigned nambrot Nov 7, 2019
@@ -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';
Copy link
Contributor

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?

Copy link
Contributor Author

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

@asaj asaj assigned nambrot and unassigned asaj Nov 7, 2019
@nambrot nambrot removed their assignment Nov 7, 2019
@nambrot nambrot added the automerge Have PR merge automatically when checks pass label Nov 11, 2019
@celo-ci-bot-user celo-ci-bot-user merged commit 7e3d507 into master Nov 11, 2019
@celo-ci-bot-user celo-ci-bot-user deleted the nambrot/actionable-attestations branch November 11, 2019 20:20
aaronmgdr added a commit that referenced this pull request Nov 14, 2019
* 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
cmcewen added a commit that referenced this pull request Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users should not be able to reference a reveal tx Developers should be able to use actionable attestations
4 participants