aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorBojie Wu <bojie@dexon.org>2018-10-09 13:28:45 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:23:39 +0800
commit03fe9c0df6977974f22f5fe80f5db6e1afd49b54 (patch)
tree71473bb0e031e5165d190f609aa484648caae120 /core
parent7e45adbb9a08b76c667d235ed397a705495f9852 (diff)
downloadgo-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar.gz
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar.bz2
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar.lz
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar.xz
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.tar.zst
go-tangerine-03fe9c0df6977974f22f5fe80f5db6e1afd49b54.zip
app: correct dexon application logic
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go81
-rw-r--r--core/tx_pool.go4
2 files changed, 37 insertions, 48 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 8d90c9348..9775f9e16 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -141,9 +141,9 @@ type BlockChain struct {
badBlocks *lru.Cache // Bad block cache
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
- confirmedBlockMu sync.Mutex
- confirmedBlock map[coreCommon.Hash]*coreTypes.Block
- filteredConfirmedBlock map[uint32]map[coreCommon.Hash]*coreTypes.Block
+ confirmedBlockMu sync.Mutex
+ confirmedBlocks map[coreCommon.Hash]*coreTypes.Block
+ chainConfirmedBlocks map[uint32][]*coreTypes.Block
}
// NewBlockChain returns a fully initialised block chain using information
@@ -165,23 +165,24 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
badBlocks, _ := lru.New(badBlockLimit)
bc := &BlockChain{
- chainConfig: chainConfig,
- cacheConfig: cacheConfig,
- db: db,
- triegc: prque.New(nil),
- stateCache: state.NewDatabaseWithCache(db, cacheConfig.TrieCleanLimit),
- quit: make(chan struct{}),
- shouldPreserve: shouldPreserve,
- bodyCache: bodyCache,
- bodyRLPCache: bodyRLPCache,
- receiptsCache: receiptsCache,
- blockCache: blockCache,
- futureBlocks: futureBlocks,
- engine: engine,
- vmConfig: vmConfig,
- badBlocks: badBlocks,
- confirmedBlock: make(map[coreCommon.Hash]*coreTypes.Block),
- filteredConfirmedBlock: make(map[uint32]map[coreCommon.Hash]*coreTypes.Block),
+ chainConfig: chainConfig,
+ cacheConfig: cacheConfig,
+ db: db,
+ triegc: prque.New(nil),
+ stateCache: state.NewDatabase(db),
+ stateCache: state.NewDatabaseWithCache(db, cacheConfig.TrieCleanLimit),
+ quit: make(chan struct{}),
+ shouldPreserve: shouldPreserve,
+ bodyCache: bodyCache,
+ bodyRLPCache: bodyRLPCache,
+ receiptsCache: receiptsCache,
+ blockCache: blockCache,
+ futureBlocks: futureBlocks,
+ engine: engine,
+ vmConfig: vmConfig,
+ badBlocks: badBlocks,
+ confirmedBlocks: make(map[coreCommon.Hash]*coreTypes.Block),
+ chainConfirmedBlocks: make(map[uint32][]*coreTypes.Block),
}
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine))
@@ -229,55 +230,47 @@ func (bc *BlockChain) AddConfirmedBlock(block *coreTypes.Block) {
bc.confirmedBlockMu.Lock()
defer bc.confirmedBlockMu.Unlock()
- bc.confirmedBlock[block.Hash] = block
- if bc.filteredConfirmedBlock[block.Position.ChainID] == nil {
- bc.filteredConfirmedBlock[block.Position.ChainID] = make(map[coreCommon.Hash]*coreTypes.Block)
- }
- bc.filteredConfirmedBlock[block.Position.ChainID][block.Hash] = block
+ bc.confirmedBlocks[block.Hash] = block
+ chainBlocks := bc.chainConfirmedBlocks[block.Position.ChainID]
+ bc.chainConfirmedBlocks[block.Position.ChainID] = append(chainBlocks, block)
}
func (bc *BlockChain) RemoveConfirmedBlock(hash coreCommon.Hash) {
bc.confirmedBlockMu.Lock()
defer bc.confirmedBlockMu.Unlock()
- block := bc.confirmedBlock[hash]
- delete(bc.filteredConfirmedBlock[block.Position.ChainID], block.Hash)
- delete(bc.confirmedBlock, block.Hash)
+ block := bc.confirmedBlocks[hash]
+ delete(bc.confirmedBlocks, block.Hash)
- if len(bc.filteredConfirmedBlock[block.Position.ChainID]) == 0 {
- bc.filteredConfirmedBlock[block.Position.ChainID] = nil
- }
+ chainBlocks := bc.chainConfirmedBlocks[block.Position.ChainID]
+ bc.chainConfirmedBlocks[block.Position.ChainID] = chainBlocks[1:]
}
func (bc *BlockChain) GetConfirmedBlockByHash(hash coreCommon.Hash) *coreTypes.Block {
- return bc.confirmedBlock[hash]
+ return bc.confirmedBlocks[hash]
}
-func (bc *BlockChain) GetNonceInConfirmedBlock(chainID uint32, address common.Address) (uint64, bool, error) {
- var nonce uint64
- var init bool
- for _, block := range bc.filteredConfirmedBlock[chainID] {
+func (bc *BlockChain) GetConfirmedTxsByAddress(chainID uint32, address common.Address) (types.Transactions, error) {
+ var addressTxs types.Transactions
+ for _, block := range bc.chainConfirmedBlocks[chainID] {
var transactions types.Transactions
err := rlp.Decode(bytes.NewReader(block.Payload), &transactions)
if err != nil {
- return 0, init, err
+ return nil, err
}
for _, tx := range transactions {
msg, err := tx.AsMessage(types.MakeSigner(bc.chainConfig, new(big.Int)))
if err != nil {
- return 0, init, err
+ return nil, err
}
- if msg.From() == address && (tx.Nonce() > nonce || !init) {
- if !init {
- init = true
- }
- nonce = tx.Nonce()
+ if msg.From() == address {
+ addressTxs = append(addressTxs, tx)
}
}
}
- return nonce, init, nil
+ return addressTxs, nil
}
// loadLastState loads the last known chain state from the database. This method
diff --git a/core/tx_pool.go b/core/tx_pool.go
index d79512d9c..eccf82e93 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -1157,10 +1157,6 @@ func (pool *TxPool) demoteUnexecutables() {
}
}
-func (pool *TxPool) ValidateTx(tx *types.Transaction, local bool) error {
- return pool.validateTx(tx, local)
-}
-
// addressByHeartbeat is an account address tagged with its last activity timestamp.
type addressByHeartbeat struct {
address common.Address