Skip to content

Commit 09fbfff

Browse files
author
Robin Bryce
committed
feat: forestrie event message additions
* Add the confirmation states representing the forestrie trust levels as described here: ** unhelpful and time wasting line length restrictions ** https://github.com/datatrails/\ epic-8120-scalable-proof-mechanisms/blob/main/event-trust-levels.md * Add the provisional extra details we need in the event for the MERKLE_LOG proof mechanism fix: the include paths for openapiv2 build: simplify the include path discovery build: export the proto dependencies under proto-include This means consumers do not need to replicate the tricky go list based include path discovery ci: add a job to check the dockerall task works For people who can't or wont install protoc and go
1 parent c7be1e4 commit 09fbfff

File tree

11 files changed

+179
-69
lines changed

11 files changed

+179
-69
lines changed

Diff for: .github/workflows/ci.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ jobs:
3030
- name: Generate, Test and Export
3131
run: |
3232
# Note: it is by design that we don't use the builder
33-
task apis:bootstrap
34-
task apis:generate
35-
task apis:test
36-
task apis:export
33+
task all
3734
3835
- name: Show exports
3936
working-directory: exported/

Diff for: .github/workflows/workflow.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Developer Workflow Tests
2+
3+
on:
4+
# we ony run these on pull request as they significantly hinder developer feed
5+
# back if they are triggered on push
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
docker-all:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Setup go-task
15+
uses: arduino/setup-task@v1
16+
with:
17+
version: 3.x
18+
repo-token: ${{ secrets.GITHUB_TOKEN }}
19+
- name: docker all
20+
run: |
21+
task dockerall

Diff for: README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
Common public api definitions for the DataTrails platform
44

5+
## Finding and including proto files for depdendecnies
6+
7+
tools/go.mod is the source of truth for all proto providing dependencies. That file alone specifies both the upstream version we are using *and* is used, via go install, to make the .proto files available locally
8+
9+
This corresponds to the practice recommended by grpc-gateway and elsewhere
10+
11+
1. *** ALWAYS *** Use tools/go.mod to specify the dependency version.
12+
2. Add the package to the `go install` command in the apis:preflight task
13+
3. If necessary, add a var for the new path in any-api **and** then add a reference to that var in the PROTO_INC var.
14+
15+
Following this practice removes the need for dual maintenance of dependency versions in the builder image. It also produces a build cycle that is significantly faster.
16+
17+
Cross repository builds in docker while using go.work to refer to locally modified sources don't work. And this setup is essential for an efficient workflow.
18+
19+
## bootstrap proto files
20+
21+
The proto's for protoc itself, the googleapis, and the grpc_health proxy are needed by almost everything and are also don't apear to be compatible with the tools/go.mod approach
22+
23+
For this reason we curl the proto's and make them available in our aggregate proto-includes archive
24+
525
## Workflow for updating common apis
626

727
### Ensure the go tool chain is setup on your host
@@ -46,12 +66,11 @@ If you want to iterate on *just* the helper go code and there tests, do one roun
4666

4767
`apis:bootstrap` -> `apis:clean:generated`
4868

49-
Then just iterate using `apis:build`
50-
69+
Then just iterate using `task apis:generate` and `task apis:test`
5170

5271
#### For avid
5372

54-
* task avid:xxx
73+
See the README.md in avid/src/api/README.md
5574

5675
##### Build one api against locally cloned go-datatrails-common-api
5776

@@ -60,8 +79,4 @@ The protos can be included exactly as they are found from a clone of go-datatrai
6079
task apis:assetsv2-api \
6180
DATATRAILS_COMMON_API="../../go-datatrails-common-api"
6281

63-
It is necessary however to run `task apis:bootsrap` after cloning go-datatrails-common
64-
65-
#### For forestrie
66-
67-
* task:xxx
82+
It is necessary however to run `task apis:bootsrap` after cloning go-datatrails-common

Diff for: Taskfile.yml

