From f9f81ffedc493360302c70913d8393fd3ae571ca Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 7 Feb 2017 21:45:19 +0100 Subject: [PATCH] core, api: go format + docs --- core/blockchain.go | 17 ++++++++++------- eth/api.go | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 97b2964553..7a5ab59040 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -121,7 +121,7 @@ func NewBlockChain(chainDb ethdb.Database, config *params.ChainConfig, pow pow.P bodyRLPCache, _ := lru.New(bodyCacheLimit) blockCache, _ := lru.New(blockCacheLimit) futureBlocks, _ := lru.New(maxFutureBlocks) - badBlocks,_ := lru.New(badBlockLimit) + badBlocks, _ := lru.New(badBlockLimit) bc := &BlockChain{ config: config, @@ -1245,22 +1245,25 @@ func (self *BlockChain) update() { } } } -// SendTxArgs represents the arguments to sumbit a new transaction into the transaction pool. + +// BadBlockArgs represents the entries in the list returned when bad blocks are queried. type BadBlockArgs struct { - Hash common.Hash `json:"hash"` - Header *types.Header `json:"header"` + Hash common.Hash `json:"hash"` + Header *types.Header `json:"header"` } + // BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network -func (bc *BlockChain) BadBlocks() ([] BadBlockArgs, error) { +func (bc *BlockChain) BadBlocks() ([]BadBlockArgs, error) { headers := make([]BadBlockArgs, 0, bc.badBlocks.Len()) for _, hash := range bc.badBlocks.Keys() { if hdr, exist := bc.badBlocks.Peek(hash); exist { - headers = append(headers, BadBlockArgs{ hdr.(*types.Header).Hash(), hdr.(*types.Header)}) + headers = append(headers, BadBlockArgs{hdr.(*types.Header).Hash(), hdr.(*types.Header)}) } } return headers, nil } -func (bc *BlockChain) addBadBlock(block *types.Block){ +// Adds a 'bad lock' to the LRU +func (bc *BlockChain) addBadBlock(block *types.Block) { bc.badBlocks.Add(block.Header().Hash(), block.Header()) } diff --git a/eth/api.go b/eth/api.go index 6d855c8e75..f38c0a6b6e 100644 --- a/eth/api.go +++ b/eth/api.go @@ -567,9 +567,8 @@ func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hex return db.Get(hash.Bytes()) } - // GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network // and returns them as a JSON list of block-hashes -func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([] core.BadBlockArgs, error) { +func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]core.BadBlockArgs, error) { return api.eth.BlockChain().BadBlocks() }