Skip to content

Commit

Permalink
Merge pull request ethereum#2 from ethereum/master
Browse files Browse the repository at this point in the history
Latest changes from go-ethereum
  • Loading branch information
AlexeyAkhunov committed Dec 18, 2017
2 parents 8b9e77d + fe070ab commit fc01745
Show file tree
Hide file tree
Showing 44 changed files with 714 additions and 156 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Expand Up @@ -129,7 +129,7 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
return string(code), nil
}
// For all others just return as is for now
return string(buffer.Bytes()), nil
return buffer.String(), nil
}

// bindType is a set of type binders that convert Solidity types to some supported
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/unpack_test.go
Expand Up @@ -368,11 +368,11 @@ func TestUnmarshal(t *testing.T) {
if err != nil {
t.Error(err)
} else {
if bytes.Compare(p0, p0Exp) != 0 {
if !bytes.Equal(p0, p0Exp) {
t.Errorf("unexpected value unpacked: want %x, got %x", p0Exp, p0)
}

if bytes.Compare(p1[:], p1Exp) != 0 {
if !bytes.Equal(p1[:], p1Exp) {
t.Errorf("unexpected value unpacked: want %x, got %x", p1Exp, p1)
}
}
Expand Down
3 changes: 3 additions & 0 deletions accounts/keystore/presale.go
Expand Up @@ -58,6 +58,9 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
if err != nil {
return nil, errors.New("invalid hex in encSeed")
}
if len(encSeedBytes) < 16 {
return nil, errors.New("invalid encSeed, too short")
}
iv := encSeedBytes[:16]
cipherText := encSeedBytes[16:]
/*
Expand Down
3 changes: 1 addition & 2 deletions bmt/bmt.go
Expand Up @@ -260,8 +260,7 @@ func NewTree(hasher BaseHasher, segmentSize, segmentCount int) *Tree {
for d := 1; d <= depth(segmentCount); d++ {
nodes := make([]*Node, count)
for i := 0; i < len(nodes); i++ {
var parent *Node
parent = prevlevel[i/2]
parent := prevlevel[i/2]
t := NewNode(level, i, parent)
nodes[i] = t
}
Expand Down
8 changes: 4 additions & 4 deletions build/ci.go
Expand Up @@ -319,8 +319,8 @@ func doLint(cmdline []string) {
packages = flag.CommandLine.Args()
}
// Get metalinter and install all supported linters
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v1"))
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), "--install")
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v2"))
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), "--install")

// Run fast linters batched together
configs := []string{
Expand All @@ -332,12 +332,12 @@ func doLint(cmdline []string) {
"--enable=goconst",
"--min-occurrences=6", // for goconst
}
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), append(configs, packages...)...)
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)

// Run slow linters one by one
for _, linter := range []string{"unconvert", "gosimple"} {
configs = []string{"--vendor", "--deadline=10m", "--disable-all", "--enable=" + linter}
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), append(configs, packages...)...)
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Expand Up @@ -506,7 +506,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {

// Send an error if too frequent funding, othewise a success
if !fund {
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil {
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil { // nolint: gosimple
log.Warn("Failed to send funding error to client", "err", err)
return
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/geth/consolecmd.go
Expand Up @@ -120,8 +120,12 @@ func remoteConsole(ctx *cli.Context) error {
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
path = ctx.GlobalString(utils.DataDirFlag.Name)
}
if path != "" && ctx.GlobalBool(utils.TestnetFlag.Name) {
path = filepath.Join(path, "testnet")
if path != "" {
if ctx.GlobalBool(utils.TestnetFlag.Name) {
path = filepath.Join(path, "testnet")
} else if ctx.GlobalBool(utils.RinkebyFlag.Name) {
path = filepath.Join(path, "rinkeby")
}
}
endpoint = fmt.Sprintf("%s/geth.ipc", path)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/puppeth/module_dashboard.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/swarm/config.go
Expand Up @@ -267,7 +267,7 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
}

//EnsApi can be set to "", so can't check for empty string, as it is allowed
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists == true {
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists {
currentConfig.EnsApi = ensapi
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/swarm/config_test.go
Expand Up @@ -124,7 +124,7 @@ func TestCmdLineOverrides(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId)
}

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func TestFileOverrides(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
}

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

Expand Down Expand Up @@ -334,7 +334,7 @@ func TestEnvVars(t *testing.T) {
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
}

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

Expand Down Expand Up @@ -431,7 +431,7 @@ func TestCmdLineOverridesFile(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId)
}

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Expand Up @@ -630,7 +630,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch
}
}
// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now())
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
if header.Difficulty.Cmp(diffNoTurn) == 0 {
// It's not our turn explicitly to sign, delay it a bit
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
Expand Down
9 changes: 5 additions & 4 deletions consensus/ethash/consensus.go
Expand Up @@ -36,9 +36,10 @@ import (

// Ethash proof-of-work protocol constants.
var (
FrontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
maxUncles = 2 // Maximum number of uncles allowed in a single block
FrontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
maxUncles = 2 // Maximum number of uncles allowed in a single block
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
)

// Various error messages to mark blocks invalid. These should be private to
Expand Down Expand Up @@ -231,7 +232,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
return errLargeBlockTime
}
} else {
if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 {
if header.Time.Cmp(big.NewInt(time.Now().Add(allowedFutureBlockTime).Unix())) > 0 {
return consensus.ErrFutureBlock
}
}
Expand Down
14 changes: 7 additions & 7 deletions console/console_test.go
Expand Up @@ -164,7 +164,7 @@ func TestWelcome(t *testing.T) {

tester.console.Welcome()

output := string(tester.output.Bytes())
output := tester.output.String()
if want := "Welcome"; !strings.Contains(output, want) {
t.Fatalf("console output missing welcome message: have\n%s\nwant also %s", output, want)
}
Expand All @@ -188,7 +188,7 @@ func TestEvaluate(t *testing.T) {
defer tester.Close(t)

tester.console.Evaluate("2 + 2")
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
if output := tester.output.String(); !strings.Contains(output, "4") {
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestInteractive(t *testing.T) {
case <-time.After(time.Second):
t.Fatalf("secondary prompt timeout")
}
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
if output := tester.output.String(); !strings.Contains(output, "4") {
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
}
}
Expand All @@ -230,7 +230,7 @@ func TestPreload(t *testing.T) {
defer tester.Close(t)

tester.console.Evaluate("preloaded")
if output := string(tester.output.Bytes()); !strings.Contains(output, "some-preloaded-string") {
if output := tester.output.String(); !strings.Contains(output, "some-preloaded-string") {
t.Fatalf("preloaded variable missing: have %s, want %s", output, "some-preloaded-string")
}
}
Expand All @@ -243,7 +243,7 @@ func TestExecute(t *testing.T) {
tester.console.Execute("exec.js")

tester.console.Evaluate("execed")
if output := string(tester.output.Bytes()); !strings.Contains(output, "some-executed-string") {
if output := tester.output.String(); !strings.Contains(output, "some-executed-string") {
t.Fatalf("execed variable missing: have %s, want %s", output, "some-executed-string")
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestPrettyPrint(t *testing.T) {
string: ` + two + `
}
`
if output := string(tester.output.Bytes()); output != want {
if output := tester.output.String(); output != want {
t.Fatalf("pretty print mismatch: have %s, want %s", output, want)
}
}
Expand All @@ -287,7 +287,7 @@ func TestPrettyError(t *testing.T) {
tester.console.Evaluate("throw 'hello'")

want := jsre.ErrorColor("hello") + "\n"
if output := string(tester.output.Bytes()); output != want {
if output := tester.output.String(); output != want {
t.Fatalf("pretty error mismatch: have %s, want %s", output, want)
}
}
Expand Down
5 changes: 1 addition & 4 deletions core/asm/asm.go
Expand Up @@ -114,10 +114,7 @@ func PrintDisassembled(code string) error {
fmt.Printf("%06v: %v\n", it.PC(), it.Op())
}
}
if err := it.Error(); err != nil {
return err
}
return nil
return it.Error()
}

// Return all disassembled EVM instructions in human-readable format.
Expand Down
5 changes: 1 addition & 4 deletions core/asm/compiler.go
Expand Up @@ -237,10 +237,7 @@ func (c *Compiler) pushBin(v interface{}) {
// isPush returns whether the string op is either any of
// push(N).
func isPush(op string) bool {
if op == "push" {
return true
}
return false
return op == "push"
}

// isJump returns whether the string op is jump(i)
Expand Down
1 change: 1 addition & 0 deletions core/genesis_alloc.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions core/vm/evm.go
Expand Up @@ -38,7 +38,7 @@ type (
)

// run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, error) {
func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
if contract.CodeAddr != nil {
precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
Expand All @@ -48,7 +48,7 @@ func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, erro
return RunPrecompiledContract(p, input, contract)
}
}
return evm.interpreter.Run(snapshot, contract, input)
return evm.interpreter.Run(contract, input)
}

// Context provides the EVM with auxiliary information. Once provided
Expand Down Expand Up @@ -171,7 +171,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
contract := NewContract(caller, to, value, gas)
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

ret, err = run(evm, snapshot, contract, input)
ret, err = run(evm, contract, input)
// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors.
Expand Down Expand Up @@ -215,7 +215,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
contract := NewContract(caller, to, value, gas)
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

ret, err = run(evm, snapshot, contract, input)
ret, err = run(evm, contract, input)
if err != nil {
evm.StateDB.RevertToSnapshot(snapshot)
if err != errExecutionReverted {
Expand Down Expand Up @@ -248,7 +248,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
contract := NewContract(caller, to, nil, gas).AsDelegate()
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

ret, err = run(evm, snapshot, contract, input)
ret, err = run(evm, contract, input)
if err != nil {
evm.StateDB.RevertToSnapshot(snapshot)
if err != errExecutionReverted {
Expand Down Expand Up @@ -291,7 +291,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in Homestead this also counts for code storage gas errors.
ret, err = run(evm, snapshot, contract, input)
ret, err = run(evm, contract, input)
if err != nil {
evm.StateDB.RevertToSnapshot(snapshot)
if err != errExecutionReverted {
Expand Down Expand Up @@ -338,7 +338,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
if evm.vmConfig.NoRecursion && evm.depth > 0 {
return nil, contractAddr, gas, nil
}
ret, err = run(evm, snapshot, contract, nil)
ret, err = run(evm, contract, nil)
// check whether the max code size has been exceeded
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
// if the contract creation ran successfully and no errors were returned
Expand Down
6 changes: 3 additions & 3 deletions core/vm/interpreter.go
Expand Up @@ -107,9 +107,9 @@ func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack
// the return byte-slice and an error if one occurred.
//
// It's important to note that any errors returned by the interpreter should be
// considered a revert-and-consume-all-gas operation. No error specific checks
// should be handled to reduce complexity and errors further down the in.
func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret []byte, err error) {
// considered a revert-and-consume-all-gas operation except for
// errExecutionReverted which means revert-and-keep-gas-left.
func (in *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err error) {
// Increment the call depth which is restricted to 1024
in.evm.depth++
defer func() { in.evm.depth-- }()
Expand Down
2 changes: 1 addition & 1 deletion crypto/crypto.go
Expand Up @@ -79,7 +79,7 @@ func ToECDSA(d []byte) (*ecdsa.PrivateKey, error) {
return toECDSA(d, true)
}

// ToECDSAUnsafe blidly converts a binary blob to a private key. It should almost
// ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost
// never be used unless you are sure the input is valid and want to avoid hitting
// errors due to bad origin encoding (0 prefixes cut off).
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey {
Expand Down

0 comments on commit fc01745

Please sign in to comment.