aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-11-21 13:37:16 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commit9d8b455d62d851d265a8383a5d34e9c594ff89c9 (patch)
treea1cde73a7a77db35f12d2a4d29b8da098f4165f3
parent708606074cba33a91026b6378456bd6311749369 (diff)
downloadgo-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar.gz
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar.bz2
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar.lz
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar.xz
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.tar.zst
go-tangerine-9d8b455d62d851d265a8383a5d34e9c594ff89c9.zip
core, dex, dex/downloader: restore insertChain to upstream version
Also rename InsertChain2, insertChain2, InsertHeaderChain2, ValidateHeaderChain2
-rw-r--r--core/blockchain.go30
-rw-r--r--core/headerchain.go8
-rw-r--r--dex/downloader/downloader.go12
-rw-r--r--dex/handler.go2
4 files changed, 25 insertions, 27 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 293bb88f4..d9401731c 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1013,9 +1013,6 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
bytes += batch.ValueSize()
batch.Reset()
}
- if _, ok := bc.GetRoundHeight(block.Round()); !ok {
- bc.storeRoundHeight(block.Round(), block.NumberU64())
- }
}
if batch.ValueSize() > 0 {
bytes += batch.ValueSize()
@@ -1391,7 +1388,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
"root", block.Root())
events = append(events, ChainSideEvent{block})
- panic("fork found")
}
blockInsertTimer.UpdateSince(start)
stats.processed++
@@ -1536,22 +1532,22 @@ func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (i
return 0, nil, nil, nil
}
-// InsertChain2 attempts to insert the given batch of blocks in to the canonical
+// InsertDexonChain attempts to insert the given batch of blocks in to the canonical
// chain or, otherwise, create a fork. If an error is returned it will return
// the index number of the failing block as well an error describing what went
// wrong.
//
// After insertion is done, all accumulated events will be fired.
-func (bc *BlockChain) InsertChain2(chain types.Blocks) (int, error) {
- n, events, logs, err := bc.insertChain2(chain)
+func (bc *BlockChain) InsertDexonChain(chain types.Blocks) (int, error) {
+ n, events, logs, err := bc.insertDexonChain(chain)
bc.PostChainEvents(events, logs)
return n, err
}
-// insertChain2 will execute the actual chain insertion and event aggregation. The
+// insertDexoonChain will execute the actual chain insertion and event aggregation. The
// only reason this method exists as a separate one is to make locking cleaner
// with deferred statements.
-func (bc *BlockChain) insertChain2(chain types.Blocks) (int, []interface{}, []*types.Log, error) {
+func (bc *BlockChain) insertDexonChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) {
// Sanity check that we have something meaningful to import
if len(chain) == 0 {
return 0, nil, nil, nil
@@ -1656,7 +1652,7 @@ func (bc *BlockChain) insertChain2(chain types.Blocks) (int, []interface{}, []*t
}
// Import all the pruned blocks to make the state available
bc.chainmu.Unlock()
- _, evs, logs, err := bc.insertChain2(winner)
+ _, evs, logs, err := bc.insertDexonChain(winner)
bc.chainmu.Lock()
events, coalescedLogs = evs, logs
@@ -1718,15 +1714,13 @@ func (bc *BlockChain) insertChain2(chain types.Blocks) (int, []interface{}, []*t
blockInsertTimer.UpdateSince(bstart)
events = append(events, ChainSideEvent{block})
+ panic("fork found")
}
stats.processed++
stats.usedGas += usedGas
cache, _ := bc.stateCache.TrieDB().Size()
stats.report(chain, i, cache)
- if _, ok := bc.GetRoundHeight(block.Round()); !ok {
- bc.storeRoundHeight(block.Round(), block.NumberU64())
- }
}
// Append a single chain head event if we've progressed the chain
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
@@ -2222,8 +2216,12 @@ func (bc *BlockChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (i
return bc.hc.InsertHeaderChain(chain, whFunc, start)
}
-func (bc *BlockChain) InsertHeaderChain2(chain []*types.HeaderWithGovState, verifierCache *dexCore.TSigVerifierCache) (int, error) {
+func (bc *BlockChain) InsertDexonHeaderChain(chain []*types.HeaderWithGovState, verifierCache *dexCore.TSigVerifierCache) (int, error) {
start := time.Now()
+ if i, err := bc.hc.ValidateDexonHeaderChain(chain, verifierCache); err != nil {
+ return i, err
+ }
+
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
@@ -2233,11 +2231,11 @@ func (bc *BlockChain) InsertHeaderChain2(chain []*types.HeaderWithGovState, veri
whFunc := func(header *types.HeaderWithGovState) error {
bc.mu.Lock()
defer bc.mu.Unlock()
- _, err := bc.hc.WriteHeader2(header)
+ _, err := bc.hc.WriteDexonHeader(header)
return err
}
- return bc.hc.InsertHeaderChain2(chain, whFunc, start)
+ return bc.hc.InsertDexonHeaderChain(chain, whFunc, start)
}
// writeHeader writes a header into the local chain, given that its parent is
diff --git a/core/headerchain.go b/core/headerchain.go
index a57e509ca..e988a53a2 100644
--- a/core/headerchain.go
+++ b/core/headerchain.go
@@ -304,7 +304,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
return 0, nil
}
-func (hc *HeaderChain) WriteHeader2(header *types.HeaderWithGovState) (status WriteStatus, err error) {
+func (hc *HeaderChain) WriteDexonHeader(header *types.HeaderWithGovState) (status WriteStatus, err error) {
// Cache some values to prevent constant recalculation
var (
hash = header.Hash()
@@ -394,7 +394,7 @@ func (hc *HeaderChain) WriteHeader2(header *types.HeaderWithGovState) (status Wr
type Wh2Callback func(*types.HeaderWithGovState) error
-func (hc *HeaderChain) ValidateHeaderChain2(chain []*types.HeaderWithGovState, verifierCache *dexCore.TSigVerifierCache) (int, error) {
+func (hc *HeaderChain) ValidateDexonHeaderChain(chain []*types.HeaderWithGovState, verifierCache *dexCore.TSigVerifierCache) (int, error) {
// Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ {
if chain[i].Number.Uint64() != chain[i-1].Number.Uint64()+1 || chain[i].ParentHash != chain[i-1].Hash() {
@@ -454,7 +454,7 @@ func (hc *HeaderChain) verifyTSig(header *types.Header, verifierCache *dexCore.T
return nil
}
-// InsertHeaderChain2 attempts to insert the given header chain in to the local
+// InsertDexonHeaderChain attempts to insert the given header chain in to the local
// chain, possibly creating a reorg. If an error is returned, it will return the
// index number of the failing header as well an error describing what went wrong.
//
@@ -462,7 +462,7 @@ func (hc *HeaderChain) verifyTSig(header *types.Header, verifierCache *dexCore.T
// should be done or not. The reason behind the optional check is because some
// of the header retrieval mechanisms already need to verfy nonces, as well as
// because nonces can be verified sparsely, not needing to check each.
-func (hc *HeaderChain) InsertHeaderChain2(chain []*types.HeaderWithGovState, writeHeader Wh2Callback, start time.Time) (int, error) {
+func (hc *HeaderChain) InsertDexonHeaderChain(chain []*types.HeaderWithGovState, writeHeader Wh2Callback, start time.Time) (int, error) {
// Collect some import statistics to report on
stats := struct{ processed, ignored int }{}
// All headers passed verification, import them into the database
diff --git a/dex/downloader/downloader.go b/dex/downloader/downloader.go
index 69d95d801..828c7c6bc 100644
--- a/dex/downloader/downloader.go
+++ b/dex/downloader/downloader.go
@@ -180,8 +180,8 @@ type LightChain interface {
// GetTd returns the total difficulty of a local block.
GetTd(common.Hash, uint64) *big.Int
- // InsertHeaderChain2 inserts a batch of headers into the local chain.
- InsertHeaderChain2([]*types.HeaderWithGovState, *dexCore.TSigVerifierCache) (int, error)
+ // InsertDexonHeaderChain inserts a batch of headers into the local chain.
+ InsertDexonHeaderChain([]*types.HeaderWithGovState, *dexCore.TSigVerifierCache) (int, error)
// Rollback removes a few recently added elements from the local chain.
Rollback([]common.Hash)
@@ -206,8 +206,8 @@ type BlockChain interface {
// FastSyncCommitHead directly commits the head block to a certain entity.
FastSyncCommitHead(common.Hash) error
- // InsertChain2 inserts a batch of blocks into the local chain.
- InsertChain2(types.Blocks) (int, error)
+ // InsertDexonChain inserts a batch of blocks into the local chain.
+ InsertDexonChain(types.Blocks) (int, error)
// InsertReceiptChain inserts a batch of receipts into the local chain.
InsertReceiptChain(types.Blocks, []types.Receipts) (int, error)
@@ -1421,7 +1421,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
}
}
- if n, err := d.lightchain.InsertHeaderChain2(chunk, d.verifierCache); err != nil {
+ if n, err := d.lightchain.InsertDexonHeaderChain(chunk, d.verifierCache); err != nil {
// If some headers were inserted, add them too to the rollback list
if n > 0 {
for _, h := range chunk[:n] {
@@ -1513,7 +1513,7 @@ func (d *Downloader) importBlockResults(results []*fetchResult) error {
for i, result := range results {
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles)
}
- if index, err := d.blockchain.InsertChain2(blocks); err != nil {
+ if index, err := d.blockchain.InsertDexonChain(blocks); err != nil {
log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err)
return errInvalidChain
}
diff --git a/dex/handler.go b/dex/handler.go
index 0c7a3e919..a86a68329 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -221,7 +221,7 @@ func NewProtocolManager(
return 0, nil
}
atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
- return manager.blockchain.InsertChain2(blocks)
+ return manager.blockchain.InsertDexonChain(blocks)
}
manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer)