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 4, 2024
2 parents fac1e72 + 443e296 commit 9a70b3d
Show file tree
Hide file tree
Showing 18 changed files with 1,032 additions and 79 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.

52 changes: 48 additions & 4 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 @@ -133,7 +134,7 @@ func (s *NodeService) GetHareMessage(ctx context.Context, layer types.LayerID, r
externalRef0.HareIter(round.Iter),
externalRef0.HareRound(round.Round))
if err != nil {
return nil, err
return nil, fmt.Errorf("get hare message: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status: %s", resp.Status)
Expand All @@ -148,7 +149,7 @@ func (s *NodeService) GetHareMessage(ctx context.Context, layer types.LayerID, r
func (s *NodeService) TotalWeight(ctx context.Context, layer types.LayerID) (uint64, error) {
resp, err := s.client.GetHareTotalWeightLayer(ctx, uint32(layer))
if err != nil {
return 0, err
return 0, fmt.Errorf("get total weight: %w", err)
}
if resp.StatusCode != http.StatusOK {
return 0, fmt.Errorf("unexpected status: %s", resp.Status)
Expand All @@ -163,7 +164,7 @@ func (s *NodeService) TotalWeight(ctx context.Context, layer types.LayerID) (uin
func (s *NodeService) MinerWeight(ctx context.Context, layer types.LayerID, node types.NodeID) (uint64, error) {
resp, err := s.client.GetHareWeightNodeIdLayer(ctx, node.String(), uint32(layer))
if err != nil {
return 0, err
return 0, fmt.Errorf("get miner weight: %w", err)
}
if resp.StatusCode != http.StatusOK {
return 0, fmt.Errorf("unexpected status: %s", resp.Status)
Expand All @@ -179,7 +180,7 @@ func (s *NodeService) Beacon(ctx context.Context, epoch types.EpochID) (types.Be
v := types.Beacon{}
resp, err := s.client.GetHareBeaconEpoch(ctx, externalRef0.EpochID(epoch))
if err != nil {
return v, err
return v, fmt.Errorf("get hare beacon: %w", err)
}
if resp.StatusCode != http.StatusOK {
return v, fmt.Errorf("unexpected status: %s", resp.Status)
Expand All @@ -191,3 +192,46 @@ 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, fmt.Errorf("get proposal layer: %w", 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{}
err = codec.Decode(bytes, &prop)
if err != nil {
return nil, 0, fmt.Errorf("decode proposal: %w", err)
}
err = prop.Initialize()
if err != nil {
return nil, 0, fmt.Errorf("proposal initialize: %w", err)
}

atxNonce := resp.Header.Get("X-Spacemesh-Atx-Nonce")
if atxNonce == "" {
return nil, 0, errors.New("missing atx nonce")
}
nonce, err := strconv.ParseUint(atxNonce, 10, 64)
if err != nil {
return nil, 0, fmt.Errorf("nonce parse: %w", err)
}
return &prop, nonce, nil
}
Loading

0 comments on commit 9a70b3d

Please sign in to comment.