Skip to content

Commit

Permalink
lint: cleaned up for lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sadoci committed Oct 27, 2021
1 parent a43e452 commit 61cf238
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 301 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ geth:
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

dbbench:
dbbench: rocksdb
ifeq ($(USE_ROCKSDB), NO)
$(GORUN) build/ci.go install $(ROCKSDB_TAG) ./cmd/dbbench
else
CGO_CFLAGS=-I$(ROCKSDB_DIR)/include \
CGO_LDFLAGS="-L$(ROCKSDB_DIR) -lrocksdb -lm -lstdc++ $(shell awk '/PLATFORM_LDFLAGS/ {sub("PLATFORM_LDFLAGS=", ""); print} /JEMALLOC=1/ {print "-ljemalloc"}' < $(ROCKSDB_DIR)/make_config.mk)" \
$(GORUN) build/ci.go install $(ROCKSDB_TAG) ./cmd/dbbench
endif

all:
$(GORUN) build/ci.go install
Expand All @@ -84,7 +90,7 @@ ios:
test: all
$(GORUN) build/ci.go test

lint: ## Run linters.
lint: metadium/governance_abi.go ## Run linters.
$(GORUN) build/ci.go lint

clean:
Expand Down Expand Up @@ -253,7 +259,7 @@ metadium/admin_abi.go: metadium/contracts/MetadiumAdmin-template.sol build/bin/s
rm -f /tmp/junk.$$$$;

AWK_CODE_2=' \
BEGIN { print "package metadium"; } \
BEGIN { print "package metadium\n"; } \
/^var Registry_contract/ { \
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
n = "Registry"; \
Expand Down
17 changes: 6 additions & 11 deletions cmd/dbbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"math/big"
"math/rand"
"os"
"os/exec"
Expand All @@ -23,19 +22,15 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
)

var (
big1 = big.NewInt(1)
)

func pack4(s []byte) []byte {
if len(s) % 4 == 0 {
if len(s)%4 == 0 {
return s
} else {
l := (len(s) + 3) / 4 * 4;
l := (len(s) + 3) / 4 * 4
b := make([]byte, l)
copy(b, s)
for i := len(s); i < l; i++ {
b[i] = ' ';
b[i] = ' '
}
return b
}
Expand Down Expand Up @@ -92,7 +87,7 @@ func read(db ethdb.Database, prefix string, start, end, numThreads int, verbose
return err
}
if verbose {
fmt.Printf("%s(<-%s): %d %s\n", hex.EncodeToString(k[:]), string(ks), len(v), hex.EncodeToString(v))
fmt.Printf("%s(<-%s): %d %s\n", hex.EncodeToString(k[:]), ks, len(v), hex.EncodeToString(v))
}
return nil
}
Expand Down Expand Up @@ -136,7 +131,7 @@ func rread(db ethdb.Database, prefix string, count, numThreads int, verbose bool
return err
}
if verbose {
fmt.Printf("%s(<-%s): %d %s\n", hex.EncodeToString(k[:]), string(ks), len(v), hex.EncodeToString(v))
fmt.Printf("%s(<-%s): %d %s\n", hex.EncodeToString(k[:]), ks, len(v), hex.EncodeToString(v))
}
return nil
}
Expand Down Expand Up @@ -286,7 +281,7 @@ func post(dbPath, device, header string, ot time.Time, count int, ss []uint64) {
}

