Skip to content

Commit 7086790

Browse files
committed
Merge branch 'release/0.9.25'
2 parents ceea1a7 + 2c532a7 commit 7086790

File tree

20 files changed

+361
-242
lines changed

20 files changed

+361
-242
lines changed

cmd/geth/admin.go

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (js *jsre) adminBindings() {
8888
debug.Set("getBlockRlp", js.getBlockRlp)
8989
debug.Set("setHead", js.setHead)
9090
debug.Set("processBlock", js.debugBlock)
91+
debug.Set("seedhash", js.seedHash)
9192
// undocumented temporary
9293
debug.Set("waitForBlocks", js.waitForBlocks)
9394
}
@@ -118,6 +119,27 @@ func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
118119
return block, nil
119120
}
120121

122+
func (js *jsre) seedHash(call otto.FunctionCall) otto.Value {
123+
if len(call.ArgumentList) > 0 {
124+
if call.Argument(0).IsNumber() {
125+
num, _ := call.Argument(0).ToInteger()
126+
hash, err := ethash.GetSeedHash(uint64(num))
127+
if err != nil {
128+
fmt.Println(err)
129+
return otto.UndefinedValue()
130+
}
131+
v, _ := call.Otto.ToValue(fmt.Sprintf("0x%x", hash))
132+
return v
133+
} else {
134+
fmt.Println("arg not a number")
135+
}
136+
} else {
137+
fmt.Println("requires number argument")
138+
}
139+
140+
return otto.UndefinedValue()
141+
}
142+
121143
func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
122144
txs := js.ethereum.TxPool().GetTransactions()
123145

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

147-
return js.re.ToVal(ltxs)
169+
v, _ := call.Otto.ToValue(ltxs)
170+
return v
148171
}
149172

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

178-
return js.re.ToVal(ret)
201+
v, _ := call.Otto.ToValue(ret)
202+
return v
179203
}
180204

181205
fmt.Println("first argument must be a transaction")
@@ -198,12 +222,13 @@ func (js *jsre) sign(call otto.FunctionCall) otto.Value {
198222
fmt.Println(err)
199223
return otto.UndefinedValue()
200224
}
201-
v, err := js.xeth.Sign(signer, data, false)
225+
signed, err := js.xeth.Sign(signer, data, false)
202226
if err != nil {
203227
fmt.Println(err)
204228
return otto.UndefinedValue()
205229
}
206-
return js.re.ToVal(v)
230+
v, _ := call.Otto.ToValue(signed)
231+
return v
207232
}
208233

209234
func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
@@ -217,10 +242,11 @@ func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
217242
vm.Debug = true
218243
_, err = js.ethereum.BlockProcessor().RetryProcess(block)
219244
if err != nil {
220-
glog.Infoln(err)
245+
fmt.Println(err)
221246
}
222247
vm.Debug = old
223248

249+
fmt.Println("ok")
224250
return otto.UndefinedValue()
225251
}
226252

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

238264
func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
239265
current, max := js.ethereum.Downloader().Stats()
240-
241-
return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
266+
v, _ := call.Otto.ToValue(fmt.Sprintf("%d/%d", current, max))
267+
return v
242268
}
243269

244270
func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
@@ -248,7 +274,8 @@ func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
248274
return otto.UndefinedValue()
249275
}
250276
encoded, _ := rlp.EncodeToBytes(block)
251-
return js.re.ToVal(fmt.Sprintf("%x", encoded))
277+
v, _ := call.Otto.ToValue(fmt.Sprintf("%x", encoded))
278+
return v
252279
}
253280

