From 2c092e8d04c991ee08ae0cd191b20c3e19ca5ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20H=C3=BCbinette?= Date: Thu, 18 Jul 2019 09:21:40 +0200 Subject: [PATCH] [VDB-751 VDB-754] Bugfix null pointer panic and improve logging (#119) * VDB-751 VDB-754 Bugfix null pointer panic and improve logging * Fix typo --- Gopkg.lock | 161 +++++++++++++++++++--- cmd/root.go | 8 +- libraries/shared/watcher/event_watcher.go | 9 +- main.go | 5 +- pkg/geth/blockchain.go | 3 + pkg/history/populate_headers.go | 1 - utils/utils.go | 4 +- 7 files changed, 166 insertions(+), 25 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index f600ed35..6446ecbe 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,39 +2,50 @@ [[projects]] + digest = "1:48a213e9dc4880bbbd6999309a476fa4d3cc67560aa7127154cf8ea95bd464c2" name = "github.com/allegro/bigcache" packages = [ ".", - "queue" + "queue", ] + pruneopts = "" revision = "f31987a23e44c5121ef8c8b2f2ea2e8ffa37b068" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:a313376bcbcce8ae8bddb8089a7293e0473a0f8e9e3710d6244e09e81875ccf0" name = "github.com/aristanetworks/goarista" packages = ["monotime"] + pruneopts = "" revision = "ff33da284e760fcdb03c33d37a719e5ed30ba844" [[projects]] branch = "master" + digest = "1:c6bf1ac7bbc0fe51637bf54d5a88ff79b171b3b42dbc665dec98303c862d8662" name = "github.com/btcsuite/btcd" packages = ["btcec"] + pruneopts = "" revision = "cff30e1d23fc9e800b2b5b4b41ef1817dda07e9f" [[projects]] + digest = "1:5d47691333460db6ac83ced03c79b4bdb9aff3e322be24affb7855bed8affc6c" name = "github.com/dave/jennifer" packages = ["jen"] + pruneopts = "" revision = "14e399b6b5e8456c66c45c955fc27b568bacb5c9" version = "v1.3.0" [[projects]] + digest = "1:aaeffbff5bd24654cb4c190ed75d6c7b57b4f5d6741914c1a7a6bb7447e756c5" name = "github.com/deckarep/golang-set" packages = ["."] + pruneopts = "" revision = "cbaa98ba5575e67703b32b4b19f73c91f3c4159e" version = "v1.7.1" [[projects]] + digest = "1:90d36f5b581e95e00ced808cd48824ed6c320c25887828cce461bdef4cb7bc7c" name = "github.com/ethereum/go-ethereum" packages = [ ".", @@ -70,50 +81,64 @@ "params", "rlp", "rpc", - "trie" + "trie", ] + pruneopts = "" revision = "cd79bc61a983d6482579d12cdd239b37bbfa12ef" [[projects]] + digest = "1:eb53021a8aa3f599d29c7102e65026242bdedce998a54837dc67f14b6a97c5fd" name = "github.com/fsnotify/fsnotify" packages = ["."] + pruneopts = "" revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" version = "v1.4.7" [[projects]] + digest = "1:a01080d20c45c031c13f3828c56e58f4f51d926a482ad10cc0316225097eb7ea" name = "github.com/go-stack/stack" packages = ["."] + pruneopts = "" revision = "2fee6af1a9795aafbe0253a0cfbdf668e1fb8a9a" version = "v1.8.0" [[projects]] + digest = "1:3dd078fda7500c341bc26cfbc6c6a34614f295a2457149fc1045cab767cbcf18" name = "github.com/golang/protobuf" packages = ["proto"] + pruneopts = "" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] branch = "master" + digest = "1:2a5888946cdbc8aa360fd43301f9fc7869d663f60d5eedae7d4e6e5e4f06f2bf" name = "github.com/golang/snappy" packages = ["."] + pruneopts = "" revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a" [[projects]] + digest = "1:5247b135b5492aa232a731acdcb52b08f32b874cb398f21ab460396eadbe866b" name = "github.com/google/uuid" packages = ["."] + pruneopts = "" revision = "d460ce9f8df2e77fb1ba55ca87fafed96c607494" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:9c776d7d9c54b7ed89f119e449983c3f24c0023e75001d6092442412ebca6b94" name = "github.com/hashicorp/golang-lru" packages = [ ".", - "simplelru" + "simplelru", ] + pruneopts = "" revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3" [[projects]] + digest = "1:d14365c51dd1d34d5c79833ec91413bfbb166be978724f15701e17080dc06dec" name = "github.com/hashicorp/hcl" packages = [ ".", @@ -125,25 +150,29 @@ "hcl/token", "json/parser", "json/scanner", - "json/token" + "json/token", ] + pruneopts = "" revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241" version = "v1.0.0" [[projects]] + digest = "1:b3c5b95e56c06f5aa72cb2500e6ee5f44fcd122872d4fec2023a488e561218bc" name = "github.com/hpcloud/tail" packages = [ ".", "ratelimiter", "util", "watch", - "winfile" + "winfile", ] + pruneopts = "" revision = "a30252cb686a21eb2d0b98132633053ec2f7f1e5" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:b6e4cc26365c004808649862e22069de09594a9222143399a7a04904e9f7018c" name = "github.com/huin/goupnp" packages = [ ".", @@ -152,65 +181,83 @@ "httpu", "scpd", "soap", - "ssdp" + "ssdp", ] + pruneopts = "" revision = "1395d1447324cbea88d249fbfcfd70ea878fdfca" [[projects]] + digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" name = "github.com/inconshreveable/mousetrap" packages = ["."] + pruneopts = "" revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" [[projects]] + digest = "1:76f836364ae83ed811c415aa92e1209ce49de9f62aad85b85fca749a8b96a110" name = "github.com/jackpal/go-nat-pmp" packages = ["."] + pruneopts = "" revision = "c9cfead9f2a36ddf3daa40ba269aa7f4bbba6b62" version = "v1.0.1" [[projects]] branch = "master" + digest = "1:617ee2434b77e911fa26b678730be9a617f75243b194eadc8201c8ac860844aa" name = "github.com/jmoiron/sqlx" packages = [ ".", - "reflectx" + "reflectx", ] + pruneopts = "" revision = "0dae4fefe7c0e190f7b5a78dac28a1c82cc8d849" [[projects]] + digest = "1:6a874e3ddfb9db2b42bd8c85b6875407c702fa868eed20634ff489bc896ccfd3" name = "github.com/konsorten/go-windows-terminal-sequences" packages = ["."] + pruneopts = "" revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242" version = "v1.0.1" [[projects]] branch = "master" + digest = "1:29145d7af4adafd72a79df5e41456ac9e232d5a28c1cd4dacf3ff008a217fc10" name = "github.com/lib/pq" packages = [ ".", - "oid" + "oid", ] + pruneopts = "" revision = "4ded0e9383f75c197b3a2aaa6d590ac52df6fd79" [[projects]] + digest = "1:961dc3b1d11f969370533390fdf203813162980c858e1dabe827b60940c909a5" name = "github.com/magiconair/properties" packages = ["."] + pruneopts = "" revision = "c2353362d570a7bfa228149c62842019201cfb71" version = "v1.8.0" [[projects]] + digest = "1:096a8a9182648da3d00ff243b88407838902b6703fc12657f76890e08d1899bf" name = "github.com/mitchellh/go-homedir" packages = ["."] + pruneopts = "" revision = "ae18d6b8b3205b561c79e8e5f69bff09736185f4" version = "v1.0.0" [[projects]] + digest = "1:5219b4506253ccc598f9340677162a42d6a78f340a4cc6df2d62db4d0593c4e9" name = "github.com/mitchellh/mapstructure" packages = ["."] + pruneopts = "" revision = "fa473d140ef3c6adf42d6b391fe76707f1f243c8" version = "v1.0.0" [[projects]] + digest = "1:a7fd918fb5bd2188436785c0424f8a50b4addfedf37a2b14d796be2a927b8007" name = "github.com/onsi/ginkgo" packages = [ ".", @@ -230,12 +277,14 @@ "reporters/stenographer", "reporters/stenographer/support/go-colorable", "reporters/stenographer/support/go-isatty", - "types" + "types", ] + pruneopts = "" revision = "3774a09d95489ccaa16032e0770d08ea77ba6184" version = "v1.6.0" [[projects]] + digest = "1:3ecd0a37c4a90c12a97e31c398cdbc173824351aa891898ee178120bfe71c478" name = "github.com/onsi/gomega" packages = [ ".", @@ -250,94 +299,122 @@ "matchers/support/goraph/edge", "matchers/support/goraph/node", "matchers/support/goraph/util", - "types" + "types", ] + pruneopts = "" revision = "7615b9433f86a8bdf29709bf288bc4fd0636a369" version = "v1.4.2" [[projects]] + digest = "1:a5484d4fa43127138ae6e7b2299a6a52ae006c7f803d98d717f60abf3e97192e" name = "github.com/pborman/uuid" packages = ["."] + pruneopts = "" revision = "adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1" version = "v1.2" [[projects]] + digest = "1:894aef961c056b6d85d12bac890bf60c44e99b46292888bfa66caf529f804457" name = "github.com/pelletier/go-toml" packages = ["."] + pruneopts = "" revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194" version = "v1.2.0" [[projects]] + digest = "1:1d7e1867c49a6dd9856598ef7c3123604ea3daabf5b83f303ff457bcbc410b1d" name = "github.com/pkg/errors" packages = ["."] + pruneopts = "" revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" version = "v0.8.1" [[projects]] + digest = "1:fdbe7e05d74cc4d175cc4515a7807a5bb8b66ebe130da382b99713c9038648ae" name = "github.com/pressly/goose" packages = ["."] + pruneopts = "" revision = "e4b98955473e91a12fc7d8816c28d06376d1d92c" version = "v2.6.0" [[projects]] + digest = "1:7143292549152d009ca9e9c493b74736a2ebd93f921bea8a4b308d7cc5edc6b3" name = "github.com/rjeczalik/notify" packages = ["."] + pruneopts = "" revision = "0f065fa99b48b842c3fd3e2c8b194c6f2b69f6b8" version = "v0.9.1" [[projects]] + digest = "1:78c9cf43ddeacd0e472f412082227a0fac2ae107ee60e9112156f9371f9912cf" name = "github.com/rs/cors" packages = ["."] + pruneopts = "" revision = "3fb1b69b103a84de38a19c3c6ec073dd6caa4d3f" version = "v1.5.0" [[projects]] + digest = "1:9d57e200ef5ccc4217fe0a34287308bac652435e7c6513f6263e0493d2245c56" name = "github.com/sirupsen/logrus" packages = ["."] + pruneopts = "" revision = "bcd833dfe83d3cebad139e4a29ed79cb2318bf95" version = "v1.2.0" [[projects]] + digest = "1:d0431c2fd72e39ee43ea7742322abbc200c3e704c9102c5c3c2e2e667095b0ca" name = "github.com/spf13/afero" packages = [ ".", - "mem" + "mem", ] + pruneopts = "" revision = "d40851caa0d747393da1ffb28f7f9d8b4eeffebd" version = "v1.1.2" [[projects]] + digest = "1:d0b38ba6da419a6d4380700218eeec8623841d44a856bb57369c172fbf692ab4" name = "github.com/spf13/cast" packages = ["."] + pruneopts = "" revision = "8965335b8c7107321228e3e3702cab9832751bac" version = "v1.2.0" [[projects]] + digest = "1:a1403cc8a94b8d7956ee5e9694badef0e7b051af289caad1cf668331e3ffa4f6" name = "github.com/spf13/cobra" packages = ["."] + pruneopts = "" revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" version = "v0.0.3" [[projects]] + digest = "1:9ceffa4ab5f7195ecf18b3a7fff90c837a9ed5e22e66d18069e4bccfe1f52aa0" name = "github.com/spf13/jwalterweatherman" packages = ["."] + pruneopts = "" revision = "4a4406e478ca629068e7768fc33f3f044173c0a6" version = "v1.0.0" [[projects]] + digest = "1:0a52bcb568386d98f4894575d53ce3e456f56471de6897bb8b9de13c33d9340e" name = "github.com/spf13/pflag" packages = ["."] + pruneopts = "" revision = "9a97c102cda95a86cec2345a6f09f55a939babf5" version = "v1.0.2" [[projects]] + digest = "1:ac25ea6cc1156aca9611411274b4a0bdd83a623845df6985aab508253955cc66" name = "github.com/spf13/viper" packages = ["."] + pruneopts = "" revision = "8fb642006536c8d3760c99d4fa2389f5e2205631" version = "v1.2.0" [[projects]] branch = "master" + digest = "1:ce5194e5afac308cc34e500cab45b4ce88a0742d689e3cf7e37b607ad76bed2f" name = "github.com/syndtr/goleveldb" packages = [ "leveldb", @@ -351,49 +428,59 @@ "leveldb/opt", "leveldb/storage", "leveldb/table", - "leveldb/util" + "leveldb/util", ] + pruneopts = "" revision = "ae2bd5eed72d46b28834ec3f60db3a3ebedd8dbd" [[projects]] branch = "master" + digest = "1:59b49c47c11a48f1054529207f65907c014ecf5f9a7c0d9c0f1616dec7b062ed" name = "golang.org/x/crypto" packages = [ "pbkdf2", "scrypt", "sha3", - "ssh/terminal" + "ssh/terminal", ] + pruneopts = "" revision = "ff983b9c42bc9fbf91556e191cc8efb585c16908" [[projects]] branch = "master" + digest = "1:fbdbb6cf8db3278412c9425ad78b26bb8eb788181f26a3ffb3e4f216b314f86a" name = "golang.org/x/net" packages = [ "context", "html", "html/atom", "html/charset", - "websocket" + "websocket", ] + pruneopts = "" revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2" [[projects]] branch = "master" + digest = "1:b2ea75de0ccb2db2ac79356407f8a4cd8f798fe15d41b381c00abf3ae8e55ed1" name = "golang.org/x/sync" packages = ["errgroup"] + pruneopts = "" revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" [[projects]] branch = "master" + digest = "1:70d519d5cddeb60ceda2db88c24c340b1b2d7efb25ab54bacb38f57ea1998df7" name = "golang.org/x/sys" packages = [ "unix", - "windows" + "windows", ] + pruneopts = "" revision = "d641721ec2dead6fe5ca284096fe4b1fcd49e427" [[projects]] + digest = "1:5acd3512b047305d49e8763eef7ba423901e85d5dd2fd1e71778a0ea8de10bd4" name = "golang.org/x/text" packages = [ "encoding", @@ -415,39 +502,79 @@ "runes", "transform", "unicode/cldr", - "unicode/norm" + "unicode/norm", ] + pruneopts = "" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] + digest = "1:eb53021a8aa3f599d29c7102e65026242bdedce998a54837dc67f14b6a97c5fd" name = "gopkg.in/fsnotify.v1" packages = ["."] + pruneopts = "" revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" source = "gopkg.in/fsnotify/fsnotify.v1" version = "v1.4.7" [[projects]] branch = "v2" + digest = "1:4f830ee018eb8c56d0def653ad7c9a1d2a053f0cef2ac6b2200f73b98fa6a681" name = "gopkg.in/natefinch/npipe.v2" packages = ["."] + pruneopts = "" revision = "c1b8fa8bdccecb0b8db834ee0b92fdbcfa606dd6" [[projects]] branch = "v1" + digest = "1:a96d16bd088460f2e0685d46c39bcf1208ba46e0a977be2df49864ec7da447dd" name = "gopkg.in/tomb.v1" packages = ["."] + pruneopts = "" revision = "dd632973f1e7218eb1089048e0798ec9ae7dceb8" [[projects]] + digest = "1:f0620375dd1f6251d9973b5f2596228cc8042e887cd7f827e4220bc1ce8c30e2" name = "gopkg.in/yaml.v2" packages = ["."] + pruneopts = "" revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d41c963e87b06f7edd9135e30472894a114d0d8298454e6b2dae7ff25ac3c62a" + input-imports = [ + "github.com/dave/jennifer/jen", + "github.com/ethereum/go-ethereum", + "github.com/ethereum/go-ethereum/accounts/abi", + "github.com/ethereum/go-ethereum/accounts/abi/bind", + "github.com/ethereum/go-ethereum/common", + "github.com/ethereum/go-ethereum/common/hexutil", + "github.com/ethereum/go-ethereum/core/rawdb", + "github.com/ethereum/go-ethereum/core/types", + "github.com/ethereum/go-ethereum/crypto", + "github.com/ethereum/go-ethereum/ethclient", + "github.com/ethereum/go-ethereum/ethdb", + "github.com/ethereum/go-ethereum/p2p", + "github.com/ethereum/go-ethereum/p2p/discv5", + "github.com/ethereum/go-ethereum/rlp", + "github.com/ethereum/go-ethereum/rpc", + "github.com/hashicorp/golang-lru", + "github.com/hpcloud/tail", + "github.com/jmoiron/sqlx", + "github.com/lib/pq", + "github.com/mitchellh/go-homedir", + "github.com/onsi/ginkgo", + "github.com/onsi/gomega", + "github.com/onsi/gomega/ghttp", + "github.com/pressly/goose", + "github.com/sirupsen/logrus", + "github.com/spf13/cobra", + "github.com/spf13/viper", + "golang.org/x/net/context", + "golang.org/x/sync/errgroup", + "gopkg.in/tomb.v1", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/root.go b/cmd/root.go index de2eee24..7d601d6f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -67,7 +67,11 @@ func Execute() { func initFuncs(cmd *cobra.Command, args []string) { database(cmd, args) - logLevel(cmd, args) + + logLvlErr := logLevel(cmd, args) + if logLvlErr != nil { + log.Fatal("Could not set log level: ", logLvlErr) + } } @@ -147,7 +151,7 @@ func getBlockChain() *geth.BlockChain { rawRpcClient, err := rpc.Dial(ipc) if err != nil { - log.Fatal(err) + log.Fatal("Could not dial client: ", err) } rpcClient := client.NewRpcClient(rawRpcClient, ipc) ethClient := ethclient.NewClient(rawRpcClient) diff --git a/libraries/shared/watcher/event_watcher.go b/libraries/shared/watcher/event_watcher.go index 99ea5ccc..0bcc82f8 100644 --- a/libraries/shared/watcher/event_watcher.go +++ b/libraries/shared/watcher/event_watcher.go @@ -100,7 +100,7 @@ func (watcher *EventWatcher) Execute(recheckHeaders constants.TransformerExecuti missingHeaders, err := repository.MissingHeaders(*watcher.StartingBlock, -1, watcher.DB, notCheckedSQL) if err != nil { - logrus.Error("Fetching of missing headers failed in watcher!") + logrus.Error("Couldn't fetch missing headers in watcher: ", err) return err } @@ -108,7 +108,11 @@ func (watcher *EventWatcher) Execute(recheckHeaders constants.TransformerExecuti // TODO Extend FetchLogs for doing several blocks at a time logs, err := watcher.Fetcher.FetchLogs(watcher.Addresses, watcher.Topics, header) if err != nil { - logrus.Errorf("Error while fetching logs for header %v in watcher", header.Id) + logrus.WithFields(logrus.Fields{ + "headerId": header.Id, + "headerHash": header.Hash, + "blockNumber": header.BlockNumber, + }).Errorf("Couldn't fetch logs for header: %v", err) return err } @@ -120,6 +124,7 @@ func (watcher *EventWatcher) Execute(recheckHeaders constants.TransformerExecuti transformErr := watcher.transformLogs(logs, header) if transformErr != nil { + logrus.Error("Could not transform logs: ", transformErr) return transformErr } } diff --git a/main.go b/main.go index bf9b2677..7d94fd94 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,10 @@ import ( ) func main() { - log.SetFormatter(&log.JSONFormatter{}) + log.SetFormatter(&log.JSONFormatter{ + PrettyPrint: true, + }) + log.SetReportCaller(true) file, err := os.OpenFile("vulcanizedb.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err == nil { diff --git a/pkg/geth/blockchain.go b/pkg/geth/blockchain.go index 7048487b..0d3fb17b 100644 --- a/pkg/geth/blockchain.go +++ b/pkg/geth/blockchain.go @@ -129,6 +129,9 @@ func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) ( func (blockChain *BlockChain) LastBlock() (*big.Int, error) { block, err := blockChain.ethClient.HeaderByNumber(context.Background(), nil) + if err != nil { + return big.NewInt(0), err + } return block.Number, err } diff --git a/pkg/history/populate_headers.go b/pkg/history/populate_headers.go index f2abc93b..1566cc64 100644 --- a/pkg/history/populate_headers.go +++ b/pkg/history/populate_headers.go @@ -61,4 +61,3 @@ func RetrieveAndUpdateHeaders(blockChain core.BlockChain, headerRepository datas } return len(blockNumbers), nil } - diff --git a/utils/utils.go b/utils/utils.go index bf098ef5..3891a00b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -31,7 +31,7 @@ import ( func LoadPostgres(database config.Database, node core.Node) postgres.DB { db, err := postgres.NewDB(database, node) if err != nil { - log.Fatalf("Error loading postgres\n%v", err) + log.Fatal("Error loading postgres: ", err) } return *db } @@ -65,7 +65,7 @@ func GetAbi(abiFilepath string, contractHash string, network string) string { } _, err := geth.ParseAbi(contractAbiString) if err != nil { - log.Fatalln("Invalid ABI") + log.Fatalln("Invalid ABI: ", err) } return contractAbiString }