Skip to content

Commit

Permalink
Remove the unused GetLeavesByIndex API.
Browse files Browse the repository at this point in the history
Part of #2245.
  • Loading branch information
pphaneuf committed Mar 23, 2021
1 parent 341f077 commit 065c62a
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 802 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
### Cleanup
* Removed the deprecated crypto.NewSHA256Signer function.
* Finish removing the `LogMetadata.GetUnsequencedCounts()` method.
* Removed `TrillianLog.GetLeavesByHash` API.
* Removed `TrillianLog.GetLeavesByHash` and `TrillianLog.GetLeavesByIndex`
API.

### Storage refactoring
* `NodeReader.GetMerkleNodes` does not accept revisions anymore. The
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ similar to those available for Certificate Transparency logs
- `GetLatestSignedLogRoot` returns information about the current root of the
Merkle tree for the log, including the tree size, hash value, timestamp and
signature.
- `GetLeavesByIndex` and `GetLeavesByRange` return leaf information for
particular leaves, specified by their index in the log.
- `GetLeavesByRange` returns leaf information for particular leaves,
specified by their index in the log.
- `QueueLeaves` requests inclusion of specified items into the log.
- For a pre-ordered log, `AddSequencedLeaves` requests the inclusion of
specified items into the log at specified places in the tree.
Expand Down
15 changes: 0 additions & 15 deletions client/log_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,6 @@ func (c *LogClient) AddLeaf(ctx context.Context, data []byte) error {
return nil
}

// GetByIndex returns a single leaf at the requested index.
func (c *LogClient) GetByIndex(ctx context.Context, index int64) (*trillian.LogLeaf, error) {
resp, err := c.client.GetLeavesByIndex(ctx, &trillian.GetLeavesByIndexRequest{
LogId: c.LogID,
LeafIndex: []int64{index},
})
if err != nil {
return nil, err
}
if got, want := len(resp.Leaves), 1; got != want {
return nil, fmt.Errorf("len(leaves): %v, want %v", got, want)
}
return resp.Leaves[0], nil
}