+31-11
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,42 @@ tasks:
6767
### -------------------------
6868
# Primary workflow tasks
6969
### -------------------------
70-
all:
71-
desc: "do everything necessary after clone (or rebase)"
70+
dockerall:
71+
desc: "do everything necessary after clone (or rebase) in the builder"
7272
cmds:
7373
- task: builder-start
7474
- defer: {task: builder-cleanup}
75-
# These steps should exactly mirror the steps in .github/workflows/ci.yml
76-
- docker exec -t {{.BUILD_CONTAINER}} task apis:bootstrap
77-
- docker exec -t {{.BUILD_CONTAINER}} task apis:generate
78-
- docker exec -t {{.BUILD_CONTAINER}} task apis:test
79-
- docker exec -t {{.BUILD_CONTAINER}} task apis:export
75+
- task: all
76+
77+
all:
78+
desc: |
79+
do everything necessary after clone (or rebase)
80+
81+
Note: This requires go and protoc installed on your host. If you are not
82+
comfortable doing this then use dockerall.
83+
84+
** The CI (ci.yml) uses this task and provides a clear illustration of the
85+
pre-requisites. It does not use docker **
86+
87+
cmds:
88+
- task: clean
89+
- task: bootstrap
90+
- task: generate
91+
- task: apis:test
92+
- task: apis:export
93+
94+
# 0. clean out generated and imported files
95+
clean:
96+
- rm -rf proto-include
97+
- rm -rf exported
98+
- task: apis:clean:generated
99+
100+
# 1. bootstrap (only needed post clone or rebase)
101+
bootstrap:
102+
- task: apis:bootstrap
80103

81104
# 2. generate
82105
generate:
83106
desc: generates all the artifacts we need pre-build
84107
cmds:
85-
- task: builder-start
86-
- defer: {task: builder-cleanup}
87-
# DO NOT add bootstrap here, use all instead
88-
- docker exec -t {{.BUILD_CONTAINER}} task apis:generate
108+
- task: apis:generate

Diff for: datatrails-common-api/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go.work

Diff for: datatrails-common-api/assets/v2/assets/enums.proto

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ enum ConfirmationStatus {
77
PENDING = 1; // not yet committed
88
CONFIRMED = 2; // committed
99
FAILED = 3; // permanent failure
10+
11+
// Regarding the new statuses for forestrie, See
12+
// https://github.com/datatrails/epic-8120-scalable-proof-mechanisms/blob/main/event-trust-levels.md
13+
STORED = 4; // forestrie, "its in the db"
14+
COMMITTED = 5; // forestrie, "you can know if its changed"
15+
// CONFIRMED = 6; // forestrie, "You can easily prove it changed"
16+
UNEQUIVOCAL = 7; // forestrie, "You easily prove it was publicly available to all"
1017
}
1118

1219
enum TrackedStatus {

Diff for: datatrails-common-api/assets/v2/assets/eventresponse.proto

+47-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ import "datatrails-common-api/assets/v2/assets/enums.proto";
99
import "datatrails-common-api/assets/v2/assets/principal.proto";
1010
import "datatrails-common-api/attribute/v2/attribute/attribute.proto";
1111

12+
message MerklLogEntry {
13+
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
14+
json_schema: {
15+
description: "The verifiable recording of an event for proof mechanism MERKLE_LOG"
16+
}
17+
};
18+
19+
// Event trust level commited fields
20+
21+
// versiona and epoch of the tenants log data.
22+
uint32 log_version = 1;
23+
uint32 log_epoch = 2;
24+
uint64 log_leaf_index = 3; // TBD: this may be redundant.
25+
uint64 log_index = 4; // TBD: this will very likely be included in the trie key
26+
27+
// triekey_committed includes a time ordered sub key for verifiable, roughly
28+
// time aligned, correlation against other indepdendently logged events. Per
29+
// tenant log the id is guaranteed unique. For all practical purposes it is
30+
// system wide unique, but there are operational assumptions to make that
31+
// hold.
32+
bytes triekey_committed = 5 [
33+
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
34+
description: "256 bit radix 2 merkle trie key for the event. this key includes a unique, time ordered 64 bit, sub key"
35+
read_only: true
36+
}];
37+
38+
// upsert & db query friendly copy of the idtimestamp field from triekey_committed
39+
40+
fixed64 idtimestamp_committed = 6 [
41+
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
42+
description: "unique and time ordered verifiable log entry id"
43+
read_only: true
44+
}];
45+
46+
// TODO: Event trust level confirmed fields
47+
48+
// TODO: Event trust level uniquivocal fields
49+
}
50+
1251
message EventResponse {
1352
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
1453
json_schema: {
@@ -102,9 +141,9 @@ message EventResponse {
102141
read_only: true
103142
}];
104143

105-
// timestamp operation has been committed on the blockchain
144+
// timestamp for when the event was committed to a verifiable log
106145
google.protobuf.Timestamp timestamp_committed = 7 [ (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
107-
description: "time of event as recorded on blockchain"
146+
description: "time of event as recorded in verifiable storage"
108147
read_only: true
109148
}];
110149

@@ -164,4 +203,10 @@ message EventResponse {
164203
"Identity of the tenant the that created this event"
165204
max_length: 1024
166205
}];
206+
207+
MerklLogEntry log_entry = 20 [ (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
208+
description:
209+
"verifiable log entry details"
210+
max_length: 1024
211+
}];
167212
}

