Skip to content

Commit

Permalink
Try #6355:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Oct 30, 2024
2 parents 55e311b + 4d6b25a commit a41c1f6
Show file tree
Hide file tree
Showing 31 changed files with 2,503 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ GOLANGCI_LINT_VERSION := v1.61.0
GOTESTSUM_VERSION := v1.12.0
GOSCALE_VERSION := v1.2.0
MOCKGEN_VERSION := v0.5.0
OAPI_CODEGEN_VERSION := v2.4.0

# Add an indicator to the branch name if dirty and use commithash if running in detached mode
ifeq ($(BRANCH),HEAD)
Expand Down Expand Up @@ -68,6 +69,7 @@ install:
go install github.com/spacemeshos/go-scale/scalegen@$(GOSCALE_VERSION)
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@$(OAPI_CODEGEN_VERSION)
.PHONY: install

build: go-spacemesh get-profiler get-postrs-service
Expand Down
4 changes: 4 additions & 0 deletions activation/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ type certifierService interface {
DeleteCertificate(id types.NodeID, pubkey []byte) error
}

type PoetDbStorer interface {
StorePoetProof(ctx context.Context, proofMessage *types.PoetProofMessage) error
}

type poetDbAPI interface {
Proof(types.PoetProofRef) (*types.PoetProof, *types.Hash32, error)
ProofForRound(poetID []byte, roundID string) (*types.PoetProof, error)
Expand Down
62 changes: 62 additions & 0 deletions activation/mocks.go

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

38 changes: 27 additions & 11 deletions activation/poetdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (

// PoetDbOptions are options for PoetDb.
type PoetDbOptions struct {
cacheSize int
cacheSize int
remoteStorer PoetDbStorer
}

type PoetDbOption func(*PoetDbOptions)
Expand All @@ -35,12 +36,19 @@ func WithCacheSize(size int) PoetDbOption {
}
}

func WithRemotePoetStorer(storer PoetDbStorer) PoetDbOption {
return func(opts *PoetDbOptions) {
opts.remoteStorer = storer
}
}

// PoetDb is a database for PoET proofs.
type PoetDb struct {
sqlDB sql.StateDatabase
poetProofsDbRequest singleflight.Group
poetProofsLru *lru.Cache[types.PoetProofRef, *types.PoetProofMessage]
logger *zap.Logger
remoteStorer PoetDbStorer
}

// NewPoetDb returns a new PoET handler.
Expand All @@ -66,6 +74,7 @@ func NewPoetDb(db sql.StateDatabase, log *zap.Logger, opts ...PoetDbOption) (*Po
sqlDB: db,
poetProofsLru: poetProofsLru,
logger: log,
remoteStorer: options.remoteStorer,
}, nil
}

Expand Down Expand Up @@ -99,6 +108,13 @@ func (db *PoetDb) ValidateAndStore(ctx context.Context, proofMessage *types.Poet
return err
}

if db.remoteStorer != nil {
err := db.remoteStorer.StorePoetProof(ctx, proofMessage)
if err != nil {
db.logger.Warn("failed to store the poet proof in remote store", zap.Error(err))
}
}

return db.StoreProof(ctx, ref, proofMessage)
}

Expand Down Expand Up @@ -178,13 +194,17 @@ func (db *PoetDb) GetProofRef(poetID []byte, roundID string) (types.PoetProofRef
}

