-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: gRPC definitions for DA interface * chore: improve protobuf generation * test: make test suite publicly visible * feat: initial gRPC proxy implementation * lint: fix linter errors * chore: go mod tidy * fix: add package directive to protobuf file * ci: use group number instead of name for docker
- Loading branch information
Showing
15 changed files
with
3,686 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1beta1 | ||
|
||
# The plugins to run. | ||
plugins: | ||
# The name of the plugin. | ||
- name: gogofaster | ||
# The the relative output directory. | ||
out: types/pb | ||
# Any options to provide to the plugin. | ||
opt: plugins=grpc,paths=source_relative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: v1beta1 | ||
|
||
build: | ||
roots: | ||
- proto | ||
- third_party/proto | ||
lint: | ||
use: | ||
- DEFAULT | ||
- COMMENTS | ||
- FILE_LOWER_SNAKE_CASE | ||
except: | ||
- COMMENT_ENUM | ||
- COMMENT_ENUM_VALUE | ||
- COMMENT_MESSAGE | ||
- COMMENT_RPC | ||
- COMMENT_SERVICE | ||
- COMMENT_FIELD | ||
- PACKAGE_VERSION_SUFFIX | ||
- RPC_REQUEST_STANDARD_NAME | ||
- SERVICE_SUFFIX | ||
- UNARY_RPC | ||
ignore: | ||
- tendermint | ||
breaking: | ||
use: | ||
- FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,12 @@ | ||
package da_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
"time" | ||
|
||
"github.com/rollkit/go-da/test" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/rollkit/go-da" | ||
) | ||
|
||
func TestDummyDA(t *testing.T) { | ||
dummy := test.NewDummyDA() | ||
RunDATestSuite(t, dummy) | ||
} | ||
|
||
func RunDATestSuite(t *testing.T, dummy *test.DummyDA) { | ||
t.Run("Basic DA test", func(t *testing.T) { | ||
BasicDATest(t, dummy) | ||
}) | ||
t.Run("Get IDs and all data", func(t *testing.T) { | ||
GetIDsTest(t, dummy) | ||
}) | ||
t.Run("Check Errors", func(t *testing.T) { | ||
CheckErrors(t, dummy) | ||
}) | ||
} | ||
|
||
// TODO(tzdybal): how to get rid of this?! | ||
type Blob = da.Blob | ||
type ID = da.ID | ||
|
||
func BasicDATest(t *testing.T, da da.DA) { | ||
msg1 := []byte("message 1") | ||
msg2 := []byte("message 2") | ||
|
||
id1, proof1, err := da.Submit([]Blob{msg1}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, id1) | ||
assert.NotEmpty(t, proof1) | ||
|
||
id2, proof2, err := da.Submit([]Blob{msg2}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, id2) | ||
assert.NotEmpty(t, proof2) | ||
|
||
id3, proof3, err := da.Submit([]Blob{msg1}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, id3) | ||
assert.NotEmpty(t, proof3) | ||
|
||
assert.NotEqual(t, id1, id2) | ||
assert.NotEqual(t, id1, id3) | ||
|
||
ret, err := da.Get(id1) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []Blob{msg1}, ret) | ||
|
||
commitment1, err := da.Commit([]Blob{msg1}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, commitment1) | ||
|
||
commitment2, err := da.Commit([]Blob{msg2}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, commitment2) | ||
|
||
oks, err := da.Validate(id1, proof1) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, oks) | ||
for _, ok := range oks { | ||
assert.True(t, ok) | ||
} | ||
|
||
oks, err = da.Validate(id2, proof2) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, oks) | ||
for _, ok := range oks { | ||
assert.True(t, ok) | ||
} | ||
|
||
oks, err = da.Validate(id1, proof2) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, oks) | ||
for _, ok := range oks { | ||
assert.False(t, ok) | ||
} | ||
|
||
oks, err = da.Validate(id2, proof1) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, oks) | ||
for _, ok := range oks { | ||
assert.False(t, ok) | ||
} | ||
} | ||
|
||
func CheckErrors(t *testing.T, da da.DA) { | ||
blob, err := da.Get([]ID{[]byte("invalid")}) | ||
assert.Error(t, err) | ||
assert.Empty(t, blob) | ||
} | ||
|
||
func GetIDsTest(t *testing.T, da da.DA) { | ||
msgs := [][]byte{[]byte("msg1"), []byte("msg2"), []byte("msg3")} | ||
|
||
ids, proofs, err := da.Submit(msgs) | ||
assert.NoError(t, err) | ||
assert.Len(t, ids, len(msgs)) | ||
assert.Len(t, proofs, len(msgs)) | ||
|
||
found := false | ||
end := time.Now().Add(1 * time.Second) | ||
for i := uint64(1); !found && !time.Now().After(end); i++ { | ||
ret, err := da.GetIDs(i) | ||
if err != nil { | ||
t.Error("failed to get IDs:", err) | ||
} | ||
if len(ret) > 0 { | ||
blobs, err := da.Get(ret) | ||
assert.NoError(t, err) | ||
|
||
if len(blobs) == len(msgs) { | ||
found = true | ||
for b := 0; b < len(blobs); b++ { | ||
if !bytes.Equal(blobs[b], msgs[b]) { | ||
found = false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert.True(t, found) | ||
test.RunDATestSuite(t, dummy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
syntax = "proto3"; | ||
package da; | ||
|
||
// DAService is the protobuf service definition for interaction with Data Availability layers. | ||
service DAService { | ||
// Get returns Blob for each given ID, or an error. | ||
rpc Get(GetRequest) returns (GetResponse) {} | ||
|
||
// GetIDs returns IDs of all Blobs located in DA at given height. | ||
rpc GetIDs(GetIDsRequest) returns (GetIDsResponse) {} | ||
|
||
// Commit creates a Commitment for each given Blob. | ||
rpc Commit(CommitRequest) returns (CommitResponse) {} | ||
|
||
// Submit submits the given Blobs to Data Availability layer. | ||
rpc Submit(SubmitRequest) returns (SubmitResponse) {} | ||
|
||
// Validate validates Commitments against corresponding Proofs. This should be possible without retrieving Blob. | ||
rpc Validate(ValidateRequest) returns (ValidateResponse) {} | ||
} | ||
|
||
// Blob is the data submitted/received from DA interface. | ||
message Blob { | ||
bytes value = 1; | ||
} | ||
|
||
// ID should contain serialized data required by the implementation to find blob in Data Availability layer. | ||
message ID { | ||
bytes value = 1; | ||
} | ||
|
||
// Commitment should contain serialized cryptographic commitment to Blob value. | ||
message Commitment { | ||
bytes value = 1; | ||
} | ||
|
||
// Proof should contain serialized proof of inclusion (publication) of Blob in Data Availability layer. | ||
message Proof { | ||
bytes value = 1; | ||
} | ||
|
||
// GetRequest is the request type for the Get rpc method. | ||
message GetRequest { | ||
repeated ID ids = 1; | ||
} | ||
|
||
// GetResponse is the response type for the Get rpc method. | ||
message GetResponse { | ||
repeated Blob blobs = 1; | ||
} | ||
|
||
// GetIDsRequest is the request type for the GetIDs rpc method. | ||
message GetIDsRequest { | ||
uint64 height = 1; | ||
} | ||
|
||
// GetIDsResponse is the response type for the GetIDs rpc method. | ||
message GetIDsResponse { | ||
repeated ID ids = 1; | ||
} | ||
|
||
// CommitRequest is the request type for the Commit rpc method. | ||
message CommitRequest { | ||
repeated Blob blobs = 1; | ||
} | ||
|
||
// CommitResponse is the response type for the Commit rpc method. | ||
message CommitResponse { | ||
repeated Commitment commitments = 1; | ||
} | ||
|
||
// SubmitRequest is the request type for the Submit rpc method. | ||
message SubmitRequest { | ||
repeated Blob blobs = 1; | ||
} | ||
|
||
// SubmitResponse is the response type for the Submit rpc method. | ||
message SubmitResponse { | ||
repeated ID ids = 1; | ||
repeated Proof proofs = 2; | ||
} | ||
|
||
// ValidateRequest is the request type for the Validate rpc method. | ||
message ValidateRequest { | ||
repeated ID ids = 1; | ||
repeated Proof proofs = 2; | ||
} | ||
|
||
// ValidateResponse is the response type for the Validate rpc method. | ||
message ValidateResponse { | ||
repeated bool results = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# see: https://stackoverflow.com/a/246128 | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"/.. | ||
TARGET_DIR=./types/pb | ||
|
||
cd $SCRIPT_DIR | ||
mkdir -p $TARGET_DIR | ||
rm -rf $TARGET_DIR/* | ||
docker run -u $UID:$(id -g) -e XDG_CACHE_HOME=/tmp/.cache -v $PWD:/workspace --workdir /workspace tendermintdev/docker-build-proto sh ./proto/protoc.sh |
Oops, something went wrong.