Skip to content

Commit

Permalink
Add labels_per_unit to network info
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Aug 5, 2024
1 parent e9450bc commit cd25afa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion api/grpcserver/v2alpha1/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ const (
Network = "network_v2alpha1"
)

func NewNetworkService(genesisTime time.Time, genesisID types.Hash20, layerDuration time.Duration) *NetworkService {
func NewNetworkService(genesisTime time.Time, genesisID types.Hash20, layerDuration time.Duration,
labelsPerUnit uint64,
) *NetworkService {
return &NetworkService{
genesisTime: genesisTime,
genesisID: genesisID,
layerDuration: layerDuration,
labelsPerUnit: labelsPerUnit,
}
}

type NetworkService struct {
genesisTime time.Time
genesisID types.Hash20
layerDuration time.Duration
labelsPerUnit uint64
}

func (s *NetworkService) RegisterService(server *grpc.Server) {
Expand All @@ -54,5 +58,6 @@ func (s *NetworkService) Info(context.Context,
Hrp: types.NetworkHRP(),
EffectiveGenesisLayer: types.GetEffectiveGenesis().Uint32(),
LayersPerEpoch: types.GetLayersPerEpoch(),
LabelsPerUnit: s.labelsPerUnit,
}, nil
}
5 changes: 4 additions & 1 deletion api/grpcserver/v2alpha1/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
spacemeshv2alpha1 "github.com/spacemeshos/api/release/go/spacemesh/v2alpha1"
"github.com/stretchr/testify/require"

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/common/types"
)

func TestNetworkService_Info(t *testing.T) {
ctx := context.Background()
genesis := time.Unix(genTimeUnix, 0)
postConfig := activation.DefaultPostConfig()

svc := NewNetworkService(genesis, genesisID, layerDuration)
svc := NewNetworkService(genesis, genesisID, layerDuration, postConfig.LabelsPerUnit)
cfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)

Expand All @@ -32,5 +34,6 @@ func TestNetworkService_Info(t *testing.T) {
require.Equal(t, types.NetworkHRP(), info.Hrp)
require.Equal(t, types.GetEffectiveGenesis().Uint32(), info.EffectiveGenesisLayer)
require.Equal(t, types.GetLayersPerEpoch(), info.LayersPerEpoch)
require.Equal(t, postConfig.LabelsPerUnit, info.LabelsPerUnit)
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/seehuhn/mt19937 v1.0.0
github.com/slok/go-http-metrics v0.12.0
github.com/spacemeshos/api/release/go v1.50.0
github.com/spacemeshos/api/release/go v1.51.0
github.com/spacemeshos/economics v0.1.3
github.com/spacemeshos/fixed v0.1.1
github.com/spacemeshos/go-scale v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spacemeshos/api/release/go v1.50.0 h1:M7Usg/LxymscwqYO7/Doyb+sU4lS1e+JIsSgqTDGk/0=
github.com/spacemeshos/api/release/go v1.50.0/go.mod h1:PvgDpjfwkZLVVNExYG7wDNzgMqT3p+ppfTU2UESSF9U=
github.com/spacemeshos/api/release/go v1.51.0 h1:MSKRIUiXBAoDrj2Lj24q9g52ZaSIC3I0UH/Y0Oaz95o=
github.com/spacemeshos/api/release/go v1.51.0/go.mod h1:Qr/pVPMmN5Q5qLHSXqVMDKDCu6LkHWzGPNflylE0u00=
github.com/spacemeshos/economics v0.1.3 h1:ACkq3mTebIky4Zwbs9SeSSRZrUCjU/Zk0wq9Z0BTh2A=
github.com/spacemeshos/economics v0.1.3/go.mod h1:FH7u0FzTIm6Kpk+X5HOZDvpkgNYBKclmH86rVwYaDAo=
github.com/spacemeshos/fixed v0.1.1 h1:N1y4SUpq1EV+IdJrWJwUCt1oBFzeru/VKVcBsvPc2Fk=
Expand Down
3 changes: 2 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,8 @@ func (app *App) grpcService(svc grpcserver.Service, lg log.Log) (grpcserver.Serv
service := v2alpha1.NewNetworkService(
app.clock.GenesisTime(),
app.Config.Genesis.GenesisID(),
app.Config.LayerDuration)
app.Config.LayerDuration,
app.postSupervisor.Config().LabelsPerUnit)
app.grpcServices[svc] = service
return service, nil
case v2alpha1.Node:
Expand Down

0 comments on commit cd25afa

Please sign in to comment.