Skip to content

Commit

Permalink
Merge pull request #9 from coinbase/patrick/fix-circle
Browse files Browse the repository at this point in the history
[BUG] Fix CircleCI Builds
  • Loading branch information
patrick-ogrady authored Sep 18, 2020
2 parents 6663cc0 + 0356f8e commit d1fd7ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ executors:
docker:
- image: circleci/golang:1.13
user: root # go directory is owned by root
working_directory: /go/src/github.com/coinbase/rosetta-sdk-go
working_directory: /go/src/github.com/coinbase/rosetta-bitcoin
environment:
- GO111MODULE: "on"

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ADDLICENCE_SCRIPT=${ADDLICENSE_CMD} -c "Coinbase, Inc." -l "apache" -v
SPELLCHECK_CMD=go run github.com/client9/misspell/cmd/misspell
GOLINES_CMD=go run github.com/segmentio/golines
GOLINT_CMD=go run golang.org/x/lint/golint
GOVERALLS_CMD=go run github.com/mattn/goveralls
GOIMPORTS_CMD=go run golang.org/x/tools/cmd/goimports
GO_PACKAGES=./services/... ./indexer/... ./bitcoin/... ./configuration/...
GO_FOLDERS=$(shell echo ${GO_PACKAGES} | sed -e "s/\.\///g" | sed -e "s/\/\.\.\.//g")
Expand Down
20 changes: 15 additions & 5 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
)

const (
// DefaultIndexCacheSize is the default size of the indexer cache. The larger
// the index cache size, the better the performance.
DefaultIndexCacheSize = 5 << 30 // 5 GB

// indexPlaceholder is provided to the syncer
// to indicate we should both start from the
// last synced block and that we should sync
Expand All @@ -52,10 +56,9 @@ const (
// block fetched by the indexer.
sizeMultiplier = 15

// BadgerDB options overrides
// Other BadgerDB options overrides
defaultBlockSize = 1 << 20 // use large blocks so less table indexes (1 MB)
defaultValueThreshold = 0 // put almost everything in value logs (only use table for key)
defaultIndexCacheSize = 5 << 30 // 5 GB
)

var (
Expand Down Expand Up @@ -117,11 +120,14 @@ func (i *Indexer) CloseDatabase(ctx context.Context) {
// the Badger default so we have a lot less indexes to store. We also
// ensure all values are stored in value log files (as to minimize
// table bloat at the cost of some performance).
func defaultBadgerOptions(path string) badger.Options {
func defaultBadgerOptions(
path string,
indexCacheSize int64,
) badger.Options {
defaultOps := storage.DefaultBadgerOptions(path)
defaultOps.BlockSize = defaultBlockSize
defaultOps.ValueThreshold = defaultValueThreshold
defaultOps.IndexCacheSize = defaultIndexCacheSize
defaultOps.IndexCacheSize = indexCacheSize

return defaultOps
}
Expand All @@ -132,12 +138,16 @@ func Initialize(
cancel context.CancelFunc,
config *configuration.Configuration,
client Client,
indexCacheSize int64,
) (*Indexer, error) {
localStore, err := storage.NewBadgerStorage(
ctx,
config.IndexerPath,
storage.WithCompressorEntries(config.Compressors),
storage.WithCustomSettings(defaultBadgerOptions(config.IndexerPath)),
storage.WithCustomSettings(defaultBadgerOptions(
config.IndexerPath,
indexCacheSize,
)),
)
if err != nil {
return nil, fmt.Errorf("%w: unable to initialize storage", err)
Expand Down
8 changes: 4 additions & 4 deletions indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestIndexer_Pruning(t *testing.T) {
IndexerPath: newDir,
}

i, err := Initialize(ctx, cancel, cfg, mockClient)
i, err := Initialize(ctx, cancel, cfg, mockClient, storage.TinyIndexCacheSize)
assert.NoError(t, err)

// Waiting for bitcoind...
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestIndexer_Transactions(t *testing.T) {
IndexerPath: newDir,
}

i, err := Initialize(ctx, cancel, cfg, mockClient)
i, err := Initialize(ctx, cancel, cfg, mockClient, storage.TinyIndexCacheSize)
assert.NoError(t, err)

// Sync to 1000
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestIndexer_Reorg(t *testing.T) {
IndexerPath: newDir,
}

i, err := Initialize(ctx, cancel, cfg, mockClient)
i, err := Initialize(ctx, cancel, cfg, mockClient, storage.TinyIndexCacheSize)
assert.NoError(t, err)

// Sync to 1000
Expand Down Expand Up @@ -692,7 +692,7 @@ func TestIndexer_HeaderReorg(t *testing.T) {
IndexerPath: newDir,
}

i, err := Initialize(ctx, cancel, cfg, mockClient)
i, err := Initialize(ctx, cancel, cfg, mockClient, storage.TinyIndexCacheSize)
assert.NoError(t, err)

// Sync to 1000
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ func startOnlineDependencies(
return bitcoin.StartBitcoind(ctx, cfg.ConfigPath, g)
})

i, err := indexer.Initialize(ctx, cancel, cfg, client)
i, err := indexer.Initialize(
ctx,
cancel,
cfg,
client,
indexer.DefaultIndexCacheSize,
)
if err != nil {
return nil, nil, fmt.Errorf("%w: unable to initialize indexer", err)
}
Expand Down

0 comments on commit d1fd7ed

Please sign in to comment.