aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-12 21:50:35 +0800
committerobscuren <geffobscura@gmail.com>2015-03-12 21:50:35 +0800
commitef6706696c39c77b20dc5127da8c62e89de39cf7 (patch)
treede5ab225e8c9f53ddf181a58e0f4652c720e4c2e /core
parent31a95151c9fb95c8527e419347556f455aebd1cb (diff)
downloaddexon-ef6706696c39c77b20dc5127da8c62e89de39cf7.tar.gz
dexon-ef6706696c39c77b20dc5127da8c62e89de39cf7.tar.zst
dexon-ef6706696c39c77b20dc5127da8c62e89de39cf7.zip
Add additional extra database for non-protocol related data
* Add transaction to extra database after a successful block process
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go20
-rw-r--r--core/block_processor_test.go2
-rw-r--r--core/chain_makers.go2
-rw-r--r--core/chain_manager_test.go4
4 files changed, 22 insertions, 6 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 7ac8a1bd2..395622a8e 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/pow"
+ "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/state"
"gopkg.in/fatih/set.v0"
)
@@ -23,7 +24,8 @@ type PendingBlockEvent struct {
var statelogger = logger.NewLogger("BLOCK")
type BlockProcessor struct {
- db ethutil.Database
+ db ethutil.Database
+ extraDb ethutil.Database
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex sync.Mutex
// Canonical block chain
@@ -45,9 +47,10 @@ type BlockProcessor struct {
eventMux *event.TypeMux
}
-func NewBlockProcessor(db ethutil.Database, pow pow.PoW, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
+func NewBlockProcessor(db, extra ethutil.Database, pow pow.PoW, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
sm := &BlockProcessor{
db: db,
+ extraDb: extra,
mem: make(map[string]*big.Int),
Pow: pow,
bc: chainManager,
@@ -230,6 +233,10 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
// Remove transactions from the pool
sm.txpool.RemoveSet(block.Transactions())
+ for _, tx := range block.Transactions() {
+ putTx(sm.extraDb, tx)
+ }
+
chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4])
return td, nil
@@ -347,3 +354,12 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
return state.Logs(), nil
}
+
+func putTx(db ethutil.Database, tx *types.Transaction) {
+ rlpEnc, err := rlp.EncodeToBytes(tx)
+ if err != nil {
+ statelogger.Infoln("Failed encoding tx", err)
+ return
+ }
+ db.Put(tx.Hash(), rlpEnc)
+}
diff --git a/core/block_processor_test.go b/core/block_processor_test.go
index a031c2669..ad29404e1 100644
--- a/core/block_processor_test.go
+++ b/core/block_processor_test.go
@@ -14,7 +14,7 @@ func proc() (*BlockProcessor, *ChainManager) {
var mux event.TypeMux
chainMan := NewChainManager(db, db, &mux)
- return NewBlockProcessor(db, ezp.New(), nil, chainMan, &mux), chainMan
+ return NewBlockProcessor(db, db, ezp.New(), nil, chainMan, &mux), chainMan
}
func TestNumber(t *testing.T) {
diff --git a/core/chain_makers.go b/core/chain_makers.go
index b5c50dc3d..f140b5c7e 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -120,7 +120,7 @@ func newChainManager(block *types.Block, eventMux *event.TypeMux, db ethutil.Dat
// block processor with fake pow
func newBlockProcessor(db ethutil.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
- bman := NewBlockProcessor(db, FakePow{}, txpool, newChainManager(nil, eventMux, db), eventMux)
+ bman := NewBlockProcessor(db, db, FakePow{}, txpool, newChainManager(nil, eventMux, db), eventMux)
return bman
}
diff --git a/core/chain_manager_test.go b/core/chain_manager_test.go
index 91822f9e2..898d37f9c 100644
--- a/core/chain_manager_test.go
+++ b/core/chain_manager_test.go
@@ -257,7 +257,7 @@ func TestChainInsertions(t *testing.T) {
var eventMux event.TypeMux
chainMan := NewChainManager(db, db, &eventMux)
txPool := NewTxPool(&eventMux)
- blockMan := NewBlockProcessor(db, nil, txPool, chainMan, &eventMux)
+ blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
chainMan.SetProcessor(blockMan)
const max = 2
@@ -303,7 +303,7 @@ func TestChainMultipleInsertions(t *testing.T) {
var eventMux event.TypeMux
chainMan := NewChainManager(db, db, &eventMux)
txPool := NewTxPool(&eventMux)
- blockMan := NewBlockProcessor(db, nil, txPool, chainMan, &eventMux)
+ blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
chainMan.SetProcessor(blockMan)
done := make(chan bool, max)
for i, chain := range chains {