Skip to content

Commit b7ff0d4

Browse files
authored
Merge pull request #14515 from karalabe/golint-tooooolong
core: fix various golint warnings and errors
2 parents 07aae19 + c98bce7 commit b7ff0d4

File tree

12 files changed

+326
-325
lines changed

12 files changed

+326
-325
lines changed

core/blockchain.go

Lines changed: 238 additions & 237 deletions
Large diffs are not rendered by default.

core/blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package core
1818

1919
import "github.com/ethereum/go-ethereum/common"
2020

21-
// Set of manually tracked bad hashes (usually hard forks)
21+
// BadHashes represent a set of manually tracked bad hashes (usually hard forks)
2222
var BadHashes = map[common.Hash]bool{
2323
common.HexToHash("05bef30ef572270f654746da22639a7a0c97dd97a7050b9e252391996aaeb689"): true,
2424
common.HexToHash("7d05d08cbc596a2e5e4f13b80a743e53e09221b5323c3a61946b20873e58583f"): true,

core/chain_makers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ func (b *BlockGen) Number() *big.Int {
9898
return new(big.Int).Set(b.header.Number)
9999
}
100100

101-
// AddUncheckedReceipts forcefully adds a receipts to the block without a
101+
// AddUncheckedReceipt forcefully adds a receipts to the block without a
102102
// backing transaction.
103103
//
104-
// AddUncheckedReceipts will cause consensus failures when used during real
104+
// AddUncheckedReceipt will cause consensus failures when used during real
105105
// chain processing. This is best used in conjunction with raw block insertion.
106106
func (b *BlockGen) AddUncheckedReceipt(receipt *types.Receipt) {
107107
b.receipts = append(b.receipts, receipt)

core/database_util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
oldBlockReceiptsPrefix = []byte("receipts-block-")
6565
oldBlockHashPrefix = []byte("block-hash-") // [deprecated by the header/block split, remove eventually]
6666

67-
ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general config not found error
67+
ErrChainConfigNotFound = errors.New("ChainConfig not found") // general config not found error
6868

6969
mipmapBloomMu sync.Mutex // protect against race condition when updating mipmap blooms
7070

@@ -546,7 +546,7 @@ func mipmapKey(num, level uint64) []byte {
546546
return append(mipmapPre, append(lkey, key.Bytes()...)...)
547547
}
548548

549-
// WriteMapmapBloom writes each address included in the receipts' logs to the
549+
// WriteMipmapBloom writes each address included in the receipts' logs to the
550550
// MIP bloom bin.
551551
func WriteMipmapBloom(db ethdb.Database, number uint64, receipts types.Receipts) error {
552552
mipmapBloomMu.Lock()
@@ -638,7 +638,7 @@ func WriteChainConfig(db ethdb.Database, hash common.Hash, cfg *params.ChainConf
638638
func GetChainConfig(db ethdb.Database, hash common.Hash) (*params.ChainConfig, error) {
639639
jsonChainConfig, _ := db.Get(append(configPrefix, hash[:]...))
640640
if len(jsonChainConfig) == 0 {
641-
return nil, ChainConfigNotFoundErr
641+
return nil, ErrChainConfigNotFound
642642
}
643643

644644
var config params.ChainConfig

core/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type NewMinedBlockEvent struct{ Block *types.Block }
4141
// RemovedTransactionEvent is posted when a reorg happens
4242
type RemovedTransactionEvent struct{ Txs types.Transactions }
4343

44-
// RemovedLogEvent is posted when a reorg happens
44+
// RemovedLogsEvent is posted when a reorg happens
4545
type RemovedLogsEvent struct{ Logs []*types.Log }
4646

4747
type ChainEvent struct {

core/fees.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ import (
2020
"math/big"
2121
)
2222

23-
var BlockReward *big.Int = big.NewInt(5e+18)
23+
var BlockReward = big.NewInt(5e+18)

core/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
133133
newcfg := genesis.configOrDefault(stored)
134134
storedcfg, err := GetChainConfig(db, stored)
135135
if err != nil {
136-
if err == ChainConfigNotFoundErr {
136+
if err == ErrChainConfigNotFound {
137137
// This case happens if a genesis write was interrupted.
138138
log.Warn("Found genesis block without chain config")
139139
err = WriteChainConfig(db, stored, newcfg)

core/headerchain.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,6 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
201201
// header writes should be protected by the parent chain mutex individually.
202202
type WhCallback func(*types.Header) error
203203

204-
// InsertHeaderChain attempts to insert the given header chain in to the local
205-
// chain, possibly creating a reorg. If an error is returned, it will return the
206-
// index number of the failing header as well an error describing what went wrong.
207-
//
208-
// The verify parameter can be used to fine tune whether nonce verification
209-
// should be done or not. The reason behind the optional check is because some
210-
// of the header retrieval mechanisms already need to verfy nonces, as well as
211-
// because nonces can be verified sparsely, not needing to check each.
212-
213204
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
214205
// Do a sanity check that the provided chain is actually ordered and linked
215206
for i := 1; i < len(chain); i++ {
@@ -257,6 +248,14 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)
257248
return 0, nil
258249
}
259250

251+
// InsertHeaderChain attempts to insert the given header chain in to the local
252+
// chain, possibly creating a reorg. If an error is returned, it will return the
253+
// index number of the failing header as well an error describing what went wrong.
254+
//
255+
// The verify parameter can be used to fine tune whether nonce verification
256+
// should be done or not. The reason behind the optional check is because some
257+
// of the header retrieval mechanisms already need to verfy nonces, as well as
258+
// because nonces can be verified sparsely, not needing to check each.
260259
func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCallback, start time.Time) (int, error) {
261260
// Collect some import statistics to report on
262261
stats := struct{ processed, ignored int }{}

core/helper_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/ethereum/go-ethereum/core/types"
24-
// "github.com/ethereum/go-ethereum/crypto"
25-
2624
"github.com/ethereum/go-ethereum/ethdb"
2725
"github.com/ethereum/go-ethereum/event"
2826
)
@@ -38,24 +36,24 @@ type TestManager struct {
3836
Blocks []*types.Block
3937
}
4038

41-
func (s *TestManager) IsListening() bool {
39+
func (tm *TestManager) IsListening() bool {
4240
return false
4341
}
4442

45-
func (s *TestManager) IsMining() bool {
43+
func (tm *TestManager) IsMining() bool {
4644
return false
4745
}
4846

49-
func (s *TestManager) PeerCount() int {
47+
func (tm *TestManager) PeerCount() int {
5048
return 0
5149
}
5250

53-
func (s *TestManager) Peers() *list.List {
51+
func (tm *TestManager) Peers() *list.List {
5452
return list.New()
5553
}
5654

57-
func (s *TestManager) BlockChain() *BlockChain {
58-
return s.blockChain
55+
func (tm *TestManager) BlockChain() *BlockChain {
56+
return tm.blockChain
5957
}
6058

6159
func (tm *TestManager) TxPool() *TxPool {

core/state_transition.go

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -134,112 +134,113 @@ func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, erro
134134
return ret, gasUsed, err
135135
}
136136

137-
func (self *StateTransition) from() vm.AccountRef {
138-
f := self.msg.From()
139-
if !self.state.Exist(f) {
140-
self.state.CreateAccount(f)
137+
func (st *StateTransition) from() vm.AccountRef {
138+
f := st.msg.From()
139+
if !st.state.Exist(f) {
140+
st.state.CreateAccount(f)
141141
}
142142
return vm.AccountRef(f)
143143
}
144144

145-
func (self *StateTransition) to() vm.AccountRef {
146-
if self.msg == nil {
145+
func (st *StateTransition) to() vm.AccountRef {
146+
if st.msg == nil {
147147
return vm.AccountRef{}
148148
}
149-
to := self.msg.To()
149+
to := st.msg.To()
150150
if to == nil {
151151
return vm.AccountRef{} // contract creation
152152
}
153153

154154
reference := vm.AccountRef(*to)
155-
if !self.state.Exist(*to) {
156-
self.state.CreateAccount(*to)
155+
if !st.state.Exist(*to) {
156+
st.state.CreateAccount(*to)
157157
}
158158
return reference
159159
}
160160

161-
func (self *StateTransition) useGas(amount uint64) error {
162-
if self.gas < amount {
161+
func (st *StateTransition) useGas(amount uint64) error {
162+
if st.gas < amount {
163163
return vm.ErrOutOfGas
164164
}
165-
self.gas -= amount
165+
st.gas -= amount
166166

167167
return nil
168168
}
169169

170-
func (self *StateTransition) buyGas() error {
171-
mgas := self.msg.Gas()
170+
func (st *StateTransition) buyGas() error {
171+
mgas := st.msg.Gas()
172172
if mgas.BitLen() > 64 {
173173
return vm.ErrOutOfGas
174174
}
175175

176-
mgval := new(big.Int).Mul(mgas, self.gasPrice)
176+
mgval := new(big.Int).Mul(mgas, st.gasPrice)
177177

178178
var (
179-
state = self.state
180-
sender = self.from()
179+
state = st.state
180+
sender = st.from()
181181
)
182182
if state.GetBalance(sender.Address()).Cmp(mgval) < 0 {
183183
return errInsufficientBalanceForGas
184184
}
185-
if err := self.gp.SubGas(mgas); err != nil {
185+
if err := st.gp.SubGas(mgas); err != nil {
186186
return err
187187
}
188-
self.gas += mgas.Uint64()
188+
st.gas += mgas.Uint64()
189189

190-
self.initialGas.Set(mgas)
190+
st.initialGas.Set(mgas)
191191
state.SubBalance(sender.Address(), mgval)
192192
return nil
193193
}
194194

195-
func (self *StateTransition) preCheck() error {
196-
msg := self.msg
197-
sender := self.from()
195+
func (st *StateTransition) preCheck() error {
196+
msg := st.msg
197+
sender := st.from()
198198

199199
// Make sure this transaction's nonce is correct
200200
if msg.CheckNonce() {
201-
if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() {
201+
if n := st.state.GetNonce(sender.Address()); n != msg.Nonce() {
202202
return fmt.Errorf("invalid nonce: have %d, expected %d", msg.Nonce(), n)
203203
}
204204
}
205-
return self.buyGas()
205+
return st.buyGas()
206206
}
207207

208208
// TransitionDb will transition the state by applying the current message and returning the result
209209
// including the required gas for the operation as well as the used gas. It returns an error if it
210210
// failed. An error indicates a consensus issue.
211-
func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *big.Int, err error) {
212-
if err = self.preCheck(); err != nil {
211+
func (st *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *big.Int, err error) {
212+
if err = st.preCheck(); err != nil {
213213
return
214214
}
215-
msg := self.msg
216-
sender := self.from() // err checked in preCheck
215+
msg := st.msg
216+
sender := st.from() // err checked in preCheck
217217

218-
homestead := self.evm.ChainConfig().IsHomestead(self.evm.BlockNumber)
218+
homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber)
219219
contractCreation := msg.To() == nil
220+
220221
// Pay intrinsic gas
221222
// TODO convert to uint64
222-
intrinsicGas := IntrinsicGas(self.data, contractCreation, homestead)
223+
intrinsicGas := IntrinsicGas(st.data, contractCreation, homestead)
223224
if intrinsicGas.BitLen() > 64 {
224225
return nil, nil, nil, vm.ErrOutOfGas
225226
}
226-
if err = self.useGas(intrinsicGas.Uint64()); err != nil {
227+
if err = st.useGas(intrinsicGas.Uint64()); err != nil {
227228
return nil, nil, nil, err
228229
}
229230

230231
var (
231-
evm = self.evm
232+
evm = st.evm
232233
// vm errors do not effect consensus and are therefor
233234
// not assigned to err, except for insufficient balance
234235
// error.
235236
vmerr error
236237
)
237238
if contractCreation {
238-
ret, _, self.gas, vmerr = evm.Create(sender, self.data, self.gas, self.value)
239+
ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
239240
} else {
240241
// Increment the nonce for the next transaction
241-
self.state.SetNonce(sender.Address(), self.state.GetNonce(sender.Address())+1)
242-
ret, self.gas, vmerr = evm.Call(sender, self.to().Address(), self.data, self.gas, self.value)
242+
st.state.SetNonce(sender.Address(), st.state.GetNonce(sender.Address())+1)
243+
ret, st.gas, vmerr = evm.Call(sender, st.to().Address(), st.data, st.gas, st.value)
243244
}
244245
if vmerr != nil {
245246
log.Debug("VM returned with error", "err", err)
@@ -250,33 +251,33 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
250251
return nil, nil, nil, vmerr
251252
}
252253
}
253-
requiredGas = new(big.Int).Set(self.gasUsed())
254+
requiredGas = new(big.Int).Set(st.gasUsed())
254255

255-
self.refundGas()
256-
self.state.AddBalance(self.evm.Coinbase, new(big.Int).Mul(self.gasUsed(), self.gasPrice))
256+
st.refundGas()
257+
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(st.gasUsed(), st.gasPrice))
257258

258-
return ret, requiredGas, self.gasUsed(), err
259+
return ret, requiredGas, st.gasUsed(), err
259260
}
260261

261-
func (self *StateTransition) refundGas() {
262+
func (st *StateTransition) refundGas() {
262263
// Return eth for remaining gas to the sender account,
263264
// exchanged at the original rate.
264-
sender := self.from() // err already checked
265-
remaining := new(big.Int).Mul(new(big.Int).SetUint64(self.gas), self.gasPrice)
266-
self.state.AddBalance(sender.Address(), remaining)
265+
sender := st.from() // err already checked
266+
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gas), st.gasPrice)
267+
st.state.AddBalance(sender.Address(), remaining)
267268

268269
// Apply refund counter, capped to half of the used gas.
269-
uhalf := remaining.Div(self.gasUsed(), common.Big2)
270-
refund := math.BigMin(uhalf, self.state.GetRefund())
271-
self.gas += refund.Uint64()
270+
uhalf := remaining.Div(st.gasUsed(), common.Big2)
271+
refund := math.BigMin(uhalf, st.state.GetRefund())
272+
st.gas += refund.Uint64()
272273

273-
self.state.AddBalance(sender.Address(), refund.Mul(refund, self.gasPrice))
274+
st.state.AddBalance(sender.Address(), refund.Mul(refund, st.gasPrice))
274275

275276
// Also return remaining gas to the block gas counter so it is
276277
// available for the next transaction.
277-
self.gp.AddGas(new(big.Int).SetUint64(self.gas))
278+
st.gp.AddGas(new(big.Int).SetUint64(st.gas))
278279
}
279280

280-
func (self *StateTransition) gasUsed() *big.Int {
281-
return new(big.Int).Sub(self.initialGas, new(big.Int).SetUint64(self.gas))
281+
func (st *StateTransition) gasUsed() *big.Int {
282+
return new(big.Int).Sub(st.initialGas, new(big.Int).SetUint64(st.gas))
282283
}

0 commit comments

Comments
 (0)