Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Add GetLatestEpoch API #915

Merged
merged 5 commits into from
Jan 30, 2018
Merged

Add GetLatestEpoch API #915

merged 5 commits into from
Jan 30, 2018

Conversation

gdbelvin
Copy link
Contributor

@gdbelvin gdbelvin commented Jan 26, 2018

The latest epoch is of interest in two use cases:

  • A client that is waiting to see if it's changes have made it into the next revision.
  • A gossiping peer that may not support gRPC streaming APIs.

By offering this API, clients will be able to efficiently poll just the Log Root until it changes before requesting a full proof for an updated entry. This is more much more efficient and would remove the need for a client to needlessly resubmit their UpdateEntry requests before a new epoch has been created.

@codecov-io
Copy link

codecov-io commented Jan 26, 2018

Codecov Report

Merging #915 into master will decrease coverage by 0.36%.
The diff coverage is 22.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #915      +/-   ##
==========================================
- Coverage   55.65%   55.29%   -0.37%     
==========================================
  Files          33       33              
  Lines        2280     2295      +15     
==========================================
  Hits         1269     1269              
- Misses        788      803      +15     
  Partials      223      223
Impacted Files Coverage Δ
core/keyserver/keyserver.go 33.83% <ø> (-1.74%) ⬇️
core/keyserver/epochs.go 37.08% <22.58%> (-1.81%) ⬇️

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 0e33469...9b39df7. Read the comment docs.

@gdbelvin gdbelvin closed this Jan 26, 2018
Copy link
Contributor

@Martin2112 Martin2112 left a comment

Choose a reason for hiding this comment

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

Mostly suggestions. It's your repo so they may not all be appropriate.

})
if err != nil {
glog.Warningf("GetSignedMapRootByRevision(%v, %v): %v", domain.MapID, in.Epoch, err)
glog.Warningf("GetSignedMapRootByRevision(%v, %v): %v", d.MapID, revision, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This style of error message might make it hard to track down where they occurred. Might want to prefix the text with the rpc method name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

LogId: logID,
})
// logProofs returns the proofs for a given epoch.
func (s *Server) logProofs(ctx context.Context, d *domain.Domain, firstTreeSize int64, epoch int64) (*tpb.SignedLogRoot, *tpb.Proof, *tpb.Proof, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if the proofs for an epoch could be wrapped into a single object for a cleaner signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a bit better.

// - LogRoot
// - LogConsistency
func (s *Server) getEntryByRevision(ctx context.Context, sth *tpb.SignedLogRoot, d *domain.Domain, userID, appID string, revision int64) (*pb.GetEntryResponse, error) {
if revision < int64(0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that cast required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. Removed.

logInclusion, err := s.tlog.GetInclusionProof(ctx,
&tpb.GetInclusionProofRequest{
LogId: domain.LogID,
LogId: d.LogID,
// SignedMapRoot must be placed in the log at MapRevision.
// MapRevisions start at 1. Log leaves start at 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify meaning of "log leaves start at 1" here as leaf indices are 0 based.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is incorrect. Updated:
MapRevisions start at 0. Log leaves start at 0.

}

// latestRevision returns the latest map revision, given the latest sth.
// The log is the authoritative source of the latest revision.
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming seems a bit odd given it takes a log STH and returns a map revision. mapRevisionFor() maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool

}, nil
}

// ListEntryHistory returns a list of EntryProofs covering a period of time.
func (s *Server) ListEntryHistory(ctx context.Context, in *pb.ListEntryHistoryRequest) (*pb.ListEntryHistoryResponse, error) {
// Lookup log and map info.
domain, err := s.domains.Read(ctx, in.DomainId, false)
domainID := in.GetDomainId()
Copy link
Contributor

Choose a reason for hiding this comment

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

GetDomainId() - should be GetDomainID().
Also looks like you often get the id then do domains.Read() on it, which might be a helper perhaps?

Copy link
Contributor Author

@gdbelvin gdbelvin Jan 26, 2018

Choose a reason for hiding this comment

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

GetDomainId is a function generated from protobuf. The protobuf people decided to not follow Go's standard for initialisms unfortunately: golang/protobuf#156.

The emerging pattern is that all user facing functions accept domain_id and the first thing they do is domains.Read. Not sure what the best way to pull out a helper. It feels more like an interceptor that puts something in ctx, but that feels a little heavy handed and makes the code path harder to follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, well it was just a suggestion.

@gdbelvin gdbelvin reopened this Jan 26, 2018
@gdbelvin
Copy link
Contributor Author

@Martin2112 thank you for the review!
I've pulled out the Catch log initialized errors commit into a separate PR: #916 and added unit tests. PTAL? Beers on me.

@gdbelvin gdbelvin requested review from taknira and removed request for phad and cesarghali January 30, 2018 10:46
@gdbelvin
Copy link
Contributor Author

Now that #916 is in, this PR is a whole lot simpler!
PTAL

// Lookup log and map info.
d, err := s.domains.Read(ctx, in.DomainId, false)
if err != nil {
glog.Errorf("adminstorage.Read(%v): %v", in.DomainId, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to prefix the errors with the method. Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return s.getEpochByRevision(ctx, d, in.GetFirstTreeSize(), currentEpoch)
}

// GetEpoch returns a the requested epoch.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@gdbelvin gdbelvin merged commit 444c2af into google:master Jan 30, 2018
@gdbelvin gdbelvin deleted the f/GetLatestEpoch branch January 30, 2018 11:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants