Skip to content

Commit

Permalink
Merge branch 'release/0.9.25'
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed May 27, 2015
2 parents ceea1a7 + 2c532a7 commit 7086790
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 242 deletions.
70 changes: 52 additions & 18 deletions cmd/geth/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (js *jsre) adminBindings() {
debug.Set("getBlockRlp", js.getBlockRlp)
debug.Set("setHead", js.setHead)
debug.Set("processBlock", js.debugBlock)
debug.Set("seedhash", js.seedHash)
// undocumented temporary
debug.Set("waitForBlocks", js.waitForBlocks)
}
Expand Down Expand Up @@ -118,6 +119,27 @@ func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
return block, nil
}

func (js *jsre) seedHash(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) > 0 {
if call.Argument(0).IsNumber() {
num, _ := call.Argument(0).ToInteger()
hash, err := ethash.GetSeedHash(uint64(num))
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
v, _ := call.Otto.ToValue(fmt.Sprintf("0x%x", hash))
return v
} else {
fmt.Println("arg not a number")
}
} else {
fmt.Println("requires number argument")
}

return otto.UndefinedValue()
}

func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
txs := js.ethereum.TxPool().GetTransactions()

Expand All @@ -144,7 +166,8 @@ func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
}
}

return js.re.ToVal(ltxs)
v, _ := call.Otto.ToValue(ltxs)
return v
}

func (js *jsre) resend(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -175,7 +198,8 @@ func (js *jsre) resend(call otto.FunctionCall) otto.Value {
}
js.ethereum.TxPool().RemoveTransactions(types.Transactions{tx.tx})

return js.re.ToVal(ret)
v, _ := call.Otto.ToValue(ret)
return v
}

fmt.Println("first argument must be a transaction")
Expand All @@ -198,12 +222,13 @@ func (js *jsre) sign(call otto.FunctionCall) otto.Value {
fmt.Println(err)
return otto.UndefinedValue()
}
v, err := js.xeth.Sign(signer, data, false)
signed, err := js.xeth.Sign(signer, data, false)
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
return js.re.ToVal(v)
v, _ := call.Otto.ToValue(signed)
return v
}

func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
Expand All @@ -217,10 +242,11 @@ func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
vm.Debug = true
_, err = js.ethereum.BlockProcessor().RetryProcess(block)
if err != nil {
glog.Infoln(err)
fmt.Println(err)
}
vm.Debug = old

fmt.Println("ok")
return otto.UndefinedValue()
}

Expand All @@ -237,8 +263,8 @@ func (js *jsre) setHead(call otto.FunctionCall) otto.Value {

func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
current, max := js.ethereum.Downloader().Stats()

return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
v, _ := call.Otto.ToValue(fmt.Sprintf("%d/%d", current, max))
return v
}

func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
Expand All @@ -248,7 +274,8 @@ func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
}
encoded, _ := rlp.EncodeToBytes(block)
return js.re.ToVal(fmt.Sprintf("%x", encoded))
v, _ := call.Otto.ToValue(fmt.Sprintf("%x", encoded))
return v
}

func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -278,8 +305,9 @@ func (js *jsre) setGasPrice(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
}

func (js *jsre) hashrate(otto.FunctionCall) otto.Value {
return js.re.ToVal(js.ethereum.Miner().HashRate())
func (js *jsre) hashrate(call otto.FunctionCall) otto.Value {
v, _ := call.Otto.ToValue(js.ethereum.Miner().HashRate())
return v
}

func (js *jsre) makeDAG(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -495,15 +523,18 @@ func (js *jsre) newAccount(call otto.FunctionCall) otto.Value {
fmt.Printf("Could not create the account: %v", err)
return otto.UndefinedValue()
}
return js.re.ToVal(acct.Address.Hex())
v, _ := call.Otto.ToValue(acct.Address.Hex())
return v
}

func (js *jsre) nodeInfo(call otto.FunctionCall) otto.Value {
return js.re.ToVal(js.ethereum.NodeInfo())
v, _ := call.Otto.ToValue(js.ethereum.NodeInfo())
return v
}

func (js *jsre) peers(call otto.FunctionCall) otto.Value {
return js.re.ToVal(js.ethereum.PeersInfo())
v, _ := call.Otto.ToValue(js.ethereum.PeersInfo())
return v
}

func (js *jsre) importChain(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -562,7 +593,8 @@ func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value {

statedb := state.New(block.Root(), js.ethereum.StateDb())
dump := statedb.RawDump()
return js.re.ToVal(dump)
v, _ := call.Otto.ToValue(dump)
return v
}

func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -611,7 +643,8 @@ func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
case height = <-wait:
}
return js.re.ToVal(height.Uint64())
v, _ := call.Otto.ToValue(height.Uint64())
return v
}

