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

Update iavl client #244

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ jobs:
script:
- echo "Test libraries"
# this image is needed for the sdk IAVLSpec
- docker run --name iavl -p 8090:8090 -p 8091:8091 -d foamspace/iavl:latest /iavlserver -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
- docker run --name iavl -p 8090:8090 -p 8091:8091 -d foamspace/iavl:grpc -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
- make test-libraries
- docker rm -f iavl
- echo "Test Libraries with Nix"
- echo "This stage is currently disabled as Nix doesn't seem to play well with libsecp256k1"

- echo "Test IAVL Client"
- docker run --name iavl -p 8090:8090 -p 8091:8091 -d foamspace/iavl:latest /iavlserver -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
- docker run --name iavl -p 8090:8090 -p 8091:8091 -d foamspace/iavl:grpc -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
- make test-iavl-client
- docker rm -f iavl

Expand Down
4 changes: 2 additions & 2 deletions hs-abci-docs/nameservice/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ services:
- "9200"
- "5601"
iavl:
image: foamspace/iavl:latest
command: /iavlserver -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
image: foamspace/iavl:grpc
command: ["-db-name", "test", "-datadir", ".", " -grpc-endpoint", "0.0.0.0:8090", "-gateway-endpoint", "0.0.0.0:8091"]
ports:
- "8090-8091:8091-8091"
expose:
Expand Down
4 changes: 2 additions & 2 deletions hs-abci-docs/simple-storage/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ services:
expose:
- "26658"
iavl:
image: foamspace/iavl:latest
command: /iavlserver -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091"
image: foamspace/iavl:grpc
command: ["-db-name", "test", "-datadir", ".", " -grpc-endpoint", "0.0.0.0:8090", "-gateway-endpoint", "0.0.0.0:8091"]
ports:
- "8090:8090"
- "8091:8091"
Expand Down
2 changes: 2 additions & 0 deletions hs-iavl-client/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ library:
generated-exposed-modules:
- Proto.Iavl.Api
- Proto.Iavl.Api_Fields
- Proto.Iavl.Proof
- Proto.Iavl.Proof_Fields
- Proto.Google.Api.Http
- Proto.Google.Api.Http_Fields
- Proto.Google.Protobuf.Empty
Expand Down
145 changes: 104 additions & 41 deletions hs-iavl-client/protos/iavl/api.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
syntax = "proto3";
package proto;
package iavl;

option go_package = "proto/proto";

import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "iavl/proof.proto";


// ----------------------------------------------------------------------------
// gRPC service
Expand All @@ -14,15 +18,21 @@ service IAVLService {
// has a given key at a specific tree version.
rpc Has(HasRequest) returns (HasResponse) {
option (google.api.http) = {
get: "/v1/tree/{version}/has"
get: "/v1/has"
};
}

rpc HasVersioned(HasVersionedRequest) returns (HasResponse) {
option (google.api.http) = {
get: "/v1/has_versioned"
};
}

// Get returns a result containing the IAVL tree version and value for a given
// key based on the current state (version) of the tree.
rpc Get(GetRequest) returns (GetResponse) {
option (google.api.http) = {
get: "/v1/tree/get"
get: "/v1/get"
};
}

Expand All @@ -31,15 +41,15 @@ service IAVLService {
// verifiable Merkle proof.
rpc GetWithProof(GetRequest) returns (GetWithProofResponse) {
option (google.api.http) = {
get: "/v1/tree/get_with_proof"
get: "/v1/get_with_proof"
};
}

// GetVersioned returns a result containing the IAVL tree version and value
// for a given key at a specific tree version.
rpc GetVersioned(GetVersionedRequest) returns (GetResponse) {
option (google.api.http) = {
get: "/v1/tree/{version}/get_versioned"
get: "/v1/{version}/get_versioned"
};
}

Expand All @@ -48,15 +58,15 @@ service IAVLService {
// proof.
rpc GetVersionedWithProof(GetVersionedRequest) returns (GetWithProofResponse) {
option (google.api.http) = {
get: "/v1/tree/{version}/get_versioned_with_proof"
get: "/v1/{version}/get_versioned_with_proof"
};
}

// Set returns a result after inserting a key/value pair into the IAVL tree
// based on the current state (version) of the tree.
rpc Set(SetRequest) returns (SetResponse) {
option (google.api.http) = {
post: "/v1/tree/set"
post: "/v1/set"
body: "*"
};
}
Expand All @@ -65,7 +75,7 @@ service IAVLService {
// based on the current state (version) of the tree.
rpc Remove(RemoveRequest) returns (RemoveResponse) {
option (google.api.http) = {
post: "/v1/tree/remove"
post: "/v1/remove"
body: "*"
};
}
Expand All @@ -75,7 +85,7 @@ service IAVLService {
// new version number.
rpc SaveVersion(google.protobuf.Empty) returns (SaveVersionResponse) {
option (google.api.http) = {
post: "/v1/tree/save_version"
post: "/v1/save_version"
body: "*"
};
}
Expand All @@ -85,72 +95,121 @@ service IAVLService {
// hash of the versioned tree that was deleted.
rpc DeleteVersion(DeleteVersionRequest) returns (DeleteVersionResponse) {
option (google.api.http) = {
post: "/v1/tree/delete_version"
post: "/v1/delete_version"
body: "*"
};
}

// Version returns the IAVL tree version based on the current state.
rpc Version(google.protobuf.Empty) returns (VersionResponse) {
option (google.api.http) = {
get: "/v1/tree/version"
get: "/v1/version"
};
}

// Hash returns the IAVL tree root hash based on the current state.
rpc Hash(google.protobuf.Empty) returns (HashResponse) {
option (google.api.http) = {
get: "/v1/tree/hash"
get: "/v1/hash"
};
}

// VersionExists returns a result containing a boolean on whether or not a given
// version exists in the IAVL tree.
rpc VersionExists(VersionExistsRequest) returns (VersionExistsResponse) {
option (google.api.http) = {
get: "/v1/tree/version_exists"
get: "/v1/version_exists"
};
}

// Verify verifies an IAVL range proof returning an error if the proof is
// invalid.
rpc Verify(VerifyRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/v1/tree/range_proof/verify"
get: "/v1/range_proof/verify"
};
}

// VerifyItem verifies if a given key/value pair in an IAVL range proof returning
// an error if the proof or key is invalid.
rpc VerifyItem(VerifyItemRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/v1/tree/range_proof/verify_item"
get: "/v1/range_proof/verify_item"
};
}

// VerifyAbsence verifies the absence of a given key in an IAVL range proof
// returning an error if the proof or key is invalid.
rpc VerifyAbsence(VerifyAbsenceRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/v1/tree/range_proof/verify_absence"
get: "/v1/range_proof/verify_absence"
};
}

// Rollback resets the working tree to the latest saved version, discarding
// any unsaved modifications.
rpc Rollback(google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v1/tree/rollback"
post: "/v1/rollback"
body: "*"
};
}

// Returns the committed versions
rpc GetAvailableVersions(google.protobuf.Empty) returns (GetAvailableVersionsResponse) {
option (google.api.http) = {
get: "/v1/available_versions"
};
}

// Load the most recent version
rpc Load(google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v1/load"
body: "*"
};
}

// Load a specific version
rpc LoadVersion(LoadVersionRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v1/load_version"
body: "*"
};
}

