Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Resolve pending linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Dec 25, 2021
1 parent 68d0e21 commit 3937fbc
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 47 deletions.
4 changes: 1 addition & 3 deletions e2e/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ func TestEthTransfer(t *testing.T) {
Value: testCase.amount,
}

fee := big.NewInt(0)

// Do the transfer
txnHash, err := rpcClient.Eth().SendTransaction(txnObject)
if testCase.shouldSucceed {
Expand Down Expand Up @@ -246,7 +244,7 @@ func TestEthTransfer(t *testing.T) {

expectedSenderBalance := previousSenderBalance
if testCase.shouldSucceed {
fee = new(big.Int).Mul(
fee := new(big.Int).Mul(
big.NewInt(int64(receipt.GasUsed)),
big.NewInt(int64(txnObject.GasPrice)),
)
Expand Down
9 changes: 7 additions & 2 deletions helper/ipc/ipc_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package ipc
Expand All @@ -24,11 +25,15 @@ func Listen(path string) (net.Listener, error) {
if err := os.MkdirAll(filepath.Dir(path), 0751); err != nil {
return nil, err
}
os.Remove(path)
if removeErr := os.Remove(path); removeErr != nil {
return nil, removeErr
}
lis, err := net.Listen("unix", path)
if err != nil {
return nil, err
}
os.Chmod(path, 0600)
if chmodErr := os.Chmod(path, 0600); chmodErr != nil {
return nil, chmodErr
}
return lis, nil
}
6 changes: 3 additions & 3 deletions helper/keccak/keccak.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Keccak struct {
// WriteRlp writes an RLP value
func (k *Keccak) WriteRlp(dst []byte, v *fastrlp.Value) []byte {
k.buf = v.MarshalTo(k.buf[:0])
k.Write(k.buf)
_, _ = k.Write(k.buf)
return k.Sum(dst)
}

Expand All @@ -39,13 +39,13 @@ func (k *Keccak) Reset() {

// Read hashes the content and returns the intermediate buffer.
func (k *Keccak) Read() []byte {
k.hash.Read(k.tmp)
_, _ = k.hash.Read(k.tmp)
return k.tmp
}

// Sum implements the hash interface
func (k *Keccak) Sum(dst []byte) []byte {
k.hash.Read(k.tmp)
_, _ = k.hash.Read(k.tmp)
dst = append(dst, k.tmp[:]...)
return dst
}
Expand Down
2 changes: 1 addition & 1 deletion helper/keccak/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *Pool) Put(k *Keccak) {
// Keccak256 hashes a src with keccak-256
func Keccak256(dst, src []byte) []byte {
h := DefaultKeccakPool.Get()
h.Write(src)
_, _ = h.Write(src)
dst = h.Sum(dst)
DefaultKeccakPool.Put(h)
return dst
Expand Down
5 changes: 1 addition & 4 deletions helper/tests/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ func GetFreePort() (port int, err error) {
var l *net.TCPListener
if l, err = net.ListenTCP("tcp", addr); err == nil {
defer func(l *net.TCPListener) {
err := l.Close()
if err != nil {

}
_ = l.Close()
}(l)
return l.Addr().(*net.TCPAddr).Port, nil
}
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (d *Dispatcher) HandleWs(reqBody []byte, conn wsConn) ([]byte, error) {
if req.Method == "eth_subscribe" {
filterID, err := d.handleSubscribe(req, conn)
if err != nil {
NewRpcResponse(req.ID, "2.0", nil, err).Bytes()
_, _ = NewRpcResponse(req.ID, "2.0", nil, err).Bytes()
}
resp, err := formatFilterResponse(req.ID, filterID)
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions jsonrpc/filter_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,23 @@ func (f *FilterManager) dispatchEvent(evnt *blockchain.Event) error {

// process old chain
for _, i := range evnt.OldChain {
processBlock(i, true)
if processErr := processBlock(i, true); processErr != nil {
f.logger.Error(fmt.Sprintf("Unable to process block, %v", processErr))
}
}
// process new chain
for _, i := range evnt.NewChain {
processBlock(i, false)
if processErr := processBlock(i, false); processErr != nil {
f.logger.Error(fmt.Sprintf("Unable to process block, %v", processErr))
}
}

// flush all the websocket values
for _, f := range f.filters {
if f.isWS() {
f.flush()
for _, filter := range f.filters {
if filter.isWS() {
if flushErr := filter.flush(); flushErr != nil {
f.logger.Error(fmt.Sprintf("Unable to process flush, %v", flushErr))
}
}
}
return nil
Expand Down
12 changes: 9 additions & 3 deletions jsonrpc/filter_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func TestFilterLog(t *testing.T) {

time.Sleep(500 * time.Millisecond)

m.GetFilterChanges(id)
if _, fetchErr := m.GetFilterChanges(id); fetchErr != nil {
t.Fatalf("Unable to get filter changes, %v", fetchErr)
}
}

func TestFilterBlock(t *testing.T) {
Expand Down Expand Up @@ -110,7 +112,9 @@ func TestFilterBlock(t *testing.T) {
// we need to wait for the manager to process the data
time.Sleep(500 * time.Millisecond)

m.GetFilterChanges(id)
if _, fetchErr := m.GetFilterChanges(id); fetchErr != nil {
t.Fatalf("Unable to get filter changes, %v", fetchErr)
}

// emit one more event, it should not return the
// first three hashes
Expand All @@ -126,7 +130,9 @@ func TestFilterBlock(t *testing.T) {

time.Sleep(500 * time.Millisecond)

m.GetFilterChanges(id)
if _, fetchErr := m.GetFilterChanges(id); fetchErr != nil {
t.Fatalf("Unable to get filter changes, %v", fetchErr)
}
}

func TestFilterTimeout(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,16 @@ func (j *JSONRPC) handle(w http.ResponseWriter, req *http.Request) {
return
}
if req.Method == "GET" {
w.Write([]byte("PolygonSDK JSON-RPC"))
_, _ = w.Write([]byte("PolygonSDK JSON-RPC"))
return
}
if req.Method != "POST" {
w.Write([]byte("method " + req.Method + " not allowed"))
_, _ = w.Write([]byte("method " + req.Method + " not allowed"))
return
}
data, err := ioutil.ReadAll(req.Body)
if err != nil {
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
return
}

Expand All @@ -218,9 +218,9 @@ func (j *JSONRPC) handle(w http.ResponseWriter, req *http.Request) {
resp, err := j.dispatcher.Handle(data)

if err != nil {
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
} else {
w.Write(resp)
_, _ = w.Write(resp)
}
j.logger.Debug("handle", "response", string(resp))

Expand Down
4 changes: 3 additions & 1 deletion network/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (g *GrpcStream) Client(stream network.Stream) interface{} {
}

func (g *GrpcStream) Serve() {
go g.grpcServer.Serve(g)
go func() {
_ = g.grpcServer.Serve(g)
}()
}

func (g *GrpcStream) Handler() func(network.Stream) {
Expand Down
10 changes: 8 additions & 2 deletions network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,16 @@ func (s *Server) Start() error {
bootnodes = append(bootnodes, node)
}

s.discovery.setup(bootnodes)
if setupErr := s.discovery.setup(bootnodes); setupErr != nil {
return fmt.Errorf("unable to setup discovery, %v", setupErr)
}
}

go s.runJoinWatcher()
go func() {
if err := s.runJoinWatcher(); err != nil {
s.logger.Error(fmt.Sprintf("Unable to start join watcher service, %v", err))
}
}()

// watch for disconnected peers
s.host.Network().Notify(&network.NotifyBundle{
Expand Down
6 changes: 4 additions & 2 deletions protocol/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ func (s *Syncer) Start() {
// setupPeers adds connected peers as syncer peers
func (s *Syncer) setupPeers() {
for _, p := range s.server.Peers() {
s.AddPeer(p.Info.ID)
if addErr := s.AddPeer(p.Info.ID); addErr != nil {
s.logger.Error(fmt.Sprintf("Error when adding peer [%s], %v", p.Info.ID, addErr))
}
}
}

Expand Down Expand Up @@ -761,4 +763,4 @@ func getHeader(clt proto.V1Client, num *uint64, hash *types.Hash) (*types.Header
return nil, err
}
return header, nil
}
}
4 changes: 2 additions & 2 deletions state/immutable-trie/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (b *KVBatch) Put(k, v []byte) {
}

func (b *KVBatch) Write() {
b.db.Write(b.batch, nil)
_ = b.db.Write(b.batch, nil)
}

func (kv *KVStorage) SetCode(hash types.Hash, code []byte) {
Expand All @@ -65,7 +65,7 @@ func (kv *KVStorage) Batch() Batch {
}

func (kv *KVStorage) Put(k, v []byte) {
kv.db.Put(k, v, nil)
_ = kv.db.Put(k, v, nil)
}

func (kv *KVStorage) Get(k []byte) ([]byte, bool) {
Expand Down
22 changes: 15 additions & 7 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ func NewTxPool(
if err != nil {
return nil, err
}
topic.Subscribe(txPool.handleGossipTxn)
if subscribeErr := topic.Subscribe(txPool.handleGossipTxn); subscribeErr != nil {
return nil, fmt.Errorf("unable to subscribe to gossip topic, %v", subscribeErr)
}

txPool.topic = topic
}

Expand Down Expand Up @@ -577,8 +580,8 @@ func (p *processEventWrapper) addTxn(txn *types.Transaction) {
// promotedTxnCleanup looks through the promoted queue for any invalid transactions
// made by a specific account, and removes them
func (t *TxPool) promotedTxnCleanup(
address types.Address, // The address to filter by
stateNonce uint64, // The valid nonce (reference for pruning)
address types.Address, // The address to filter by
stateNonce uint64, // The valid nonce (reference for pruning)
cleanupCallback func(txn *types.Transaction), // Additional cleanup logic
) {
// Prune out all the now possibly low-nonce transactions in the promoted queue
Expand Down Expand Up @@ -757,7 +760,7 @@ func (t *TxPool) ProcessEvent(evnt *blockchain.Event) {
// validateTx validates that the transaction conforms to specific constraints to be added to the txpool
func (t *TxPool) validateTx(
tx *types.Transaction, // The transaction that should be validated
isLocal bool, // Flag indicating if the transaction is from a local account
isLocal bool, // Flag indicating if the transaction is from a local account
) error {
// Check the transaction size to overcome DOS Attacks
if uint64(len(tx.MarshalRLP())) > txMaxSize {
Expand Down Expand Up @@ -828,7 +831,10 @@ func (t *TxPool) Underpriced(tx *types.Transaction) bool {
}
// tx.GasPrice < lowestTx.Price
underpriced := tx.GasPrice.Cmp(lowestTx.price) < 0
t.remoteTxns.Push(lowestTx.tx)
if pushErr := t.remoteTxns.Push(lowestTx.tx); pushErr != nil {
t.logger.Error(fmt.Sprintf("Unable to push transaction to remoteTxn queue, %v", pushErr))
}

return underpriced
}

Expand All @@ -853,7 +859,9 @@ func (t *TxPool) Discard(slotsToRemove uint64, force bool) ([]*types.Transaction
// Put back if couldn't make required space
if slotsToRemove > 0 && !force {
for _, tx := range dropped {
t.remoteTxns.Push(tx)
if pushErr := t.remoteTxns.Push(tx); pushErr != nil {
t.logger.Error(fmt.Sprintf("Unable to push transaction to remoteTxn queue, %v", pushErr))
}
}
return nil, false
}
Expand Down Expand Up @@ -1277,4 +1285,4 @@ func (a *localAccounts) addAddr(addr types.Address) {
// slotsRequired() calculates the number of slotsRequired for given transaction
func slotsRequired(tx *types.Transaction) uint64 {
return (tx.Size() + txSlotSize - 1) / txSlotSize
}
}
13 changes: 9 additions & 4 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestTxnQueue_Promotion(t *testing.T) {
pool.EnableDev()
pool.AddSigner(&mockSigner{})

pool.addImpl("", &types.Transaction{
_ = pool.addImpl("", &types.Transaction{
From: addr1,
Gas: validGasLimit,
GasPrice: big.NewInt(1),
Expand All @@ -278,7 +278,7 @@ func TestTxnQueue_Promotion(t *testing.T) {

// though txn0 is not being processed yet and the current nonce is 0
// we need to consider that txn0 is on the pendingQueue pool so this one is promoted too
pool.addImpl("", &types.Transaction{
_ = pool.addImpl("", &types.Transaction{
From: addr1,
Nonce: 1,
Gas: validGasLimit,
Expand Down Expand Up @@ -545,7 +545,10 @@ func TestTx_MaxSize(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data := make([]byte, tt.size)
rand.Read(data)
if _, readErr := rand.Read(data); readErr != nil {
t.Fatalf("Unable to read data, %v", readErr)
}

txn := generateTx(tt.address, 0, big.NewInt(0), big.NewInt(1), data)
err := pool.addImpl("", txn)
if tt.succeed {
Expand Down Expand Up @@ -701,7 +704,9 @@ func generateAddTx(arg addTx, signer crypto.TxSigner) *types.Transaction {
}

input := make([]byte, size)
rand.Read(input)
if _, readErr := rand.Read(input); readErr != nil {
return nil
}

tx := &types.Transaction{
Nonce: arg.nonce,
Expand Down
4 changes: 2 additions & 2 deletions types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func CreateBloom(receipts []*Receipt) (b Bloom) {

func (b *Bloom) setEncode(hasher *keccak.Keccak, h []byte) {
hasher.Reset()
hasher.Write(h[:])
_, _ = hasher.Write(h[:])
buf := hasher.Read()

for i := 0; i < 6; i += 2 {
Expand Down Expand Up @@ -131,7 +131,7 @@ func (b *Bloom) IsLogInBloom(log *Log) bool {
// isByteArrPresent checks if the byte array is possibly present in the Bloom filter
func (b *Bloom) isByteArrPresent(hasher *keccak.Keccak, data []byte) bool {
hasher.Reset()
hasher.Write(data[:])
_, _ = hasher.Write(data[:])
buf := hasher.Read()

for i := 0; i < 6; i += 2 {
Expand Down

0 comments on commit 3937fbc

Please sign in to comment.