-
Notifications
You must be signed in to change notification settings - Fork 381
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
testonly/hammer/hammer.go
Outdated
@@ -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 { |
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.
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?
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.
Cool!
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.
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): |
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.
Should you be referencing types.MapRootV1
here, or is that considered an implementation detail?
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.
That's a Go specific implementation detail and not technically part of the public API.
testonly/hammer/hammer.go
Outdated
@@ -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) { |
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.
What is ctf
? Is it an abbreviation of config? I'd go for conf
, config
or mc
here.
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 typo
testonly/hammer/hammer.go
Outdated
|
||
s.pushSMR(rsp.MapRoot) | ||
if err := s.updateContents(rsp.MapRoot.MapRevision, leaves); err != nil { | ||
if err := s.updateContents(int64(root.Revision), leaves); err != nil { |
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.
How about changing updateContents
to accept int64
instead?
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.
Done
storage/mysql/map_storage_test.go
Outdated
@@ -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) |
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.
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.
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.
Good idea.
storage/mysql/map_storage_test.go
Outdated
} | ||
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) |
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 you could return
after this condition too, to abort the sub-test.
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.
Done
storage/mysql/map_storage_test.go
Outdated
} | ||
if err == nil { | ||
var mapRoot types.MapRootV1 | ||
if err := mapRoot.UnmarshalBinary(root.MapRoot); err != nil { | ||
t.Errorf("UmarshalBinary(): %v", err) |
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.
Possibly return
after this too: if you fail to unmarshal the maproot there'll be nothing worth testing about the fields you expected.
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.
done
j, err := json.Marshal(obj) | ||
if err != nil { | ||
return err | ||
// VerifySignedMapRoot verifies the signature on the SignedMapRoot. |
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.
Not clear from this documentation why it is also returning a MapRootV1.
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.
added docs
fc448e8
to
97a8348
Compare
97a8348
to
a1d851b
Compare
Updated and ready for a second look |
* master: Move SignedMapRoot fields to MapRootV1 (google#1060)
This PR moves the rest of the fields in
SignedMapRoot
intoMapRoot
and usesMapRootV1
throughout the code base.#958