Diff for: datatrails-common-api/assets/v2/assets/service.proto

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package archivist.v2;
55
option go_package="github.com/datatrails/go-datatrails-common-api-gen/assets/v2/assets;assets";
66

77
import "google/api/annotations.proto";
8-
import "validate/validate.proto";
98
import "protoc-gen-openapiv2/options/annotations.proto";
109

1110
import "datatrails-common-api/assets/v2/assets/assetresponse.proto";

Diff for: datatrails-common-api/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go 1.21
88
// This allows this module to operate as tho it were the generated module. This
99
// allows us to manage the proto tool dependencies via this go.mod. This go.mod
1010
// is also used as the go.mod for the generated package.
11-
replace github.com/datatrails/go-datatrails-common-api-gen => ./
11+
// replace github.com/datatrails/go-datatrails-common-api-gen => ./
1212

1313
require (
1414
github.com/datatrails/go-datatrails-common v0.10.2

Diff for: getproto.sh

-3
This file was deleted.

Diff for: taskfiles/Taskfile_apis.yml

+47-39
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ env_build: &env_build
1717
# The GOCACHE in a linux container on Docker for windows MUST be on a linuxy
1818
# file system
1919
GOCACHE: /tmp/datatrails/go-datatrails-common-api
20+
GOBIN:
21+
sh: echo ${GOBIN:-$HOME/go/bin}
2022

2123

2224
vars:
@@ -43,7 +45,9 @@ vars:
4345
# imports
4446
GOPKG_OVERRIDES: ",Mgoogle/protobuf/field_mask.proto=google.golang.org/genproto/protobuf/field_mask"
4547

46-
# Upstream proto definition files are placed here by the bootstrap tasks
48+
# proto definition files whose versions can not be controlled by tools/go.mod
49+
# are collected in proto-include by the bootstrap tasks. Note the grpc_health
50+
# proto's are not currently versioned and are always taken from master
4751
GOOGLE_COMMON_PROTOS_VERSION: '{{.GOOGLE_COMMON_PROTOS_VERSION | default "1.50.0"}}'
4852
GOOGLE_COMMON_INC_ARCHIVE_BASEDIR: '{{.GOOGLE_COMMON_INC_ARCHIVE_BASEDIR | default "api-common-protos"}}'
4953

@@ -96,11 +100,20 @@ tasks:
96100
- for ff in $(find . -name "*.swagger.json"); do rm -f $ff; done
97101

98102
preflight:
99-
summary: run prior to api generation tasks
103+
summary: |
104+
installs the tools/go.mod specified protoc plugins and .proto definitions
105+
the common apis depend upon
106+
107+
And prepares the .proto's under proto-include so that consumers do not
108+
need to replicate the arrangements for finding the proto include paths
109+
100110
dir: '../datatrails-common-api'
111+
vars:
112+
API_PROTO_DEPS: >-
113+
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
114+
github.com/envoyproxy/protoc-gen-validate
101115
cmds:
102116
- |
103-
go mod download
104117
go get github.com/datatrails/go-datatrails-common-api-gen/tools
105118
106119
go install \
@@ -111,6 +124,32 @@ tasks:
111124
github.com/envoyproxy/protoc-gen-validate \
112125
github.com/lyft/protoc-gen-star/v2 \
113126
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
127+
- for: { var: API_PROTO_DEPS }
128+
cmd: |
129+
depdir=$(GOCACHE=/tmp/datatrails/go-datatrails-common-api/api \
130+
go list -f {{"{{"}}.Dir{{"}}"}} {{.ITEM}})
131+
132+
basedir=$(basename $depdir)
133+
basedir=${basedir%%@*} # strip the go module version
134+
rm -rf ../proto-include/${basedir}
135+
for proto in $(find $depdir -type f -name "*.proto"); do
136+
target=../proto-include/${basedir}/${proto#$depdir/}
137+
mkdir -p $(dirname $target)
138+
cp -v $proto $target
139+
done
140+
# find ../proto-include/${basedir}
141+
# find $d -type f -name "*.proto"
142+
# echo $(dirname $d)
143+
144+
# move things around so that consumers only need to -I proto-include,
145+
# and do any general pruning or tidy up.
146+
- |
147+
# consumers of protoc-gen-validate expect a -I which allows them to do
148+
# import "validate/validate.proto". And we don't need the java bindings or the example bindings
149+
rm -rf ../proto-include/validate
150+
mv -v ../proto-include/protoc-gen-validate/validate ../proto-include/
151+
rm -rf ../proto-include/protoc-gen-validate
152+
114153
115154
postflight:
116155
summary: run after all api generation tasks
@@ -134,7 +173,6 @@ tasks:
134173
go build ./...
135174
go test ./...
136175
137-
138176
export:
139177
desc: export the sources to the desired DESTDIR
140178
dir: '../datatrails-common-api'
@@ -163,7 +201,9 @@ tasks:
163201
mkdir -p {{.DESTDIR}}/swagger
164202
165203
# The source protos are all gathered under a 'google' common top dir
166-
cp -vr ../proto-include/* {{.DESTDIR}}proto-include/
204+
for d in $(ls -d ../proto-include/*);
205+
do cp -vr $d {{.DESTDIR}}proto-include/
206+
done
167207
168208
for api in {{.APIS}}; do
169209
mkdir -vp {{.DESTDIR}}{{.COMMON_GODIR}}/${api}
@@ -220,7 +260,7 @@ tasks:
220260
# Generates the swagger definitions for the gRPC service.
221261
# Generates the html docs for the gRPC service.
222262
- |
223-
protoc -I {{.SELF_INC}} {{.PROTOC_INC}} \
263+
protoc -I . -I proto-include \
224264
--go_out=paths=source_relative:{{.OUTPATH}} \
225265
--go-grpc_out=paths=source_relative:{{.OUTPATH}} \
226266
--validate_out=lang=go,paths=source_relative:{{.OUTPATH}} \
@@ -238,36 +278,4 @@ tasks:
238278
# OUTPATH: datatrails-common-api
239279
OUTPATH: .
240280
GOBIN:
241-
sh: echo ${GOBIN:-$HOME/go/bin}
242-
# These variables capture the locations that .proto files for third party
243-
# packages can be found at. The locations can change as a consequence of go
244-
# mod module updates, so we require a dynamic approach. The particularly
245-
# grotty bit is the -f argment - we need to pass -f {{.Dir}} to the go list
246-
# command. To do so we have to prevent go template from evaluating it.
247-
#
248-
PROTO_GEN_GO_DIR:
249-
# Notice; the tricksy 'cd datatrails-common-api' rather than just
250-
# running in that directory via tasks 'dir:' directive is so that we can
251-
# have the same import statements in the proto files *everywhere*. All
252-
# consumers of datatrails-common-api get to do things very simply in
253-
# return for this. AND it makes iteratively generating proto changes
254-
# across repositories a lot more efficient
255-
sh: |
256-
echo $(./getproto.sh google.golang.org/protobuf/cmd/protoc-gen-go)
257-
258-
GRPC_GATEWAY_DIR:
259-
sh: |
260-
echo $(dirname $(./getproto.sh github.com/grpc-ecosystem/grpc-gateway/v2/runtime))
261-
262-
ENVOY_VALIDATE:
263-
sh: |
264-
echo $(./getproto.sh github.com/envoyproxy/protoc-gen-validate)
265-
266-
SELF_INC: .
267-
268-
# Global includes used for all protoc invocations.
269-
# task sets cwd initially to the directory of the Taskfile.yml
270-
PROTOC_INC: "-I {{.ENVOY_VALIDATE}} \
271-
-I {{.PROTO_GEN_GO_DIR}} \
272-
-I {{.GRPC_GATEWAY_DIR}} \
273-
-I proto-include"
281+
sh: echo ${GOBIN:-$HOME/go/bin}

0 commit comments

Comments
 (0)