Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Enable contractWatcher without prior headerSync
Browse files Browse the repository at this point in the history
- Previous setup would fail if there were no headers in the db. This
  makes sense because we need headers that haven't been checked for
  logs to exist so that we can fetch logs for those headers. But it
  also prevents us from kicking off the headerSync and contractWatcher
  processes concurrently. These changes enable kicking off both
  processes at the same time with the idea that we will have unchecked
  headers upon transformer execution.
  • Loading branch information
rmulhol committed Oct 4, 2019
1 parent f6ab938 commit d0e33dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/contract_watcher/header/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package transformer

import (
"database/sql"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -124,7 +125,11 @@ func (tr *Transformer) Init() error {
// Get first block and most recent block number in the header repo
firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock()
if retrieveErr != nil {
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error())
if retrieveErr == sql.ErrNoRows {
firstBlock = 0
} else {
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error())
}
}

// Set to specified range if it falls within the bounds
Expand Down
13 changes: 12 additions & 1 deletion pkg/contract_watcher/header/transformer/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package transformer_test

import (
"database/sql"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -101,7 +102,17 @@ var _ = Describe("Transformer", func() {
Expect(c.Address).To(Equal(fakeAddress))
})

It("Fails to initialize if first block cannot be fetched from vDB headers table", func() {
It("uses first block from config if vDB headers table has no rows", func() {
blockRetriever := &fakes.MockHeaderSyncBlockRetriever{}
blockRetriever.FirstBlockErr = sql.ErrNoRows
t := getFakeTransformer(blockRetriever, &fakes.MockParser{}, &fakes.MockPoller{})

err := t.Init()

Expect(err).ToNot(HaveOccurred())
})

It("returns error if fetching first block fails for other reason", func() {
blockRetriever := &fakes.MockHeaderSyncBlockRetriever{}
blockRetriever.FirstBlockErr = fakes.FakeError
t := getFakeTransformer(blockRetriever, &fakes.MockParser{}, &fakes.MockPoller{})
Expand Down

0 comments on commit d0e33dc

Please sign in to comment.