254281
func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {
@@ -278,8 +305,9 @@ func (js *jsre) setGasPrice(call otto.FunctionCall) otto.Value {
278305
return otto.UndefinedValue()
279306
}
280307

281-
func (js *jsre) hashrate(otto.FunctionCall) otto.Value {
282-
return js.re.ToVal(js.ethereum.Miner().HashRate())
308+
func (js *jsre) hashrate(call otto.FunctionCall) otto.Value {
309+
v, _ := call.Otto.ToValue(js.ethereum.Miner().HashRate())
310+
return v
283311
}
284312

285313
func (js *jsre) makeDAG(call otto.FunctionCall) otto.Value {
@@ -495,15 +523,18 @@ func (js *jsre) newAccount(call otto.FunctionCall) otto.Value {
495523
fmt.Printf("Could not create the account: %v", err)
496524
return otto.UndefinedValue()
497525
}
498-
return js.re.ToVal(acct.Address.Hex())
526+
v, _ := call.Otto.ToValue(acct.Address.Hex())
527+
return v
499528
}
500529

501530
func (js *jsre) nodeInfo(call otto.FunctionCall) otto.Value {
502-
return js.re.ToVal(js.ethereum.NodeInfo())
531+
v, _ := call.Otto.ToValue(js.ethereum.NodeInfo())
532+
return v
503533
}
504534

505535
func (js *jsre) peers(call otto.FunctionCall) otto.Value {
506-
return js.re.ToVal(js.ethereum.PeersInfo())
536+
v, _ := call.Otto.ToValue(js.ethereum.PeersInfo())
537+
return v
507538
}
508539

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

563594
statedb := state.New(block.Root(), js.ethereum.StateDb())
564595
dump := statedb.RawDump()
565-
return js.re.ToVal(dump)
596+
v, _ := call.Otto.ToValue(dump)
597+
return v
566598
}
567599

568600
func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
@@ -611,7 +643,8 @@ func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
611643
return otto.UndefinedValue()
612644
case height = <-wait:
613645
}
614-
return js.re.ToVal(height.Uint64())
646+
v, _ := call.Otto.ToValue(height.Uint64())
647+
return v
615648
}
616649

617650
func (js *jsre) sleep(call otto.FunctionCall) otto.Value {
@@ -704,8 +737,8 @@ func (js *jsre) register(call otto.FunctionCall) otto.Value {
704737
return otto.UndefinedValue()
705738
}
706739

707-
return js.re.ToVal(contenthash.Hex())
708-
740+
v, _ := call.Otto.ToValue(contenthash.Hex())
741+
return v
709742
}
710743

711744
func (js *jsre) registerUrl(call otto.FunctionCall) otto.Value {
@@ -764,7 +797,8 @@ func (js *jsre) getContractInfo(call otto.FunctionCall) otto.Value {
764797
fmt.Println(err)
765798
return otto.UndefinedValue()
766799
}
767-
return js.re.ToVal(info)
800+
v, _ := call.Otto.ToValue(info)
801+
return v
768802
}
769803