// ListByIndex returns the requested leaves by index.
func (c *LogClient) ListByIndex(ctx context.Context, start, count int64) ([]*trillian.LogLeaf, error) {
resp, err := c.client.GetLeavesByRange(ctx,
Expand Down
28 changes: 0 additions & 28 deletions client/log_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,6 @@ func clientEnvForTest(ctx context.Context, t *testing.T, template *trillian.Tree
return env, client
}

func TestGetByIndex(t *testing.T) {
ctx := context.Background()
env, client := clientEnvForTest(ctx, t, stestonly.PreorderedLogTree)
defer env.Close()

// Add a few test leaves.
leafData := [][]byte{
[]byte("A"),
[]byte("B"),
[]byte("C"),
}

if err := addSequencedLeaves(ctx, env, client, leafData); err != nil {
t.Fatalf("Failed to add leaves: %v", err)
}

for i, l := range leafData {
leaf, err := client.GetByIndex(ctx, int64(i))
if err != nil {
t.Errorf("Failed to GetByIndex(%v): %v", i, err)
continue
}
if got, want := leaf.LeafValue, l; !bytes.Equal(got, want) {
t.Errorf("GetByIndex(%v) = %x, want %x", i, got, want)
}
}
}

func TestListByIndex(t *testing.T) {
ctx := context.Background()
env, client := clientEnvForTest(ctx, t, stestonly.PreorderedLogTree)
Expand Down
36 changes: 0 additions & 36 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
- [GetInclusionProofResponse](#trillian.GetInclusionProofResponse)
- [GetLatestSignedLogRootRequest](#trillian.GetLatestSignedLogRootRequest)
- [GetLatestSignedLogRootResponse](#trillian.GetLatestSignedLogRootResponse)
- [GetLeavesByIndexRequest](#trillian.GetLeavesByIndexRequest)
- [GetLeavesByIndexResponse](#trillian.GetLeavesByIndexResponse)
- [GetLeavesByRangeRequest](#trillian.GetLeavesByRangeRequest)
- [GetLeavesByRangeResponse](#trillian.GetLeavesByRangeResponse)
- [InitLogRequest](#trillian.InitLogRequest)
Expand Down Expand Up @@ -319,39 +317,6 @@ As an example, a Certificate Transparency frontend might set the following user



<a name="trillian.GetLeavesByIndexRequest"></a>

### GetLeavesByIndexRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| log_id | [int64](#int64) | | |
| leaf_index | [int64](#int64) | repeated | |
| charge_to | [ChargeTo](#trillian.ChargeTo) | | |






<a name="trillian.GetLeavesByIndexResponse"></a>

### GetLeavesByIndexResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| leaves | [LogLeaf](#trillian.LogLeaf) | repeated | TODO(gbelvin): Response syntax does not allow for some requested leaves to be available, and some not (but using QueuedLogLeaf might) |
| signed_log_root | [SignedLogRoot](#trillian.SignedLogRoot) | | |






<a name="trillian.GetLeavesByRangeRequest"></a>

### GetLeavesByRangeRequest
Expand Down Expand Up @@ -595,7 +560,6 @@ If the requested tree size is unavailable but the leaf is in scope for the curre
| InitLog | [InitLogRequest](#trillian.InitLogRequest) | [InitLogResponse](#trillian.InitLogResponse) | InitLog initializes a particular tree, creating the initial signed log root (which will be of size 0). |
| QueueLeaves | [QueueLeavesRequest](#trillian.QueueLeavesRequest) | [QueueLeavesResponse](#trillian.QueueLeavesResponse) | QueueLeaf adds a batch of leaves to the queue of pending leaves for a normal log. |
| AddSequencedLeaves | [AddSequencedLeavesRequest](#trillian.AddSequencedLeavesRequest) | [AddSequencedLeavesResponse](#trillian.AddSequencedLeavesResponse) | AddSequencedLeaves adds a batch of leaves with assigned sequence numbers to a pre-ordered log. The indices of the provided leaves must be contiguous. |
| GetLeavesByIndex | [GetLeavesByIndexRequest](#trillian.GetLeavesByIndexRequest) | [GetLeavesByIndexResponse](#trillian.GetLeavesByIndexResponse) | GetLeavesByIndex returns a batch of leaves whose leaf indices are provided in the request. |
| GetLeavesByRange | [GetLeavesByRangeRequest](#trillian.GetLeavesByRangeRequest) | [GetLeavesByRangeResponse](#trillian.GetLeavesByRangeResponse) | GetLeavesByRange returns a batch of leaves whose leaf indices are in a sequential range. |


Expand Down
3 changes: 0 additions & 3 deletions server/interceptor/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ func newRPCInfoForRequest(req interface{}) (*rpcInfo, error) {
*trillian.GetLatestSignedLogRootRequest:
info.treeTypes = []trillian.TreeType{trillian.TreeType_LOG, trillian.TreeType_PREORDERED_LOG}
info.tokens = 1
case *trillian.GetLeavesByIndexRequest:
info.treeTypes = []trillian.TreeType{trillian.TreeType_LOG, trillian.TreeType_PREORDERED_LOG}
info.tokens = len(req.GetLeafIndex())
case *trillian.GetLeavesByRangeRequest:
info.treeTypes = []trillian.TreeType{trillian.TreeType_LOG, trillian.TreeType_PREORDERED_LOG}
info.tokens = 1
Expand Down
10 changes: 0 additions & 10 deletions server/interceptor/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ func TestTrillianInterceptor_QuotaInterception(t *testing.T) {
},
wantTokens: 1,
},
{
desc: "logReadIndices",
method: "/trillian.TrillianLog/GetLeavesByIndex",
req: &trillian.GetLeavesByIndexRequest{LogId: logTree.TreeId, LeafIndex: []int64{1, 2, 3}},
specs: []quota.Spec{
{Group: quota.Tree, Kind: quota.Read, TreeID: logTree.TreeId},
{Group: quota.Global, Kind: quota.Read, Refundable: true},
},
wantTokens: 3,
},
{
desc: "logReadRange",
method: "/trillian.TrillianLog/GetLeavesByRange",
Expand Down
43 changes: 0 additions & 43 deletions server/log_rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,49 +463,6 @@ func tryGetConsistencyProof(ctx context.Context, firstTreeSize, secondTreeSize,
return proof, nil
}

// GetLeavesByIndex obtains one or more leaves based on their sequence number within the
// tree. It is not possible to fetch leaves that have been queued but not yet integrated.
// TODO: Validate indices against published tree size in case we implement write sharding that
// can get ahead of this point. Not currently clear what component should own this state.
func (t *TrillianLogRPCServer) GetLeavesByIndex(ctx context.Context, req *trillian.GetLeavesByIndexRequest) (*trillian.GetLeavesByIndexResponse, error) {
ctx, spanEnd := spanFor(ctx, "GetLeavesByIndex")
defer spanEnd()
if err := validateGetLeavesByIndexRequest(req); err != nil {
return nil, err
}

tree, ctx, err := t.getTreeAndContext(ctx, req.LogId, optsLogRead)
if err != nil {
return nil, err
}
tx, err := t.snapshotForTree(ctx, tree, "GetLeavesByIndex")
if err != nil {
return nil, err
}
defer t.closeAndLog(ctx, tree.TreeId, tx, "GetLeavesByIndex")

leaves, err := tx.GetLeavesByIndex(ctx, req.LeafIndex)
if err != nil {
return nil, err
}
t.fetchedLeaves.Add(float64(len(leaves)))

if err := t.commitAndLog(ctx, req.LogId, tx, "GetLeavesByIndex"); err != nil {
return nil, err
}

slr, err := tx.LatestSignedLogRoot(ctx)
if err != nil {
return nil, err
}
var root types.LogRootV1
if err := root.UnmarshalBinary(slr.LogRoot); err != nil {
return nil, status.Errorf(codes.Internal, "Could not read current log root: %v", err)
}

return &trillian.GetLeavesByIndexResponse{Leaves: leaves, SignedLogRoot: slr}, nil
}

// GetLeavesByRange obtains leaves based on a range of sequence numbers within the tree.
// This only fetches sequenced leaves; leaves that have been queued but not yet integrated
// are not visible.
Expand Down
Loading

0 comments on commit 065c62a

Please sign in to comment.