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

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
i-norden committed Oct 28, 2019
1 parent cd92056 commit 41ed9a0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 132 deletions.
27 changes: 0 additions & 27 deletions libraries/shared/repository/repository.go

This file was deleted.

67 changes: 0 additions & 67 deletions libraries/shared/repository/repository_test.go

This file was deleted.

27 changes: 6 additions & 21 deletions pkg/contract_watcher/header/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (tr *Transformer) Init() error {
firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock()
if retrieveErr != nil {
if retrieveErr == sql.ErrNoRows {
logrus.Error(retrieveErr)
logrus.Error(fmt.Errorf("error retrieving first block: %s", retrieveErr.Error()))
firstBlock = 0
} else {
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error())
Expand Down Expand Up @@ -252,12 +252,6 @@ func (tr *Transformer) Execute() error {
continue
}

// Sort logs by the contract they belong to
// Start by adding every contract addr to the map
// So that if we don't have any logs for it, it is caught and the header is still marked checked for its events
for _, addr := range tr.contractAddresses {
sortedLogs[addr] = nil
}
for _, log := range allLogs {
addr := strings.ToLower(log.Address.Hex())
sortedLogs[addr] = append(sortedLogs[addr], log)
Expand All @@ -267,14 +261,6 @@ func (tr *Transformer) Execute() error {
for conAddr, logs := range sortedLogs {
con := tr.Contracts[conAddr]
if len(logs) < 1 {
eventIds := make([]string, 0)
for eventName := range con.Events {
eventIds = append(eventIds, strings.ToLower(eventName+"_"+con.Address))
}
markCheckedErr := tr.HeaderRepository.MarkHeaderCheckedForAll(header.Id, eventIds)
if markCheckedErr != nil {
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
}
logrus.Tracef("no logs found for contract %s at block %d, continuing", conAddr, header.BlockNumber)
continue
}
Expand All @@ -290,23 +276,22 @@ func (tr *Transformer) Execute() error {
for eventName, logs := range convertedLogs {
// If logs for this event are empty, mark them checked at this header and continue
if len(logs) < 1 {
eventID := strings.ToLower(eventName + "_" + con.Address)
markCheckedErr := tr.HeaderRepository.MarkHeaderChecked(header.Id, eventID)
if markCheckedErr != nil {
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
}
logrus.Tracef("no logs found for event %s on contract %s at block %d, continuing", eventName, conAddr, header.BlockNumber)
continue
}
// If logs aren't empty, persist them
// Header is marked checked in the transactions
persistErr := tr.EventRepository.PersistLogs(logs, con.Events[eventName], con.Address, con.Name)
if persistErr != nil {
return fmt.Errorf("error persisting logs: %s", persistErr.Error())
}
}
}

markCheckedErr := tr.HeaderRepository.MarkHeaderCheckedForAll(header.Id, tr.eventIds)
if markCheckedErr != nil {
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
}

// Poll contracts at this block height
pollingErr := tr.methodPolling(header, tr.sortedMethodIds)
if pollingErr != nil {
Expand Down
12 changes: 0 additions & 12 deletions pkg/contract_watcher/shared/repository/event_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/hashicorp/golang-lru"
"github.com/sirupsen/logrus"

"github.com/vulcanize/vulcanizedb/libraries/shared/repository"
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/types"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
Expand Down Expand Up @@ -144,17 +143,6 @@ func (r *eventRepository) persistHeaderSyncLogs(logs []types.Log, eventInfo type
}
}

// Mark header as checked for this eventId
eventID := strings.ToLower(eventInfo.Name + "_" + contractAddr)
markCheckedErr := repository.MarkContractWatcherHeaderCheckedInTransaction(logs[0].ID, tx, eventID) // This assumes all logs are from same block
if markCheckedErr != nil {
rollbackErr := tx.Rollback()
if rollbackErr != nil {
logrus.Warnf("error rolling back transaction while marking header checked: %s", rollbackErr.Error())
}
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
}

return tx.Commit()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,6 @@ var _ = Describe("Repository", func() {
Expect(count).To(Equal(2))
})

It("Fails if the persisted event does not have a corresponding eventID column in the checked_headers table", func() {
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
Expect(err).To(HaveOccurred())
})

It("Fails with empty log", func() {
err = dataStore.PersistLogs([]types.Log{}, event, con.Address, con.Name)
Expect(err).To(HaveOccurred())
Expand Down

0 comments on commit 41ed9a0

Please sign in to comment.