Skip to content

Commit

Permalink
Merge branch 'dev' into refactor-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Apr 7, 2021
2 parents cba0966 + 55d523e commit 11034c4
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .ci/run_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Using Avalanche Image: $AVALANCHE_IMAGE"

DOCKER_REPO="avaplatform"
BYZANTINE_IMAGE="$DOCKER_REPO/avalanche-byzantine:v0.2.0-rc.1"
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.11.0-rc.1"
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.11.0-rc.2"

# Kurtosis Environment Parameters
KURTOSIS_CORE_CHANNEL="1.0.3"
Expand Down
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.ci
.git
.github
.gitignore
.golangci.yml
.idea
.vscode

LICENSE
*.md
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# syntax=docker/dockerfile:experimental

ARG AVALANCHEGO_COMMIT
FROM golang:1.15.5-buster

ARG AVALANCHEGO_COMMIT

RUN mkdir -p /go/src/github.com/ava-labs

WORKDIR $GOPATH/src/github.com/ava-labs/
COPY . avalanchego

WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego
RUN export AVALANCHEGO_COMMIT=$AVALANCHEGO_COMMIT
RUN ./scripts/build.sh

RUN ln -sv $GOPATH/src/github.com/ava-labs/avalanchego/ /avalanchego
3 changes: 2 additions & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (s *Server) Initialize(

s.log.Info("API created with allowed origins: %v", allowedOrigins)
corsWrapper := cors.New(cors.Options{
AllowedOrigins: allowedOrigins,
AllowedOrigins: allowedOrigins,
AllowCredentials: true,
})
s.handler = corsWrapper.Handler(s.router)

Expand Down
8 changes: 6 additions & 2 deletions database/rpcdb/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ func (it *iterator) Value() []byte { return it.value }

// Release frees any resources held by the iterator
func (it *iterator) Release() {
_, err := it.db.client.IteratorRelease(context.Background(), &rpcdbproto.IteratorReleaseRequest{
resp, err := it.db.client.IteratorRelease(context.Background(), &rpcdbproto.IteratorReleaseRequest{
Id: it.id,
})
it.errs.Add(err)
if err != nil {
it.errs.Add(err)
} else {
it.errs.Add(errCodeToError[resp.Err])
}
}
11 changes: 7 additions & 4 deletions database/rpcdb/db_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@ func (db *DatabaseServer) IteratorRelease(_ context.Context, req *rpcdbproto.Ite
defer db.lock.Unlock()

it, exists := db.iterators[req.Id]
if exists {
delete(db.iterators, req.Id)
it.Release()
if !exists {
return &rpcdbproto.IteratorReleaseResponse{Err: 0}, nil
}
return &rpcdbproto.IteratorReleaseResponse{}, nil

delete(db.iterators, req.Id)
err := it.Error()
it.Release()
return &rpcdbproto.IteratorReleaseResponse{Err: errorToErrCode[err]}, errorToRPCError(err)
}
94 changes: 51 additions & 43 deletions database/rpcdb/rpcdbproto/rpcdb.pb.go

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

4 changes: 3 additions & 1 deletion database/rpcdb/rpcdbproto/rpcdb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ message IteratorReleaseRequest {
uint64 id = 1;
}

message IteratorReleaseResponse {}
message IteratorReleaseResponse {
uint32 err = 1;
}

service Database {
rpc Has(HasRequest) returns (HasResponse);
Expand Down
71 changes: 71 additions & 0 deletions database/test_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var (
TestIteratorStartPrefix,
TestIteratorMemorySafety,
TestIteratorClosed,
TestIteratorError,
TestIteratorErrorAfterRelease,
TestStatNoPanic,
TestCompactNoPanic,
TestMemorySafetyDatabase,
Expand Down Expand Up @@ -805,6 +807,75 @@ func TestIteratorClosed(t *testing.T, db Database) {
}
}

// TestIteratorError tests to make sure that an iterator still works after the
// database is closed.
func TestIteratorError(t *testing.T, db Database) {
key := []byte("hello1")
value := []byte("world1")

if err := db.Put(key, value); err != nil {
t.Fatalf("Unexpected error on batch.Put: %s", err)
}

iterator := db.NewIterator()
if iterator == nil {
t.Fatalf("db.NewIterator returned nil")
}
defer iterator.Release()

if err := db.Close(); err != nil {
t.Fatalf("Unexpected error on db.Close: %s", err)
}

if !iterator.Next() {
t.Fatalf("iterator.Next Returned: %v ; Expected: %v", false, true)
}
if itKey := iterator.Key(); !bytes.Equal(itKey, key) {
t.Fatalf("iterator.Key Returned: 0x%x ; Expected: 0x%x", itKey, key)
}
if itValue := iterator.Value(); !bytes.Equal(itValue, value) {
t.Fatalf("iterator.Value Returned: 0x%x ; Expected: 0x%x", itValue, value)
}
if err := iterator.Error(); err != nil {
t.Fatalf("Expected no error on iterator.Error but got %s", err)
}
}

// TestIteratorErrorAfterRelease tests to make sure that an iterator that was
// released still reports the error correctly.
func TestIteratorErrorAfterRelease(t *testing.T, db Database) {
key := []byte("hello1")
value := []byte("world1")

if err := db.Put(key, value); err != nil {
t.Fatalf("Unexpected error on batch.Put: %s", err)
}

if err := db.Close(); err != nil {
t.Fatalf("Unexpected error on db.Close: %s", err)
}

iterator := db.NewIterator()
if iterator == nil {
t.Fatalf("db.NewIterator returned nil")
}

iterator.Release()

if iterator.Next() {
t.Fatalf("iterator.Next Returned: %v ; Expected: %v", false, true)
}
if key := iterator.Key(); key != nil {
t.Fatalf("iterator.Key Returned: 0x%x ; Expected: nil", key)
}
if value := iterator.Value(); value != nil {
t.Fatalf("iterator.Value Returned: 0x%x ; Expected: nil", value)
}
if err := iterator.Error(); err != ErrClosed {
t.Fatalf("Expected %s on iterator.Error", ErrClosed)
}
}

// TestStatNoPanic tests to make sure that Stat never panics.
func TestStatNoPanic(t *testing.T, db Database) {
key1 := []byte("hello1")
Expand Down
2 changes: 1 addition & 1 deletion genesis/genesis_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ava-labs/avalanchego/utils/units"
)

// PrivateKey-vmRQiZeXEXYMyJhEiqdC2z5JhuDbxL8ix9UVvjgMu2Er1NepE => X-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2
// PrivateKey-vmRQiZeXEXYMyJhEiqdC2z5JhuDbxL8ix9UVvjgMu2Er1NepE => P-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2
// PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN => X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u

var (
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_avalanche.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GOPATH="$(go env GOPATH)"
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Directory above this script
BUILD_DIR=$AVALANCHE_PATH/build # Where binaries go

GIT_COMMIT=$( git rev-list -1 HEAD )
GIT_COMMIT=${AVALANCHEGO_COMMIT:-$( git rev-list -1 HEAD )}

# Build aVALANCHE
echo "Building Avalanche..."
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_coreth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BUILD_DIR="$AVALANCHE_PATH/build" # Where binaries go
PLUGIN_DIR="$BUILD_DIR/plugins" # Where plugin binaries (namely coreth) go
BINARY_PATH="$PLUGIN_DIR/evm"

CORETH_VER="v0.4.1-rc.1"
CORETH_VER="v0.4.2-rc.3"

CORETH_PATH="$GOPATH/pkg/mod/github.com/ava-labs/coreth@$CORETH_VER"

Expand Down
2 changes: 1 addition & 1 deletion scripts/build_local_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ FULL_COMMIT_HASH="$(git --git-dir="$AVALANCHE_PATH/.git" rev-parse HEAD)"
COMMIT_HASH="${FULL_COMMIT_HASH::8}"

echo "Building Docker Image: $DOCKERHUB_REPO:$COMMIT_HASH"
docker build -t "$DOCKERHUB_REPO:$COMMIT_HASH" "$AVALANCHE_PATH" -f "$AVALANCHE_PATH/Dockerfile"
docker build -t "$DOCKERHUB_REPO:$COMMIT_HASH" "$AVALANCHE_PATH" -f "$AVALANCHE_PATH/Dockerfile" --build-arg AVALANCHEGO_COMMIT="$FULL_COMMIT_HASH"
Loading

0 comments on commit 11034c4

Please sign in to comment.