Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng762 committed Nov 29, 2023
1 parent 3b97004 commit b6abdd3
Show file tree
Hide file tree
Showing 38 changed files with 85 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ run:
skip-files:
- core/genesis_alloc.go
- log/term/terminal_notwindows.go
- params/version_history.go
skip-dirs:
- common/math
- common/json
- common/sort
- tests

linters:
disable-all: true
Expand Down
10 changes: 3 additions & 7 deletions cmd/rlpdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/common"
"io"
"os"
"strconv"
"strings"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"github.com/PlatONnetwork/PlatON-Go/rlp"
"github.com/PlatONnetwork/PlatON-Go/x/gov"

"github.com/PlatONnetwork/PlatON-Go/x/restricting"

"github.com/PlatONnetwork/PlatON-Go/x/slashing"

"github.com/PlatONnetwork/PlatON-Go/x/staking"

"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"github.com/PlatONnetwork/PlatON-Go/rlp"
)

var (
Expand Down
7 changes: 0 additions & 7 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,6 @@ func (a Address) Hex() string {
return "0x" + a.HexWithNoPrefix()
}

func (a Address) hex() []byte {
var buf [len(a)*2 + 2]byte
copy(buf[:2], "0x")
hex.Encode(buf[2:], a[:])
return buf[:]
}

func (a Address) HexWithNoPrefix() string {
unchecksummed := hex.EncodeToString(a[:])
sha := sha3.NewLegacyKeccak256()
Expand Down
1 change: 0 additions & 1 deletion common/bech32util/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func ConvertAndEncode(hrp string, data []byte) (string, error) {
return "", errors.Wrap(err, "encoding bech32 failed")
}
return bech32.Encode(hrp, converted)

}

// DecodeAndConvert decodes a bech32 encoded string and converts to base64 encoded bytes
Expand Down
1 change: 0 additions & 1 deletion common/bech32util/bech32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestEncodeAndDecode(t *testing.T) {

sum := sha256.Sum256([]byte("hello world\n"))

bech, err := ConvertAndEncode("shasum", sum[:])
Expand Down
2 changes: 1 addition & 1 deletion common/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func BytesToInt64(b []byte) int64 {
bytesBuffer := bytes.NewBuffer(b)
var tmp int64
binary.Read(bytesBuffer, binary.BigEndian, &tmp)
return int64(tmp)
return tmp
}

func Float32ToBytes(float float32) []byte {
Expand Down
12 changes: 4 additions & 8 deletions common/byteutil/byteutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,31 @@ func TestBytesToString(t *testing.T) {
}

func TestBytesToUint8(t *testing.T) {
var msg uint8
msg = 255
var msg uint8 = 255
data, err := rlp.EncodeToBytes(msg)
assert.Nil(t, err)
dmsg := BytesToUint8(data)
assert.Equal(t, msg, dmsg)
}

func TestBytesToUint16(t *testing.T) {
var msg uint16
msg = 65535
var msg uint16 = 65535
data, err := rlp.EncodeToBytes(msg)
assert.Nil(t, err)
dmsg := BytesToUint16(data)
assert.Equal(t, msg, dmsg)
}

func TestBytesToUint32(t *testing.T) {
var msg uint32
msg = 4294967295
var msg uint32 = 4294967295
data, err := rlp.EncodeToBytes(msg)
assert.Nil(t, err)
dmsg := BytesToUint32(data)
assert.Equal(t, msg, dmsg)
}

func TestBytesToUint64(t *testing.T) {
var msg uint64
msg = 18446744073709551612
var msg uint64 = 18446744073709551612
data, err := rlp.EncodeToBytes(msg)
assert.Nil(t, err)
dmsg := BytesToUint64(data)
Expand Down
61 changes: 0 additions & 61 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package common
import (
"encoding/json"
"fmt"
"net"
"os"
)

Expand Down Expand Up @@ -52,63 +51,3 @@ func findLine(data []byte, offset int64) (line int) {
}
return
}

func LocalIPv4s() []string {
ifaces, err := net.Interfaces()
if err != nil {
fmt.Println(err)
}
ips := []string{}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 {
continue // interface down
}
if iface.Flags&net.FlagLoopback != 0 {
continue // loopback interface
}

if addrs, err := iface.Addrs(); err == nil {
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip == nil || ip.IsLoopback() {
continue
}
ip = ip.To4()
if ip == nil {
continue // not an ipv4 address
}
ips = append(ips, ip.String())
}
}
}
return ips
}

func StringsContains(array []string, val string) (index int) {
index = -1
for i := 0; i < len(array); i++ {
if array[i] == val {
index = i
return
}
}
return
}

func AnyContains(array []string, vals []string) bool {

for i := 0; i < len(array); i++ {
for j := 0; j < len(vals); j++ {
if array[i] == vals[j] {
return true
}
}
}
return false
}
10 changes: 5 additions & 5 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (cbft *Cbft) Start(chain consensus.ChainReader, blockCacheWriter consensus.

if err != nil {
cbft.log.Error("It's not genesis", "err", err)
return errors.Wrap(err, fmt.Sprintf("start cbft failed"))
return errors.Wrap(err, "start cbft failed")
}
}

Expand Down Expand Up @@ -507,9 +507,9 @@ func (cbft *Cbft) receiveLoop() {
cbft.network.MarkBlacklist(msg.PeerID)
cbft.network.RemovePeer(msg.PeerID)
}
} else {
//cbft.log.Trace("The message has been processed, discard it", "msgHash", msg.Msg.MsgHash(), "peerID", msg.PeerID)
}
} /* else {
cbft.log.Trace("The message has been processed, discard it", "msgHash", msg.Msg.MsgHash(), "peerID", msg.PeerID)
}*/
cbft.forgetMessage(msg.PeerID)
}

