diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-22 00:58:57 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-22 00:58:57 +0800 |
commit | 2c1c78a6d9e59de1d4cdeb32737d281814d690f7 (patch) | |
tree | 05471c7e1862733478b08e18bd7ed9419f7f7297 /core/block_processor.go | |
parent | 915fc0e581c042a8d4896880d45e680003809254 (diff) | |
parent | 3ea9868b656077c38af5ea8590761c3218ce558e (diff) | |
download | go-tangerine-v0.9.23.tar go-tangerine-v0.9.23.tar.gz go-tangerine-v0.9.23.tar.bz2 go-tangerine-v0.9.23.tar.lz go-tangerine-v0.9.23.tar.xz go-tangerine-v0.9.23.tar.zst go-tangerine-v0.9.23.zip |
Merge branch 'release/0.9.23'v0.9.23
Diffstat (limited to 'core/block_processor.go')
-rw-r--r-- | core/block_processor.go | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index cae618b39..3f10e5efd 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -24,6 +24,8 @@ const ( BlockChainVersion = 2 ) +var receiptsPre = []byte("receipts-") + type BlockProcessor struct { db common.Database extraDb common.Database @@ -189,7 +191,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st state := state.New(parent.Root(), sm.db) // Block validation - if err = sm.ValidateHeader(block.Header(), parent.Header()); err != nil { + if err = sm.ValidateHeader(block.Header(), parent.Header(), false); err != nil { return } @@ -263,13 +265,27 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st putTx(sm.extraDb, tx, block, uint64(i)) } + receiptsRlp := block.Receipts().RlpEncode() + sm.extraDb.Put(append(receiptsPre, block.Hash().Bytes()...), receiptsRlp) + return state.Logs(), nil } +func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { + var rdata []byte + rdata, err = self.extraDb.Get(append(receiptsPre, bhash[:]...)) + + if err == nil { + err = rlp.DecodeBytes(rdata, &receipts) + } + return + +} + // Validates the current block. Returns an error if the block was invalid, // an uncle or anything that isn't on the current block chain. // Validation validates easy over difficult (dagger takes longer time = difficult) -func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { +func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow bool) error { if big.NewInt(int64(len(block.Extra))).Cmp(params.MaximumExtraDataSize) == 1 { return fmt.Errorf("Block extra data too long (%d)", len(block.Extra)) } @@ -300,9 +316,11 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { return BlockEqualTSErr //ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time) } - // Verify the nonce of the block. Return an error if it's not valid - if !sm.Pow.Verify(types.NewBlockWithHeader(block)) { - return ValidationError("Block's nonce is invalid (= %x)", block.Nonce) + if checkPow { + // Verify the nonce of the block. Return an error if it's not valid + if !sm.Pow.Verify(types.NewBlockWithHeader(block)) { + return ValidationError("Block's nonce is invalid (= %x)", block.Nonce) + } } return nil @@ -351,6 +369,13 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty uncles.Add(hash) if ancestors.Has(hash) { + branch := fmt.Sprintf(" O - %x\n |\n", block.Hash()) + ancestors.Each(func(item interface{}) bool { + branch += fmt.Sprintf(" O - %x\n |\n", hash) + return true + }) + glog.Infoln(branch) + return UncleError("uncle[%d](%x) is ancestor", i, hash[:4]) } @@ -358,7 +383,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4]) } - if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash]); err != nil { + if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash], true); err != nil { return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, hash[:4], err)) } } |