flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Snapshot management via CLI not working

Open bartolomej opened this issue 3 years ago • 2 comments

Instructions

Creating snapshot via CLI

I ran flow emulator --persist with default configuration (previously created by flow init). After emulator started, I ran the command to create a snapshot of the current emulator state:

➜ flow snapshot save temp.json --network emulator
❗  warning: using insecure client connection to download snapshot, you should use a secure network configuration...
❌ Command Error: failed to get latest finalized protocol snapshot from gateway: client: rpc error: code = Unavailable desc = error reading from server: EOF

Note that this command failed for the emulator network but worked for the testnet.

The emulator emitted the following logs, while I ran the above command:

➜  flow emulator --persist
INFO[0000] ⚙️   Using service account 0xf8d6e0586b0a20c7  serviceAddress=f8d6e0586b0a20c7 serviceHashAlgo=SHA3_256 servicePrivKey=c352ff3900a3a790813dcadf83a89662f3bcf6f7c97a02a2011d0da901c9c6c2 servicePubKey=aada506b7837942b9bf395d5aac2e108ccd219ab5f26ef4cefb601dd2f687e275c2adc8a437c432b587c19fe7512ffc3936369d453259571d94f49584d9a6009 serviceSigAlgo=ECDSA_P256
INFO[0000] 📜  Flow contract                              FlowServiceAccount=0xf8d6e0586b0a20c7
INFO[0000] 📜  Flow contract                              FlowToken=0x0ae53cb6e3f42a79
INFO[0000] 📜  Flow contract                              FungibleToken=0xee82856bf20e2aa6
INFO[0000] 📜  Flow contract                              FlowFees=0xe5a8b7f23e8b548f
INFO[0000] 📜  Flow contract                              FlowStorageFees=0xf8d6e0586b0a20c7
INFO[0000] 🌱  Starting gRPC server on port 3569          port=3569
INFO[0000] 🌱  Starting REST API on port 8888             port=8888
INFO[0000] 🌱  Starting admin server on port 8080         port=8080
panic: implement me

goroutine 322 [running]:
github.com/onflow/flow-emulator/server/backend.(*Backend).GetLatestProtocolStateSnapshot(...)
	github.com/onflow/[email protected]/server/backend/backend.go:593
github.com/onflow/flow-emulator/server/backend.(*Adapter).GetLatestProtocolStateSnapshot(0x140009b79d8?, {0x100e96938?, 0x101c09580?})
	github.com/onflow/[email protected]/server/backend/adapter.go:199 +0x30
github.com/onflow/flow-go/access.(*Handler).GetLatestProtocolStateSnapshot(0x140009b7a18?, {0x101cadbd0?, 0x1400093c210?}, 0x1400093c690?)
	github.com/onflow/flow-go@v0.26.14-test-synchronization.0.20220801105506-320bb18569ff/access/handler.go:468 +0x30
github.com/onflow/flow/protobuf/go/flow/access._AccessAPI_GetLatestProtocolStateSnapshot_Handler.func1({0x101cadbd0, 0x1400093c210}, {0x101ba6d40?, 0x14000952040})
	github.com/onflow/flow/protobuf/go/[email protected]/access/access_grpc.pb.go:918 +0x74
github.com/grpc-ecosystem/go-grpc-prometheus.(*ServerMetrics).UnaryServerInterceptor.func1({0x101cadbd0, 0x1400093c210}, {0x101ba6d40, 0x14000952040}, 0x140005e1ad8?, 0x1400090a4b0)
	github.com/grpc-ecosystem/[email protected]/server_metrics.go:107 +0x74
github.com/onflow/flow/protobuf/go/flow/access._AccessAPI_GetLatestProtocolStateSnapshot_Handler({0x101c4c4a0?, 0x14000643bc0}, {0x101cadbd0, 0x1400093c210}, 0x140005b8720, 0x14000630250)
	github.com/onflow/flow/protobuf/go/[email protected]/access/access_grpc.pb.go:920 +0x138
google.golang.org/grpc.(*Server).processUnaryRPC(0x140005a8c40, {0x101cbbe78, 0x140063a2000}, 0x140001b9320, 0x14000643c50, 0x1027e9948, 0x0)
	google.golang.org/[email protected]/server.go:1283 +0xb50
google.golang.org/grpc.(*Server).handleStream(0x140005a8c40, {0x101cbbe78, 0x140063a2000}, 0x140001b9320, 0x0)
	google.golang.org/[email protected]/server.go:1620 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/[email protected]/server.go:922 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/[email protected]/server.go:920 +0x290

Creating snapshot via HTTP

Then I saw there is supposedly another way to create a snapshot using an HTTP request, described here. So I ran the bellow command, and got a promising response back:

➜  http GET http://localhost:8080/emulator/snapshot/first
HTTP/1.1 200 OK
Content-Length: 108
Content-Type: application/json
Date: Fri, 12 Aug 2022 12:23:32 GMT

{
    "blockId": "13c7ff23bb65feb5757cc65fdd75cd243506518c126385fae530ddebdad10b17",
    "context": "first",
    "height": 0
}

Emulator logs:

2022/08/12 14:23:32 http: superfluous response.WriteHeader call from github.com/onflow/flow-emulator/server.EmulatorAPIServer.Snapshot (emulator.go:129)

Problem

Snapshot management doesn't seem to work when using CLI, but does work when using HTTP API.

Another thing I should mention is that the flow-emulator README mentions that you need to use --persist flag to be able to use snapshot features, but flow docs doesn't mention that anywhere. I was also a bit confused about whether I needed to use the persist flag.

Steps to Reproduce

See reproducible steps in the instructions section above.

Acceptance Criteria

Users should be able to use both CLI and HTTP APIs to manage snapshots.

Context

I'm working on implementing the new snapshot feature in Flowser tool.

bartolomej avatar Aug 12 '22 12:08 bartolomej

I found a related issue comment that already mentions the above error: https://github.com/onflow/flow-cli/issues/420#issuecomment-1158076367

bartolomej avatar Aug 12 '22 12:08 bartolomej

Thanks for flagging this, will lyk when we are implementing this feature @bartolomej

sukantoraymond avatar Aug 12 '22 21:08 sukantoraymond

Thank you for reporting this, but the command you were using is not intended to do a snapshot of the emulator, but something else. We need to yet support making snapshots in the CLI, currently you can only make them using the emulator API directly as found here https://github.com/onflow/flow-emulator#managing-emulator-state We already have an issue documented to add this to the CLI so closing this one.

devbugging avatar Aug 17 '22 06:08 devbugging