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 6, 2024
2 parents fac1e72 + 51f5fc0 commit c8d50c2
Show file tree
Hide file tree
Showing 19 changed files with 1,138 additions and 164 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
7 changes: 4 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,10 @@
"logging": {
"trtl": "WARN",
"beacon": "ERROR",
"proposalBuilder": "ERROR",
"atxBuilder": "DEBUG",
"hare": "DEBUG"
"proposalBuilder": "DEBUG",
"atxBuilder": "ERROR",
"hare": "ERROR",
"nodeServiceClient": "ERROR"
},
"main": {
"node-service-address": "http://0.0.0.0:9099",
Expand Down
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"
}
}
}
5 changes: 4 additions & 1 deletion activation_service_poc/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ services:

node-service:
image: ${IMAGE}
command: ["-c", "/config.json", "--smeshing-opts-datadir", "/tmp/spacemesh-node-post"]
command: ["-c", "/config.json" ]
volumes:
- /tmp/spacemesh-node-service:/tmp/spacemesh-node-service
- ./config.standalone.node-service.json:/config.json
networks:
- spacemesh-net
ports:
- 9092:9092
- 9093:9093

networks:
spacemesh-net:
Expand Down
7 changes: 4 additions & 3 deletions activation_service_poc/start.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ cd activation_service_poc
export IMAGE=$(docker images | head -n 2 | tail -n 1 | awk '{print $3}')

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
for file in config.standalone.client.json config.standalone.node-service.json;do
jq ".genesis.\"genesis-time\" |= \"$TIME\"" "$file" > temp.json && mv temp.json "$file"
done

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.

67 changes: 57 additions & 10 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,22 +134,30 @@ 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 {
switch resp.StatusCode {
case http.StatusOK:
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read all: %w", err)
}
return bytes, nil

case http.StatusNoContent:
// no message to return, special case, return nil,nil
// and the caller should assume there's no message to process,
// therefore hare probably terminated.
return nil, nil
default:
return nil, fmt.Errorf("unexpected status: %s", resp.Status)
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read all: %w", err)
}
return bytes, nil
}

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 +172,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 +188,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 +200,41 @@ 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)
}
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 c8d50c2

Please sign in to comment.