Skip to content

Commit

Permalink
Migrate to new fetchers methods + tessera dependency (#50)
Browse files Browse the repository at this point in the history
* different fetcher functions + update dep

* go get go mod tidy

* swap cpkt size and i

* remove projectID

* Revert "pass verifier"

This reverts commit 6310637.

* remove verifiers
  • Loading branch information
phbnf authored Nov 14, 2024
1 parent 5816176 commit df7e2e0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 38 deletions.
9 changes: 4 additions & 5 deletions cmd/gcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,12 @@ func awaitSignal(doneFn func()) {
doneFn()
}

func newGCPStorage(ctx context.Context, signer note.Signer, verifier note.Verifier) (*sctfe.CTStorage, error) {
func newGCPStorage(ctx context.Context, signer note.Signer) (*sctfe.CTStorage, error) {
gcpCfg := gcpTessera.Config{
ProjectID: *projectID,
Bucket: *bucket,
Spanner: *spannerDB,
Bucket: *bucket,
Spanner: *spannerDB,
}
tesseraStorage, err := gcpTessera.New(ctx, gcpCfg, tessera.WithCheckpointSignerVerifier(signer, verifier), tessera.WithCTLayout())
tesseraStorage, err := gcpTessera.New(ctx, gcpCfg, tessera.WithCheckpointSigner(signer), tessera.WithCTLayout())
if err != nil {
return nil, fmt.Errorf("Failed to initialize GCP Tessera storage: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/rs/cors v1.11.1
github.com/transparency-dev/formats v0.0.0-20240909113624-7ce4ea605e8b
github.com/transparency-dev/trillian-tessera v0.0.0-20240911103714-727b99dc32a7
github.com/transparency-dev/trillian-tessera v0.0.0-20241112165219-498d39b5fc7c
go.etcd.io/bbolt v1.3.11
golang.org/x/crypto v0.29.0
golang.org/x/mod v0.22.0
Expand Down Expand Up @@ -42,7 +42,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cisco/go-tls-syntax v0.0.0-20200617162716-46b0cfb76b9b // indirect
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
github.com/envoyproxy/go-control-plane v0.13.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
Expand Down Expand Up @@ -75,7 +74,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,6 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cisco/go-tls-syntax v0.0.0-20200617162716-46b0cfb76b9b h1:Ves2turKTX7zruivAcUOQg155xggcbv3suVdbKCBQNM=
github.com/cisco/go-tls-syntax v0.0.0-20200617162716-46b0cfb76b9b/go.mod h1:0AZAV7lYvynZQ5ErHlGMKH+4QYMyNCFd+AiL9MlrCYA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down Expand Up @@ -967,8 +965,8 @@ github.com/transparency-dev/formats v0.0.0-20240909113624-7ce4ea605e8b h1:zayRkU
github.com/transparency-dev/formats v0.0.0-20240909113624-7ce4ea605e8b/go.mod h1:nA3+izsIcFoFgSKm3bHxS2/W4xdzSHMweE7REPunqUM=
github.com/transparency-dev/merkle v0.0.2 h1:Q9nBoQcZcgPamMkGn7ghV8XiTZ/kRxn1yCG81+twTK4=
github.com/transparency-dev/merkle v0.0.2/go.mod h1:pqSy+OXefQ1EDUVmAJ8MUhHB9TXGuzVAT58PqBoHz1A=
github.com/transparency-dev/trillian-tessera v0.0.0-20240911103714-727b99dc32a7 h1:8Wg8K8HO2Srmfsk94J2mIADbwhFjL3Bp+OqHJObnYuY=
github.com/transparency-dev/trillian-tessera v0.0.0-20240911103714-727b99dc32a7/go.mod h1:90QYeyW+bGY0wtDrlfrGU8F/N1h7r+3CAZtVgkQZcqE=
github.com/transparency-dev/trillian-tessera v0.0.0-20241112165219-498d39b5fc7c h1:AoxWHGmBZjZd2wi0N4NG5DmKk6vqnRbfI6HIZumKBdM=
github.com/transparency-dev/trillian-tessera v0.0.0-20241112165219-498d39b5fc7c/go.mod h1:TxAuGjZBDJddTBYXAjNumwhsMxmSOHIHVcLzhJeRNys=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -1139,8 +1137,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
16 changes: 2 additions & 14 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ import (
"github.com/google/certificate-transparency-go/asn1"
"github.com/google/certificate-transparency-go/x509util"
"github.com/google/trillian/monitoring"
tnote "github.com/transparency-dev/formats/note"
"golang.org/x/mod/sumdb/note"
)

type createStorageFunc func(context.Context, note.Signer, note.Verifier) (*CTStorage, error)

// InstanceOptions describes the options for a log instance.
type InstanceOptions struct {
// Validated holds the original configuration options for the log, and some
// of its fields parsed as a result of validating it.
Validated *ValidatedLogConfig
// CreateStorage instantiates a Tessera storage implementation with a signer option.
CreateStorage createStorageFunc
CreateStorage func(context.Context, note.Signer) (*CTStorage, error)
// Deadline is a timeout for Tessera requests.
Deadline time.Duration
// MetricFactory allows creating metrics.
Expand Down Expand Up @@ -95,19 +92,10 @@ func SetUpInstance(ctx context.Context, opts InstanceOptions) (*Instance, error)
timeSource := new(SystemTimeSource)
ctSigner := NewCpSigner(cfg.Signer, cfg.Origin, logID, timeSource)

vkey, err := tnote.RFC6962VerifierString(cfg.Origin, cfg.Signer.Public())
if err != nil {
return nil, fmt.Errorf("failed to create verifier key: %v", err)
}
ctVerifier, err := tnote.NewRFC6962Verifier(vkey)
if err != nil {
return nil, fmt.Errorf("failed to create verifier: %v", err)
}

if opts.CreateStorage == nil {
return nil, fmt.Errorf("failed to initiate storage backend: nil createStorage")
}
storage, err := opts.CreateStorage(ctx, ctSigner, ctVerifier)
storage, err := opts.CreateStorage(ctx, ctSigner)
if err != nil {
return nil, fmt.Errorf("failed to initiate storage backend: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"golang.org/x/mod/sumdb/note"
)

func fakeCTStorage(_ context.Context, _ note.Signer, _ note.Verifier) (*CTStorage, error) {
func fakeCTStorage(_ context.Context, _ note.Signer) (*CTStorage, error) {
return &CTStorage{}, nil
}

Expand All @@ -52,7 +52,7 @@ func TestSetUpInstance(t *testing.T) {
extKeyUsages string
rejectExtensions string
signer crypto.Signer
ctStorage createStorageFunc
ctStorage func(context.Context, note.Signer) (*CTStorage, error)
wantErr string
}{
{
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestSetUpInstance(t *testing.T) {
spannerDB: "spanner",
rootsPemFile: "./testdata/fake-ca.cert",
signer: signer,
ctStorage: func(_ context.Context, _ note.Signer, _ note.Verifier) (*CTStorage, error) {
ctStorage: func(_ context.Context, _ note.Signer) (*CTStorage, error) {
return nil, fmt.Errorf("I failed")
},
wantErr: "failed to initiate storage backend",
Expand Down
12 changes: 5 additions & 7 deletions modules/dedup/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strconv"
"time"

"github.com/transparency-dev/trillian-tessera/api/layout"
"github.com/transparency-dev/trillian-tessera/client"
"k8s.io/klog/v2"
)
Expand All @@ -50,24 +49,24 @@ type LocalBEDedupStorage interface {
type ParseBundleFunc func([]byte, uint64) ([]LeafIdx, error)

// UpdateFromLog synchronises a local best effort deduplication storage with a log.
func UpdateFromLog(ctx context.Context, lds LocalBEDedupStorage, t time.Duration, f client.Fetcher, pb ParseBundleFunc) {
func UpdateFromLog(ctx context.Context, lds LocalBEDedupStorage, t time.Duration, fcp client.CheckpointFetcherFunc, fb client.EntryBundleFetcherFunc, pb ParseBundleFunc) {
tck := time.NewTicker(t)
defer tck.Stop()
for {
select {
case <-ctx.Done():
return
case <-tck.C:
if err := sync(ctx, lds, pb, f); err != nil {
if err := sync(ctx, lds, pb, fcp, fb); err != nil {
klog.Warningf("error updating deduplication data: %v", err)
}
}
}
}

// sync synchronises a deduplication storage with the corresponding log content.
func sync(ctx context.Context, lds LocalBEDedupStorage, pb ParseBundleFunc, f client.Fetcher) error {
cpRaw, err := f(ctx, layout.CheckpointPath)
func sync(ctx context.Context, lds LocalBEDedupStorage, pb ParseBundleFunc, fcp client.CheckpointFetcherFunc, fb client.EntryBundleFetcherFunc) error {
cpRaw, err := fcp(ctx)
if err != nil {
return fmt.Errorf("error fetching checkpoint: %v", err)
}
Expand All @@ -91,8 +90,7 @@ func sync(ctx context.Context, lds LocalBEDedupStorage, pb ParseBundleFunc, f cl
if ckptSize > oldSize {
klog.V(2).Infof("LocalBEDEdup.sync(): log at size %d, dedup database at size %d, startig to sync", ckptSize, oldSize)
for i := oldSize / 256; i <= ckptSize/256; i++ {
p := fmt.Sprintf("tile/data/%s", layout.NWithSuffix(0, i, ckptSize))
eRaw, err := f(ctx, p)
eRaw, err := fb(ctx, i, ckptSize)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("leaf bundle at index %d not found: %v", i, err)
Expand Down

0 comments on commit df7e2e0

Please sign in to comment.