Merge pull request #82 from vulcanize/fixup-transactions-syncing

Don't lookup transactions if no log events
This commit is contained in:
Rob Mulholand 2019-04-18 10:11:45 -05:00 committed by GitHub
commit 9c06e9387c
3 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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,
@ -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))
@ -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())
@ -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))

View File

@ -18,7 +18,6 @@ package geth
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum"
"math/big"
"strconv"
@ -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
}