Skip to content

Commit f186b39

Browse files
committed
eth/downloader: add fast and light sync strategies
1 parent c33cc38 commit f186b39

11 files changed

Lines changed: 1437 additions & 809 deletions

File tree

‎core/transaction_util.go‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ func GetBlockReceipts(db ethdb.Database, hash common.Hash) types.Receipts {
140140
if len(data) == 0 {
141141
return nil
142142
}
143-
144-
var receipts types.Receipts
145-
err := rlp.DecodeBytes(data, &receipts)
146-
if err != nil {
147-
glog.V(logger.Core).Infoln("GetReceiptse err", err)
143+
receipts := new(types.Receipts)
144+
if err := rlp.DecodeBytes(data, receipts); err != nil {
145+
glog.V(logger.Error).Infof("invalid receipt array RLP for hash %x: %v", hash, err)
146+
return nil
148147
}
149-
return receipts
148+
return *receipts
150149
}
151150

152151
// PutBlockReceipts stores the block's transactions associated receipts

‎core/types/block.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ type storageblock struct {
172172
}
173173

174174
var (
175-
emptyRootHash = DeriveSha(Transactions{})
176-
emptyUncleHash = CalcUncleHash(nil)
175+
EmptyRootHash = DeriveSha(Transactions{})
176+
EmptyUncleHash = CalcUncleHash(nil)
177177
)
178178

179179
// NewBlock creates a new block. The input data is copied,
@@ -188,15 +188,15 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*
188188

189189
// TODO: panic if len(txs) != len(receipts)
190190
if len(txs) == 0 {
191-
b.header.TxHash = emptyRootHash
191+
b.header.TxHash = EmptyRootHash
192192
} else {
193193
b.header.TxHash = DeriveSha(Transactions(txs))
194194
b.transactions = make(Transactions, len(txs))
195195
copy(b.transactions, txs)
196196
}
197197

198198
if len(receipts) == 0 {
199-
b.header.ReceiptHash = emptyRootHash
199+
b.header.ReceiptHash = EmptyRootHash
200200
} else {
201201
b.header.ReceiptHash = DeriveSha(Receipts(receipts))
202202
b.header.Bloom = CreateBloom(receipts)
@@ -205,7 +205,7 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*
205205
}
206206

207207
if len(uncles) == 0 {
208-
b.header.UncleHash = emptyUncleHash
208+
b.header.UncleHash = EmptyUncleHash
209209
} else {
210210
b.header.UncleHash = CalcUncleHash(uncles)
211211
b.uncles = make([]*Header, len(uncles))

‎eth/downloader/downloader.go‎

Lines changed: 438 additions & 229 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)