aboutsummaryrefslogtreecommitdiffstats
path: root/chain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-02 03:18:09 +0800
committerobscuren <geffobscura@gmail.com>2014-12-02 03:18:09 +0800
commit6dc46d3341dc5fa25bd005f9606de258874139be (patch)
tree39b5d7dad5a943de4e187f99c93da5aa7fc9f2b8 /chain
parenta3559c5e1b469890bb8d71e9992175febaae31c7 (diff)
downloadgo-tangerine-6dc46d3341dc5fa25bd005f9606de258874139be.tar.gz
go-tangerine-6dc46d3341dc5fa25bd005f9606de258874139be.tar.zst
go-tangerine-6dc46d3341dc5fa25bd005f9606de258874139be.zip
Changed the way transactions are being added to the transaction pool
Diffstat (limited to 'chain')
-rw-r--r--chain/block_manager.go2
-rw-r--r--chain/chain_manager.go21
-rw-r--r--chain/transaction.go7
-rw-r--r--chain/transaction_pool.go31
4 files changed, 53 insertions, 8 deletions
diff --git a/chain/block_manager.go b/chain/block_manager.go
index fdb221cc3..4d8d8dae6 100644
--- a/chain/block_manager.go
+++ b/chain/block_manager.go
@@ -246,7 +246,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
return
}
- state.Update(nil)
+ state.Update(ethutil.Big0)
if !block.State().Cmp(state) {
err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root())
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 0c3a7a928..75c8b22a2 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -322,6 +322,24 @@ func NewChain(blocks Blocks) *BlockChain {
}
// This function assumes you've done your checking. No checking is done at this stage anymore
+func (self *ChainManager) InsertChain(chain Blocks) error {
+ for _, block := range chain {
+ td, messages, err := self.Ethereum.BlockManager().Process(block)
+ if err != nil {
+ return err
+ }
+
+ self.add(block)
+ self.SetTotalDifficulty(td)
+ self.Ethereum.EventMux().Post(NewBlockEvent{block})
+ self.Ethereum.EventMux().Post(messages)
+ }
+
+ return nil
+}
+
+/*
+// This function assumes you've done your checking. No checking is done at this stage anymore
func (self *ChainManager) InsertChain(chain *BlockChain) {
for e := chain.Front(); e != nil; e = e.Next() {
link := e.Value.(*link)
@@ -338,7 +356,9 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4])
}
}
+*/
+/*
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
self.workingChain = chain
defer func() { self.workingChain = nil }()
@@ -381,3 +401,4 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
return
}
+*/
diff --git a/chain/transaction.go b/chain/transaction.go
index d81a0ea1b..47257a3f0 100644
--- a/chain/transaction.go
+++ b/chain/transaction.go
@@ -79,12 +79,7 @@ func (tx *Transaction) IsContract() bool {
func (tx *Transaction) CreationAddress(state *state.State) []byte {
// Generate a new address
- addr := crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
- //for i := uint64(0); state.GetStateObject(addr) != nil; i++ {
- // addr = crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce + i}).Encode())[12:]
- //}
-
- return addr
+ return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
}
func (tx *Transaction) Signature(key []byte) []byte {
diff --git a/chain/transaction_pool.go b/chain/transaction_pool.go
index ff75089d6..fbf882163 100644
--- a/chain/transaction_pool.go
+++ b/chain/transaction_pool.go
@@ -114,7 +114,6 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
}
// Get the sender
- //sender := pool.Ethereum.BlockManager().procState.GetAccount(tx.Sender())
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value)
@@ -136,6 +135,34 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
return nil
}
+func (self *TxPool) Add(tx *Transaction) error {
+ hash := tx.Hash()
+ foundTx := FindTx(self.pool, func(tx *Transaction, e *list.Element) bool {
+ return bytes.Compare(tx.Hash(), hash) == 0
+ })
+
+ if foundTx != nil {
+ return fmt.Errorf("Known transaction (%x)", hash[0:4])
+ }
+
+ err := self.ValidateTransaction(tx)
+ if err != nil {
+ return err
+ }
+
+ self.addTransaction(tx)
+
+ tmp := make([]byte, 4)
+ copy(tmp, tx.Recipient)
+
+ txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
+
+ // Notify the subscribers
+ self.Ethereum.EventMux().Post(TxPreEvent{tx})
+
+ return nil
+}
+
func (pool *TxPool) queueHandler() {
out:
for {
@@ -172,9 +199,11 @@ out:
}
}
+/*
func (pool *TxPool) QueueTransaction(tx *Transaction) {
pool.queueChan <- tx
}
+*/
func (pool *TxPool) CurrentTransactions() []*Transaction {
pool.mutex.Lock()