diff --git a/core/block_processor.go b/core/block_processor.go index 362036445a..f9c89f5e06 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -400,3 +400,15 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check return nil } + +func getBlockReceipts(db common.Database, bhash common.Hash) (receipts types.Receipts, err error) { + var rdata []byte + rdata, err = db.Get(append(receiptsPre, bhash[:]...)) + + if err == nil { + err = rlp.DecodeBytes(rdata, &receipts) + } else { + glog.V(logger.Detail).Infof("getBlockReceipts error %v\n", err) + } + return +} diff --git a/core/block_processor_test.go b/core/block_processor_test.go index 8c38d531fb..99681dabf2 100644 --- a/core/block_processor_test.go +++ b/core/block_processor_test.go @@ -64,9 +64,12 @@ func TestPutReceipt(t *testing.T) { Index: 0, }}) - PutReceipts(db, types.Receipts{receipt}) - receipt = GetReceipt(db, common.Hash{}) - if receipt == nil { - t.Error("expected to get 1 receipt, got none.") + PutReceipts(db, hash, types.Receipts{receipt}) + receipts, err := getBlockReceipts(db, hash) + if err != nil { + t.Error("got err:", err) + } + if len(receipts) != 1 { + t.Error("expected to get 1 receipt, got", len(receipts)) } } diff --git a/core/chain_manager.go b/core/chain_manager.go index 682ddd2d5f..f7cdc4e036 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -634,7 +634,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) { // This puts transactions in a extra db for rpc PutTransactions(self.extraDb, block, block.Transactions()) // store the receipts - PutReceipts(self.extraDb, receipts) + PutReceipts(self.extraDb, block.Hash(), receipts) case SideStatTy: if glog.V(logger.Detail) { glog.Infof("inserted forked block #%d (TD=%v) (%d TXs %d UNCs) (%x...). Took %v\n", block.Number(), block.Difficulty(), len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4], time.Since(bstart)) diff --git a/core/transaction_util.go b/core/transaction_util.go index 7d432848a7..3bd150e80d 100644 --- a/core/transaction_util.go +++ b/core/transaction_util.go @@ -8,9 +8,6 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -var receiptsPre = []byte("receipts-") - -// PutTransactions stores the transactions in the given database func PutTransactions(db common.Database, block *types.Block, txs types.Transactions) { for i, tx := range block.Transactions() { rlpEnc, err := rlp.EncodeToBytes(tx) @@ -37,6 +34,7 @@ func PutTransactions(db common.Database, block *types.Block, txs types.Transacti } } +<<<<<<< HEAD // PutReceipts stores the receipts in the current database func PutReceipts(db common.Database, receipts types.Receipts) error { for _, receipt := range receipts { @@ -82,4 +80,20 @@ func GetReceiptsFromBlock(db common.Database, block *types.Block) types.Receipts } return receipts +======= +func PutReceipts(db common.Database, hash common.Hash, receipts types.Receipts) error { + storageReceipts := make([]*types.ReceiptForStorage, len(receipts)) + for i, receipt := range receipts { + storageReceipts[i] = (*types.ReceiptForStorage)(receipt) + } + + bytes, err := rlp.EncodeToBytes(storageReceipts) + if err != nil { + return err + } + + db.Put(append(receiptsPre, hash[:]...), bytes) + + return nil +>>>>>>> core, miner: miner header validation, transaction & receipt writing } diff --git a/miner/worker.go b/miner/worker.go index 840609721a..0bd316a39e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -240,7 +240,11 @@ func (self *worker) wait() { glog.V(logger.Error).Infoln("Invalid block found during mining") continue } +<<<<<<< HEAD if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil && err != core.BlockFutureErr { +======= + if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil { +>>>>>>> core, miner: miner header validation, transaction & receipt writing glog.V(logger.Error).Infoln("Invalid header on mined block:", err) continue } @@ -255,7 +259,7 @@ func (self *worker) wait() { // This puts transactions in a extra db for rpc core.PutTransactions(self.extraDb, block, block.Transactions()) // store the receipts - core.PutReceipts(self.extraDb, self.current.receipts) + core.PutReceipts(self.extraDb, block.Hash(), self.current.receipts) } // check staleness and display confirmation @@ -271,13 +275,13 @@ func (self *worker) wait() { glog.V(logger.Info).Infof("🔨 Mined %sblock (#%v / %x). %s", stale, block.Number(), block.Hash().Bytes()[:4], confirm) // broadcast before waiting for validation - go func(block *types.Block, logs state.Logs) { + go func() { self.mux.Post(core.NewMinedBlockEvent{block}) - self.mux.Post(core.ChainEvent{block, block.Hash(), logs}) + self.mux.Post(core.ChainEvent{block, block.Hash(), self.current.state.Logs()}) if stat == core.CanonStatTy { self.mux.Post(core.ChainHeadEvent{block}) } - }(block, self.current.state.Logs()) + }() self.commitNewWork() }