// GetProofMessage returns the originally received PoET proof message.
func (db *PoetDb) GetProofMessage(proofRef types.PoetProofRef) ([]byte, error) {
func (db *PoetDb) ProofMessage(proofRef types.PoetProofRef) (*types.PoetProofMessage, error) {
proof, err := poets.Get(db.sqlDB, proofRef)
if err != nil {
return proof, fmt.Errorf("get proof from store: %w", err)
return nil, fmt.Errorf("get proof from store: %w", err)
}
var proofMessage types.PoetProofMessage
if err := codec.Decode(proof, &proofMessage); err != nil {
return nil, fmt.Errorf("failed to unmarshal poet proof for ref %x: %w", proofRef, err)
}

return proof, nil
return &proofMessage, nil
}

// Proof returns full proof.
Expand All @@ -194,16 +214,12 @@ func (db *PoetDb) Proof(proofRef types.PoetProofRef) (*types.PoetProof, *types.H
if ok && cachedProof != nil {
return cachedProof, nil
}
proofMessageBytes, err := db.GetProofMessage(proofRef)
proofMessage, err := db.ProofMessage(proofRef)
if err != nil {
return nil, fmt.Errorf("could not fetch poet proof for ref %x: %w", proofRef, err)
}
var proofMessage types.PoetProofMessage
if err := codec.Decode(proofMessageBytes, &proofMessage); err != nil {
return nil, fmt.Errorf("failed to unmarshal poet proof for ref %x: %w", proofRef, err)
}
db.poetProofsLru.Add(proofRef, &proofMessage)
return &proofMessage, nil
db.poetProofsLru.Add(proofRef, proofMessage)
return proofMessage, nil
})
if err != nil {
return nil, nil, err
Expand Down
31 changes: 31 additions & 0 deletions activation_service_poc/config.standalone.client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"preset": "standalone",
"api": {
"grpc-public-listener": "0.0.0.0:9082",
"grpc-private-listener": "0.0.0.0:9083"
},
"genesis": {
"genesis-time": "2024-09-25T13:00:00.000Z"
},
"logging": {
"trtl": "WARN",
"beacon": "ERROR",
"proposalBuilder": "ERROR",
"atxBuilder": "DEBUG"
},
"main": {
"node-service-address": "http://0.0.0.0:9099",
"data-folder": "/tmp/spacemesh-client",
"filelock": "/tmp/spacemesh-client/node.lock",
"poet-servers": [
{
"address": "http://127.0.0.1:10011"
}
]
},
"smeshing": {
"smeshing-opts": {
"smeshing-opts-datadir": "/tmp/spacemesh-client/post-data"
}
}
}
23 changes: 23 additions & 0 deletions activation_service_poc/config.standalone.node-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"preset": "standalone",
"api": {
"grpc-public-listener": "0.0.0.0:9092",
"grpc-private-listener": "0.0.0.0:9093",
"node-service-listener": "0.0.0.0:9099"
},
"genesis": {
"genesis-time": "2024-09-25T13:00:00.000Z"
},
"logging": {
"trtl": "WARN",
"beacon": "ERROR",
"proposalBuilder": "ERROR"
},
"main": {
"data-folder": "/tmp/spacemesh-node-service",
"filelock": "/tmp/spacemesh-node-service/node.lock"
},
"smeshing": {
"smeshing-start": false
}
}
24 changes: 24 additions & 0 deletions activation_service_poc/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'

services:
activation-service:
image: spacemeshos/go-spacemesh-dev:activation-service-poc.0
command: ["-c", "/config.json", "--node-service-address", "http://node-service:9099"]
volumes:
- /tmp/spacemesh-client:/tmp/spacemesh-client
- ./config.standalone.client.json:/config.json
networks:
- spacemesh-net

node-service:
image: spacemeshos/go-spacemesh-dev:activation-service-poc.0
command: ["-c", "/config.json"]
volumes:
- /tmp/spacemesh-node-service:/tmp/spacemesh-node-service
- ./config.standalone.node-service.json:/config.json
networks:
- spacemesh-net

networks:
spacemesh-net:
driver: bridge
2 changes: 2 additions & 0 deletions api/grpcserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Config struct {
JSONListener string `mapstructure:"grpc-json-listener"`
JSONCorsAllowedOrigins []string `mapstructure:"grpc-cors-allowed-origins"`

NodeServiceListener string `mapstructure:"node-service-listener"`

SmesherStreamInterval time.Duration `mapstructure:"smesherstreaminterval"`

DatabaseConnections int `mapstructure:"db-connections"`
Expand Down
Loading

0 comments on commit a41c1f6

Please sign in to comment.