core: prefer nil slices over zero-length slices

This commit is contained in:
Matthew Halpern 2019-02-14 13:49:02 -08:00
parent ba90a4aaa4
commit 9fac512f94
7 changed files with 9 additions and 9 deletions

View file

@ -673,7 +673,7 @@ func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*type
// GetUnclesInChain retrieves all the uncles from a given block backwards until // GetUnclesInChain retrieves all the uncles from a given block backwards until
// a specific distance is reached. // a specific distance is reached.
func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header { func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header {
uncles := []*types.Header{} var uncles []*types.Header
for i := 0; block != nil && i < length; i++ { for i := 0; block != nil && i < length; i++ {
uncles = append(uncles, block.Uncles()...) uncles = append(uncles, block.Uncles()...)
block = bc.GetBlock(block.ParentHash(), block.NumberU64()-1) block = bc.GetBlock(block.ParentHash(), block.NumberU64()-1)

View file

@ -702,7 +702,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
blocks, receipts := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), gendb, int(height), nil) blocks, receipts := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), gendb, int(height), nil)
// Configure a subchain to roll back // Configure a subchain to roll back
remove := []common.Hash{} var remove []common.Hash
for _, block := range blocks[height/2:] { for _, block := range blocks[height/2:] {
remove = append(remove, block.Hash()) remove = append(remove, block.Hash())
} }

View file

@ -288,7 +288,7 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece
return nil return nil
} }
// Convert the receipts from their storage form to their internal representation // Convert the receipts from their storage form to their internal representation
storageReceipts := []*types.ReceiptForStorage{} var storageReceipts []*types.ReceiptForStorage
if err := rlp.DecodeBytes(data, &storageReceipts); err != nil { if err := rlp.DecodeBytes(data, &storageReceipts); err != nil {
log.Error("Invalid receipt array RLP", "hash", hash, "err", err) log.Error("Invalid receipt array RLP", "hash", hash, "err", err)
return nil return nil

View file

@ -42,7 +42,7 @@ func makeTestState() (Database, common.Hash, []*testAccount) {
state, _ := New(common.Hash{}, db) state, _ := New(common.Hash{}, db)
// Fill it with some arbitrary data // Fill it with some arbitrary data
accounts := []*testAccount{} var accounts []*testAccount
for i := byte(0); i < 96; i++ { for i := byte(0); i < 96; i++ {
obj := state.GetOrNewStateObject(common.BytesToAddress([]byte{i})) obj := state.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
acc := &testAccount{address: common.BytesToAddress([]byte{i})} acc := &testAccount{address: common.BytesToAddress([]byte{i})}
@ -298,7 +298,7 @@ func TestIncompleteStateSync(t *testing.T) {
dstDb := ethdb.NewMemDatabase() dstDb := ethdb.NewMemDatabase()
sched := NewStateSync(srcRoot, dstDb) sched := NewStateSync(srcRoot, dstDb)
added := []common.Hash{} var added []common.Hash
queue := append([]common.Hash{}, sched.Missing(1)...) queue := append([]common.Hash{}, sched.Missing(1)...)
for len(queue) > 0 { for len(queue) > 0 {
// Fetch a batch of state nodes // Fetch a batch of state nodes

View file

@ -1015,7 +1015,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
} }
} }
// Gradually drop transactions from offenders // Gradually drop transactions from offenders
offenders := []common.Address{} var offenders []common.Address
for pending > pool.config.GlobalSlots && !spammers.Empty() { for pending > pool.config.GlobalSlots && !spammers.Empty() {
// Retrieve the next offender if not local address // Retrieve the next offender if not local address
offender, _ := spammers.Pop() offender, _ := spammers.Pop()

View file

@ -571,7 +571,7 @@ func TestTransactionPostponing(t *testing.T) {
pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(50100)) pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(50100))
} }
// Add a batch consecutive pending transactions for validation // Add a batch consecutive pending transactions for validation
txs := []*types.Transaction{} var txs []*types.Transaction
for i, key := range keys { for i, key := range keys {
for j := 0; j < 100; j++ { for j := 0; j < 100; j++ {
@ -980,7 +980,7 @@ func testTransactionLimitingEquivalency(t *testing.T, origin uint64) {
account2, _ := deriveSender(transaction(0, 0, key2)) account2, _ := deriveSender(transaction(0, 0, key2))
pool2.currentState.AddBalance(account2, big.NewInt(1000000)) pool2.currentState.AddBalance(account2, big.NewInt(1000000))
txs := []*types.Transaction{} var txs []*types.Transaction
for i := uint64(0); i < testTxPoolConfig.AccountQueue+5; i++ { for i := uint64(0); i < testTxPoolConfig.AccountQueue+5; i++ {
txs = append(txs, transaction(origin+i, 100000, key2)) txs = append(txs, transaction(origin+i, 100000, key2))
} }

View file

@ -30,7 +30,7 @@ import (
//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go //go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
var ( var (
receiptStatusFailedRLP = []byte{} receiptStatusFailedRLP []byte
receiptStatusSuccessfulRLP = []byte{0x01} receiptStatusSuccessfulRLP = []byte{0x01}
) )