770804
func (js *jsre) startNatSpec(call otto.FunctionCall) otto.Value {

cmd/geth/js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
104104
func (js *jsre) apiBindings(f xeth.Frontend) {
105105
xe := xeth.New(js.ethereum, f)
106106
ethApi := rpc.NewEthereumApi(xe)
107-
jeth := rpc.NewJeth(ethApi, js.re.ToVal, js.re)
107+
jeth := rpc.NewJeth(ethApi, js.re)
108108

109109
js.re.Set("jeth", struct{}{})
110110
t, _ := js.re.Get("jeth")

cmd/geth/js_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535

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

@@ -72,6 +73,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) {
7273
ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore"))
7374
am := accounts.NewManager(ks)
7475
ethereum, err := eth.New(&eth.Config{
76+
NodeKey: testNodeKey,
7577
DataDir: tmp,
7678
AccountManager: am,
7779
MaxPeers: 0,
@@ -122,7 +124,7 @@ func TestNodeInfo(t *testing.T) {
122124
}
123125
defer ethereum.Stop()
124126
defer os.RemoveAll(tmp)
125-
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"}`
127+
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"}`
126128
checkEvalJSON(t, repl, `admin.nodeInfo()`, want)
127129
}
128130

cmd/geth/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import _ "net/http/pprof"
4848

4949
const (
5050
ClientIdentifier = "Geth"
51-
Version = "0.9.24"
51+
Version = "0.9.25"
5252
)
5353

5454
var (
@@ -260,6 +260,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
260260
utils.AutoDAGFlag,
261261
utils.NATFlag,
262262
utils.NatspecEnabledFlag,
263+
utils.NoDiscoverFlag,
263264
utils.NodeKeyFileFlag,
264265
utils.NodeKeyHexFlag,
265266
utils.RPCEnabledFlag,
@@ -532,9 +533,9 @@ func importchain(ctx *cli.Context) {
532533
}
533534

534535
// force database flush
535-
ethereum.BlockDb().Close()
536-
ethereum.StateDb().Close()
537-
ethereum.ExtraDb().Close()
536+
ethereum.BlockDb().Flush()
537+
ethereum.StateDb().Flush()
538+
ethereum.ExtraDb().Flush()
538539

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

@@ -629,9 +630,9 @@ func upgradeDb(ctx *cli.Context) {
629630
}
630631

631632
// force database flush
632-
ethereum.BlockDb().Close()
633-
ethereum.StateDb().Close()
634-
ethereum.ExtraDb().Close()
633+
ethereum.BlockDb().Flush()
634+
ethereum.StateDb().Flush()
635+
ethereum.ExtraDb().Flush()
635636

636637
os.Remove(exportFile)
637638

cmd/utils/flags.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ var (
235235
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
236236
Value: "any",
237237
}
238+
NoDiscoverFlag = cli.BoolFlag{
239+
Name: "nodiscover",
240+
Usage: "Disables the peer discovery mechanism (manual peer addition)",
241+
}
238242
WhisperEnabledFlag = cli.BoolFlag{
239243
Name: "shh",
240244
Usage: "Enable whisper",
@@ -312,6 +316,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
312316
Port: ctx.GlobalString(ListenPortFlag.Name),
313317
NAT: GetNAT(ctx),
314318
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
319+
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
315320
NodeKey: GetNodeKey(ctx),
316321
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
317322
Dial: true,
@@ -320,7 +325,6 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
320325
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
321326
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
322327
}
323-
324328
}
325329

326330
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {

common/compiler/solidity.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var (
3434
"file", //
3535
"--natspec-dev", // Request to output the contract's Natspec developer documentation.
3636
"file",
37+
"--add-std",
38+
"1",
3739
}
3840
)
3941

core/block_processor.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
const (
2222
// must be bumped when consensus algorithm is changed, this forces the upgradedb
2323
// command to be run (forces the blocks to be imported again using the new algorithm)
24-
BlockChainVersion = 2
24+
BlockChainVersion = 3
2525
)
2626

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

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

core/chain_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ out:
750750

751751
func blockErr(block *types.Block, err error) {
752752
h := block.Header()
753-
glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes())
753+
glog.V(logger.Error).Infof("Bad block #%v (%x)\n", h.Number, h.Hash().Bytes())
754754
glog.V(logger.Error).Infoln(err)
755755
glog.V(logger.Debug).Infoln(block)
756756
}

core/transaction_pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value")
2626
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
2727
ErrGasLimit = errors.New("Exceeds block gas limit")
28+
ErrNegativeValue = errors.New("Negative value")
2829
)
2930

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

129+
if tx.Amount.Cmp(common.Big0) < 0 {
130+
return ErrNegativeValue
131+
}
132+
128133
total := new(big.Int).Mul(tx.Price, tx.GasLimit)
129134
total.Add(total, tx.Value())
130135
if pool.currentState().GetBalance(from).Cmp(total) < 0 {

core/transaction_pool_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ func TestRemoveTx(t *testing.T) {
138138
t.Error("expected txs to be 0, got", len(pool.txs))
139139
}
140140
}
141+
142+
func TestNegativeValue(t *testing.T) {
143+
pool, key := setupTxPool()
144+
145+
tx := transaction()
146+
tx.Value().Set(big.NewInt(-1))
147+
tx.SignECDSA(key)
148+
from, _ := tx.From()
149+
pool.currentState().AddBalance(from, big.NewInt(1))
150+
err := pool.Add(tx)
151+
if err != ErrNegativeValue {
152+
t.Error("expected", ErrNegativeValue, "got", err)
153+
}
154+
}

0 commit comments

Comments
 (0)