fmt.Printf("%s,%d,%d,%.3f,%d", header, ot.Unix(), dur/1000,
float64(count) * 1000.0 / float64(dur), du)
float64(count)*1000.0/float64(dur), du)
for i := 0; i < len(se); i++ {
v := se[i]
// 1: disk read bytes
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/governancedeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func deployGovernanceContracts(cliCtx *cli.Context) error {
}
fmt.Printf("Initializing environment storage.\n")
envStorageImp.To = envStorage.To
if txs[0], err = metclient.SendContract(ctx, envStorageImp, "initialize", []interface{}(envDefaults)); err != nil {
if txs[0], err = metclient.SendContract(ctx, envStorageImp, "initialize", envDefaults); err != nil {
return err
}

Expand Down
22 changes: 10 additions & 12 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,18 @@ func limitMaxRss(max int64) {
interval := 10 * time.Second
timer := time.NewTimer(interval)
for {
select {
case <-timer.C:
rusage := syscall.Rusage{}
err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
if err != nil {
log.Error("Getrusage() failed:", "reason", err)
} else {
if rusage.Maxrss > max {
log.Info("Calling FreeOSMemory()", "Max", max, "Rusage.Maxrss", rusage.Maxrss)
godebug.FreeOSMemory()
}
<-timer.C
rusage := syscall.Rusage{}
err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
if err != nil {
log.Error("Getrusage() failed:", "reason", err)
} else {
if rusage.Maxrss > max {
log.Info("Calling FreeOSMemory()", "Max", max, "Rusage.Maxrss", rusage.Maxrss)
godebug.FreeOSMemory()
}
timer.Reset(interval)
}
timer.Reset(interval)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/geth/metadiumcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func newAccount(ctx *cli.Context) error {
return err
}

_, err = w.Write([]byte(keyjson))
_, err = w.Write(keyjson)
return err
}

Expand Down Expand Up @@ -427,7 +427,7 @@ func genAdminContract(ctx *cli.Context) error {
scanner := bufio.NewScanner(f)
for scanner.Scan() {
l := scanner.Text()
if strings.Index(l, "// To Be Substituted") < 0 {
if !strings.Contains(l, "// To Be Substituted") {
_, err = fmt.Fprintln(w, l)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
Flags: metricsFlags,
},
{
Name: "METADIUM",
Name: "METADIUM",
Flags: []cli.Flag{
utils.ConsensusMethodFlag,
utils.FixedDifficultyFlag,
Expand Down
2 changes: 0 additions & 2 deletions common/batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ func (b *Batch) Run() {

if !itstimer {
if ln == 0 {
lt = time.Now()
ln = len(data)
timer.Stop()
timer.Reset(b.toInterval)
} else if len(data) >= b.batchCount {
Expand Down
11 changes: 4 additions & 7 deletions consensus/ethash/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block
abort := make(chan struct{})
found := make(chan *types.Block)
go ethash.mine(block, 0, uint64(ethash.rand.Int63()), abort, found)
var result *types.Block
result := <-found
select {
case result = <-found:
select {
case results <- result:
default:
ethash.config.Log.Warn("Sealing result is not read by miner", "sealhash", ethash.SealHash(block.Header()))
}
case results <- result:
default:
ethash.config.Log.Warn("Sealing result is not read by miner", "sealhash", ethash.SealHash(block.Header()))
}
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,14 @@ func DefaultGenesisBlock() *Genesis {
return genesis
}
/*
return &Genesis{
Config: params.MainnetChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: decodePrealloc(mainnetAllocData),
}
return &Genesis{
Config: params.MainnetChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: decodePrealloc(mainnetAllocData),
}
*/
}

Expand Down
18 changes: 3 additions & 15 deletions core/tx_sender_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
package core

import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
Expand Down Expand Up @@ -54,6 +52,8 @@ func (s *SenderResolver) Run() {
j.f(j.param)
}()
}
default:
eor = true
}
if eor {
break
Expand All @@ -74,9 +74,8 @@ func (s *SenderResolver) Post(f func(interface{}), p interface{}) {
// ResolveSenders resolves sender accounts from given transactions
// concurrently using SenderResolver worker pool.
func (pool *TxPool) ResolveSenders(signer types.Signer, txs []*types.Transaction) {
ot := time.Now()
s := pool.senderResolver
var total, by_ecrecover, failed int64 = int64(len(txs)), 0, 0
var by_ecrecover, failed int64

var wg sync.WaitGroup
for _, tx := range txs {
Expand Down Expand Up @@ -106,17 +105,6 @@ func (pool *TxPool) ResolveSenders(signer types.Signer, txs []*types.Transaction
}

wg.Wait()

if false && total > 1 {
dt := float64(time.Now().Sub(ot) / time.Millisecond)
if dt <= 0 {
dt = 1
}
ps := float64(total) * 1000.0 / dt
fmt.Printf("=== %d/%d/%d : took %.3f ms %.3f/sec %d\n", total, total-by_ecrecover, failed, dt, ps, s.tx2addr.Count())
}

return
}

// ResolveSender resolves sender address from a transaction
Expand Down
44 changes: 22 additions & 22 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {

// Header represents a block header in the Ethereum blockchain.
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Fees *big.Int `json:"fees" gencodec:"required"`
Time uint64 `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
Rewards []byte `json:"rewards" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce BlockNonce `json:"nonce"`
MinerNodeId []byte `json:"minerNode"`
MinerNodeSig []byte `json:"minerNodeSig"`
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Fees *big.Int `json:"fees" gencodec:"required"`
Time uint64 `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
Rewards []byte `json:"rewards" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce BlockNonce `json:"nonce"`
MinerNodeId []byte `json:"minerNode"`
MinerNodeSig []byte `json:"minerNodeSig"`

// BaseFee was added by EIP-1559 and is ignored in legacy headers.
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
Expand All @@ -100,7 +100,7 @@ type headerMarshaling struct {
Fees *hexutil.Big
Time hexutil.Uint64
Extra hexutil.Bytes
Rewards hexutil.Bytes
Rewards hexutil.Bytes
MinerNodeId hexutil.Bytes
MinerNodeSig hexutil.Bytes
BaseFee *hexutil.Big
Expand Down Expand Up @@ -315,8 +315,8 @@ func (b *Block) UncleHash() common.Hash { return b.header.UncleHash }
func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
func (b *Block) Rewards() []byte { return common.CopyBytes(b.header.Rewards) }

func (b *Block) MinerNodeId() []byte { return b.header.MinerNodeId }
func (b *Block) MinerNodeSig() []byte { return b.header.MinerNodeSig }
func (b *Block) MinerNodeId() []byte { return b.header.MinerNodeId }
func (b *Block) MinerNodeSig() []byte { return b.header.MinerNodeSig }

func (b *Block) BaseFee() *big.Int {
if b.header.BaseFee == nil {
Expand Down
3 changes: 0 additions & 3 deletions ethdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package ethdb

import (
"io"

//"github.com/ethereum/go-ethereum/ethdb/rocksdb"
)

// KeyValueReader wraps the Has and Get method of a backing data store.
Expand Down Expand Up @@ -143,7 +141,6 @@ type Database interface {

func EnableStats(b bool) {
//rocksdb.EnableStats(b)
return
}

func Stats(device string) (disk_r_count, disk_r_bytes, disk_w_couhnt, disk_w_bytes, r_count, r_bytes, w_count, w_bytes, l_count, d_count uint64) {
Expand Down
2 changes: 1 addition & 1 deletion internal/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (*HandlerT) DbStats(device string, b interface{}) []uint64 {
}

disk_r_count, disk_r_bytes, disk_w_count, disk_w_bytes, r_count, r_bytees, w_count, w_bytes, l_count, d_count := ethdb.Stats(device)
return []uint64{ disk_r_count, disk_r_bytes, disk_w_count, disk_w_bytes, r_count, r_bytees, w_count, w_bytes, l_count, d_count }
return []uint64{disk_r_count, disk_r_bytes, disk_w_count, disk_w_bytes, r_count, r_bytees, w_count, w_bytes, l_count, d_count}
}

func (*HandlerT) VerifyBlockRewards(block *big.Int) interface{} {
Expand Down
8 changes: 4 additions & 4 deletions internal/jsre/offline_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ func (re *JSRE) getTxArgs(jtx string) (*SendTxArgs, error) {
}

fixNum := func(v interface{}) (*big.Int, error) {
switch v.(type) {
switch w := v.(type) {
case json.Number:
ui, err := v.(json.Number).Int64()
ui, err := w.Int64()
if err != nil {
return nil, err
} else {
return big.NewInt(ui), nil
}
case string:
bi, _ := new(big.Int).SetString(v.(string), 0)
bi, _ := new(big.Int).SetString(w, 0)
return bi, nil
default:
fmt.Printf("%T %v\n", v, v)
Expand Down Expand Up @@ -433,7 +433,7 @@ func (re *JSRE) offlineWalletSignTx(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
} else {
_, stx, err := w.SignTx(accounts.DefaultBaseDerivationPath, tx,
big.NewInt(int64(chainID)))
big.NewInt(chainID))
if err != nil {
throwJSException(err)
}
Expand Down
Loading

0 comments on commit 61cf238

Please sign in to comment.