Merge branch 'develop' into feature/rpc

pull/150/head
Maran 11 years ago
commit c54788338a
  1. 10
      ethchain/keypair.go
  2. 1
      ethchain/state_object.go
  3. 14
      ethchain/transaction_pool.go
  4. 44
      ethchain/vm.go
  5. 2
      ethereum.go
  6. 4
      natupnp.go
  7. 54
      peer.go

@ -2,6 +2,7 @@ package ethchain
import ( import (
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
"math/big" "math/big"
) )
@ -14,6 +15,15 @@ type KeyPair struct {
state *State state *State
} }
func NewKeyPairFromSec(seckey []byte) (*KeyPair, error) {
pubkey, err := secp256k1.GeneratePubKey(seckey)
if err != nil {
return nil, err
}
return &KeyPair{PrivateKey: seckey, PublicKey: pubkey}, nil
}
func NewKeyPairFromValue(val *ethutil.Value) *KeyPair { func NewKeyPairFromValue(val *ethutil.Value) *KeyPair {
keyPair := &KeyPair{PrivateKey: val.Get(0).Bytes(), PublicKey: val.Get(1).Bytes()} keyPair := &KeyPair{PrivateKey: val.Get(0).Bytes(), PublicKey: val.Get(1).Bytes()}

@ -80,7 +80,6 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
func (c *StateObject) SetMem(num *big.Int, val *ethutil.Value) { func (c *StateObject) SetMem(num *big.Int, val *ethutil.Value) {
addr := ethutil.BigToBytes(num, 256) addr := ethutil.BigToBytes(num, 256)
c.SetAddr(addr, val) c.SetAddr(addr, val)
//c.state.trie.Update(string(addr), string(val.Encode()))
} }
func (c *StateObject) GetMem(num *big.Int) *ethutil.Value { func (c *StateObject) GetMem(num *big.Int) *ethutil.Value {

@ -91,14 +91,12 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
// Process transaction validates the Tx and processes funds from the // Process transaction validates the Tx and processes funds from the
// sender to the recipient. // sender to the recipient.
func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block, toContract bool) (err error) { func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block, toContract bool) (err error) {
/* defer func() {
defer func() { if r := recover(); r != nil {
if r := recover(); r != nil { log.Println(r)
log.Println(r) err = fmt.Errorf("%v", r)
err = fmt.Errorf("%v", r) }
} }()
}()
*/
// Get the sender // Get the sender
sender := block.state.GetAccount(tx.Sender()) sender := block.state.GetAccount(tx.Sender())

@ -73,10 +73,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
} }
}() }()
// If the amount of gas supplied is less equal to 0 ethutil.Config.Log.Debugf("[VM] Running closure %x\n", closure.object.Address())
if closure.Gas.Cmp(big.NewInt(0)) <= 0 {
// TODO Do something
}
// Memory for the current closure // Memory for the current closure
mem := &Memory{} mem := &Memory{}
@ -107,9 +104,11 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
val := closure.Get(pc) val := closure.Get(pc)
// Get the opcode (it must be an opcode!) // Get the opcode (it must be an opcode!)
op := OpCode(val.Uint()) op := OpCode(val.Uint())
if ethutil.Config.Debug { /*
ethutil.Config.Log.Debugf("%-3d %-4s", pc, op.String()) if ethutil.Config.Debug {
} ethutil.Config.Log.Debugf("%-3d %-4s", pc, op.String())
}
*/
gas := new(big.Int) gas := new(big.Int)
useGas := func(amount *big.Int) { useGas := func(amount *big.Int) {
@ -163,9 +162,6 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case oLOG: case oLOG:
stack.Print() stack.Print()
mem.Print() mem.Print()
case oSTOP: // Stop the closure
return closure.Return(nil), nil
// 0x20 range // 0x20 range
case oADD: case oADD:
require(2) require(2)
@ -520,22 +516,18 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
return closure.Return(ret), nil return closure.Return(ret), nil
case oSUICIDE: case oSUICIDE:
/* require(1)
recAddr := stack.Pop().Bytes()
// Purge all memory receiver := vm.state.GetAccount(stack.Pop().Bytes())
deletedMemory := contract.state.Purge() receiver.AddAmount(closure.object.Amount)
// Add refunds to the pop'ed address
refund := new(big.Int).Mul(StoreFee, big.NewInt(int64(deletedMemory))) vm.stateManager.manifest.AddObjectChange(receiver)
account := state.GetAccount(recAddr)
account.Amount.Add(account.Amount, refund) closure.object.state.Purge()
// Update the refunding address
state.UpdateAccount(recAddr, account) fallthrough
// Delete the contract case oSTOP: // Stop the closure
state.trie.Update(string(addr), "") return closure.Return(nil), nil
ethutil.Config.Log.Debugf("(%d) => %x\n", deletedMemory, recAddr)
break out
*/
default: default:
ethutil.Config.Log.Debugf("Invalid opcode %x\n", op) ethutil.Config.Log.Debugf("Invalid opcode %x\n", op)

@ -354,7 +354,7 @@ func (s *Ethereum) WaitForShutdown() {
func (s *Ethereum) upnpUpdateThread() { func (s *Ethereum) upnpUpdateThread() {
// Go off immediately to prevent code duplication, thereafter we renew // Go off immediately to prevent code duplication, thereafter we renew
// lease every 15 minutes. // lease every 15 minutes.
timer := time.NewTimer(0 * time.Second) timer := time.NewTimer(5 * time.Minute)
lport, _ := strconv.ParseInt(s.Port, 10, 16) lport, _ := strconv.ParseInt(s.Port, 10, 16)
first := true first := true
out: out:

@ -246,6 +246,10 @@ func soapRequest(url, function, message string) (r *http.Response, err error) {
//fmt.Println(fullMessage) //fmt.Println(fullMessage)
r, err = http.DefaultClient.Do(req) r, err = http.DefaultClient.Do(req)
if err != nil {
return
}
if r.Body != nil { if r.Body != nil {
defer r.Body.Close() defer r.Body.Close()
} }

@ -440,14 +440,14 @@ func (p *Peer) HandleInbound() {
// If a parent is found send back a reply // If a parent is found send back a reply
if parent != nil { if parent != nil {
ethutil.Config.Log.Infof("[PEER] Found conical block, returning chain from: %x ", parent.Hash()) ethutil.Config.Log.Debugf("[PEER] Found conical block, returning chain from: %x ", parent.Hash())
chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks) chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks)
if len(chain) > 0 { if len(chain) > 0 {
ethutil.Config.Log.Infof("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash()) ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash())
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, chain)) p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, chain))
} }
} else { } else {
ethutil.Config.Log.Infof("[PEER] Could not find a similar block") ethutil.Config.Log.Debugf("[PEER] Could not find a similar block")
// If no blocks are found we send back a reply with msg not in chain // If no blocks are found we send back a reply with msg not in chain
// and the last hash from get chain // and the last hash from get chain
lastHash := msg.Data.Get(l - 1) lastHash := msg.Data.Get(l - 1)
@ -455,7 +455,7 @@ func (p *Peer) HandleInbound() {
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()})) p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()}))
} }
case ethwire.MsgNotInChainTy: case ethwire.MsgNotInChainTy:
ethutil.Config.Log.Infof("Not in chain %x\n", msg.Data) ethutil.Config.Log.Debugf("Not in chain %x\n", msg.Data)
// TODO // TODO
case ethwire.MsgGetTxsTy: case ethwire.MsgGetTxsTy:
// Get the current transactions of the pool // Get the current transactions of the pool
@ -478,29 +478,6 @@ func (p *Peer) HandleInbound() {
p.Stop() p.Stop()
} }
func packAddr(address, port string) ([]interface{}, uint16) {
addr := strings.Split(address, ".")
a, _ := strconv.Atoi(addr[0])
b, _ := strconv.Atoi(addr[1])
c, _ := strconv.Atoi(addr[2])
d, _ := strconv.Atoi(addr[3])
host := []interface{}{int32(a), int32(b), int32(c), int32(d)}
prt, _ := strconv.Atoi(port)
return host, uint16(prt)
}
func unpackAddr(value *ethutil.Value, p uint64) string {
a := strconv.Itoa(int(value.Get(0).Uint()))
b := strconv.Itoa(int(value.Get(1).Uint()))
c := strconv.Itoa(int(value.Get(2).Uint()))
d := strconv.Itoa(int(value.Get(3).Uint()))
host := strings.Join([]string{a, b, c, d}, ".")
port := strconv.Itoa(int(p))
return net.JoinHostPort(host, port)
}
func (p *Peer) Start() { func (p *Peer) Start() {
peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String()) peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String())
servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
@ -662,3 +639,26 @@ func (p *Peer) CatchupWithPeer(blockHash []byte) {
func (p *Peer) RlpData() []interface{} { func (p *Peer) RlpData() []interface{} {
return []interface{}{p.host, p.port, p.pubkey} return []interface{}{p.host, p.port, p.pubkey}
} }
func packAddr(address, port string) ([]interface{}, uint16) {
addr := strings.Split(address, ".")
a, _ := strconv.Atoi(addr[0])
b, _ := strconv.Atoi(addr[1])
c, _ := strconv.Atoi(addr[2])
d, _ := strconv.Atoi(addr[3])
host := []interface{}{int32(a), int32(b), int32(c), int32(d)}
prt, _ := strconv.Atoi(port)
return host, uint16(prt)
}
func unpackAddr(value *ethutil.Value, p uint64) string {
a := strconv.Itoa(int(value.Get(0).Uint()))
b := strconv.Itoa(int(value.Get(1).Uint()))
c := strconv.Itoa(int(value.Get(2).Uint()))
d := strconv.Itoa(int(value.Get(3).Uint()))
host := strings.Join([]string{a, b, c, d}, ".")
port := strconv.Itoa(int(p))
return net.JoinHostPort(host, port)
}

Loading…
Cancel
Save