Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #609 from ethereumproject/fix/atxi-interrupt-looping
Browse files Browse the repository at this point in the history
fix atxi.auto-build looping after proc interrupt
  • Loading branch information
whilei authored May 29, 2018
2 parents 4932e71 + 61422e3 commit 4851b12
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 10 additions & 0 deletions cmd/geth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/ethereumproject/go-ethereum/pow"
"github.com/ethereumproject/go-ethereum/rlp"
"gopkg.in/urfave/cli.v1"
"math"
)

const (
Expand Down Expand Up @@ -718,11 +719,20 @@ func startNode(ctx *cli.Context, stack *node.Node) *eth.Ethereum {
}

// Start auxiliary services if enabled
if ctx.GlobalBool(aliasableName(AddrTxIndexFlag.Name, ctx)) && ctx.GlobalBool(aliasableName(AddrTxIndexAutoBuildFlag.Name, ctx)) {
a := ethereum.BlockChain().GetAtxi()
if a == nil {
panic("somehow atxi did not get enabled in backend setup. this is not expected")
}
a.AutoMode = true
go core.BuildAddrTxIndex(ethereum.BlockChain(), ethereum.ChainDb(), a.Db, math.MaxUint64, math.MaxUint64, 10000)
}
if ctx.GlobalBool(aliasableName(MiningEnabledFlag.Name, ctx)) {
if err := ethereum.StartMining(ctx.GlobalInt(aliasableName(MinerThreadsFlag.Name, ctx)), ctx.GlobalString(aliasableName(MiningGPUFlag.Name, ctx))); err != nil {
glog.Fatalf("Failed to start mining: %v", err)
}
}

return ethereum
}

Expand Down
10 changes: 0 additions & 10 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ethereumproject/go-ethereum/eth"
"github.com/ethereumproject/go-ethereum/logger"
"github.com/ethereumproject/go-ethereum/metrics"
"math"
)

// Version is the application revision identifier. It can be set with the linker
Expand Down Expand Up @@ -354,15 +353,6 @@ func geth(ctx *cli.Context) error {
}
logLoggingConfiguration(ctx)

if ctx.GlobalBool(aliasableName(AddrTxIndexFlag.Name, ctx)) && ctx.GlobalBool(aliasableName(AddrTxIndexAutoBuildFlag.Name, ctx)) {
a := ethe.BlockChain().GetAtxi()
if a == nil {
panic("somehow atxi did not get enabled in backend setup. this is not expected")
}
a.AutoMode = true
go core.BuildAddrTxIndex(ethe.BlockChain(), ethe.ChainDb(), a.Db, math.MaxUint64, math.MaxUint64, 10000)
}

n.Wait()

return nil
Expand Down
16 changes: 16 additions & 0 deletions core/atxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"github.com/ethereumproject/go-ethereum/logger"
"github.com/ethereumproject/go-ethereum/logger/glog"
"math"
"os"
"os/signal"
"sort"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -195,7 +198,12 @@ func BuildAddrTxIndex(bc *BlockChain, chainDB, indexDB ethdb.Database, startInde
err := fmt.Errorf("block %d is nil", blockIndex)
bc.atxi.Progress.LastError = err
glog.Error(err)
return err
}
// sigc is a single-val channel for listening to program interrupt
var sigc = make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigc)

startTime := time.Now()
totalTxCount := uint64(0)
Expand Down Expand Up @@ -235,6 +243,14 @@ func BuildAddrTxIndex(bc *BlockChain, chainDB, indexDB ethdb.Database, startInde
glog.D(logger.Error).Infof("atxi-build: block %d / %d txs: %d took: %v %.2f bps %.2f txps", i+step, stopIndex, txsCount, time.Since(stepStartTime).Round(time.Millisecond), float64(step)/time.Since(stepStartTime).Seconds(), float64(txsCount)/time.Since(stepStartTime).Seconds())
glog.V(logger.Info).Infof("atxi-build: block %d / %d txs: %d took: %v %.2f bps %.2f txps", i+step, stopIndex, txsCount, time.Since(stepStartTime).Round(time.Millisecond), float64(step)/time.Since(stepStartTime).Seconds(), float64(txsCount)/time.Since(stepStartTime).Seconds())

// Listen for interrupts, nonblocking
select {
case s := <-sigc:
glog.D(logger.Info).Warnln("atxi build", "got interrupt:", s, "quitting")
return nil
default:
}

if breaker {
break
}
Expand Down

0 comments on commit 4851b12

Please sign in to comment.