Skip to content

Commit

Permalink
chore(all): remove unnecessary flags
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Koehler <[email protected]>
  • Loading branch information
sophia1ch committed Dec 19, 2024
1 parent b272564 commit 2c079f1
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions backend/sim/channel/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewRandomAsset(rng *rand.Rand) *Asset {
// MarshalBinary marshals the address into its binary representation.
func (a Asset) MarshalBinary() ([]byte, error) {
data := make([]byte, assetLen)
byteOrder.PutUint64(data, uint64(a.ID)) //nolint:gosec
byteOrder.PutUint64(data, uint64(a.ID))
return data, nil
}

Expand All @@ -53,7 +53,7 @@ func (a *Asset) UnmarshalBinary(data []byte) error {
if len(data) != assetLen {
return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) //nolint:goerr113 // We do not want to define this as constant error.
}
a.ID = int64(byteOrder.Uint64(data)) //nolint:gosec
a.ID = int64(byteOrder.Uint64(data))
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions channel/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewAllocation(numParts int, backends []wallet.BackendID, assets ...Asset) *
func (a *Allocation) AssetIndex(asset Asset) (Index, bool) {
for idx, _asset := range a.Assets {
if asset.Equal(_asset) {
return Index(idx), true //nolint:gosec
return Index(idx), true
}
}
return 0, false
Expand Down Expand Up @@ -325,12 +325,12 @@ func (a Allocation) Encode(w io.Writer) error {
err, "invalid allocations cannot be encoded, got %v", a)
}
// encode dimensions
if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { //nolint:gosec
if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil {
return err
}
// encode assets
for i, asset := range a.Assets {
if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { //nolint:gosec
if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil {
return errors.WithMessagef(err, "encoding backends %d", i)
}
if err := perunio.Encode(w, asset); err != nil {
Expand Down Expand Up @@ -436,7 +436,7 @@ func (b Balances) Encode(w io.Writer) error {
return errors.Errorf("expected maximum number of parts %d, got %d", MaxNumParts, numParts)
}

if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { //nolint:gosec
if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil {
return errors.WithMessage(err, "encoding dimensions")
}
for i := range b {
Expand Down Expand Up @@ -667,7 +667,7 @@ func (s SubAlloc) Encode(w io.Writer) error {
err, "invalid sub-allocations cannot be encoded, got %v", s)
}
// encode ID and dimension
if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { //nolint:gosec
if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil {
return errors.WithMessagef(
err, "encoding sub-allocation ID or dimension, id %v", s.ID)
}
Expand All @@ -679,7 +679,7 @@ func (s SubAlloc) Encode(w io.Writer) error {
}
}
// Encode IndexMap.
if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { //nolint:gosec
if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil {
return errors.WithMessage(err, "encoding length of index map")
}
for i, x := range s.IndexMap {
Expand Down
4 changes: 2 additions & 2 deletions channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func newMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*machin
return &machine{
phase: InitActing,
acc: acc,
idx: Index(idx), //nolint:gosec
idx: Index(idx),
params: params,
Embedding: log.MakeEmbedding(log.WithField("ID", params.id)),
}, nil
Expand Down Expand Up @@ -190,7 +190,7 @@ func (m *machine) Params() *Params {

// N returns the number of participants of the channel parameters of this machine.
func (m *machine) N() Index {
return Index(len(m.params.Parts)) //nolint:gosec
return Index(len(m.params.Parts))
}

// Phase returns the current phase.
Expand Down
8 changes: 4 additions & 4 deletions channel/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool {
}

func (ids IDMap) Encode(w stdio.Writer) error {

Check warning on line 77 in channel/params.go

View workflow job for this annotation

GitHub Actions / Vetting

exported: exported method IDMap.Encode should have comment or be unexported (revive)
length := int32(len(ids)) //nolint:gosec
length := int32(len(ids))
if err := perunio.Encode(w, length); err != nil {
return errors.WithMessage(err, "encoding map length")
}
for i, id := range ids {
if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec
if err := perunio.Encode(w, int32(i)); err != nil {
return errors.WithMessage(err, "encoding map index")
}
if err := perunio.Encode(w, id); err != nil {
Expand Down Expand Up @@ -112,14 +112,14 @@ func (ids *IDMap) Decode(r stdio.Reader) error {

func IDKey(ids IDMap) string {
var buff strings.Builder
length := int32(len(ids)) //nolint:gosec
length := int32(len(ids))
err := binary.Write(&buff, binary.BigEndian, length)
if err != nil {
log.Panic("could not encode map length in Key: ", err)
}
sortedKeys, sortedIDs := sortIDMap(ids)
for i, id := range sortedIDs {
if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { //nolint:gosec
if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil {
log.Panicf("could not encode map key: " + err.Error())
}
if err := perunio.Encode(&buff, id); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/test/persistrestorertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) NewChannel(t require.TestingT, p map[wallet.BackendID]wire.Addr
c.ctx,
t,
c.pr,
channel.Index(idx), //nolint:gosec
channel.Index(idx),
peers,
parent,
c.rng)
Expand Down
4 changes: 2 additions & 2 deletions client/channelconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *channelConn) Close() error {
func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error {
var eg errgroup.Group
for i, peer := range c.peers {
if channel.Index(i) == c.idx { //nolint:gosec
if channel.Index(i) == c.idx {
continue // skip own peer
}
c.log.WithField("peer", peer).Debugf("channelConn: publishing message: %v: %+v", msg.Type(), msg)
Expand Down Expand Up @@ -168,5 +168,5 @@ func (r *channelMsgRecv) Next(ctx context.Context) (channel.Index, ChannelMsg, e
if !ok {
return 0, nil, errors.Errorf("unexpected message type: expected ChannelMsg, got %T", env.Msg)
}
return channel.Index(idx), msg, nil //nolint:gosec
return channel.Index(idx), msg, nil
}
6 changes: 3 additions & 3 deletions client/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type (

// Encode encodes the object to the writer.
func (a channelIDsWithLen) Encode(w io.Writer) (err error) {
length := int32(len(a)) //nolint:gosec
length := int32(len(a))
if err := perunio.Encode(w, length); err != nil {
return errors.WithMessage(err, "encoding array length")
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func (a *channelIDsWithLen) Decode(r io.Reader) (err error) {

// Encode encodes the object to the writer.
func (a indexMapsWithLen) Encode(w io.Writer) (err error) {
err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec
err = perunio.Encode(w, sliceLen(len(a)))
if err != nil {
return
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (a *indexMapsWithLen) Decode(r io.Reader) (err error) {

// Encode encodes the object to the writer.
func (a indexMapWithLen) Encode(w io.Writer) (err error) {
err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec
err = perunio.Encode(w, sliceLen(len(a)))
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions client/test/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su
},
}, subChannels...)

timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec
timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond)
for _, ch := range channels {
b.setLatestEvent(
ch.Params.ID(),
Expand Down Expand Up @@ -228,7 +228,7 @@ func (b *MockBackend) Progress(_ context.Context, req channel.ProgressReq) error
b.mu.Lock()
defer b.mu.Unlock()

timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec
timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond)
b.setLatestEvent(
req.Params.ID(),
channel.NewProgressedEvent(
Expand Down Expand Up @@ -559,7 +559,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad

// WaitForFunding waits until all participants have funded the channel.
func (f *assetHolder) WaitForFunding(ctx context.Context, req channel.FundingReq) error {
challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second //nolint:gosec
challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second
fundCtx, cancel := context.WithTimeout(ctx, challengeDuration)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion client/test/mallory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *Mallory) exec(_cfg ExecConfig, ch *paymentChannel) {
r.waitStage()

// Register version 0 AdjudicatorReq
challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second //nolint:gosec
challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second
regCtx, regCancel := context.WithTimeout(context.Background(), r.timeout)
defer regCancel()
r.log.Debug("Registering version 0 state.")
Expand Down
2 changes: 1 addition & 1 deletion client/test/syncmsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ChannelSyncMsgSerializationTest(t *testing.T, serializerTest func(t *testin
for i := 0; i < 4; i++ {
state := test.NewRandomState(rng)
m := &client.ChannelSyncMsg{
Phase: channel.Phase(rng.Intn(channel.LastPhase)), //nolint:gosec
Phase: channel.Phase(rng.Intn(channel.LastPhase)),
CurrentTX: channel.Transaction{
State: state,
Sigs: newRandomSigs(rng, state.NumParts()),
Expand Down
6 changes: 3 additions & 3 deletions client/test/updatemsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func channelUpdateAccSerializationTest(t *testing.T, serializerTest func(t *test
sig := newRandomSig(rng, 0)
m := &client.ChannelUpdateAccMsg{
ChannelID: test.NewRandomChannelID(rng),
Version: uint64(rng.Int63()), //nolint:gosec
Version: uint64(rng.Int63()),
Sig: sig,
}
serializerTest(t, m)
Expand All @@ -112,7 +112,7 @@ func channelUpdateRejSerializationTest(t *testing.T, serializerTest func(t *test
for i := 0; i < 4; i++ {
m := &client.ChannelUpdateRejMsg{
ChannelID: test.NewRandomChannelID(rng),
Version: uint64(rng.Int63()), //nolint:gosec
Version: uint64(rng.Int63()),
Reason: newRandomASCIIString(rng, minLen, maxLenDiff),
}
serializerTest(t, m)
Expand All @@ -125,7 +125,7 @@ func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg {
return &client.ChannelUpdateMsg{
ChannelUpdate: client.ChannelUpdate{
State: state,
ActorIdx: channel.Index(rng.Intn(state.NumParts())), //nolint:gosec
ActorIdx: channel.Index(rng.Intn(state.NumParts())),
},
Sig: sig,
}
Expand Down
4 changes: 2 additions & 2 deletions client/virtual_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, pee
}

for i, sig := range sigs {
err = ch.machine.AddSig(ctx, channel.Index(i), sig) //nolint:gosec
err = ch.machine.AddSig(ctx, channel.Index(i), sig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func (c *Channel) pushVirtualUpdate(ctx context.Context, state *channel.State, s
}

for i, sig := range sigs {
idx := channel.Index(i) //nolint:gosec
idx := channel.Index(i)
if err := m.AddSig(ctx, idx, sig); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/virtual_channel_settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (c *Channel) forceFinalState(ctx context.Context, final channel.SignedState
return err
}
for i, sig := range final.Sigs {
if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil { //nolint:gosec
if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions wire/net/simple/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (a *Address) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer

// Encode the length of the name string and the name itself
nameLen := uint16(len(a.Name)) //nolint:gosec
nameLen := uint16(len(a.Name))
if err := binary.Write(&buf, binary.BigEndian, nameLen); err != nil {
return nil, err
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func (a *Address) Backend() wallet.BackendID {
func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error {
// Encode modulus length and modulus
modulusBytes := key.N.Bytes()
modulusLen := uint16(len(modulusBytes)) //nolint:gosec
modulusLen := uint16(len(modulusBytes))
if err := binary.Write(buf, binary.BigEndian, modulusLen); err != nil {
return err
}
Expand All @@ -119,7 +119,7 @@ func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error {
}

// Encode public exponent
if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil { //nolint:gosec
if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil {
return err
}

Expand Down
18 changes: 9 additions & 9 deletions wire/protobuf/proposalmsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func ToIndexMap(protoIndexMap []uint32) (indexMap []channel.Index, err error) {
if protoIndexMap[i] > math.MaxUint16 {
return nil, fmt.Errorf("%d'th index is invalid", i) //nolint:goerr113 // We do not want to define this as constant error.
}
indexMap[i] = channel.Index(uint16(protoIndexMap[i])) //nolint:gosec
indexMap[i] = channel.Index(uint16(protoIndexMap[i]))
}
return indexMap, nil
}
Expand Down Expand Up @@ -453,8 +453,8 @@ func FromWalletAddr(addr map[wallet.BackendID]wallet.Address) (*Address, error)
var addressMappings []*AddressMapping //nolint:prealloc

for key, address := range addr {
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key))

addressBytes, err := address.MarshalBinary()
if err != nil {
Expand All @@ -477,8 +477,8 @@ func FromWireAddr(addr map[wallet.BackendID]wire.Address) (*Address, error) {
var addressMappings []*AddressMapping //nolint:prealloc

for key, address := range addr {
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key))

addressBytes, err := address.MarshalBinary()
if err != nil {
Expand Down Expand Up @@ -525,8 +525,8 @@ func FromIDs(ids map[wallet.BackendID]channel.ID) (*ID, error) {
var idMappings []*IDMapping //nolint:prealloc

for key, id := range ids {
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec
keyBytes := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(keyBytes, uint32(key))

idBytes := make([]byte, 32) //nolint:gomnd
copy(idBytes, id[:])
Expand Down Expand Up @@ -603,8 +603,8 @@ func FromAllocation(alloc channel.Allocation) (protoAlloc *Allocation, err error
protoAlloc = &Allocation{}
protoAlloc.Backends = make([][]byte, len(alloc.Backends))
for i := range alloc.Backends {
protoAlloc.Backends[i] = make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) //nolint:gosec
protoAlloc.Backends[i] = make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i]))
}
protoAlloc.Assets = make([][]byte, len(alloc.Assets))
for i := range alloc.Assets {
Expand Down
2 changes: 1 addition & 1 deletion wire/protobuf/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func writeEnvelope(w io.Writer, env *Envelope) error {
if err != nil {
return errors.Wrap(err, "marshalling envelope")
}
if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil { //nolint:gosec
if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil {
return errors.Wrap(err, "writing length to wire")
}
_, err = w.Write(data)
Expand Down
2 changes: 1 addition & 1 deletion wire/protobuf/syncmsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func toChannelSyncMsg(protoEnvMsg *Envelope_ChannelSyncMsg) (msg *client.Channel
protoMsg := protoEnvMsg.ChannelSyncMsg

msg = &client.ChannelSyncMsg{}
msg.Phase = channel.Phase(protoMsg.Phase) //nolint:gosec
msg.Phase = channel.Phase(protoMsg.Phase)
msg.CurrentTX.Sigs = make([][]byte, len(protoMsg.CurrentTx.Sigs))
for i := range protoMsg.CurrentTx.Sigs {
msg.CurrentTX.Sigs[i] = make([]byte, len(protoMsg.CurrentTx.Sigs[i]))
Expand Down
2 changes: 1 addition & 1 deletion wire/protobuf/updatemsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func ToChannelUpdate(protoUpdate *ChannelUpdateMsg) (update client.ChannelUpdate
if protoUpdate.ChannelUpdate.ActorIdx > math.MaxUint16 {
return update, errors.New("actor index is invalid")
}
update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx) //nolint:gosec
update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx)
update.Sig = make([]byte, len(protoUpdate.Sig))
copy(update.Sig, protoUpdate.Sig)
update.State, err = ToState(protoUpdate.ChannelUpdate.State)
Expand Down

0 comments on commit 2c079f1

Please sign in to comment.