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

Add client method for getting latest protocol state snapshot #144

Merged
merged 4 commits into from
Feb 8, 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
12 changes: 12 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,15 @@ func getEventsResult(res *access.EventsResponse) ([]BlockEvents, error) {

return results, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

have the access node implementations already been done for this changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in review onflow/flow-go#377

// GetLatestProtocolStateSnapshot retrieves the latest snapshot of the protocol
// state in serialized form. This is used to generate a root snapshot file
// used by Flow nodes to bootstrap their local protocol state database.
func (c *Client) GetLatestProtocolStateSnapshot(ctx context.Context, opts ...grpc.CallOption) ([]byte, error) {
res, err := c.rpcClient.GetLatestProtocolStateSnapshot(ctx, &access.GetLatestProtocolStateSnapshotRequest{}, opts...)
if err != nil {
return nil, newRPCError(err)
}

return res.GetSerializedSnapshot(), nil
}
26 changes: 26 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package client_test

import (
"context"
"math/rand"
"testing"

"github.com/golang/protobuf/ptypes"
Expand Down Expand Up @@ -812,3 +813,28 @@ func TestClient_GetEventsForBlockIDs(t *testing.T) {
assert.Empty(t, blocks)
}))
}

func TestClient_GetLatestProtocolStateSnapshot(t *testing.T) {
t.Run("Success", clientTest(func(t *testing.T, ctx context.Context, rpc *MockRPCClient, c *client.Client) {
expected := &access.ProtocolStateSnapshotResponse{
SerializedSnapshot: make([]byte, 128),
}
_, err := rand.Read(expected.SerializedSnapshot)
assert.NoError(t, err)

rpc.On("GetLatestProtocolStateSnapshot", ctx, mock.Anything).Return(expected, nil)

res, err := c.GetLatestProtocolStateSnapshot(ctx)
assert.NoError(t, err)
assert.Equal(t, expected.SerializedSnapshot, res)
}))

t.Run("Internal error", clientTest(func(t *testing.T, ctx context.Context, rpc *MockRPCClient, c *client.Client) {
rpc.On("GetLatestProtocolStateSnapshot", ctx, mock.Anything).
Return(nil, errInternal)

_, err := c.GetLatestProtocolStateSnapshot(ctx)
assert.Error(t, err)
assert.Equal(t, codes.Internal, status.Code(err))
}))
}
30 changes: 30 additions & 0 deletions client/mock_client_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ethereum/go-ethereum v1.9.9
github.com/golang/protobuf v1.4.2
github.com/onflow/cadence v0.12.6
github.com/onflow/flow/protobuf/go/flow v0.1.8
github.com/onflow/flow/protobuf/go/flow v0.1.9
github.com/pkg/errors v0.8.1
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXW
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onflow/cadence v0.12.6 h1:IvKSx5C84B4DGBf4DUAtLE2WtC24KAZR4z5XZyGGPYM=
github.com/onflow/cadence v0.12.6/go.mod h1:CHQIgovf2fks/6kwrpBaatNarHxX5qJggynAbjEnSvQ=
github.com/onflow/flow/protobuf/go/flow v0.1.8 h1:jBR8aXEL0MOh3gVJmCr0KYXmtG3JUBhzADonKkYE6oI=
github.com/onflow/flow/protobuf/go/flow v0.1.8/go.mod h1:kRugbzZjwQqvevJhrnnCFMJZNmoSJmxlKt6hTGXZojM=
github.com/onflow/flow/protobuf/go/flow v0.1.9 h1:ugK6/9K4AkMxqPbCvQzbbV24AH50Ozze43nqpukQoOM=
github.com/onflow/flow/protobuf/go/flow v0.1.9/go.mod h1:kRugbzZjwQqvevJhrnnCFMJZNmoSJmxlKt6hTGXZojM=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down