Skip to content

Commit 56aa240

Browse files
committed
Clean up
1 parent 711be70 commit 56aa240

5 files changed

Lines changed: 20 additions & 21 deletions

File tree

‎block_pool.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ out:
323323

324324
self.Reset()
325325

326-
poollogger.Debugf("Punishing peer for supplying bad chain (%v)\n", self.peer.conn.RemoteAddr())
326+
if self.peer != nil && self.peer.conn != nil {
327+
poollogger.Debugf("Punishing peer for supplying bad chain (%v)\n", self.peer.conn.RemoteAddr())
328+
}
329+
327330
// This peer gave us bad hashes and made us fetch a bad chain, therefor he shall be punished.
328331
self.eth.BlacklistPeer(self.peer)
329332
self.peer.StopWithReason(DiscBadPeer)

‎chain/block.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (block *Block) SetUncles(uncles []*Block) {
238238
func (self *Block) SetReceipts(receipts Receipts) {
239239
self.receipts = receipts
240240
self.ReceiptSha = DeriveSha(receipts)
241-
self.LogsBloom = CreateBloom(self)
241+
self.LogsBloom = CreateBloom(receipts)
242242
}
243243

244244
func (self *Block) SetTransactions(txs Transactions) {

‎chain/block_manager.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ done:
159159

160160
txGas.Sub(txGas, st.gas)
161161
cumulative := new(big.Int).Set(totalUsedGas.Add(totalUsedGas, txGas))
162-
bloom := ethutil.LeftPadBytes(LogsBloom(state.Logs()).Bytes(), 64)
163-
receipt := &Receipt{ethutil.CopyBytes(state.Root()), cumulative, bloom, state.Logs()}
162+
receipt := &Receipt{ethutil.CopyBytes(state.Root()), cumulative, nil /*bloom*/, state.Logs()}
163+
receipt.Bloom = CreateBloom(Receipts{receipt})
164164

165165
// Notify all subscribers
166166
go self.eth.EventMux().Post(TxPostEvent{tx})
@@ -217,38 +217,38 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
217217

218218
txSha := DeriveSha(block.transactions)
219219
if bytes.Compare(txSha, block.TxSha) != 0 {
220-
err = fmt.Errorf("Error validating transaction root. Received %x, got %x", block.TxSha, txSha)
220+
err = fmt.Errorf("validating transaction root. received=%x got=%x", block.TxSha, txSha)
221221
return
222222
}
223223

224224
receiptSha := DeriveSha(receipts)
225225
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
226-
err = fmt.Errorf("Error validating receipt root. Received %x, got %x", block.ReceiptSha, receiptSha)
226+
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
227227
return
228228
}
229229

230230
// Block validation
231231
if err = sm.ValidateBlock(block, parent); err != nil {
232-
statelogger.Errorln("Error validating block:", err)
232+
statelogger.Errorln("validating block:", err)
233233
return
234234
}
235235

236236
if err = sm.AccumelateRewards(state, block, parent); err != nil {
237-
statelogger.Errorln("Error accumulating reward", err)
237+
statelogger.Errorln("accumulating reward", err)
238238
return
239239
}
240240

241-
block.receipts = receipts
242-
rbloom := CreateBloom(block)
241+
block.receipts = receipts // although this isn't necessary it be in the future
242+
rbloom := CreateBloom(receipts)
243243
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
244-
err = fmt.Errorf("unable to replicate block's bloom: %x", rbloom)
244+
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
245245
return
246246
}
247247

248248
state.Update()
249249

250250
if !block.State().Cmp(state) {
251-
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().Root(), state.Root())
251+
err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root())
252252
return
253253
}
254254

‎chain/bloom9.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"github.com/ethereum/go-ethereum/state"
99
)
1010

11-
func CreateBloom(block *Block) []byte {
11+
func CreateBloom(receipts Receipts) []byte {
1212
bin := new(big.Int)
13-
for _, receipt := range block.Receipts() {
14-
bin.Or(bin, LogsBloom(receipt.logs))
13+
for _, receipt := range receipts {
14+
bin.Or(bin, logsBloom(receipt.logs))
1515
}
1616

1717
return ethutil.LeftPadBytes(bin.Bytes(), 64)
1818
}
1919

20-
func LogsBloom(logs state.Logs) *big.Int {
20+
func logsBloom(logs state.Logs) *big.Int {
2121
bin := new(big.Int)
2222
for _, log := range logs {
2323
data := [][]byte{log.Address}

‎chain/receipt.go‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ func (self *Receipt) Cmp(other *Receipt) bool {
5151
}
5252

5353
func (self *Receipt) String() string {
54-
return fmt.Sprintf(`Receipt: %x
55-
cumulative gas: %v
56-
bloom: %x
57-
logs: %v
58-
rlp: %x`, self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs, self.RlpEncode())
54+
return fmt.Sprintf("receipt{med=%x cgas=%v bloom=%x logs=%v}", self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs)
5955
}
6056

6157
type Receipts []*Receipt

0 commit comments

Comments
 (0)