// Load a specific version and delete all the more recent versions
rpc LoadVersionForOverwriting(LoadVersionForOverwritingRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v1/load_version_for_overwriting"
body: "*"
};
}

// Get the number of leaves in the tree
rpc Size(google.protobuf.Empty) returns (SizeResponse) {
option (google.api.http) = {
get: "/v1/size"
};
}

rpc List(ListElementsRequest) returns (stream ListElementsResponse) {
option (google.api.http) = {
get: "/v1/list"
};
}

}

// ----------------------------------------------------------------------------
// Request types
// ----------------------------------------------------------------------------

message HasRequest {
bytes key = 1;
}

message HasVersionedRequest {
int64 version = 1;
bytes key = 2;
}
Expand Down Expand Up @@ -183,22 +242,37 @@ message VersionExistsRequest {

message VerifyRequest {
bytes root_hash = 1;
RangeProof proof = 2;
iavl.RangeProof proof = 2;
}

message VerifyItemRequest {
bytes root_hash = 1;
RangeProof proof = 2;
iavl.RangeProof proof = 2;
bytes key = 3;
bytes value = 4;
}

message VerifyAbsenceRequest {
bytes root_hash = 1;
RangeProof proof = 2;
iavl.RangeProof proof = 2;
bytes key = 3;
}

message LoadVersionRequest {
int64 version = 1;
}

message LoadVersionForOverwritingRequest {
int64 version = 1;
}

message ListElementsRequest {
bytes from_key = 1;
bytes to_key = 2;
bool ascending = 3;
}


// ----------------------------------------------------------------------------
// Response types
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -245,30 +319,19 @@ message VersionExistsResponse {

message GetWithProofResponse {
bytes value = 1;
RangeProof proof = 2;
iavl.RangeProof proof = 2;
}

message ProofInnerNode {
int32 height = 1;
int64 size = 2;
int64 version = 3;
bytes left = 4;
bytes right = 5;
message GetAvailableVersionsResponse {
repeated int64 versions = 1;
}

message ProofLeafNode {
bytes key = 1;
bytes value_hash = 2;
int64 version = 3;
}

message PathToLeaf {
repeated ProofInnerNode nodes = 1;
message SizeResponse {
int64 size = 1;
}

message RangeProof {
message ListElementsResponse {
bytes key = 1;
PathToLeaf left_path = 2;
repeated PathToLeaf inner_nodes = 3;
repeated ProofLeafNode leaves = 4;
bytes value = 2;
}
42 changes: 42 additions & 0 deletions hs-iavl-client/protos/iavl/proof.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package iavl;

option go_package = "proto/iavl";

// ValueOp is a Protobuf representation of iavl.ValueOp.
message ValueOp {
RangeProof proof = 1;
}

// AbsenceOp is a Protobuf representation of iavl.AbsenceOp.
message AbsenceOp {
RangeProof proof = 1;
}

// RangeProof is a Protobuf representation of iavl.RangeProof.
message RangeProof {
repeated ProofInnerNode left_path = 1;
repeated PathToLeaf inner_nodes = 2;
repeated ProofLeafNode leaves = 3;
}

// PathToLeaf is a Protobuf representation of iavl.PathToLeaf.
message PathToLeaf {
repeated ProofInnerNode inners = 1;
}

// ProofInnerNode is a Protobuf representation of iavl.ProofInnerNode.
message ProofInnerNode {
sint32 height = 1;
int64 size = 2;
int64 version = 3;
bytes left = 4;
bytes right = 5;
}

// ProofLeafNode is a Protobuf representation of iavl.ProofInnerNode.
message ProofLeafNode {
bytes key = 1;
bytes value_hash = 2;
int64 version = 3;
}
Loading