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

Move SignedMapRoot fields to MapRootV1 #1060

Merged
merged 12 commits into from
Mar 21, 2018

Conversation

gdbelvin
Copy link
Contributor

This PR moves the rest of the fields in SignedMapRoot into MapRoot and uses MapRootV1 throughout the code base.

#958

@gdbelvin gdbelvin requested a review from phad March 19, 2018 15:12
@codecov-io
Copy link

codecov-io commented Mar 19, 2018

Codecov Report

Merging #1060 into master will decrease coverage by 0.12%.
The diff coverage is 43.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1060      +/-   ##
==========================================
- Coverage    62.6%   62.47%   -0.13%     
==========================================
  Files         103      103              
  Lines        8455     8462       +7     
==========================================
- Hits         5293     5287       -6     
- Misses       2632     2642      +10     
- Partials      530      533       +3
Impacted Files Coverage Δ
client/map_verifier.go 0% <0%> (ø) ⬆️
examples/ct/ctmapper/mapper/mapper.go 11.81% <0%> (-0.19%) ⬇️
integration/maptest/map.go 72.05% <37.5%> (-0.75%) ⬇️
crypto/verifier.go 48.14% <42.85%> (-0.95%) ⬇️
server/map_rpc_server.go 30.58% <50%> (-1.13%) ⬇️
storage/mysql/map_storage.go 66.66% <61.11%> (-1.93%) ⬇️
crypto/signer.go 72% <77.77%> (+2.76%) ⬆️
util/tracker.go 96.61% <0%> (-3.39%) ⬇️

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 6282acf...a1d851b. Read the comment docs.

@@ -806,15 +838,20 @@ func (s *hammerState) getSMRRevInvalid(ctx context.Context) error {
return nil
}

func timeFromNanos(nanos int64) time.Time {
return time.Unix(nanos/1e9, nanos%1e9)
func timeFromNanos(nanos uint64) time.Time {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this, you can pass nano >= 10^9 into https://golang.org/pkg/time/#Unix
i.e. your func is equivalent to

func timeFromNanos(nanos uint64) time.Time {
  return time.Unix(0, int64(nanos))
}

BTW do you need to use uint64 here?

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using uint64 allows me to avoid a few typecasts.

reserved 8; // Deprecated: Was metadata bytes. Use map_root.

// map_root holds the TLS-serialization of the following
// structure (described in RFC5246 notation):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you be referencing types.MapRootV1 here, or is that considered an implementation detail?

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 Go specific implementation detail and not technically part of the public API.

@@ -167,6 +168,16 @@ func (c MapConfig) String() string {
c.MapID, c.EPBias, c.Operations, c.EmitInterval, c.IgnoreErrors, c.CheckSignatures)
}

// CheckSignature verifies the signature and returns the map root contents.
func CheckSignature(ctf *MapConfig, r *trillian.SignedMapRoot) (*types.MapRootV1, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is ctf? Is it an abbreviation of config? I'd go for conf, config or mc here.

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 typo


s.pushSMR(rsp.MapRoot)
if err := s.updateContents(rsp.MapRoot.MapRevision, leaves); err != nil {
if err := s.updateContents(int64(root.Revision), leaves); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about changing updateContents to accept int64 instead?

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

@@ -149,23 +161,27 @@ func TestMapReadWriteTransaction(t *testing.T) {
err := s.ReadWriteTransaction(ctx, tree, func(ctx context.Context, tx storage.MapTreeTX) error {
root, err := tx.LatestSignedMapRoot(ctx)
if err != nil && !strings.Contains(err.Error(), test.wantRootErr) {
t.Errorf("%v: LatestSignedMapRoot() returned err = %v", test.desc, err)
t.Errorf("LatestSignedMapRoot() returned err = %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about return after this error? It'll abort this sub-test, allowing you to un-indent the main test in the if err == nil block further down.

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.

}
if err == nil && len(test.wantRootErr) != 0 {
t.Errorf("%v: LatestSignedMapRoot() returned err = %v, want: nil", test.desc, err)
t.Errorf("LatestSignedMapRoot() returned err = %v, want: nil", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could return after this condition too, to abort the sub-test.

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

}
if err == nil {
var mapRoot types.MapRootV1
if err := mapRoot.UnmarshalBinary(root.MapRoot); err != nil {
t.Errorf("UmarshalBinary(): %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly return after this too: if you fail to unmarshal the maproot there'll be nothing worth testing about the fields you expected.

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

j, err := json.Marshal(obj)
if err != nil {
return err
// VerifySignedMapRoot verifies the signature on the SignedMapRoot.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clear from this documentation why it is also returning a MapRootV1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added docs

@gdbelvin gdbelvin force-pushed the f/sig/signmaproot branch from fc448e8 to 97a8348 Compare March 21, 2018 09:51
@gdbelvin gdbelvin force-pushed the f/sig/signmaproot branch from 97a8348 to a1d851b Compare March 21, 2018 11:28
@gdbelvin
Copy link
Contributor Author

Updated and ready for a second look

@gdbelvin gdbelvin merged commit 0c12c84 into google:master Mar 21, 2018
@gdbelvin gdbelvin deleted the f/sig/signmaproot branch March 21, 2018 14:04
gdbelvin added a commit to gdbelvin/trillian that referenced this pull request Mar 21, 2018
* master:
  Move SignedMapRoot fields to MapRootV1 (google#1060)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants