Changed the way transactions are being added to the transaction pool
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -321,6 +321,24 @@ func NewChain(blocks Blocks) *BlockChain {
|
||||
return chain
|
||||
}
|
||||
|
||||
// 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() {
|
||||
@@ -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
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user