Skip to content

Commit 89630d2

Browse files
committed
merge upstream
2 parents 12972b4 + 550407b commit 89630d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+13642
-136
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
*un~
1010
.DS_Store
1111
*/**/.DS_Store
12-

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
before_install: sudo apt-get install libgmp3-dev
2+
language: go
3+
go:
4+
- 1.2

ethchain/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int {
168168
result := new(big.Int).Add(previous, curInt)
169169
result.Div(result, big.NewInt(1024))
170170

171-
min := ethutil.BigPow(10, 4)
171+
min := big.NewInt(125000)
172172

173173
return ethutil.BigMax(min, result)
174174
/*

ethchain/block_chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func AddTestNetFunds(block *Block) {
271271
for _, addr := range []string{
272272
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
273273
"e4157b34ea9615cfbde6b4fda419828124b70c78",
274-
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df",
274+
"b9c015918bdaba24b4ff057a92a3873d6eb201be",
275275
"6c386a4b26f73c802f34673f7248bb118f97424a",
276276
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
277277
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",

ethchain/dagger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
3232
for {
3333
select {
3434
case <-reactChan:
35+
powlogger.Infoln("Breaking from mining")
3536
return nil
3637
default:
3738
i++

ethchain/state.go

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
127127
}
128128

129129
func (self *State) NewStateObject(addr []byte) *StateObject {
130-
statelogger.Infof("(+) %x\n", addr)
130+
//statelogger.Infof("(+) %x\n", addr)
131131

132132
stateObject := NewStateObject(addr)
133133
self.stateObjects[string(addr)] = stateObject
@@ -206,84 +206,3 @@ func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte
206206

207207
m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
208208
}
209-
210-
/*
211-
212-
// Resets the trie and all siblings
213-
func (s *State) Reset() {
214-
s.trie.Undo()
215-
216-
// Reset all nested states
217-
for _, state := range s.states {
218-
state.Reset()
219-
}
220-
}
221-
222-
// Syncs the trie and all siblings
223-
func (s *State) Sync() {
224-
// Sync all nested states
225-
for _, state := range s.states {
226-
state.Sync()
227-
}
228-
229-
s.trie.Sync()
230-
}
231-
func (s *State) GetStateObject(addr []byte) *StateObject {
232-
data := s.trie.Get(string(addr))
233-
if data == "" {
234-
return nil
235-
}
236-
237-
stateObject := NewStateObjectFromBytes(addr, []byte(data))
238-
239-
// Check if there's a cached state for this contract
240-
cachedStateObject := s.states[string(addr)]
241-
if cachedStateObject != nil {
242-
//fmt.Printf("get cached #%d %x addr: %x\n", cachedStateObject.trie.Cache().Len(), cachedStateObject.Root(), addr[0:4])
243-
stateObject.state = cachedStateObject
244-
}
245-
246-
return stateObject
247-
}
248-
249-
// Updates any given state object
250-
func (s *State) UpdateStateObject(object *StateObject) {
251-
addr := object.Address()
252-
253-
if object.state != nil && s.states[string(addr)] == nil {
254-
s.states[string(addr)] = object.state
255-
}
256-
257-
ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
258-
259-
s.trie.Update(string(addr), string(object.RlpEncode()))
260-
261-
s.manifest.AddObjectChange(object)
262-
}
263-
264-
func (s *State) GetAccount(addr []byte) (account *StateObject) {
265-
data := s.trie.Get(string(addr))
266-
if data == "" {
267-
account = NewAccount(addr, big.NewInt(0))
268-
} else {
269-
account = NewStateObjectFromBytes(addr, []byte(data))
270-
}
271-
272-
// Check if there's a cached state for this contract
273-
cachedStateObject := s.states[string(addr)]
274-
if cachedStateObject != nil {
275-
account.state = cachedStateObject
276-
}
277-
278-
return
279-
}
280-
281-
func (s *State) Copy() *State {
282-
state := NewState(s.trie.Copy())
283-
for k, subState := range s.states {
284-
state.states[k] = subState.Copy()
285-
}
286-
287-
return state
288-
}
289-
*/

ethchain/state_manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ethchain
33
import (
44
"bytes"
55
"container/list"
6+
"fmt"
67
"github.com/ethereum/eth-go/ethcrypto"
78
"github.com/ethereum/eth-go/ethlog"
89
"github.com/ethereum/eth-go/ethutil"
@@ -125,6 +126,8 @@ done:
125126
break done
126127
default:
127128
statelogger.Infoln(err)
129+
err = nil
130+
//return nil, nil, nil, err
128131
}
129132
}
130133

