aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorbojie <bojie@dexon.org>2019-03-11 17:43:52 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461 (patch)
tree3c54d34e573b97ed4120a33bc5d6593e618a9d49 /core
parent04cb64b849988c1cf71fd66a3142f01e8ba7cb23 (diff)
downloadgo-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar.gz
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar.bz2
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar.lz
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar.xz
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.tar.zst
go-tangerine-8ffc8f2b78bfb3cc352f71ca569ad6c09bda1461.zip
app: new app test flow (#244)
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go40
-rw-r--r--core/blockchain_test.go6
-rw-r--r--core/genesis.go2
-rw-r--r--core/rawdb/accessors_chain.go15
-rw-r--r--core/rawdb/schema.go2
-rw-r--r--core/tx_pool.go8
6 files changed, 8 insertions, 65 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index aa2326c8d..f829c0e8e 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -931,13 +931,6 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
bytes += batch.ValueSize()
batch.Reset()
}
-
- if i == len(blockChain)-1 {
- err := bc.updateLastRoundNumber(block.Round())
- if err != nil {
- return 0, err
- }
- }
}
if batch.ValueSize() > 0 {
bytes += batch.ValueSize()
@@ -1664,13 +1657,6 @@ func (bc *BlockChain) insertDexonChain(chain types.Blocks) (int, []interface{},
cache, _ := bc.stateCache.TrieDB().Size()
stats.report(chain, i, cache)
-
- if i == len(chain)-1 {
- err = bc.updateLastRoundNumber(block.Round())
- if err != nil {
- return 0, nil, nil, err
- }
- }
}
// Append a single chain head event if we've progressed the chain
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
@@ -1807,11 +1793,6 @@ func (bc *BlockChain) processBlock(
cache, _ := bc.stateCache.TrieDB().Size()
stats.report([]*types.Block{newBlock}, 0, cache)
- err = bc.updateLastRoundNumber(newBlock.Round())
- if err != nil {
- return nil, nil, nil, err
- }
-
return &root, events, coalescedLogs, nil
}
@@ -1894,11 +1875,6 @@ func (bc *BlockChain) ProcessEmptyBlock(block *types.Block) (*common.Hash, error
cache, _ := bc.stateCache.TrieDB().Size()
stats.report([]*types.Block{newBlock}, 0, cache)
- err = bc.updateLastRoundNumber(newBlock.Round())
- if err != nil {
- return nil, err
- }
-
bc.PostChainEvents([]interface{}{ChainEvent{newBlock, newBlock.Hash(), nil},
ChainHeadEvent{newBlock}}, nil)
@@ -2327,19 +2303,3 @@ func (bc *BlockChain) GetRoundHeight(round uint64) (uint64, bool) {
func (bc *BlockChain) storeRoundHeight(round uint64, height uint64) {
bc.roundHeightMap.Store(round, height)
}
-
-func (bc *BlockChain) updateLastRoundNumber(round uint64) error {
- currentLastRound, err := rawdb.ReadLastRoundNumber(bc.db)
- if err != nil {
- return err
- }
-
- if round > currentLastRound {
- err = rawdb.WriteLastRoundNumber(bc.db, round)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index f972eb0b2..f8956da46 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -654,9 +654,6 @@ func TestFastVsFullChains(t *testing.T) {
// Fast import the chain as a non-archive node to test
fastDb := ethdb.NewMemDatabase()
gspec.MustCommit(fastDb)
- if err := rawdb.WriteLastRoundNumber(fastDb, 0); err != nil {
- t.Fatalf("failed to write last round: %v", err)
- }
fast, _ := NewBlockChain(fastDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil)
defer fast.Stop()
@@ -748,9 +745,6 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
// Import the chain as a non-archive node and ensure all pointers are updated
fastDb := ethdb.NewMemDatabase()
gspec.MustCommit(fastDb)
- if err := rawdb.WriteLastRoundNumber(fastDb, 0); err != nil {
- t.Fatalf("failed to write last round: %v", err)
- }
fast, _ := NewBlockChain(fastDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil)
defer fast.Stop()
diff --git a/core/genesis.go b/core/genesis.go
index 7f2cafbf5..f2df4f62f 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -169,8 +169,6 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
return SetupGenesisBlockWithOverride(db, genesis, nil)
}
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, constantinopleOverride *big.Int) (*params.ChainConfig, common.Hash, error) {
- rawdb.WriteLastRoundNumber(db, 0)
-
if genesis != nil && genesis.Config == nil {
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
}
diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index 5e23bef8f..801ad9362 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -348,21 +348,6 @@ func WriteBlock(db DatabaseWriter, block *types.Block) {
WriteHeader(db, block.Header())
}
-// ReadLastRoundNumber get current round number.
-func ReadLastRoundNumber(db DatabaseReader) (uint64, error) {
- number, err := db.Get(lastRoundNum)
- if err != nil {
- return 0, err
- }
-
- return new(big.Int).SetBytes(number).Uint64(), nil
-}
-
-// WriteLastRoundNumber write current round number.
-func WriteLastRoundNumber(db DatabaseWriter, number uint64) error {
- return db.Put(lastRoundNum, new(big.Int).SetUint64(number).Bytes())
-}
-
// DeleteBlock removes all block data associated with a hash.
func DeleteBlock(db DatabaseDeleter, hash common.Hash, number uint64) {
DeleteReceipts(db, hash, number)
diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go
index 954ebfc1d..87a56c0ba 100644
--- a/core/rawdb/schema.go
+++ b/core/rawdb/schema.go
@@ -63,8 +63,6 @@ var (
// Chain index prefixes (use `i` + single byte to avoid mixing data types).
BloomBitsIndexPrefix = []byte("iB") // BloomBitsIndexPrefix is the data table of a chain indexer to track its progress
- lastRoundNum = []byte("LastRoundNum")
-
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
preimageHitCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
)
diff --git a/core/tx_pool.go b/core/tx_pool.go
index 1719b4b4e..e7dbab0d2 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -429,6 +429,14 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
pool.promoteExecutables(nil)
}
+// Reset only for testing.
+func (pool *TxPool) Reset(newHead *types.Header) {
+ pool.mu.Lock()
+ defer pool.mu.Unlock()
+
+ pool.reset(nil, newHead)
+}
+
// Stop terminates the transaction pool.
func (pool *TxPool) Stop() {
// Unsubscribe all subscriptions registered from txpool