@@ -18,10 +18,12 @@ package transformer
18
18
19
19
import (
20
20
"errors"
21
+ "fmt"
21
22
"strings"
22
23
23
24
"github.com/ethereum/go-ethereum/common"
24
25
gethTypes "github.com/ethereum/go-ethereum/core/types"
26
+ "github.com/sirupsen/logrus"
25
27
26
28
"github.com/vulcanize/vulcanizedb/pkg/config"
27
29
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/header/converter"
@@ -107,22 +109,22 @@ func (tr *Transformer) Init() error {
107
109
// Configure Abi
108
110
if tr .Config .Abis [contractAddr ] == "" {
109
111
// If no abi is given in the config, this method will try fetching from internal look-up table and etherscan
110
- err := tr .Parser .Parse (contractAddr )
111
- if err != nil {
112
- return err
112
+ parseErr := tr .Parser .Parse (contractAddr )
113
+ if parseErr != nil {
114
+ return fmt . Errorf ( "error parsing contract by address: %s" , parseErr . Error ())
113
115
}
114
116
} else {
115
117
// If we have an abi from the config, load that into the parser
116
- err := tr .Parser .ParseAbiStr (tr .Config .Abis [contractAddr ])
117
- if err != nil {
118
- return err
118
+ parseErr := tr .Parser .ParseAbiStr (tr .Config .Abis [contractAddr ])
119
+ if parseErr != nil {
120
+ return fmt . Errorf ( "error parsing contract abi: %s" , parseErr . Error ())
119
121
}
120
122
}
121
123
122
124
// Get first block and most recent block number in the header repo
123
- firstBlock , err := tr .Retriever .RetrieveFirstBlock ()
124
- if err != nil {
125
- return err
125
+ firstBlock , retrieveErr := tr .Retriever .RetrieveFirstBlock ()
126
+ if retrieveErr != nil {
127
+ return fmt . Errorf ( "error retrieving first block: %s" , retrieveErr . Error ())
126
128
}
127
129
128
130
// Set to specified range if it falls within the bounds
@@ -132,7 +134,11 @@ func (tr *Transformer) Init() error {
132
134
133
135
// Get contract name if it has one
134
136
var name = new (string )
135
- tr .Poller .FetchContractData (tr .Parser .Abi (), contractAddr , "name" , nil , name , - 1 )
137
+ pollingErr := tr .Poller .FetchContractData (tr .Parser .Abi (), contractAddr , "name" , nil , name , - 1 )
138
+ if pollingErr != nil {
139
+ // can't return this error because "name" might not exist on the contract
140
+ logrus .Warnf ("error fetching contract data: %s" , pollingErr .Error ())
141
+ }
136
142
137
143
// Remove any potential accidental duplicate inputs
138
144
eventArgs := map [string ]bool {}
@@ -165,9 +171,9 @@ func (tr *Transformer) Init() error {
165
171
tr .sortedEventIds [con .Address ] = make ([]string , 0 , len (con .Events ))
166
172
for _ , event := range con .Events {
167
173
eventId := strings .ToLower (event .Name + "_" + con .Address )
168
- err := tr .HeaderRepository .AddCheckColumn (eventId )
169
- if err != nil {
170
- return err
174
+ addColumnErr := tr .HeaderRepository .AddCheckColumn (eventId )
175
+ if addColumnErr != nil {
176
+ return fmt . Errorf ( "error adding check column: %s" , addColumnErr . Error ())
171
177
}
172
178
// Keep track of this event id; sorted and unsorted
173
179
tr .sortedEventIds [con .Address ] = append (tr .sortedEventIds [con .Address ], eventId )
@@ -180,9 +186,9 @@ func (tr *Transformer) Init() error {
180
186
tr .sortedMethodIds [con .Address ] = make ([]string , 0 , len (con .Methods ))
181
187
for _ , m := range con .Methods {
182
188
methodId := strings .ToLower (m .Name + "_" + con .Address )
183
- err := tr .HeaderRepository .AddCheckColumn (methodId )
184
- if err != nil {
185
- return err
189
+ addColumnErr := tr .HeaderRepository .AddCheckColumn (methodId )
190
+ if addColumnErr != nil {
191
+ return fmt . Errorf ( "error adding check column: %s" , addColumnErr . Error ())
186
192
}
187
193
tr .sortedMethodIds [con .Address ] = append (tr .sortedMethodIds [con .Address ], methodId )
188
194
}
@@ -202,9 +208,9 @@ func (tr *Transformer) Execute() error {
202
208
}
203
209
204
210
// Find unchecked headers for all events across all contracts; these are returned in asc order
205
- missingHeaders , err := tr .HeaderRepository .MissingHeadersForAll (tr .Start , - 1 , tr .eventIds )
206
- if err != nil {
207
- return err
211
+ missingHeaders , missingHeadersErr := tr .HeaderRepository .MissingHeadersForAll (tr .Start , - 1 , tr .eventIds )
212
+ if missingHeadersErr != nil {
213
+ return fmt . Errorf ( "error getting missing headers: %s" , missingHeadersErr . Error ())
208
214
}
209
215
210
216
// Iterate over headers
@@ -216,23 +222,24 @@ func (tr *Transformer) Execute() error {
216
222
// Map to sort batch fetched logs by which contract they belong to, for post fetch processing
217
223
sortedLogs := make (map [string ][]gethTypes.Log )
218
224
// And fetch all event logs across contracts at this header
219
- allLogs , err := tr .Fetcher .FetchLogs (tr .contractAddresses , tr .eventFilters , header )
220
- if err != nil {
221
- return err
225
+ allLogs , fetchErr := tr .Fetcher .FetchLogs (tr .contractAddresses , tr .eventFilters , header )
226
+ if fetchErr != nil {
227
+ return fmt . Errorf ( "error fetching logs: %s" , fetchErr . Error ())
222
228
}
223
229
224
230
// If no logs are found mark the header checked for all of these eventIDs
225
231
// and continue to method polling and onto the next iteration
226
232
if len (allLogs ) < 1 {
227
- err = tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , tr .eventIds )
228
- if err != nil {
229
- return err
233
+ markCheckedErr : = tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , tr .eventIds )
234
+ if markCheckedErr != nil {
235
+ return fmt . Errorf ( "error marking header checked: %s" , markCheckedErr . Error ())
230
236
}
231
- err = tr .methodPolling (header , tr .sortedMethodIds )
232
- if err != nil {
233
- return err
237
+ pollingErr : = tr .methodPolling (header , tr .sortedMethodIds )
238
+ if pollingErr != nil {
239
+ return fmt . Errorf ( "error polling methods: %s" , pollingErr . Error ())
234
240
}
235
241
tr .Start = header .BlockNumber + 1 // Empty header; setup to start at the next header
242
+ logrus .Tracef ("no logs found for block %d, continuing" , header .BlockNumber )
236
243
continue
237
244
}
238
245
@@ -245,41 +252,43 @@ func (tr *Transformer) Execute() error {
245
252
// Process logs for each contract
246
253
for conAddr , logs := range sortedLogs {
247
254
if logs == nil {
255
+ logrus .Tracef ("no logs found for contract %s at block %d, continuing" , conAddr , header .BlockNumber )
248
256
continue
249
257
}
250
258
// Configure converter with this contract
251
259
con := tr .Contracts [conAddr ]
252
260
tr .Converter .Update (con )
253
261
254
262
// Convert logs into batches of log mappings (eventName => []types.Logs
255
- convertedLogs , err := tr .Converter .ConvertBatch (logs , con .Events , header .Id )
256
- if err != nil {
257
- return err
263
+ convertedLogs , convertErr := tr .Converter .ConvertBatch (logs , con .Events , header .Id )
264
+ if convertErr != nil {
265
+ return fmt . Errorf ( "error converting logs: %s" , convertErr . Error ())
258
266
}
259
267
// Cycle through each type of event log and persist them
260
268
for eventName , logs := range convertedLogs {
261
269
// If logs for this event are empty, mark them checked at this header and continue
262
270
if len (logs ) < 1 {
263
271
eventId := strings .ToLower (eventName + "_" + con .Address )
264
- err = tr .HeaderRepository .MarkHeaderChecked (header .Id , eventId )
265
- if err != nil {
266
- return err
272
+ markCheckedErr : = tr .HeaderRepository .MarkHeaderChecked (header .Id , eventId )
273
+ if markCheckedErr != nil {
274
+ return fmt . Errorf ( "error marking header checked: %s" , markCheckedErr . Error ())
267
275
}
276
+ logrus .Tracef ("no logs found for event %s on contract %s at block %d, continuing" , eventName , conAddr , header .BlockNumber )
268
277
continue
269
278
}
270
279
// If logs aren't empty, persist them
271
280
// Header is marked checked in the transactions
272
- err = tr .EventRepository .PersistLogs (logs , con .Events [eventName ], con .Address , con .Name )
273
- if err != nil {
274
- return err
281
+ persistErr : = tr .EventRepository .PersistLogs (logs , con .Events [eventName ], con .Address , con .Name )
282
+ if persistErr != nil {
283
+ return fmt . Errorf ( "error persisting logs: %s" , persistErr . Error ())
275
284
}
276
285
}
277
286
}
278
287
279
288
// Poll contracts at this block height
280
- err = tr .methodPolling (header , tr .sortedMethodIds )
281
- if err != nil {
282
- return err
289
+ pollingErr : = tr .methodPolling (header , tr .sortedMethodIds )
290
+ if pollingErr != nil {
291
+ return fmt . Errorf ( "error polling methods: %s" , pollingErr . Error ())
283
292
}
284
293
// Success; setup to start at the next header
285
294
tr .Start = header .BlockNumber + 1
@@ -294,19 +303,20 @@ func (tr *Transformer) methodPolling(header core.Header, sortedMethodIds map[str
294
303
// Skip method polling processes if no methods are specified
295
304
// Also don't try to poll methods below this contract's specified starting block
296
305
if len (con .Methods ) == 0 || header .BlockNumber < con .StartingBlock {
306
+ logrus .Tracef ("not polling contract: %s" , con .Address )
297
307
continue
298
308
}
299
309
300
310
// Poll all methods for this contract at this header
301
- err := tr .Poller .PollContractAt (* con , header .BlockNumber )
302
- if err != nil {
303
- return err
311
+ pollingErr := tr .Poller .PollContractAt (* con , header .BlockNumber )
312
+ if pollingErr != nil {
313
+ return fmt . Errorf ( "error polling contract %s: %s" , con . Address , pollingErr . Error ())
304
314
}
305
315
306
316
// Mark this header checked for the methods
307
- err = tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , sortedMethodIds [con .Address ])
308
- if err != nil {
309
- return err
317
+ markCheckedErr : = tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , sortedMethodIds [con .Address ])
318
+ if markCheckedErr != nil {
319
+ return fmt . Errorf ( "error marking header checked: %s" , markCheckedErr . Error ())
310
320
}
311
321
}
312
322
0 commit comments