@@ -202,7 +205,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
202205
}
203206

204207
if !block.State().Cmp(state) {
205-
statelogger.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
208+
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
206209
return
207210
}
208211

@@ -237,7 +240,10 @@ func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts
237240
coinbase.SetGasPool(block.CalcGasLimit(parent))
238241

239242
// Process the transactions on to current block
240-
receipts, _, _, _ = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
243+
receipts, _, _, err = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
244+
if err != nil {
245+
return nil, err
246+
}
241247

242248
return receipts, nil
243249
}

ethchain/state_object.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
5050
}
5151

5252
func NewStateObject(addr []byte) *StateObject {
53-
return &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
53+
object := &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
54+
object.state = NewState(ethutil.NewTrie(ethutil.Config.Db, ""))
55+
56+
return object
5457
}
5558

5659
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {

ethchain/state_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func TestSnapshot(t *testing.T) {
1616
state.UpdateStateObject(stateObject)
1717
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
1818

19-
snapshot := state.Snapshot()
19+
snapshot := state.Copy()
2020

2121
stateObject = state.GetStateObject([]byte("aa"))
2222
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
2323

24-
state.Revert(snapshot)
24+
state.Set(snapshot)
2525

2626
stateObject = state.GetStateObject([]byte("aa"))
2727
if !stateObject.GetStorage(ethutil.Big("0")).Cmp(ethutil.NewValue(42)) {

ethchain/state_transition.go

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package ethchain
22

33
import (
4+
"bytes"
45
"fmt"
6+
"github.com/ethereum/eth-go/ethutil"
57
"math/big"
68
)
79

@@ -224,15 +226,11 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
224226
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Amount)
225227
}
226228

227-
//if self.value.Cmp(ethutil.Big0) > 0 {
228229
// Subtract the amount from the senders account
229230
sender.SubAmount(self.value)
230231
// Add the amount to receivers account which should conclude this transaction
231232
receiver.AddAmount(self.value)
232233

233-
//statelogger.Debugf("%x => %x (%v)\n", sender.Address()[:4], receiver.Address()[:4], self.value)
234-
//}
235-
236234
return nil
237235
}
238236

@@ -255,8 +253,50 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
255253
Value: self.value,
256254
})
257255
vm.Verbose = true
258-
ret, _, err = closure.Call(vm, self.data, nil)
256+
257+
ret, err, deepErr = Call(vm, closure, self.data)
258+
259+
return
260+
}
261+
262+
func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) {
263+
ret, _, err = closure.Call(vm, data, nil)
259264
deepErr = vm.err != nil
260265

266+
Paranoia := ethutil.Config.Paranoia
267+
if Paranoia {
268+
var (
269+
context = closure.object
270+
trie = context.state.trie
271+
trie2 = ethutil.NewTrie(ethutil.Config.Db, "")
272+
)
273+
274+
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
275+
trie2.Update(key, v.Str())
276+
})
277+
278+
a := ethutil.NewValue(trie2.Root).Bytes()
279+
b := ethutil.NewValue(context.state.trie.Root).Bytes()
280+
if bytes.Compare(a, b) != 0 {
281+
// TODO FIXME ASAP
282+
context.state.trie = trie2
283+
/*
284+
statelogger.Debugf("(o): %x\n", trie.Root)
285+
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
286+
v.Decode()
287+
statelogger.Debugf("%x : %x\n", key, v.Str())
288+
})
289+
290+
statelogger.Debugf("(c): %x\n", trie2.Root)
291+
trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
292+
v.Decode()
293+
statelogger.Debugf("%x : %x\n", key, v.Str())
294+
})
295+
*/
296+
297+
//return nil, fmt.Errorf("PARANOIA: Different state object roots during copy"), false
298+
}
299+
}
300+
261301
return
262302
}

0 commit comments

Comments
 (0)