From 2c079f1daf17e55610a08208a328b4e1498dafd3 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:47:29 +0100 Subject: [PATCH] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- backend/sim/channel/asset.go | 4 ++-- channel/allocation.go | 12 ++++++------ channel/machine.go | 4 ++-- channel/params.go | 8 ++++---- .../persistence/test/persistrestorertest.go | 2 +- client/channelconn.go | 4 ++-- client/serialize.go | 6 +++--- client/test/backend.go | 6 +++--- client/test/mallory.go | 2 +- client/test/syncmsgs.go | 2 +- client/test/updatemsgs.go | 6 +++--- client/virtual_channel.go | 4 ++-- client/virtual_channel_settlement.go | 2 +- wire/net/simple/address.go | 6 +++--- wire/protobuf/proposalmsgs.go | 18 +++++++++--------- wire/protobuf/serializer.go | 2 +- wire/protobuf/syncmsgs.go | 2 +- wire/protobuf/updatemsgs.go | 2 +- 18 files changed, 46 insertions(+), 46 deletions(-) diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 0dd1d495a..a7ae10fce 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -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 } @@ -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 } diff --git a/channel/allocation.go b/channel/allocation.go index 72a31ba76..d61316027 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -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 @@ -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 { @@ -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 { @@ -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) } @@ -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 { diff --git a/channel/machine.go b/channel/machine.go index 6198b34e9..78e742dff 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -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 @@ -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. diff --git a/channel/params.go b/channel/params.go index d8151ae71..6d1ab6df3 100644 --- a/channel/params.go +++ b/channel/params.go @@ -75,12 +75,12 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool { } func (ids IDMap) Encode(w stdio.Writer) error { - 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 { @@ -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 { diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 9fdb9e738..075728830 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -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) diff --git a/client/channelconn.go b/client/channelconn.go index bd31a66b6..3c4c6e761 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -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) @@ -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 } diff --git a/client/serialize.go b/client/serialize.go index e1ea51fec..2449b4533 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -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") } @@ -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 } @@ -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 } diff --git a/client/test/backend.go b/client/test/backend.go index 80f9de7f6..f4fa401cf 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -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(), @@ -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( @@ -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() diff --git a/client/test/mallory.go b/client/test/mallory.go index 36aa38444..ef30ec27d 100644 --- a/client/test/mallory.go +++ b/client/test/mallory.go @@ -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.") diff --git a/client/test/syncmsgs.go b/client/test/syncmsgs.go index fe452c6e3..4d9e87063 100644 --- a/client/test/syncmsgs.go +++ b/client/test/syncmsgs.go @@ -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()), diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 159da7ed4..931b467a5 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -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) @@ -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) @@ -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, } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 0af4d033f..596a6d359 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -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 } @@ -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 } diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 35947f051..532dc28b3 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -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 } } diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 5a177252a..ad7bb67e7 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -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 } @@ -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 } @@ -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 } diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 87a2c34a4..1dc048e25 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -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 } @@ -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 { @@ -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 { @@ -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[:]) @@ -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 { diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index 79afd36fa..1b4fe8140 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -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) diff --git a/wire/protobuf/syncmsgs.go b/wire/protobuf/syncmsgs.go index 1b8ff3516..fb94a5b19 100644 --- a/wire/protobuf/syncmsgs.go +++ b/wire/protobuf/syncmsgs.go @@ -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])) diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index 784cc7871..70dcf33af 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -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)