Skip to content

Commit

Permalink
fix issue according to the analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
bufrr authored and yilunzhang committed Jan 30, 2023
1 parent 17da8fa commit ebbae35
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 153 deletions.
2 changes: 1 addition & 1 deletion api/httpjson/RPCserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewServer(localNode node.ILocalNode, wallet *vault.Wallet) *RPCServer {
}
}

// Handle is the funciton that should be called in order to answer an rpc call
// Handle is the function that should be called in order to answer an rpc call
// should be registered like "http.HandleFunc("/", httpjsonrpc.Handle)"
func (s *RPCServer) Handle(w http.ResponseWriter, r *http.Request) {
host, _, err := net.SplitHostPort(r.RemoteAddr)
Expand Down
66 changes: 0 additions & 66 deletions api/httpjson/auth.go

This file was deleted.

10 changes: 5 additions & 5 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (b *Block) FromTrimmedData(r io.Reader) error {
if err != nil {
return err
}
transaction := new(transaction.Transaction)
transaction.SetHash(txhash)
b.Transactions = append(b.Transactions, transaction)
tx := new(transaction.Transaction)
tx.SetHash(txhash)
b.Transactions = append(b.Transactions, tx)
tharray = append(tharray, txhash)
}

root, err := crypto.ComputeRoot(tharray)
if err != nil {
return fmt.Errorf("Block Deserialize merkleTree compute failed: %v", err)
return fmt.Errorf("block Deserialize merkleTree compute failed: %v", err)
}
b.Header.UnsignedHeader.TransactionsRoot = root.ToArray()

Expand Down Expand Up @@ -225,7 +225,7 @@ func GenesisBlockInit() (*Block, error) {

func (b *Block) RebuildMerkleRoot() error {
txs := b.Transactions
transactionHashes := []common.Uint256{}
var transactionHashes []common.Uint256
for _, tx := range txs {
transactionHashes = append(transactionHashes, tx.Hash())
}
Expand Down
6 changes: 3 additions & 3 deletions block/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (h *Header) Unmarshal(buf []byte) error {
return proto.Unmarshal(buf, h.Header)
}

//Serialize the blockheader data without program
// Serialize the blockheader data without program
func (h *Header) SerializeUnsigned(w io.Writer) error {
err := serialization.WriteUint32(w, h.UnsignedHeader.Version)
if err != nil {
Expand Down Expand Up @@ -145,7 +145,7 @@ func (h *Header) GetSigner() ([]byte, []byte, error) {
}

func (h *Header) GetProgramHashes() ([]common.Uint160, error) {
programHashes := []common.Uint160{}
var programHashes []common.Uint160

programHash, err := program.CreateProgramHash(h.UnsignedHeader.SignerPk)
if err != nil {
Expand All @@ -169,7 +169,7 @@ func (h *Header) Hash() common.Uint256 {
return *h.hash
}
d := signature.GetHashData(h)
temp := sha256.Sum256([]byte(d))
temp := sha256.Sum256(d)
f := sha256.Sum256(temp[:])
hash := common.Uint256(f)
h.hash = &hash
Expand Down
2 changes: 1 addition & 1 deletion chain/blockvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TransactionCheck(ctx context.Context, block *block.Block, fastSync bool) er
func GetNextBlockSigner(height uint32, timestamp int64) ([]byte, []byte, pb.WinnerType, error) {
currentHeight := DefaultLedger.Store.GetHeight()
if height > currentHeight {
return nil, nil, 0, fmt.Errorf("Height %d is higher than current height %d", height, currentHeight)
return nil, nil, 0, fmt.Errorf("height %d is higher than current height %d", height, currentHeight)
}

headerHash := DefaultLedger.Store.GetHeaderHashByHeight(height)
Expand Down
2 changes: 1 addition & 1 deletion chain/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type LevelDBConfig struct {
}

const (
// used to compute the size of bloom filter bits array, too small will lead to
// BITSPERKEY used to compute the size of bloom filter bits array, too small will lead to
// high false positive rate.
BITSPERKEY = 10
DBConfigSuffix = ".config"
Expand Down
2 changes: 1 addition & 1 deletion chain/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (l *Ledger) IsDoubleSpend(Tx *transaction.Transaction) bool {
// get the default ledger
func GetDefaultLedger() (*Ledger, error) {
if DefaultLedger == nil {
return nil, errors.New("[Ledger] GetDefaultLedger failed, DefaultLedger not Exist.")
return nil, errors.New("[Ledger] GetDefaultLedger failed, DefaultLedger not Exist")
}
return DefaultLedger, nil
}
Expand Down
6 changes: 3 additions & 3 deletions chain/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ func (bm *BuiltinMining) BuildBlock(ctx context.Context, height uint32, chordID
},
}

block := &block.Block{
b := &block.Block{
Header: header,
Transactions: txnList,
}

curStateHash, err := DefaultLedger.Store.GenerateStateRoot(ctx, block, true, false)
curStateHash, err := DefaultLedger.Store.GenerateStateRoot(ctx, b, true, false)
if err != nil {
return nil, err
}

header.UnsignedHeader.StateRoot = curStateHash.ToArray()

return block, nil
return b, nil
}

func (bm *BuiltinMining) SignBlock(b *block.Block, timestamp int64) error {
Expand Down
4 changes: 2 additions & 2 deletions chain/pool/txlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
)

var (
ErrNonceSortedTxsEmpty = errors.New("Empty NonceSortedTxs")
ErrNonceSortedTxsEmpty = errors.New("empty NonceSortedTxs")
ErrNonceOutofRange = errors.New("nonce is not in range")
)

// NonceSortedTxs store the txns that can be add into blockchain.
// NonceSortedTxs store the txns that can be added into blockchain.
// The txns are sorted by nonce in Increasing order.
type NonceSortedTxs struct {
mu sync.RWMutex
Expand Down
2 changes: 1 addition & 1 deletion chain/pool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (tp *TxnPool) processTx(txn *transaction.Transaction) error {

switch txn.UnsignedTx.Payload.Type {
case pb.PayloadType_COINBASE_TYPE:
return fmt.Errorf("Invalid txn type %v", txn.UnsignedTx.Payload.Type)
return fmt.Errorf("invalid txn type %v", txn.UnsignedTx.Payload.Type)
case pb.PayloadType_SIG_CHAIN_TXN_TYPE:
// sigchain txn should not be added to txn pool
return nil
Expand Down
2 changes: 1 addition & 1 deletion chain/pool/txwithtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// sync txn
const MaxSyncTxnInterval = 16000 // in milli seconds
const MaxSyncTxnInterval = 16000 // in milliseconds

type txnWithTime struct { // abbreviation is twt: txn with time
arriveTime int64
Expand Down
2 changes: 1 addition & 1 deletion chain/store/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (sdb *StateDB) SetAsset(assetID common.Uint256, name string, symbol string,

func (sdb *StateDB) setAsset(assetID common.Uint256, asset *Asset) error {
if asset, err := sdb.getAsset(assetID); err == nil && asset != nil {
return fmt.Errorf("asset %v has already exist.", assetID.ToHexString())
return fmt.Errorf("asset %v has already exist", assetID.ToHexString())
}

sdb.assets.Store(assetID, asset)
Expand Down
4 changes: 2 additions & 2 deletions chain/store/nanopay.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func (np *nanoPay) Serialize(w io.Writer) error {
func (np *nanoPay) Deserialize(r io.Reader) error {
err := np.balance.Deserialize(r)
if err != nil {
return fmt.Errorf("Deserialize nanoPay error: %v", err)
return fmt.Errorf("deserialize nanoPay error: %v", err)
}

np.expiresAt, err = serialization.ReadUint32(r)
if err != nil {
return fmt.Errorf("Deserialize nanoPay error: %v", err)
return fmt.Errorf("deserialize nanoPay error: %v", err)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions chain/trie/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (n hashNode) Serialize(w io.Writer) error {
if err := serialization.WriteVarUint(w, uint64(TagHashNode)); err != nil {
return err
}
if err := serialization.WriteVarBytes(w, []byte(n)); err != nil {
if err := serialization.WriteVarBytes(w, n); err != nil {
return err
}

Expand All @@ -169,7 +169,7 @@ func (n valueNode) Serialize(w io.Writer) error {
return err
}

if err := serialization.WriteVarBytes(w, []byte(n)); err != nil {
if err := serialization.WriteVarBytes(w, n); err != nil {
return err
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func Deserialize(hash []byte, r io.Reader, needFlags bool) (node, error) {
return nil, err
}
if needFlags {
s.flags.hash = hashNode(hash)
s.flags.hash = hash
s.flags.dirty = false
}

Expand All @@ -235,7 +235,7 @@ func Deserialize(hash []byte, r io.Reader, needFlags bool) (node, error) {
f.Children[i] = n
}
if needFlags {
f.flags.hash = hashNode(hash)
f.flags.hash = hash
f.flags.dirty = false
}

Expand Down
4 changes: 2 additions & 2 deletions chain/trie/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ func (ref *RefCounts) prune(n node, inMemory bool) error {

return nil
case hashNode:
hs, _ := common.Uint256ParseFromBytes([]byte(n))
hs, _ := common.Uint256ParseFromBytes(n)
count, ok := ref.counts[hs]
if !inMemory {
if !ok {
v, err := ref.trie.db.Get(db.TrieRefCountKey([]byte(n)))
v, err := ref.trie.db.Get(db.TrieRefCountKey(n))
if err == nil {
count = binary.LittleEndian.Uint32(v)
ref.counts[hs] = count
Expand Down
4 changes: 2 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func BytesToInt16(b []byte) int16 {
bytesBuffer := bytes.NewBuffer(b)
var tmp int16
binary.Read(bytesBuffer, binary.BigEndian, &tmp)
return int16(tmp)
return tmp
}

func BytesToInt(b []byte) []int {
Expand Down Expand Up @@ -74,7 +74,7 @@ func GetUint16Array(source []byte) ([]uint16, error) {
}

if len(source)%2 != 0 {
return nil, errors.New("[Common] , GetUint16Array err, length of source is odd.")
return nil, errors.New("[Common] , GetUint16Array err, length of source is odd")
}

dst := make([]uint16, len(source)/2)
Expand Down
4 changes: 2 additions & 2 deletions common/uint160.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (u *Uint160) Serialize(w io.Writer) (int, error) {
b_buf := bytes.NewBuffer([]byte{})
binary.Write(b_buf, binary.LittleEndian, u)

len, err := w.Write(b_buf.Bytes())
length, err := w.Write(b_buf.Bytes())

if err != nil {
return 0, err
}

return len, nil
return length, nil
}

func (f *Uint160) Deserialize(r io.Reader) error {
Expand Down
4 changes: 2 additions & 2 deletions common/uint256.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func (u *Uint256) Serialize(w io.Writer) (int, error) {
b_buf := bytes.NewBuffer([]byte{})
binary.Write(b_buf, binary.LittleEndian, u)

len, err := w.Write(b_buf.Bytes())
length, err := w.Write(b_buf.Bytes())

if err != nil {
return 0, err
}

return len, nil
return length, nil
}

func (u *Uint256) Deserialize(r io.Reader) error {
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (consensus *Consensus) prefillNeighborVotes(elc *election.Election, height
if rn.GetHeight() < height && height < rn.GetMinVerifiableHeight() {
continue
}
// Neighbor's consensus state is not up to date
// Neighbor's consensus state is not up-to-date
if time.Since(rn.GetLastUpdateTime()) > getConsensusStateInterval*2 {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (consensus *Consensus) getBlockProposal(blockHash common.Uint256) (*block.B
return nil, fmt.Errorf("block %s not found in local cache", blockHash.ToHexString())
}

block, ok := value.(*block.Block)
b, ok := value.(*block.Block)
if !ok {
return nil, fmt.Errorf("convert block %s from proposal cache error", blockHash.ToHexString())
}

return block, nil
return b, nil
}

func (consensus *Consensus) canVerifyHeight(height uint32) bool {
Expand Down
8 changes: 4 additions & 4 deletions consensus/proposing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (consensus *Consensus) startProposing() {

ctx, cancel = context.WithTimeout(context.Background(), proposingTimeout)

block, err := consensus.proposeBlock(ctx, expectedHeight)
b, err := consensus.proposeBlock(ctx, expectedHeight)
if err != nil {
log.Errorf("Propose block %d at %v error: %v", expectedHeight, timestamp, err)
break
Expand All @@ -43,21 +43,21 @@ func (consensus *Consensus) startProposing() {
log.Errorf("I'm no longer the block proposer at height %d at %v", expectedHeight, timestamp)
break
}
err = consensus.mining.SignBlock(block, timestamp)
err = consensus.mining.SignBlock(b, timestamp)
if err != nil {
log.Errorf("Sign block with timestamp %v error: %v", timestamp, err)
break
}

blockHash := block.Hash()
blockHash := b.Hash()
log.Infof("Propose block %s at height %d", blockHash.ToHexString(), expectedHeight)

consensus.localNode.IncrementProposalSubmitted()

// Prevent neighbor from receiving proposal before last consensus stops
time.Sleep(proposalPropagationDelay)

err = consensus.receiveProposal(block)
err = consensus.receiveProposal(b)
if err != nil {
log.Error(err)
break
Expand Down
Loading

0 comments on commit ebbae35

Please sign in to comment.