diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 1fa4882b5b6db2e3b699632c4d60291e9bdc8492..6205a23e05b54e04837337dadeb77b48f34295cd 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -92,87 +92,87 @@ }, { "ImportPath": "github.com/tendermint/tendermint/account", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/alert", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/blockchain", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/common", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/config", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/consensus", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/db", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/events", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/logger", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/mempool", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/merkle", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/node", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/p2p", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/permission/types", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/rpc/core", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/rpc/server", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/rpc/types", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/state", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/types", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/vm", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tendermint/tendermint/wire", - "Rev": "4ee387d0770ed379e2d524f7077938517b38cd7c" + "Rev": "3d35594e18621bce075d18fc354ac2f1e5485464" }, { "ImportPath": "github.com/tommy351/gin-cors", diff --git a/Godeps/_workspace/src/github.com/tendermint/tendermint/state/block_cache.go b/Godeps/_workspace/src/github.com/tendermint/tendermint/state/block_cache.go index 823681b8abd5628588361f9afe648a17ced6ebee..0d0cb0fe8f152716d67b1ef1019cdcb125d6ec28 100644 --- a/Godeps/_workspace/src/github.com/tendermint/tendermint/state/block_cache.go +++ b/Godeps/_workspace/src/github.com/tendermint/tendermint/state/block_cache.go @@ -177,7 +177,7 @@ func (cache *BlockCache) Sync() { addr, key := Tuple256Split(storageKey) if addr != curAddr || curAcc == nil { acc, storage, removed, _ := cache.accounts[string(addr.Postfix(20))].unpack() - if storage == nil { + if !removed && storage == nil { storage = makeStorage(cache.db, acc.StorageRoot) } curAddr = addr @@ -211,7 +211,7 @@ func (cache *BlockCache) Sync() { for _, addrStr := range addrStrs { acc, storage, removed, dirty := cache.accounts[addrStr].unpack() if removed { - removed := cache.backend.RemoveAccount(acc.Address) + removed := cache.backend.RemoveAccount([]byte(addrStr)) if !removed { PanicCrisis(Fmt("Could not remove account to be removed: %X", acc.Address)) } diff --git a/Godeps/_workspace/src/github.com/tendermint/tendermint/state/state_test.go b/Godeps/_workspace/src/github.com/tendermint/tendermint/state/state_test.go index 50e753abc6db51eb42e32518a4f9d3b65e638b83..5793cd97027877be61b973e3e68c24c3ca8d3e45 100644 --- a/Godeps/_workspace/src/github.com/tendermint/tendermint/state/state_test.go +++ b/Godeps/_workspace/src/github.com/tendermint/tendermint/state/state_test.go @@ -569,6 +569,52 @@ proof-of-work chain as proof of what happened while they were gone ` } +func TestSuicide(t *testing.T) { + + state, privAccounts, _ := RandGenesisState(3, true, 1000, 1, true, 1000) + + acc0 := state.GetAccount(privAccounts[0].PubKey.Address()) + acc0PubKey := privAccounts[0].PubKey + acc1 := state.GetAccount(privAccounts[1].PubKey.Address()) + acc2 := state.GetAccount(privAccounts[2].Address) + sendingAmount, leftoverBalance, oldBalance := int64(1), acc1.Balance, acc2.Balance + + newAcc1 := state.GetAccount(acc1.Address) + + // store 0x1 and 0x1, then suicide :) + contractCode := []byte{0x60, 0x01, 0x60, 0x01, 0x55, 0x73} + contractCode = append(contractCode, acc2.Address...) + contractCode = append(contractCode, 0xff) + newAcc1.Code = contractCode + state.UpdateAccount(newAcc1) + tx := &types.CallTx{ + Input: &types.TxInput{ + Address: acc0.Address, + Amount: sendingAmount, + Sequence: acc0.Sequence + 1, + PubKey: acc0PubKey, + }, + Address: acc1.Address, + GasLimit: 1000, + } + + tx.Input.Signature = privAccounts[0].Sign(state.ChainID, tx) + err := execTxWithState(state, tx, true) + if err != nil { + t.Errorf("Got error in executing call transaction, %v", err) + } + newAcc2 := state.GetAccount(acc2.Address) + newBalance := sendingAmount + leftoverBalance + oldBalance + if newAcc2.Balance != newBalance { + t.Errorf("Unexpected newAcc2 balance. Expected %v, got %v", + newAcc2.Balance, newBalance) + } + newAcc1 = state.GetAccount(acc1.Address) + if newAcc1 != nil { + t.Errorf("Expected account to be removed") + } +} + func TestAddValidator(t *testing.T) { // Generate a state, save & load it. diff --git a/Godeps/_workspace/src/github.com/tendermint/tendermint/vm/vm.go b/Godeps/_workspace/src/github.com/tendermint/tendermint/vm/vm.go index 9eb275701ff42abfc2aee24f07837d1e9a71e507..e59212c65e951dcb29276829b1fec3e13afb76b6 100644 --- a/Godeps/_workspace/src/github.com/tendermint/tendermint/vm/vm.go +++ b/Godeps/_workspace/src/github.com/tendermint/tendermint/vm/vm.go @@ -174,9 +174,6 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas switch op { - case STOP: // 0x00 - return nil, nil - case ADD: // 0x01 x, y := stack.Pop(), stack.Pop() xb := new(big.Int).SetBytes(x[:]) @@ -703,6 +700,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas vm.appState.AddLog(log) if vm.evc != nil { eventId := types.EventStringLogEvent(callee.Address.Postfix(20)) + fmt.Printf("eventId: %s\n", eventId) vm.evc.FireEvent(eventId, log) } // Using sol-log for this as well since 'log' will print garbage. @@ -837,7 +835,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas if useGasNegative(gas, GasGetAccount, &err) { return nil, err } - // TODO if the receiver is , then make it the fee. + // TODO if the receiver is , then make it the fee. (?) + // TODO: create account if doesn't exist (no reason not to) receiver := vm.appState.GetAccount(addr) if receiver == nil { return nil, firstErr(err, ErrUnknownAddress) @@ -849,6 +848,9 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas dbg.Printf(" => (%X) %v\n", addr[:4], balance) fallthrough + case STOP: // 0x00 + return nil, nil + default: dbg.Printf("(pc) %-3v Invalid opcode %X\n", pc, op) return nil, fmt.Errorf("Invalid opcode %X", op)