Skip to content

Commit c3f8e4b

Browse files
author
vlad
committed
build fix
1 parent da241cd commit c3f8e4b

File tree

4 files changed

+16
-66
lines changed

4 files changed

+16
-66
lines changed

x/compute/client/cli/tx.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"context"
55
"encoding/hex"
6-
"encoding/json"
76
"fmt"
87
"os"
98
"strconv"
@@ -676,15 +675,15 @@ Each machine ID must be exactly 20 bytes.`,
676675
}
677676

678677
// Read machine IDs from file
679-
machineIDs, err := readMachineIDsFromFile(args[1])
678+
machineId, err := hex.DecodeString(args[1])
680679
if err != nil {
681680
return err
682681
}
683682

684683
msg := &types.MsgUpdateMachineWhitelist{
685684
Sender: clientCtx.GetFromAddress().String(),
686685
ProposalId: proposalID,
687-
MachineIds: machineIDs,
686+
MachineId: machineId,
688687
}
689688

690689
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
@@ -694,32 +693,3 @@ Each machine ID must be exactly 20 bytes.`,
694693
flags.AddTxFlagsToCmd(cmd)
695694
return cmd
696695
}
697-
698-
func readMachineIDsFromFile(filename string) ([][]byte, error) {
699-
data, err := os.ReadFile(filename)
700-
if err != nil {
701-
return nil, fmt.Errorf("failed to read file: %w", err)
702-
}
703-
704-
var config struct {
705-
MachineIDs []string `json:"machine_ids"`
706-
}
707-
708-
if err := json.Unmarshal(data, &config); err != nil {
709-
return nil, fmt.Errorf("failed to parse JSON: %w", err)
710-
}
711-
712-
machineIDs := make([][]byte, len(config.MachineIDs))
713-
for i, idHex := range config.MachineIDs {
714-
id, err := hex.DecodeString(idHex)
715-
if err != nil {
716-
return nil, fmt.Errorf("invalid hex at index %d: %w", i, err)
717-
}
718-
if len(id) != 20 {
719-
return nil, fmt.Errorf("machine ID at index %d must be 20 bytes, got %d", i, len(id))
720-
}
721-
machineIDs[i] = id
722-
}
723-
724-
return machineIDs, nil
725-
}

x/compute/internal/keeper/ante.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,10 @@ func (a *CountTXDecorator) validateUpdateMachineWhitelist(ctx sdk.Context, msgUp
147147
return err
148148
}
149149

150-
if len(msgUpdateWhitelist.MachineIds) != len(updateMachineWhitelistProposalMsg.MachineIds) {
151-
return sdkerrors.ErrInvalidRequest.Wrapf("machine ids count %d does not match the proposal %d", len(msgUpdateWhitelist.MachineIds), len(updateMachineWhitelistProposalMsg.MachineIds))
152-
}
153-
// ensure the machine ids match the proposal exactly in order
154-
for i, mid := range msgUpdateWhitelist.MachineIds {
155-
if !bytes.Equal(mid, updateMachineWhitelistProposalMsg.MachineIds[i]) {
156-
return sdkerrors.ErrInvalidRequest.Wrapf("machine id %s at position %d does not match the proposal", mid, i)
157-
}
150+
if !bytes.Equal(msgUpdateWhitelist.MachineId, updateMachineWhitelistProposalMsg.MachineId) {
151+
return sdkerrors.ErrInvalidRequest.Wrapf("machine id %s does not match the proposal %s", msgUpdateWhitelist.MachineId, updateMachineWhitelistProposalMsg.MachineId)
158152
}
153+
159154
return nil
160155
}
161156

x/compute/internal/keeper/msg_server.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func (m msgServer) UpdateMachineWhitelistProposal(goCtx context.Context, msg *ty
328328

329329
ctx.EventManager().EmitEvent(sdk.NewEvent(
330330
types.EventTypeMachineWhitelistProposal,
331-
sdk.NewAttribute("machine_count", fmt.Sprintf("%d", len(msg.MachineIds))),
331+
sdk.NewAttribute("machine_id", fmt.Sprintf("%x", len(msg.MachineId))),
332332
sdk.NewAttribute(sdk.AttributeKeySender, msg.Authority),
333333
))
334334

@@ -345,22 +345,21 @@ func (m msgServer) UpdateMachineWhitelist(goCtx context.Context, msg *types.MsgU
345345
ctx.EventManager().EmitEvent(sdk.NewEvent(
346346
types.EventTypeMachineWhitelistUpdate,
347347
sdk.NewAttribute("proposal_id", fmt.Sprintf("%d", msg.ProposalId)),
348-
sdk.NewAttribute("machine_count", fmt.Sprintf("%d", len(msg.MachineIds))),
348+
sdk.NewAttribute("machine_id", fmt.Sprintf("%x", len(msg.MachineId))),
349349
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
350350
))
351351

352352
store := m.keeper.storeService.OpenKVStore(ctx)
353353

354-
for _, id := range msg.MachineIds {
355-
354+
id := msg.MachineId
355+
{
356356
proof := [32]byte{}
357357
if err := api.OnApproveMachineID(id, &proof, true); err != nil {
358358
return nil, err
359-
360-
key := append(types.MachineIDEvidencePrefix, id...)
361-
_ = store.Set(key, proof[:])
362-
363359
}
360+
361+
key := append(types.MachineIDEvidencePrefix, id...)
362+
_ = store.Set(key, proof[:])
364363
}
365364

366365
return &types.MsgUpdateMachineWhitelistResponse{}, nil

x/compute/internal/types/msg.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,8 @@ func (msg MsgUpdateMachineWhitelistProposal) ValidateBasic() error {
332332
return errorsmod.Wrap(err, "invalid authority")
333333
}
334334

335-
if len(msg.MachineIds) == 0 {
336-
return errorsmod.Wrap(ErrEmpty, "machine_ids cannot be empty")
337-
}
338-
339-
for i, id := range msg.MachineIds {
340-
if len(id) != 20 {
341-
return errorsmod.Wrapf(ErrInvalid,
342-
"machine_id at index %d must be 20 bytes, got %d", i, len(id))
343-
}
335+
if len(msg.MachineId) != 20 {
336+
return errorsmod.Wrap(ErrInvalid, "machine_id must be 20 bytes")
344337
}
345338

346339
return nil
@@ -375,15 +368,8 @@ func (msg MsgUpdateMachineWhitelist) ValidateBasic() error {
375368
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "proposal ID cannot be zero")
376369
}
377370

378-
if len(msg.MachineIds) == 0 {
379-
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "machine IDs cannot be empty")
380-
}
381-
382-
// Validate each machine ID is exactly 20 bytes
383-
for i, id := range msg.MachineIds {
384-
if len(id) != 20 {
385-
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "machine ID at index %d must be 20 bytes, got %d", i, len(id))
386-
}
371+
if len(msg.MachineId) != 20 {
372+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "machine ID must be 20 bytes")
387373
}
388374

389375
return nil

0 commit comments

Comments
 (0)