func (js *jsre) sleep(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -704,8 +737,8 @@ func (js *jsre) register(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
}

return js.re.ToVal(contenthash.Hex())

v, _ := call.Otto.ToValue(contenthash.Hex())
return v
}

func (js *jsre) registerUrl(call otto.FunctionCall) otto.Value {
Expand Down Expand Up @@ -764,7 +797,8 @@ func (js *jsre) getContractInfo(call otto.FunctionCall) otto.Value {
fmt.Println(err)
return otto.UndefinedValue()
}
return js.re.ToVal(info)
v, _ := call.Otto.ToValue(info)
return v
}

func (js *jsre) startNatSpec(call otto.FunctionCall) otto.Value {
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
func (js *jsre) apiBindings(f xeth.Frontend) {
xe := xeth.New(js.ethereum, f)
ethApi := rpc.NewEthereumApi(xe)
jeth := rpc.NewJeth(ethApi, js.re.ToVal, js.re)
jeth := rpc.NewJeth(ethApi, js.re)

js.re.Set("jeth", struct{}{})
t, _ := js.re.Get("jeth")
Expand Down
4 changes: 3 additions & 1 deletion cmd/geth/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (

var (
versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`))
testNodeKey = crypto.ToECDSA(common.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
testGenesis = `{"` + testAddress[2:] + `": {"balance": "` + testBalance + `"}}`
)

Expand Down Expand Up @@ -72,6 +73,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore"))
am := accounts.NewManager(ks)
ethereum, err := eth.New(&eth.Config{
NodeKey: testNodeKey,
DataDir: tmp,
AccountManager: am,
MaxPeers: 0,
Expand Down Expand Up @@ -122,7 +124,7 @@ func TestNodeInfo(t *testing.T) {
}
defer ethereum.Stop()
defer os.RemoveAll(tmp)
want := `{"DiscPort":0,"IP":"0.0.0.0","ListenAddr":"","Name":"test","NodeID":"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","NodeUrl":"enode://00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000@0.0.0.0:0","TCPPort":0,"Td":"0"}`
want := `{"DiscPort":0,"IP":"0.0.0.0","ListenAddr":"","Name":"test","NodeID":"4cb2fc32924e94277bf94b5e4c983beedb2eabd5a0bc941db32202735c6625d020ca14a5963d1738af43b6ac0a711d61b1a06de931a499fe2aa0b1a132a902b5","NodeUrl":"enode://4cb2fc32924e94277bf94b5e4c983beedb2eabd5a0bc941db32202735c6625d020ca14a5963d1738af43b6ac0a711d61b1a06de931a499fe2aa0b1a132a902b5@0.0.0.0:0","TCPPort":0,"Td":"131072"}`
checkEvalJSON(t, repl, `admin.nodeInfo()`, want)
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import _ "net/http/pprof"

const (
ClientIdentifier = "Geth"
Version = "0.9.24"
Version = "0.9.25"
)

var (
Expand Down Expand Up @@ -260,6 +260,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.AutoDAGFlag,
utils.NATFlag,
utils.NatspecEnabledFlag,
utils.NoDiscoverFlag,
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
utils.RPCEnabledFlag,
Expand Down Expand Up @@ -532,9 +533,9 @@ func importchain(ctx *cli.Context) {
}

// force database flush
ethereum.BlockDb().Close()
ethereum.StateDb().Close()
ethereum.ExtraDb().Close()
ethereum.BlockDb().Flush()
ethereum.StateDb().Flush()
ethereum.ExtraDb().Flush()

fmt.Printf("Import done in %v", time.Since(start))

Expand Down Expand Up @@ -629,9 +630,9 @@ func upgradeDb(ctx *cli.Context) {
}

// force database flush
ethereum.BlockDb().Close()
ethereum.StateDb().Close()
ethereum.ExtraDb().Close()
ethereum.BlockDb().Flush()
ethereum.StateDb().Flush()
ethereum.ExtraDb().Flush()

os.Remove(exportFile)

Expand Down
6 changes: 5 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ var (
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
Value: "any",
}
NoDiscoverFlag = cli.BoolFlag{
Name: "nodiscover",
Usage: "Disables the peer discovery mechanism (manual peer addition)",
}
WhisperEnabledFlag = cli.BoolFlag{
Name: "shh",
Usage: "Enable whisper",
Expand Down Expand Up @@ -312,6 +316,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
Port: ctx.GlobalString(ListenPortFlag.Name),
NAT: GetNAT(ctx),
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
NodeKey: GetNodeKey(ctx),
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
Dial: true,
Expand All @@ -320,7 +325,6 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
}

}

func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
Expand Down
2 changes: 2 additions & 0 deletions common/compiler/solidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
"file", //
"--natspec-dev", // Request to output the contract's Natspec developer documentation.
"file",
"--add-std",
"1",
}
)

Expand Down
7 changes: 5 additions & 2 deletions core/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
const (
// must be bumped when consensus algorithm is changed, this forces the upgradedb
// command to be run (forces the blocks to be imported again using the new algorithm)
BlockChainVersion = 2
BlockChainVersion = 3
)

var receiptsPre = []byte("receipts-")
Expand Down Expand Up @@ -159,6 +159,9 @@ func (sm *BlockProcessor) RetryProcess(block *types.Block) (logs state.Logs, err
return nil, ParentError(header.ParentHash)
}
parent := sm.bc.GetBlock(header.ParentHash)
if !sm.Pow.Verify(block) {
return nil, ValidationError("Block's nonce is invalid (= %x)", block.Nonce)
}

return sm.processWithParent(block, parent)
}
Expand Down Expand Up @@ -299,7 +302,7 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow b
a := new(big.Int).Sub(block.GasLimit, parent.GasLimit)
a.Abs(a)
b := new(big.Int).Div(parent.GasLimit, params.GasLimitBoundDivisor)
if !(a.Cmp(b) < 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) {
if !(a.Cmp(b) <= 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) {
return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b)
}

Expand Down
2 changes: 1 addition & 1 deletion core/chain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ out:

func blockErr(block *types.Block, err error) {
h := block.Header()
glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes())
glog.V(logger.Error).Infof("Bad block #%v (%x)\n", h.Number, h.Hash().Bytes())
glog.V(logger.Error).Infoln(err)
glog.V(logger.Debug).Infoln(block)
}
Expand Down
5 changes: 5 additions & 0 deletions core/transaction_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value")
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
ErrGasLimit = errors.New("Exceeds block gas limit")
ErrNegativeValue = errors.New("Negative value")
)

const txPoolQueueSize = 50
Expand Down Expand Up @@ -125,6 +126,10 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return ErrGasLimit
}

if tx.Amount.Cmp(common.Big0) < 0 {
return ErrNegativeValue
}

total := new(big.Int).Mul(tx.Price, tx.GasLimit)
total.Add(total, tx.Value())
if pool.currentState().GetBalance(from).Cmp(total) < 0 {
Expand Down
14 changes: 14 additions & 0 deletions core/transaction_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,17 @@ func TestRemoveTx(t *testing.T) {
t.Error("expected txs to be 0, got", len(pool.txs))
}
}

func TestNegativeValue(t *testing.T) {
pool, key := setupTxPool()

tx := transaction()
tx.Value().Set(big.NewInt(-1))
tx.SignECDSA(key)
from, _ := tx.From()
pool.currentState().AddBalance(from, big.NewInt(1))
err := pool.Add(tx)
if err != ErrNegativeValue {
t.Error("expected", ErrNegativeValue, "got", err)
}
}
Loading

0 comments on commit 7086790

Please sign in to comment.