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

Commit

Permalink
Merge pull request #82 from vulcanize/fixup-transactions-syncing
Browse files Browse the repository at this point in the history
Don't lookup transactions if no log events
  • Loading branch information
rmulhol authored Apr 18, 2019
2 parents 13cd712 + 3fd6269 commit 9c06e93
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions libraries/shared/transactions/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func NewTransactionsSyncer(db *postgres.DB, blockChain core.BlockChain) Transact

func (syncer TransactionsSyncer) SyncTransactions(headerID int64, logs []types.Log) error {
transactionHashes := getUniqueTransactionHashes(logs)
if len(transactionHashes) < 1 {
return nil
}
transactions, transactionErr := syncer.BlockChain.GetTransactions(transactionHashes)
if transactionErr != nil {
return transactionErr
Expand Down
15 changes: 11 additions & 4 deletions libraries/shared/transactions/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ var _ = Describe("Transaction syncer", func() {
})

It("fetches transactions for logs", func() {
err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).NotTo(HaveOccurred())
Expect(blockChain.GetTransactionsCalled).To(BeTrue())
})

It("does not fetch transactions if no logs", func() {
err := syncer.SyncTransactions(0, []types.Log{})

Expect(err).NotTo(HaveOccurred())
Expect(blockChain.GetTransactionsCalled).To(BeFalse())
})

It("only fetches transactions with unique hashes", func() {
err := syncer.SyncTransactions(0, []types.Log{{
TxHash: fakes.FakeHash,
Expand All @@ -44,7 +51,7 @@ var _ = Describe("Transaction syncer", func() {
It("returns error if fetching transactions fails", func() {
blockChain.GetTransactionsError = fakes.FakeError

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
Expand All @@ -55,7 +62,7 @@ var _ = Describe("Transaction syncer", func() {
mockHeaderRepository := fakes.NewMockHeaderRepository()
syncer.Repository = mockHeaderRepository

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).NotTo(HaveOccurred())
Expect(mockHeaderRepository.CreateTransactionsCalled).To(BeTrue())
Expand All @@ -67,7 +74,7 @@ var _ = Describe("Transaction syncer", func() {
mockHeaderRepository.CreateTransactionsError = fakes.FakeError
syncer.Repository = mockHeaderRepository

err := syncer.SyncTransactions(0, []types.Log{})
err := syncer.SyncTransactions(0, []types.Log{{TxHash: fakes.FakeHash}})

Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
Expand Down
2 changes: 0 additions & 2 deletions pkg/geth/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package geth

import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum"
"math/big"
"strconv"
Expand Down Expand Up @@ -122,7 +121,6 @@ func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) (

rpcErr := blockChain.rpcClient.BatchCall(batch)
if rpcErr != nil {
fmt.Println("rpc err")
return []core.TransactionModel{}, rpcErr
}

Expand Down

0 comments on commit 9c06e93

Please sign in to comment.