Skip to content

Commit

Permalink
Try #6400:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Nov 1, 2024
2 parents fac1e72 + cd78aa8 commit f31bc5b
Show file tree
Hide file tree
Showing 18 changed files with 979 additions and 75 deletions.
5 changes: 4 additions & 1 deletion activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,10 @@ func (b *Builder) PublishActivationTx(ctx context.Context, sig *signing.EdSigner
)
size, err := b.broadcast(ctx, atx)
if err == nil {
b.logger.Info("atx published", log.ZShortStringer("atx_id", atx.ID()), zap.Int("size", size))
b.logger.Info("atx published",
log.ZShortStringer("atx_id", atx.ID()),
zap.Stringer("coinbase", b.Coinbase()),
zap.Int("size", size))
break
}

Expand Down
6 changes: 3 additions & 3 deletions activation_service_poc/config.standalone.client.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"logging": {
"trtl": "WARN",
"beacon": "ERROR",
"proposalBuilder": "ERROR",
"atxBuilder": "DEBUG",
"hare": "DEBUG"
"proposalBuilder": "DEBUG",
"atxBuilder": "ERROR",
"hare": "ERROR"
},
"main": {
"node-service-address": "http://0.0.0.0:9099",
Expand Down
32 changes: 32 additions & 0 deletions activation_service_poc/config.standalone.client2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"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": "DEBUG",
"atxBuilder": "ERROR",
"hare": "ERROR"
},
"main": {
"node-service-address": "http://0.0.0.0:9099",
"data-folder": "/tmp/spacemesh-client2",
"filelock": "/tmp/spacemesh-client2/node.lock",
"poet-servers": [
{
"address": "http://127.0.0.1:10011"
}
]
},
"smeshing": {
"smeshing-opts": {
"smeshing-opts-datadir": "/tmp/spacemesh-client2/post-data"
}
}
}
7 changes: 6 additions & 1 deletion activation_service_poc/config.standalone.node-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
"trtl": "WARN",
"beacon": "ERROR",
"proposalBuilder": "ERROR",
"hare": "DEBUG"
"hare": "ERROR"
},
"hare3": {
"enable": true
},
"main": {
"data-folder": "/tmp/spacemesh-node-service",
"filelock": "/tmp/spacemesh-node-service/node.lock"
},
"smeshing": {
"smeshing-opts": {
"smeshing-opts-datadir": "/tmp/spacemesh-node-service/post-data"
}
}
}
3 changes: 3 additions & 0 deletions activation_service_poc/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
- ./config.standalone.node-service.json:/config.json
networks:
- spacemesh-net
ports:
- 9092:9092
- 9093:9093

networks:
spacemesh-net:
Expand Down
2 changes: 1 addition & 1 deletion activation_service_poc/start.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ TIME=$(date -u -d '2 minutes' "+%Y-%m-%dT%H:%M:%S%:z")
jq ".genesis.\"genesis-time\" |= \"$TIME\"" config.standalone.client.json
jq ".genesis.\"genesis-time\" |= \"$TIME\"" config.standalone.node-service.json

rm -rf /tmp/spacemesh*
rm -rf /tmp/space*
docker compose up
105 changes: 105 additions & 0 deletions api/node/client/client.gen.go

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

36 changes: 36 additions & 0 deletions api/node/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -191,3 +192,38 @@ func (s *NodeService) Beacon(ctx context.Context, epoch types.EpochID) (types.Be
copy(v[:], bytes)
return v, nil
}

func (s *NodeService) Proposal(ctx context.Context, layer types.LayerID, node types.NodeID) (
*types.Proposal, uint64, error,
) {
resp, err := s.client.GetProposalLayerNode(ctx, externalRef0.LayerID(layer), node.String())
if err != nil {
return nil, 0, err
}
switch resp.StatusCode {
case http.StatusOK:
case http.StatusNoContent:
// special case - no error but also no proposal, means
// we're no eligibile this epoch with this node ID
return nil, 0, nil
default:
return nil, 0, fmt.Errorf("unexpected status: %s", resp.Status)
}

bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, 0, fmt.Errorf("read all: %w", err)
}

prop := types.Proposal{}
codec.MustDecode(bytes, &prop)
atxNonce := resp.Header.Get("X-Spacemesh-Atx-Nonce")
if atxNonce == "" {
return nil, 0, errors.New("atx nonce header not found")
}
nonce, err := strconv.ParseUint(atxNonce, 10, 64)
if err != nil {
return nil, 0, fmt.Errorf("nonce parse: %w", err)
}
return &prop, nonce, nil
}
9 changes: 8 additions & 1 deletion api/node/client/client_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type mocks struct {
poetDb *server.MockpoetDB
hare *server.Mockhare
publisher *pubsub.MockPublisher
proposals *server.MockproposalBuilder
}

func setupE2E(t *testing.T) (*client.NodeService, *mocks) {
Expand All @@ -37,9 +38,15 @@ func setupE2E(t *testing.T) (*client.NodeService, *mocks) {
poetDb: server.NewMockpoetDB(ctrl),
hare: server.NewMockhare(ctrl),
publisher: pubsub.NewMockPublisher(ctrl),
proposals: server.NewMockproposalBuilder(ctrl),
}

activationServiceServer := server.NewServer(m.atxService, m.publisher, m.poetDb, m.hare, log.Named("server"))
activationServiceServer := server.NewServer(m.atxService,
m.publisher,
m.poetDb,
m.hare,
m.proposals,
log.Named("server"))

listener, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
Expand Down
28 changes: 28 additions & 0 deletions api/node/node_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,32 @@ paths:
format: binary
"204":
description: did not find a message to retrieve
/proposal/{layer}/{node}:
get:
summary: Get a partial proposal for a given node in a layer
tags:
- "proposals"
parameters:
- in: path
name: layer
required: true
schema:
$ref: "models/components.yaml#/components/schemas/LayerID"
- in: path
name: node
required: true
schema:
$ref: "models/components.yaml#/components/schemas/NodeID"
responses:
"200":
description: successfully created a partial proposal
content:
application/octet-stream:
schema:
type: string
format: binary
"204":
description: no eligibilities for this node in this epoch
"500":
description: could not generate proposal

Loading

0 comments on commit f31bc5b

Please sign in to comment.