Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions itests/clients/node_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ func (c *NodesClients) SynchronizedWavesBalances(
if err != nil {
t.Logf("Errors while requesting balances: %v", err)
}
const retryInterval = 1 * time.Second
timer := time.NewTimer(retryInterval)
defer timer.Stop()
for {
commonHeight := mostCommonHeight(sbs)
toRetry := make([]proto.WavesAddress, 0, len(addresses))
Expand All @@ -302,22 +305,22 @@ func (c *NodesClients) SynchronizedWavesBalances(
}

t.Logf("Heights differ, retrying for %d addresses", len(toRetry))

timer.Reset(retryInterval)
select {
case <-ctx.Done():
case <-time.After(1 * time.Second): // Wait for a second before retrying
t.Logf("No results because of context error: %v", ctx.Err())
return NewSynchronisedBalances()
case <-timer.C: // Wait for a second (retryInterval) before retrying
}
rr, rrErr := c.requestAvailableBalancesForAddresses(ctx, toRetry)
if rrErr != nil {
t.Logf("Errors while requesting balances: %v", rrErr)
}
// Update the map with retry results.
maps.Copy(sbs, rr)
if errors.Is(ctx.Err(), context.Canceled) { // handle context cancellation
t.Logf("Context cancelled, returning empty result")
return NewSynchronisedBalances()
}
if errors.Is(ctx.Err(), context.DeadlineExceeded) { // handle context deadline exceeded
t.Logf("Deadline exceeded, returning empty result")
if errors.Is(ctx.Err(), context.Canceled) || errors.Is(ctx.Err(), context.DeadlineExceeded) {
t.Logf("No results because of context error: %v", ctx.Err())
return NewSynchronisedBalances()
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (a *Node) serveIncomingPeers(ctx context.Context) error {
for {
conn, acErr := l.Accept()
if acErr != nil {
if ctx.Err() != nil { // context has been canceled
return nil
if errors.Is(err, net.ErrClosed) && errors.Is(ctx.Err(), context.Canceled) {
return nil // Listener closed due to context cancellation this is fine.
}
slog.Error("Failed to accept new peer", logging.Error(acErr))
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/peers/score_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
}
// The peer was not found in the larges group, time to change the peer.
// Select the random peer from the group and return it along with a new score value.
i := rand.IntN(len(g.peers)) // #nosec: it's ok to use math/rand/v2 here
i := rand.IntN(len(g.peers)) //nolint: gosec // it's ok to use math/rand/v2 here.

Check failure

Code scanning / gosec

Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand) Error

Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
heap.Push(s.groups, g)
return g.peers[i], g.score
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/proto/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (r *aliasRecipient) String() string {
return r.al.String()
}

func (r *aliasRecipient) MarshalJSON() ([]byte, error) {
func (r aliasRecipient) MarshalJSON() ([]byte, error) {
return r.al.MarshalJSON()
}

Expand Down Expand Up @@ -726,7 +726,7 @@ func (r *wavesAddressRecipient) ToProtobuf() (*g.Recipient, error) {
return &g.Recipient{Recipient: &g.Recipient_PublicKeyHash{PublicKeyHash: r.addr.Body()}}, nil
}

func (r *wavesAddressRecipient) MarshalJSON() ([]byte, error) {
func (r wavesAddressRecipient) MarshalJSON() ([]byte, error) {
return r.addr.MarshalJSON()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/proto/block_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ type txSnapshotJSON struct {
AccountData NonNullableSlice[DataEntriesSnapshot] `json:"accountData"`
}

func (s *txSnapshotJSON) MarshalJSON() ([]byte, error) {
func (s txSnapshotJSON) MarshalJSON() ([]byte, error) {
if s.ApplicationStatus == unknownTransactionStatus {
return nil, errors.New("empty transaction status")
}
type shadowed txSnapshotJSON
return json.Marshal((*shadowed)(s))
return json.Marshal((shadowed)(s))
}

func (s *txSnapshotJSON) UnmarshalJSON(bytes []byte) error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/proto/eth_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
btcECDSA "github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/pkg/errors"

"github.com/wavesplatform/gowaves/pkg/crypto"
)

Expand Down Expand Up @@ -128,7 +129,7 @@ func (es *EthereumSignature) UnmarshalBinary(data []byte) error {
return nil
}

func (es *EthereumSignature) MarshalJSON() ([]byte, error) {
func (es EthereumSignature) MarshalJSON() ([]byte, error) {
sig := es.Bytes()
return HexBytes(sig).MarshalJSON()
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/proto/eth_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mr-tron/base58/base58"
"github.com/pkg/errors"
"github.com/umbracle/fastrlp"

"github.com/wavesplatform/gowaves/pkg/crypto"
)

Expand All @@ -34,7 +35,7 @@ func (esk *EthereumPrivateKey) EthereumPublicKey() *EthereumPublicKey {
type EthereumPublicKey btcec.PublicKey

// MarshalJSON marshal EthereumPublicKey in hex encoding.
func (epk *EthereumPublicKey) MarshalJSON() ([]byte, error) {
func (epk EthereumPublicKey) MarshalJSON() ([]byte, error) {
data := epk.SerializeXYCoordinates()
return HexBytes(data).MarshalJSON()
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,8 @@
return -1
} else if a == b {
return 0
} else {
return 1
}
return 1
}
x := cmp(a[i].major, a[j].major)
y := cmp(a[i].minor, a[j].minor)
Expand All @@ -560,12 +559,10 @@
return true
} else if y == 0 {
return z < 0
} else {
return false
}
} else {
return false
}
return false
}

type TCPAddr net.TCPAddr
Expand Down Expand Up @@ -968,7 +965,7 @@
if err != nil {
return PeerInfo{}, err
}
n := rand.IntN(len(ips)) // #nosec: it's ok to use math/rand/v2 here
n := rand.IntN(len(ips)) //nolint: gosec // it's ok to use math/rand/v2 here.

Check failure

Code scanning / gosec

Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand) Error

Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)
ip := ips[n] // Select random IPv4 from the list
return PeerInfo{
Addr: ip,
Expand Down Expand Up @@ -1391,9 +1388,8 @@
}
if block.Version >= ProtobufBlockVersion {
return &PBBlockMessage{bts}, nil
} else {
return &BlockMessage{bts}, nil
}
return &BlockMessage{bts}, nil
}

// BlockMessage represents Block message
Expand Down
6 changes: 3 additions & 3 deletions pkg/proto/transactions_with_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2708,12 +2708,12 @@ func (tx *CreateAliasWithProofs) UnmarshalJSONWithScheme(data []byte, scheme Sch
return nil
}

func (tx *CreateAliasWithProofs) MarshalJSON() ([]byte, error) {
func (tx CreateAliasWithProofs) MarshalJSON() ([]byte, error) {
type shadowed CreateAliasWithProofs
tmp := struct {
Alias string `json:"alias"`
*shadowed
}{tx.Alias.Alias, (*shadowed)(tx)}
shadowed
}{tx.Alias.Alias, (shadowed)(tx)}
return json.Marshal(tmp)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/proto/transactions_with_sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2247,12 +2247,12 @@ func (tx *CreateAliasWithSig) UnmarshalJSONWithScheme(data []byte, scheme Scheme
return nil
}

func (tx *CreateAliasWithSig) MarshalJSON() ([]byte, error) {
func (tx CreateAliasWithSig) MarshalJSON() ([]byte, error) {
type shadowed CreateAliasWithSig
tmp := struct {
Alias string `json:"alias"`
*shadowed
}{tx.Alias.Alias, (*shadowed)(tx)}
shadowed
}{tx.Alias.Alias, (shadowed)(tx)}
return json.Marshal(tmp)
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/proto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ type ethereumPublicKeyBase58Wrapper struct {
inner *EthereumPublicKey
}

func (w *ethereumPublicKeyBase58Wrapper) MarshalJSON() ([]byte, error) {
func (w ethereumPublicKeyBase58Wrapper) MarshalJSON() ([]byte, error) {
data := w.inner.SerializeXYCoordinates()
return B58Bytes(data).MarshalJSON()
}
Expand Down Expand Up @@ -3570,7 +3570,7 @@ func (a *IntegerArgument) UnmarshalBinary(data []byte) error {
}

// MarshalJSON writes a JSON representation of integer argument.
func (a *IntegerArgument) MarshalJSON() ([]byte, error) {
func (a IntegerArgument) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
T string `json:"type"`
V int `json:"value"`
Expand Down Expand Up @@ -3643,7 +3643,7 @@ func (a *BooleanArgument) UnmarshalBinary(data []byte) error {
}

// MarshalJSON writes the argument to a JSON representation.
func (a *BooleanArgument) MarshalJSON() ([]byte, error) {
func (a BooleanArgument) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
T string `json:"type"`
V bool `json:"value"`
Expand Down Expand Up @@ -3715,7 +3715,7 @@ func (a *BinaryArgument) UnmarshalBinary(data []byte) error {
}

// MarshalJSON converts an argument to its JSON representation. Note that BASE64 is used to represent the binary value.
func (a *BinaryArgument) MarshalJSON() ([]byte, error) {
func (a BinaryArgument) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
T string `json:"type"`
V string `json:"value"`
Expand Down Expand Up @@ -3789,7 +3789,7 @@ func (a *StringArgument) UnmarshalBinary(data []byte) error {
}

// MarshalJSON writes the entry to its JSON representation.
func (a *StringArgument) MarshalJSON() ([]byte, error) {
func (a StringArgument) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
T string `json:"type"`
V string `json:"value"`
Expand Down Expand Up @@ -3864,7 +3864,7 @@ func (a *ListArgument) UnmarshalBinary(data []byte) error {
}

// MarshalJSON writes the entry to its JSON representation.
func (a *ListArgument) MarshalJSON() ([]byte, error) {
func (a ListArgument) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
T string `json:"type"`
V []Argument `json:"value"`
Expand Down
Loading