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 j, valid := range []bool{true, false} {
var results <-chan error
state, _ := chain.State()
if valid {
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 {
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
select {
@ -104,15 +104,14 @@ func testHeaderConcurrentVerification(t *testing.T, threads int) {
// also an invalid chain (enough if one arbitrary block is invalid).
for i, valid := range []bool{true, false} {
var results <-chan error
if valid {
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{})
state, _ := chain.State()
_, results = chain.engine.VerifyHeaders(chain, state, headers, seals)
_, results = chain.engine.VerifyHeaders(chain, headers, seals)
chain.Stop()
} else {
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeFailer(uint64(len(headers)-1)), vm.Config{})
state, _ := chain.State()
_, results = chain.engine.VerifyHeaders(chain, state, headers, seals)
_, results = chain.engine.VerifyHeaders(chain, headers, seals)
chain.Stop()
}
// Wait for all the verification results
@ -176,8 +175,8 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
// Start the verifications and immediately abort
chain, _ := NewBlockChain(testdb, nil, params.TestChainConfig, ethash.NewFakeDelayer(time.Millisecond), vm.Config{})
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)
// Deplete the results channel
@ -197,4 +196,4 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
if verified > 2*threads {
t.Errorf("verification count too large: have %d, want below %d", verified, 2*threads)
}
}
}

View file

@ -1,4 +1,3 @@
// Copyright 2014 The go-ethereum Authors
// 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/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
)
@ -142,9 +141,10 @@ type BlockChain struct {
validator Validator // block and state validator interface
vmConfig vm.Config
badBlocks *lru.Cache // Bad block cache
IPCEndpoint string
Client *ethclient.Client // Global ipc client instance.
badBlocks *lru.Cache // Bad block cache
IPCEndpoint string
Client *ethclient.Client // Global ipc client instance.
HookWriteRewards func(header *types.Header)
}
// NewBlockChain returns a fully initialised block chain using information
@ -507,12 +507,6 @@ func (bc *BlockChain) insert(block *types.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 updateHeads {
bc.hc.SetCurrentHeader(block.Header())
@ -1020,11 +1014,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if status == CanonStatTy {
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())
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
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})
log.Debug("New ChainHeadEvent from fetcher ", "number", block.NumberU64(), "hash", block.Hash())
}
if bc.HookWriteRewards != nil {
bc.HookWriteRewards(block.Header())
}
return events, coalescedLogs, nil
}
@ -1670,9 +1665,11 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
log.Error(fmt.Sprintf(`
########## BAD BLOCK #########
Chain config: %v
Number: %v
Hash: 0x%x
%v
Error: %v
##############################
`, bc.chainConfig, block.Number(), block.Hash(), receiptString, err))
@ -1836,7 +1833,7 @@ func (bc *BlockChain) UpdateM1() error {
return err
}
addr := common.HexToAddress(common.MasternodeVotingSMC)
validator, err := contractValidator.NewXDCValidator(addr, client)
validator, err := contractValidator.NewKyc(addr, client)
if err != nil {
return err
}
@ -1880,4 +1877,4 @@ func (bc *BlockChain) UpdateM1() error {
log.Info("Masternodes are ready for the next epoch")
}
return nil
}
}

View file

@ -1,4 +1,3 @@
// Copyright 2014 The go-ethereum Authors
// 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 {
for _, block := range chain {
// Try and process the block
st, _ := blockchain.State()
err := blockchain.engine.VerifyHeader(blockchain, st, block.Header(), true)
err := blockchain.engine.VerifyHeader(blockchain, block.Header(), true)
if err == nil {
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 {
for _, header := range chain {
// Try and validate the header
state, _ := blockchain.State()
if err := blockchain.engine.VerifyHeader(blockchain, state, header, false); err != nil {
if err := blockchain.engine.VerifyHeader(blockchain, header, false); err != nil {
return err
}
// Manually insert the header into the database, but don't reorganise (allows subsequent testing)
@ -1333,4 +1330,4 @@ func TestLargeReorgTrieGC(t *testing.T) {
t.Fatalf("competitor %d: competing chain state missing", i)
}
}
}
}