This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathbuild_atxi_cmd.go
70 lines (62 loc) · 2.16 KB
/
build_atxi_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"math"
"github.com/ethereumproject/go-ethereum/core"
"github.com/ethereumproject/go-ethereum/ethdb"
"github.com/ethereumproject/go-ethereum/logger/glog"
"gopkg.in/urfave/cli.v1"
)
var buildAddrTxIndexCommand = cli.Command{
Action: buildAddrTxIndexCmd,
Name: "atxi-build",
Usage: "Generate index for transactions by address",
Description: `
Builds an index for transactions by address.
The command is idempotent; it will not hurt to run multiple times on the same range.
If run without --start flag, the command makes use of a persistent placeholder, so you can
run the command on multiple occasions and pick up indexing progress where the last session
left off.
To enable address-transaction indexing during block sync and import, use the '--atxi' flag.
`,
Flags: []cli.Flag{
cli.IntFlag{
Name: "start",
Usage: "Block number at which to begin building index",
},
cli.IntFlag{
Name: "stop",
Usage: "Block number at which to stop building index",
},
cli.IntFlag{
Name: "step",
Usage: "Step increment for batching. Higher number requires more mem, but may be faster",
Value: 10000,
},
},
}
func buildAddrTxIndexCmd(ctx *cli.Context) error {
// Divide global cache availability equally between chaindata (pre-existing blockdata) and
// address-transaction database. This ratio is arbitrary and could potentially be optimized or delegated to be user configurable.
ethdb.SetCacheRatio("chaindata", 0.5)
ethdb.SetHandleRatio("chaindata", 1)
ethdb.SetCacheRatio("indexes", 0.5)
ethdb.SetHandleRatio("indexes", 1)
var startIndex uint64 = math.MaxUint64
if ctx.IsSet("start") {
startIndex = uint64(ctx.Int("start"))
}
stopIndex := uint64(ctx.Int("stop"))
step := uint64(ctx.Int("step"))
indexDB := MakeIndexDatabase(ctx)
if indexDB == nil {
glog.Fatalln("can't open index database")
}
defer indexDB.Close()
bc, chainDB := MakeChain(ctx)
if bc == nil || chainDB == nil {
glog.Fatalln("can't open chain database")
}
defer chainDB.Close()
bc.SetAtxi(&core.AtxiT{Db: indexDB, AutoMode: false, Progress: &core.AtxiProgressT{}})
return core.BuildAddrTxIndex(bc, chainDB, indexDB, startIndex, stopIndex, step)
}