Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] Activation Service builds and publishes ATXs with Node Service help #6355

Open
wants to merge 17 commits into
base: node-split-poc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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 WithRemotePoetStorer(storer PoetDbStorer) PoetDbOption {
return func(opts *PoetDbOptions) {
opts.remoteStorer = storer
}

Check warning on line 42 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L39-L42

Added lines #L39 - L42 were not covered by tests
}

// 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 @@
sqlDB: db,
poetProofsLru: poetProofsLru,
logger: log,
remoteStorer: options.remoteStorer,
}, nil
}

Expand Down Expand Up @@ -99,6 +108,13 @@
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))
}

Check warning on line 115 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L112-L115

Added lines #L112 - L115 were not covered by tests
}

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

Expand Down Expand Up @@ -178,13 +194,17 @@
}

// 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) {

Check warning on line 197 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L197

Added line #L197 was not covered by tests
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)

Check warning on line 204 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L200-L204

Added lines #L200 - L204 were not covered by tests
}

return proof, nil
return &proofMessage, nil

Check warning on line 207 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L207

Added line #L207 was not covered by tests
}

// Proof returns full proof.
Expand All @@ -194,16 +214,12 @@
if ok && cachedProof != nil {
return cachedProof, nil
}
proofMessageBytes, err := db.GetProofMessage(proofRef)
proofMessage, err := db.ProofMessage(proofRef)

Check warning on line 217 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L217

Added line #L217 was not covered by tests
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

Check warning on line 222 in activation/poetdb.go

View check run for this annotation

Codecov / codecov/patch

activation/poetdb.go#L221-L222

Added lines #L221 - L222 were not covered by tests
})
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
Loading