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 a constant down the call stack. #2493

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions log/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/merkle/compact"
"github.com/google/trillian/merkle/hashers"
"github.com/google/trillian/merkle/rfc6962/hasher"
"github.com/google/trillian/monitoring"
"github.com/google/trillian/quota"
"github.com/google/trillian/storage"
Expand Down Expand Up @@ -102,20 +102,17 @@ func InitMetrics(mf monitoring.MetricFactory) {
// There is no strong ordering guarantee but in general entries will be processed
// in order of submission to the log.
type Sequencer struct {
hasher hashers.LogHasher
timeSource clock.TimeSource
logStorage storage.LogStorage
qm quota.Manager
}

// NewSequencer creates a new Sequencer instance for the specified inputs.
func NewSequencer(
hasher hashers.LogHasher,
timeSource clock.TimeSource,
logStorage storage.LogStorage,
qm quota.Manager) *Sequencer {
return &Sequencer{
hasher: hasher,
timeSource: timeSource,
logStorage: logStorage,
qm: qm,
Expand All @@ -125,7 +122,7 @@ func NewSequencer(
// initCompactRangeFromStorage builds a compact range that matches the latest
// data in the database. Ensures that the root hash matches the passed in root.
func (s Sequencer) initCompactRangeFromStorage(ctx context.Context, root *types.LogRootV1, tx storage.TreeTX) (*compact.Range, error) {
fact := compact.RangeFactory{Hash: s.hasher.HashChildren}
fact := compact.RangeFactory{Hash: hasher.DefaultHasher.HashChildren}
if root.TreeSize == 0 {
return fact.NewEmptyRange(0), nil
}
Expand Down Expand Up @@ -414,7 +411,7 @@ func (s Sequencer) IntegrateBatch(ctx context.Context, tree *trillian.Tree, limi
// Create the log root ready for signing.
if cr.End() == 0 {
// Override the nil root hash returned by the compact range.
newRoot = s.hasher.EmptyRoot()
newRoot = hasher.DefaultHasher.EmptyRoot()
}
newLogRoot = &types.LogRootV1{
RootHash: newRoot,
Expand Down
3 changes: 1 addition & 2 deletions log/sequencer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/extension"
rfc6962 "github.com/google/trillian/merkle/rfc6962/hasher"
"github.com/google/trillian/trees"
)

Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *SequencerManager) ExecutePass(ctx context.Context, logID int64, info *O
}
ctx = trees.NewContext(ctx, tree)

sequencer := NewSequencer(rfc6962.DefaultHasher, info.TimeSource, s.registry.LogStorage, s.registry.QuotaManager)
sequencer := NewSequencer(info.TimeSource, s.registry.LogStorage, s.registry.QuotaManager)

maxRootDuration := tree.MaxRootDuration.AsDuration()
if !tree.MaxRootDuration.IsValid() {
Expand Down
5 changes: 2 additions & 3 deletions log/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func createTestContext(ctrl *gomock.Controller, params testParameters) (testCont
qm = quota.Noop()
}
InitMetrics(nil)
sequencer := NewSequencer(rfc6962.DefaultHasher, clock.NewFake(fakeTime), fakeStorage, qm)
sequencer := NewSequencer(clock.NewFake(fakeTime), fakeStorage, qm)
return testContext{mockTx: mockTx, fakeStorage: fakeStorage, sequencer: sequencer}, context.Background()
}

Expand Down Expand Up @@ -623,7 +623,6 @@ func TestIntegrateBatch_PutTokens(t *testing.T) {
defer ctrl.Finish()

// Needed to create a signer
hasher := rfc6962.DefaultHasher
ts := clock.NewFake(fakeTime)

// Needed for IntegrateBatch calls
Expand Down Expand Up @@ -717,7 +716,7 @@ func TestIntegrateBatch_PutTokens(t *testing.T) {
qm.EXPECT().PutTokens(any, test.wantTokens, specs)
}

sequencer := NewSequencer(hasher, ts, logStorage, qm)
sequencer := NewSequencer(ts, logStorage, qm)
tree := &trillian.Tree{TreeId: treeID, TreeType: trillian.TreeType_LOG}
leaves, err := sequencer.IntegrateBatch(ctx, tree, limit, guardWindow, maxRootDuration)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions storage/tools/dump_tree/dumplib.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ func Main(args Options) string {
tree := createTree(as, ls)

log.InitMetrics(nil)
seq := log.NewSequencer(rfc6962.DefaultHasher,
clock.System,
ls,
quota.Noop())
seq := log.NewSequencer(clock.System, ls, quota.Noop())

// Create the initial tree head at size 0, which is required. And then sequence the leaves.
sequence(tree, seq, 0, args.BatchSize)
Expand Down