FIxed issue in core

This commit is contained in:
AnilChinchawale 2019-01-17 04:38:29 +05:30
parent d67d59a659
commit ffd60b3685
3 changed files with 27 additions and 34 deletions

View file

@ -48,13 +48,13 @@ func TestHeaderVerification(t *testing.T) {
for i := 0; i < len(blocks); i++ { for i := 0; i < len(blocks); i++ {
for j, valid := range []bool{true, false} { for j, valid := range []bool{true, false} {
var results <-chan error var results <-chan error
state, _ := chain.State()
if valid { if valid {
engine := ethash.NewFaker() engine := ethash.NewFaker()
_, results = engine.VerifyHeaders(chain, state, []*types.Header{headers[i]}, []bool{true}) _, results = engine.VerifyHeaders(chain, []*types.Header{headers[i]}, []bool{true})
} else { } else {
engine := ethash.NewFakeFailer(headers[i].Number.Uint64()) engine := ethash.NewFakeFailer(headers[i].Number.Uint64())
_, results = engine.VerifyHeaders(chain, state, []*types.Header{headers[i]}, []bool{true}) _, results = engine.VerifyHeaders(chain, []*types.Header{headers[i]}, []bool{true})
} }
// Wait for the verification result // Wait for the verification result
select { select {
@ -104,15 +104,14 @@ func testHeaderConcurrentVerification(t *testing.T, threads int) {
// also an invalid chain (enough if one arbitrary block is invalid). // also an invalid chain (enough if one arbitrary block is invalid).
for i, valid := range []bool{true, false} { for i, valid := range []bool{true, false} {
var results <-chan error var results <-chan error
if valid { if valid {
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}) chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{})
state, _ := chain.State() _, results = chain.engine.VerifyHeaders(chain, headers, seals)
_, results = chain.engine.VerifyHeaders(chain, state, headers, seals)
chain.Stop() chain.Stop()
} else { } else {
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeFailer(uint64(len(headers)-1)), vm.Config{}) chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeFailer(uint64(len(headers)-1)), vm.Config{})
state, _ := chain.State() _, results = chain.engine.VerifyHeaders(chain, headers, seals)
_, results = chain.engine.VerifyHeaders(chain, state, headers, seals)
chain.Stop() chain.Stop()
} }
// Wait for all the verification results // Wait for all the verification results
@ -176,8 +175,8 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
// Start the verifications and immediately abort // Start the verifications and immediately abort
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeDelayer(time.Millisecond), vm.Config{}) chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeDelayer(time.Millisecond), vm.Config{})
defer chain.Stop() defer chain.Stop()
state, _ := chain.State()
abort, results := chain.engine.VerifyHeaders(chain, state, headers, seals) abort, results := chain.engine.VerifyHeaders(chain, headers, seals)
close(abort) close(abort)
// Deplete the results channel // Deplete the results channel

View file

@ -1,4 +1,3 @@
// Copyright 2014 The go-ethereum Authors // Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
@ -47,7 +46,7 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"gopkg.in/karalabe/cookiejar.v2/collections/prque" "gopkg.in/karalabe/cookiejar.v2/collections/prque"
) )
@ -142,9 +141,10 @@ type BlockChain struct {
validator Validator // block and state validator interface validator Validator // block and state validator interface
vmConfig vm.Config vmConfig vm.Config
badBlocks *lru.Cache // Bad block cache badBlocks *lru.Cache // Bad block cache
IPCEndpoint string IPCEndpoint string
Client *ethclient.Client // Global ipc client instance. Client *ethclient.Client // Global ipc client instance.
HookWriteRewards func(header *types.Header)
} }
// NewBlockChain returns a fully initialised block chain using information // NewBlockChain returns a fully initialised block chain using information
@ -507,12 +507,6 @@ func (bc *BlockChain) insert(block *types.Block) {
} }
bc.currentBlock.Store(block) bc.currentBlock.Store(block)
// save cache BlockSigners
if bc.chainConfig.XDPoS != nil && !bc.chainConfig.IsTIPEVMSigner(block.Number()) {
engine := bc.Engine().(*XDPoS.XDPoS)
engine.CacheData(block.Header(), block.Transactions(), bc.GetReceiptsByHash(block.Hash()))
}
// If the block is better than our head or is on a different chain, force update heads // If the block is better than our head or is on a different chain, force update heads
if updateHeads { if updateHeads {
bc.hc.SetCurrentHeader(block.Header()) bc.hc.SetCurrentHeader(block.Header())
@ -1020,11 +1014,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if status == CanonStatTy { if status == CanonStatTy {
bc.insert(block) bc.insert(block)
} }
// save cache BlockSigners
if bc.chainConfig.XDPoS != nil && bc.chainConfig.IsTIPEVMSigner(block.Number()) {
engine := bc.Engine().(*XDPoS.XDPoS)
engine.CacheSigner(block.Header(), block.Transactions())
}
bc.futureBlocks.Remove(block.Hash()) bc.futureBlocks.Remove(block.Hash())
return status, nil return status, nil
} }
@ -1233,6 +1222,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
} }
} }
} }
if bc.HookWriteRewards != nil {
bc.HookWriteRewards(block.Header())
}
} }
// Append a single chain head event if we've progressed the chain // Append a single chain head event if we've progressed the chain
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() { if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
@ -1439,6 +1431,9 @@ func (bc *BlockChain) insertBlock(block *types.Block) ([]interface{}, []*types.L
events = append(events, ChainHeadEvent{block}) events = append(events, ChainHeadEvent{block})
log.Debug("New ChainHeadEvent from fetcher ", "number", block.NumberU64(), "hash", block.Hash()) log.Debug("New ChainHeadEvent from fetcher ", "number", block.NumberU64(), "hash", block.Hash())
} }
if bc.HookWriteRewards != nil {
bc.HookWriteRewards(block.Header())
}
return events, coalescedLogs, nil return events, coalescedLogs, nil
} }
@ -1670,9 +1665,11 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
log.Error(fmt.Sprintf(` log.Error(fmt.Sprintf(`
########## BAD BLOCK ######### ########## BAD BLOCK #########
Chain config: %v Chain config: %v
Number: %v Number: %v
Hash: 0x%x Hash: 0x%x
%v %v
Error: %v Error: %v
############################## ##############################
`, bc.chainConfig, block.Number(), block.Hash(), receiptString, err)) `, bc.chainConfig, block.Number(), block.Hash(), receiptString, err))
@ -1836,7 +1833,7 @@ func (bc *BlockChain) UpdateM1() error {
return err return err
} }
addr := common.HexToAddress(common.MasternodeVotingSMC) addr := common.HexToAddress(common.MasternodeVotingSMC)
validator, err := contractValidator.NewXDCValidator(addr, client) validator, err := contractValidator.NewKyc(addr, client)
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,4 +1,3 @@
// Copyright 2014 The go-ethereum Authors // Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
@ -104,8 +103,7 @@ func printChain(bc *BlockChain) {
func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error { func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
for _, block := range chain { for _, block := range chain {
// Try and process the block // Try and process the block
st, _ := blockchain.State() err := blockchain.engine.VerifyHeader(blockchain, block.Header(), true)
err := blockchain.engine.VerifyHeader(blockchain, st, block.Header(), true)
if err == nil { if err == nil {
err = blockchain.validator.ValidateBody(block) err = blockchain.validator.ValidateBody(block)
} }
@ -143,8 +141,7 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
func testHeaderChainImport(chain []*types.Header, blockchain *BlockChain) error { func testHeaderChainImport(chain []*types.Header, blockchain *BlockChain) error {
for _, header := range chain { for _, header := range chain {
// Try and validate the header // Try and validate the header
state, _ := blockchain.State() if err := blockchain.engine.VerifyHeader(blockchain, header, false); err != nil {
if err := blockchain.engine.VerifyHeader(blockchain, state, header, false); err != nil {
return err return err
} }
// Manually insert the header into the database, but don't reorganise (allows subsequent testing) // Manually insert the header into the database, but don't reorganise (allows subsequent testing)