Skip to content

Commit

Permalink
Add persistence, and refactor code to make it possible (#89)
Browse files Browse the repository at this point in the history
* Add persistence layer and new storage interface

This adds persistence options to RUN-DSP by doing the following:

- Bump Go to 1.23.3
- Add new storage interfaces
- Create badger implementation for new interfaces
- Make fields in contracts and transfer reqs public for storage.
- Add some helper methods to contracts and transfer request

* Refactor contracts, transfers, agreements, and storage.

This does the following:

- Move ContractNegotiations to their own package
- Do the same to TransferRequests
- Modify all the code to reflect the move
- Add locking to the badger storage layer
- Clean up code where it made sense

* Bump linter

* Small fixes to get DSP working.

* Integrate review feedback
  • Loading branch information
ainmosni authored Dec 3, 2024
1 parent 89bedee commit 39546c7
Show file tree
Hide file tree
Showing 47 changed files with 2,345 additions and 1,956 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/golang:1.22
FROM docker.io/library/golang:1.23.3

RUN apt-get update && \
# Go tools:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test-and-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.22.5
- 1.23.3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -39,7 +39,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.22.5
- 1.23.3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -49,14 +49,14 @@ jobs:
- name: lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
version: v1.62.2

vulncheck:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.22.5
- 1.23.3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -77,7 +77,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.22.5
- 1.23.3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- asciicheck
- cyclop
- canonicalheader
- copyloopvar
- decorder
- dupl
- dupword
Expand All @@ -29,7 +30,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- fatcontext
- forbidigo
- forcetypeassert
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.58.2
rev: v1.62.2
hooks:
- id: golangci-lint
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM docker.io/library/golang:1.22.9 AS builder
FROM docker.io/library/golang:1.23.3 AS builder
WORKDIR /app
COPY . ./
RUN make build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
###########################################
# DO NOT USE ANYWHERE NEAR SENSITIVE DATA #
###########################################
FROM docker.io/library/golang:1.22.9 AS builder
FROM docker.io/library/golang:1.23.3 AS builder
WORKDIR /app
COPY . ./
RUN make debug
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- SERVER.PROVIDER.ADDRESS=reference-provider:9090
- SERVER.PROVIDER.INSECURE=true
- SERVER.DSP.EXTERNALURL=http://127.0.0.1:8080/
- SERVER.PERSISTENCE.BADGER.MEMORY=true
ports:
- '18080:8080'
depends_on:
Expand Down
2 changes: 2 additions & 0 deletions docs/development/dev-dataspace/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
- SERVER.DSP.EXTERNALURL=http://run-dsp-client:8080/
- SERVER.CONTROL.ENABLED=true
- SERVER.CONTROL.INSECURE=true
- SERVER.PERSISTENCE.BADGER.MEMORY=true
ports:
- '18081:8081'
- '14000:4000'
Expand All @@ -53,6 +54,7 @@ services:
- SERVER.PROVIDER.ADDRESS=reference-provider:9090
- SERVER.PROVIDER.INSECURE=true
- SERVER.DSP.EXTERNALURL=http://run-dsp-provider:8080/
- SERVER.PERSISTENCE.BADGER.MEMORY=true
ports:
- '28081:8081'
- '24000:4000'
Expand Down
3 changes: 2 additions & 1 deletion dsp/common_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"net/url"

"github.com/go-dataspace/run-dsp/dsp/persistence"
"github.com/go-dataspace/run-dsp/dsp/shared"
"github.com/go-dataspace/run-dsp/dsp/statemachine"
"github.com/go-dataspace/run-dsp/internal/constants"
Expand All @@ -29,7 +30,7 @@ import (
)

type dspHandlers struct {
store statemachine.Archiver
store persistence.StorageProvider
provider providerv1.ProviderServiceClient
reconciler *statemachine.Reconciler
selfURL *url.URL
Expand Down
23 changes: 23 additions & 0 deletions dsp/constants/roles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package constants

// DataspaceRole signifies what role in a dataspace exchange this is.
type DataspaceRole uint8

const (
DataspaceConsumer DataspaceRole = iota
DataspaceProvider
)
16 changes: 16 additions & 0 deletions dsp/contract/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package contract contains the Negotiation type and all related code.
package contract
Loading

0 comments on commit 39546c7

Please sign in to comment.