Expand Down Expand Up @@ -1271,7 +1271,7 @@ func (cbft *Cbft) OnShouldSeal(result chan error) {

rtt := cbft.avgRTT()
if cbft.state.Deadline().Sub(time.Now()) <= rtt {
cbft.log.Debug("Not enough time to propagated block, stopped sealing", "deadline", cbft.state.Deadline(), "interval", cbft.state.Deadline().Sub(time.Now()), "rtt", rtt)
cbft.log.Debug("Not enough time to propagated block, stopped sealing", "deadline", cbft.state.Deadline(), "interval", time.Until(cbft.state.Deadline()), "rtt", rtt)
result <- errors.New("not enough time to propagated block, stopped sealing")
return
}
Expand Down
19 changes: 10 additions & 9 deletions consensus/cbft/types/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package types

import (
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/PlatONnetwork/PlatON-Go/common"
)

func TestSyncCache(t *testing.T) {
Expand Down Expand Up @@ -101,11 +102,11 @@ func TestCSMsgPool(t *testing.T) {
}

for i := uint32(0); i < 10; i++ {
assert.NotNil(t, pool.GetPrepareBlock(1, 1, uint32(i)))
assert.NotNil(t, pool.GetPrepareBlock(1, 1, i))
}

for i := uint32(10); i < 11; i++ {
assert.Nil(t, pool.GetPrepareBlock(1, 1, uint32(i)))
assert.Nil(t, pool.GetPrepareBlock(1, 1, i))
}

for i := uint32(0); i < 10; i++ {
Expand All @@ -117,11 +118,11 @@ func TestCSMsgPool(t *testing.T) {
}

for i := uint32(0); i < 10; i++ {
assert.NotNil(t, pool.GetPrepareQC(1, 1, uint32(i)))
assert.NotNil(t, pool.GetPrepareQC(1, 1, i))
}

for i := uint32(10); i < 11; i++ {
assert.Nil(t, pool.GetPrepareQC(1, 1, uint32(i)))
assert.Nil(t, pool.GetPrepareQC(1, 1, i))
}

//re-add
Expand All @@ -130,15 +131,15 @@ func TestCSMsgPool(t *testing.T) {
}

for i := uint32(0); i < 10; i++ {
assert.NotNil(t, pool.GetPrepareBlock(1, 1, uint32(i)))
assert.NotNil(t, pool.GetPrepareBlock(1, 1, i))
}

for i := uint32(0); i < 10; i++ {
pool.AddPrepareQC(1, 1, i, defaultMsg)
}

for i := uint32(0); i < 10; i++ {
assert.NotNil(t, pool.GetPrepareQC(1, 1, uint32(i)))
assert.NotNil(t, pool.GetPrepareQC(1, 1, i))
}

for i := uint32(0); i < 10; i++ {
Expand Down
2 changes: 1 addition & 1 deletion consensus/cbft/wal_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (b *baseBridge) UpdateChainState(qcState, lockState, commitState *protocols
return
}
if !chainState.ValidChainState() {
panic(fmt.Sprintf("invalid chain state from wal"))
panic("invalid chain state from wal")
}
walCommitNumber := chainState.Commit.QuorumCert.BlockNumber
commitNumber := commitState.QuorumCert.BlockNumber
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"sync/atomic"
"time"

lru "github.com/hashicorp/golang-lru"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/mclock"
"github.com/PlatONnetwork/PlatON-Go/common/prque"
Expand All @@ -43,7 +45,6 @@ import (
"github.com/PlatONnetwork/PlatON-Go/metrics"
"github.com/PlatONnetwork/PlatON-Go/params"
"github.com/PlatONnetwork/PlatON-Go/trie"
lru "github.com/hashicorp/golang-lru"
)

var (
Expand Down Expand Up @@ -1662,7 +1663,6 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
l := *log
if removed {
l.Removed = true
} else {
}
logs = append(logs, &l)
}
Expand Down
1 change: 0 additions & 1 deletion core/dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

func TestDag(t *testing.T) {

dag := NewDag(10)
dag.AddEdge(0, 1)
dag.AddEdge(0, 2)
Expand Down
2 changes: 1 addition & 1 deletion core/snapshotdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestRecover(t *testing.T) {
return
}
if !bytes.Equal(v, value.value) {
t.Error("should be equal", v, []byte(value.value))
t.Error("should be equal", v, value.value)
return
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/types/bloom9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package types

import (
"fmt"
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/crypto"
"math/big"
"testing"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/crypto"
)

func TestBloom(t *testing.T) {
Expand Down Expand Up @@ -91,7 +92,6 @@ func BenchmarkBloom9Lookup(b *testing.B) {
}

func BenchmarkCreateBloom(b *testing.B) {

var txs = Transactions{
NewContractCreation(1, big.NewInt(1), 1, big.NewInt(1), nil),
NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil),
Expand Down
2 changes: 1 addition & 1 deletion core/types/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package types

import (
json2 "github.com/PlatONnetwork/PlatON-Go/common/json"
"io"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
json2 "github.com/PlatONnetwork/PlatON-Go/common/json"
"github.com/PlatONnetwork/PlatON-Go/rlp"
)

Expand Down
2 changes: 1 addition & 1 deletion core/types/transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package types
import (
"encoding/json"
"errors"
json2 "github.com/PlatONnetwork/PlatON-Go/common/json"
"math/big"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
json2 "github.com/PlatONnetwork/PlatON-Go/common/json"
)

// txJSON is the JSON representation of transactions.
Expand Down
Loading

0 comments on commit b6abdd3

Please sign in to comment.