Skip to content

Commit 9befdc6

Browse files
committed
workaroud identityd not working
1 parent c897ab6 commit 9befdc6

File tree

4 files changed

+73
-74
lines changed

4 files changed

+73
-74
lines changed

bins/packages/vector/files/zinit-vector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exec: |
66
77
pkill vector || true
88
9-
export NODE=$(identityd -address)
9+
export NODE=$(identityd -id)
1010
export FARM=$(identityd -farm)
1111
export NETWORK=$(identityd -net)
1212

cmds/identityd/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ func main() {
4747
ver bool
4848
debug bool
4949

50-
id bool
51-
net bool
52-
farm bool
53-
// address bool
50+
id bool
51+
net bool
52+
farm bool
53+
address bool
5454
)
5555

5656
flag.StringVar(&root, "root", "/var/cache/modules/identityd", "root working directory of the module")
@@ -61,7 +61,7 @@ func main() {
6161
flag.BoolVar(&id, "id", false, "[deprecated] prints the node ID and exits")
6262
flag.BoolVar(&net, "net", false, "prints the node network and exits")
6363
flag.BoolVar(&farm, "farm", false, "prints the node farm id and exits")
64-
// flag.BoolVar(&address, "address", false, "prints the node ss58 address and exits")
64+
flag.BoolVar(&address, "address", false, "prints the node ss58 address and exits")
6565

6666
flag.Parse()
6767
if ver {
@@ -78,7 +78,7 @@ func main() {
7878
env := environment.MustGet()
7979
fmt.Println(env.RunningMode.String())
8080
os.Exit(0)
81-
} else if id {
81+
} else if id || address {
8282
ctx := context.Background()
8383
if err != nil {
8484
log.Fatal().Err(err).Msg("failed to connect to zbus")

cmds/modules/api_gateway/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func action(cli *cli.Context) error {
6969
}
7070

7171
router := peer.NewRouter()
72-
gw, err := registrar.NewRegistrarGateway(redis, manager)
72+
gw, err := registrar.NewRegistrarGateway(redis)
7373
if err != nil {
7474
return fmt.Errorf("failed to create api gateway: %w", err)
7575
}

pkg/registrar_gateway/registrar_gateway.go

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,29 @@ import (
2323
"github.com/threefoldtech/zos4/pkg/types"
2424
"github.com/threefoldtech/zosbase/pkg"
2525
"github.com/threefoldtech/zosbase/pkg/environment"
26-
"github.com/threefoldtech/zosbase/pkg/gridtypes"
2726
)
2827

2928
const AuthHeader = "X-Auth"
3029

3130
type registrarGateway struct {
32-
sub *substrate.Substrate
3331
mu sync.Mutex
3432
baseURL string
3533
httpClient *http.Client
36-
identity gridtypes.Identity
3734
privKey ed25519.PrivateKey
3835
nodeID uint64
3936
twinID uint64
4037
}
4138

4239
var ErrorRecordNotFound = errors.New("could not fine the reqested record")
4340

44-
func NewRegistrarGateway(cl zbus.Client, manager substrate.Manager) (zos4Pkg.RegistrarGateway, error) {
41+
func NewRegistrarGateway(cl zbus.Client) (zos4Pkg.RegistrarGateway, error) {
4542
client := http.DefaultClient
4643
env := environment.MustGet()
47-
sub, err := manager.Substrate()
48-
if err != nil {
49-
return &registrarGateway{}, err
50-
}
5144

5245
identity := stubs.NewIdentityManagerStub(cl)
5346
sk := ed25519.PrivateKey(identity.PrivateKey(context.TODO()))
5447

5548
gw := &registrarGateway{
56-
sub: sub,
5749
httpClient: client,
5850
baseURL: env.RegistrarURL,
5951
mu: sync.Mutex{},
@@ -108,22 +100,22 @@ func (g *registrarGateway) EnsureAccount(twinID uint64, pk []byte) (twin types.A
108100
}
109101

110102
func (g *registrarGateway) GetContract(id uint64) (result substrate.Contract, serr pkg.SubstrateError) {
111-
log.Trace().Str("method", "GetContract").Uint64("id", id).Msg("method called")
112-
contract, err := g.sub.GetContract(id)
113-
114-
serr = buildSubstrateError(err)
115-
if err != nil {
116-
return
117-
}
118-
return *contract, serr
103+
// log.Trace().Str("method", "GetContract").Uint64("id", id).Msg("method called")
104+
// contract, err := g.sub.GetContract(id)
105+
//
106+
// serr = buildSubstrateError(err)
107+
// if err != nil {
108+
// return
109+
// }
110+
return
119111
}
120112

121113
func (g *registrarGateway) GetContractIDByNameRegistration(name string) (result uint64, serr pkg.SubstrateError) {
122-
log.Trace().Str("method", "GetContractIDByNameRegistration").Str("name", name).Msg("method called")
123-
contractID, err := g.sub.GetContractIDByNameRegistration(name)
124-
125-
serr = buildSubstrateError(err)
126-
return contractID, serr
114+
// log.Trace().Str("method", "GetContractIDByNameRegistration").Str("name", name).Msg("method called")
115+
// contractID, err := g.sub.GetContractIDByNameRegistration(name)
116+
//
117+
// serr = buildSubstrateError(err)
118+
return
127119
}
128120

129121
func (r *registrarGateway) GetFarm(id uint64) (farm types.Farm, err error) {
@@ -148,16 +140,17 @@ func (r *registrarGateway) GetNodeByTwinID(twin uint64) (result uint64, err erro
148140
}
149141

150142
func (g *registrarGateway) GetNodeContracts(node uint32) ([]subTypes.U64, error) {
151-
log.Trace().Str("method", "GetNodeContracts").Uint32("node", node).Msg("method called")
152-
return g.sub.GetNodeContracts(node)
143+
// log.Trace().Str("method", "GetNodeContracts").Uint32("node", node).Msg("method called")
144+
// return g.sub.GetNodeContracts(node)
145+
return []subTypes.U64{}, nil
153146
}
154147

155148
func (g *registrarGateway) GetNodeRentContract(node uint32) (result uint64, serr pkg.SubstrateError) {
156-
log.Trace().Str("method", "GetNodeRentContract").Uint32("node", node).Msg("method called")
157-
contractID, err := g.sub.GetNodeRentContract(node)
158-
159-
serr = buildSubstrateError(err)
160-
return contractID, serr
149+
// log.Trace().Str("method", "GetNodeRentContract").Uint32("node", node).Msg("method called")
150+
// contractID, err := g.sub.GetNodeRentContract(node)
151+
//
152+
// serr = buildSubstrateError(err)
153+
return
161154
}
162155

163156
func (r *registrarGateway) GetNodes(farmID uint32) (nodeIDs []uint32, err error) {
@@ -168,8 +161,9 @@ func (r *registrarGateway) GetNodes(farmID uint32) (nodeIDs []uint32, err error)
168161
}
169162

170163
func (g *registrarGateway) GetPowerTarget() (power substrate.NodePower, err error) {
171-
log.Trace().Str("method", "GetPowerTarget").Uint32("node id", uint32(g.nodeID)).Msg("method called")
172-
return g.sub.GetPowerTarget(uint32(g.nodeID))
164+
// log.Trace().Str("method", "GetPowerTarget").Uint32("node id", uint32(g.nodeID)).Msg("method called")
165+
// return g.sub.GetPowerTarget(uint32(g.nodeID))
166+
return
173167
}
174168

175169
func (r *registrarGateway) GetTwin(id uint64) (result types.Account, err error) {
@@ -187,43 +181,46 @@ func (r *registrarGateway) GetTwinByPubKey(pk []byte) (result uint64, err error)
187181
}
188182

189183
func (r *registrarGateway) Report(consumptions []substrate.NruConsumption) (subTypes.Hash, error) {
190-
contractIDs := make([]uint64, 0, len(consumptions))
191-
for _, v := range consumptions {
192-
contractIDs = append(contractIDs, uint64(v.ContractID))
193-
}
194-
195-
log.Debug().Str("method", "Report").Uints64("contract ids", contractIDs).Msg("method called")
196-
r.mu.Lock()
197-
defer r.mu.Unlock()
198-
199-
url := fmt.Sprintf("%s/v1/nodes/%d/consumption", r.baseURL, r.nodeID)
200-
201-
var body bytes.Buffer
202-
_, err := r.httpClient.Post(url, "application/json", &body)
203-
if err != nil {
204-
return subTypes.Hash{}, err
205-
}
206-
207-
// I need to know what is hash to be able to respond with it
208-
return r.sub.Report(r.identity, consumptions)
184+
// contractIDs := make([]uint64, 0, len(consumptions))
185+
// for _, v := range consumptions {
186+
// contractIDs = append(contractIDs, uint64(v.ContractID))
187+
// }
188+
//
189+
// log.Debug().Str("method", "Report").Uints64("contract ids", contractIDs).Msg("method called")
190+
// r.mu.Lock()
191+
// defer r.mu.Unlock()
192+
//
193+
// url := fmt.Sprintf("%s/v1/nodes/%d/consumption", r.baseURL, r.nodeID)
194+
//
195+
// var body bytes.Buffer
196+
// _, err := r.httpClient.Post(url, "application/json", &body)
197+
// if err != nil {
198+
// return subTypes.Hash{}, err
199+
// }
200+
//
201+
// // I need to know what is hash to be able to respond with it
202+
// return r.sub.Report(r.identity, consumptions)
203+
return subTypes.Hash{}, nil
209204
}
210205

211206
func (g *registrarGateway) SetContractConsumption(resources ...substrate.ContractResources) error {
212-
contractIDs := make([]uint64, 0, len(resources))
213-
for _, v := range resources {
214-
contractIDs = append(contractIDs, uint64(v.ContractID))
215-
}
216-
log.Debug().Str("method", "SetContractConsumption").Uints64("contract ids", contractIDs).Msg("method called")
217-
g.mu.Lock()
218-
defer g.mu.Unlock()
219-
return g.sub.SetContractConsumption(g.identity, resources...)
207+
// contractIDs := make([]uint64, 0, len(resources))
208+
// for _, v := range resources {
209+
// contractIDs = append(contractIDs, uint64(v.ContractID))
210+
// }
211+
// log.Debug().Str("method", "SetContractConsumption").Uints64("contract ids", contractIDs).Msg("method called")
212+
// g.mu.Lock()
213+
// defer g.mu.Unlock()
214+
// return g.sub.SetContractConsumption(g.identity, resources...)
215+
return nil
220216
}
221217

222218
func (g *registrarGateway) SetNodePowerState(up bool) (hash subTypes.Hash, err error) {
223-
log.Debug().Str("method", "SetNodePowerState").Bool("up", up).Msg("method called")
224-
g.mu.Lock()
225-
defer g.mu.Unlock()
226-
return g.sub.SetNodePowerState(g.identity, up)
219+
// log.Debug().Str("method", "SetNodePowerState").Bool("up", up).Msg("method called")
220+
// g.mu.Lock()
221+
// defer g.mu.Unlock()
222+
// return g.sub.SetNodePowerState(g.identity, up)
223+
return subTypes.Hash{}, nil
227224
}
228225

229226
func (r *registrarGateway) UpdateNode(node types.NodeRegistrationRequest) (uint64, error) {
@@ -249,9 +246,10 @@ func (r *registrarGateway) UpdateNodeUptimeV2(uptime uint64, timestampHint uint6
249246
}
250247

251248
func (g *registrarGateway) GetTime() (time.Time, error) {
252-
log.Trace().Str("method", "Time").Msg("method called")
253-
254-
return g.sub.Time()
249+
// log.Trace().Str("method", "Time").Msg("method called")
250+
//
251+
// return g.sub.Time()
252+
return time.Now(), nil
255253
}
256254

257255
func buildSubstrateError(err error) (serr pkg.SubstrateError) {
@@ -442,7 +440,8 @@ func (r *registrarGateway) getZosVersion(url string) (string, error) {
442440

443441
defer resp.Body.Close()
444442

445-
var version gridtypes.Versioned
443+
var version types.ZosVersion
444+
446445
err = json.NewDecoder(resp.Body).Decode(&version)
447446

448447
return version.Version, err

0 commit comments

Comments
 (0)