merge upstream
This commit is contained in:
@@ -168,7 +168,7 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int {
|
||||
result := new(big.Int).Add(previous, curInt)
|
||||
result.Div(result, big.NewInt(1024))
|
||||
|
||||
min := ethutil.BigPow(10, 4)
|
||||
min := big.NewInt(125000)
|
||||
|
||||
return ethutil.BigMax(min, result)
|
||||
/*
|
||||
|
@@ -271,7 +271,7 @@ func AddTestNetFunds(block *Block) {
|
||||
for _, addr := range []string{
|
||||
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
|
||||
"e4157b34ea9615cfbde6b4fda419828124b70c78",
|
||||
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df",
|
||||
"b9c015918bdaba24b4ff057a92a3873d6eb201be",
|
||||
"6c386a4b26f73c802f34673f7248bb118f97424a",
|
||||
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
|
||||
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",
|
||||
|
@@ -32,6 +32,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
|
||||
for {
|
||||
select {
|
||||
case <-reactChan:
|
||||
powlogger.Infoln("Breaking from mining")
|
||||
return nil
|
||||
default:
|
||||
i++
|
||||
|
@@ -127,7 +127,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
|
||||
}
|
||||
|
||||
func (self *State) NewStateObject(addr []byte) *StateObject {
|
||||
statelogger.Infof("(+) %x\n", addr)
|
||||
//statelogger.Infof("(+) %x\n", addr)
|
||||
|
||||
stateObject := NewStateObject(addr)
|
||||
self.stateObjects[string(addr)] = stateObject
|
||||
@@ -206,84 +206,3 @@ func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte
|
||||
|
||||
m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
// Resets the trie and all siblings
|
||||
func (s *State) Reset() {
|
||||
s.trie.Undo()
|
||||
|
||||
// Reset all nested states
|
||||
for _, state := range s.states {
|
||||
state.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
// Syncs the trie and all siblings
|
||||
func (s *State) Sync() {
|
||||
// Sync all nested states
|
||||
for _, state := range s.states {
|
||||
state.Sync()
|
||||
}
|
||||
|
||||
s.trie.Sync()
|
||||
}
|
||||
func (s *State) GetStateObject(addr []byte) *StateObject {
|
||||
data := s.trie.Get(string(addr))
|
||||
if data == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
stateObject := NewStateObjectFromBytes(addr, []byte(data))
|
||||
|
||||
// Check if there's a cached state for this contract
|
||||
cachedStateObject := s.states[string(addr)]
|
||||
if cachedStateObject != nil {
|
||||
//fmt.Printf("get cached #%d %x addr: %x\n", cachedStateObject.trie.Cache().Len(), cachedStateObject.Root(), addr[0:4])
|
||||
stateObject.state = cachedStateObject
|
||||
}
|
||||
|
||||
return stateObject
|
||||
}
|
||||
|
||||
// Updates any given state object
|
||||
func (s *State) UpdateStateObject(object *StateObject) {
|
||||
addr := object.Address()
|
||||
|
||||
if object.state != nil && s.states[string(addr)] == nil {
|
||||
s.states[string(addr)] = object.state
|
||||
}
|
||||
|
||||
ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
|
||||
|
||||
s.trie.Update(string(addr), string(object.RlpEncode()))
|
||||
|
||||
s.manifest.AddObjectChange(object)
|
||||
}
|
||||
|
||||
func (s *State) GetAccount(addr []byte) (account *StateObject) {
|
||||
data := s.trie.Get(string(addr))
|
||||
if data == "" {
|
||||
account = NewAccount(addr, big.NewInt(0))
|
||||
} else {
|
||||
account = NewStateObjectFromBytes(addr, []byte(data))
|
||||
}
|
||||
|
||||
// Check if there's a cached state for this contract
|
||||
cachedStateObject := s.states[string(addr)]
|
||||
if cachedStateObject != nil {
|
||||
account.state = cachedStateObject
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *State) Copy() *State {
|
||||
state := NewState(s.trie.Copy())
|
||||
for k, subState := range s.states {
|
||||
state.states[k] = subState.Copy()
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
*/
|
||||
|
@@ -3,6 +3,7 @@ package ethchain
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethlog"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
@@ -125,6 +126,8 @@ done:
|
||||
break done
|
||||
default:
|
||||
statelogger.Infoln(err)
|
||||
err = nil
|
||||
//return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +205,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
|
||||
}
|
||||
|
||||
if !block.State().Cmp(state) {
|
||||
statelogger.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
|
||||
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -237,7 +240,10 @@ func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts
|
||||
coinbase.SetGasPool(block.CalcGasLimit(parent))
|
||||
|
||||
// Process the transactions on to current block
|
||||
receipts, _, _, _ = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
|
||||
receipts, _, _, err = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return receipts, nil
|
||||
}
|
||||
|
@@ -50,7 +50,10 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
|
||||
}
|
||||
|
||||
func NewStateObject(addr []byte) *StateObject {
|
||||
return &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
|
||||
object := &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
|
||||
object.state = NewState(ethutil.NewTrie(ethutil.Config.Db, ""))
|
||||
|
||||
return object
|
||||
}
|
||||
|
||||
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
|
||||
|
@@ -16,12 +16,12 @@ func TestSnapshot(t *testing.T) {
|
||||
state.UpdateStateObject(stateObject)
|
||||
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
|
||||
|
||||
snapshot := state.Snapshot()
|
||||
snapshot := state.Copy()
|
||||
|
||||
stateObject = state.GetStateObject([]byte("aa"))
|
||||
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
|
||||
|
||||
state.Revert(snapshot)
|
||||
state.Set(snapshot)
|
||||
|
||||
stateObject = state.GetStateObject([]byte("aa"))
|
||||
if !stateObject.GetStorage(ethutil.Big("0")).Cmp(ethutil.NewValue(42)) {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package ethchain
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
@@ -224,15 +226,11 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
|
||||
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Amount)
|
||||
}
|
||||
|
||||
//if self.value.Cmp(ethutil.Big0) > 0 {
|
||||
// Subtract the amount from the senders account
|
||||
sender.SubAmount(self.value)
|
||||
// Add the amount to receivers account which should conclude this transaction
|
||||
receiver.AddAmount(self.value)
|
||||
|
||||
//statelogger.Debugf("%x => %x (%v)\n", sender.Address()[:4], receiver.Address()[:4], self.value)
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -255,8 +253,50 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
|
||||
Value: self.value,
|
||||
})
|
||||
vm.Verbose = true
|
||||
ret, _, err = closure.Call(vm, self.data, nil)
|
||||
deepErr = vm.err != nil
|
||||
|
||||
ret, err, deepErr = Call(vm, closure, self.data)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) {
|
||||
ret, _, err = closure.Call(vm, data, nil)
|
||||
deepErr = vm.err != nil
|
||||
|
||||
Paranoia := ethutil.Config.Paranoia
|
||||
if Paranoia {
|
||||
var (
|
||||
context = closure.object
|
||||
trie = context.state.trie
|
||||
trie2 = ethutil.NewTrie(ethutil.Config.Db, "")
|
||||
)
|
||||
|
||||
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
|
||||
trie2.Update(key, v.Str())
|
||||
})
|
||||
|
||||
a := ethutil.NewValue(trie2.Root).Bytes()
|
||||
b := ethutil.NewValue(context.state.trie.Root).Bytes()
|
||||
if bytes.Compare(a, b) != 0 {
|
||||
// TODO FIXME ASAP
|
||||
context.state.trie = trie2
|
||||
/*
|
||||
statelogger.Debugf("(o): %x\n", trie.Root)
|
||||
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
|
||||
v.Decode()
|
||||
statelogger.Debugf("%x : %x\n", key, v.Str())
|
||||
})
|
||||
|
||||
statelogger.Debugf("(c): %x\n", trie2.Root)
|
||||
trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
|
||||
v.Decode()
|
||||
statelogger.Debugf("%x : %x\n", key, v.Str())
|
||||
})
|
||||
*/
|
||||
|
||||
//return nil, fmt.Errorf("PARANOIA: Different state object roots during copy"), false
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@@ -347,6 +347,29 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
||||
} else {
|
||||
stack.Push(ethutil.BigFalse)
|
||||
}
|
||||
|
||||
case SLT:
|
||||
require(2)
|
||||
x, y := stack.Popn()
|
||||
vm.Printf(" %v < %v", y, x)
|
||||
// x < y
|
||||
if y.Cmp(x) < 0 {
|
||||
stack.Push(ethutil.BigTrue)
|
||||
} else {
|
||||
stack.Push(ethutil.BigFalse)
|
||||
}
|
||||
case SGT:
|
||||
require(2)
|
||||
x, y := stack.Popn()
|
||||
vm.Printf(" %v > %v", y, x)
|
||||
|
||||
// x > y
|
||||
if y.Cmp(x) > 0 {
|
||||
stack.Push(ethutil.BigTrue)
|
||||
} else {
|
||||
stack.Push(ethutil.BigFalse)
|
||||
}
|
||||
|
||||
case EQ:
|
||||
require(2)
|
||||
x, y := stack.Popn()
|
||||
@@ -661,7 +684,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
||||
// Create a new callable closure
|
||||
closure := NewClosure(closure, stateObject, stateObject.script, vm.state, gas, closure.Price)
|
||||
// Executer the closure and get the return value (if any)
|
||||
ret, _, err := closure.Call(vm, args, hook)
|
||||
//ret, _, err := closure.Call(vm, args, hook)
|
||||
ret, err, _ := Call(vm, closure, args)
|
||||
if err != nil {
|
||||
stack.Push(ethutil.BigFalse)
|
||||
|
||||
@@ -700,7 +724,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
||||
|
||||
return closure.Return(nil), nil
|
||||
default:
|
||||
vmlogger.Debugf("Invalid opcode %x\n", op)
|
||||
vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op)
|
||||
fmt.Println(Code(closure.Script))
|
||||
|
||||
return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op)
|
||||
}
|
||||
|
@@ -5,9 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethdb"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/obscuren/mutan"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -17,7 +15,7 @@ func TestRun4(t *testing.T) {
|
||||
db, _ := ethdb.NewMemDatabase()
|
||||
state := NewState(ethutil.NewTrie(db, ""))
|
||||
|
||||
callerScript, err := mutan.Compile(strings.NewReader(`
|
||||
callerScript, err := ethutil.Compile(`
|
||||
this.store[this.origin()] = 10**20
|
||||
hello := "world"
|
||||
|
||||
@@ -31,7 +29,7 @@ func TestRun4(t *testing.T) {
|
||||
this.store[to] = this.store[to] + value
|
||||
}
|
||||
}
|
||||
`), false)
|
||||
`)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
@@ -55,7 +53,7 @@ func TestRun4(t *testing.T) {
|
||||
|
||||
vm := NewVm(state, nil, RuntimeVars{
|
||||
Origin: account.Address(),
|
||||
BlockNumber: 1,
|
||||
BlockNumber: big.NewInt(1),
|
||||
PrevHash: ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
|
||||
Coinbase: ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
|
||||
Time: 1,
|
||||
|
Reference in New Issue
Block a user