From f846fb610b8acfac9d953aa142350b8d2f6563da Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 12 Jul 2023 22:26:02 +0800 Subject: [PATCH] tidy up log begin/end messages as trace clean up comments quiet test logs --- builder.go | 10 +++++----- indexer/database/file/csv_writer.go | 6 +++--- mainnet_tests/builder_test.go | 4 ++++ scripts/integration-setup.sh | 5 ----- service_test.go | 7 ++----- test_helpers/util.go | 13 +++++++++++++ utils/log/log.go | 5 ----- 7 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 test_helpers/util.go diff --git a/builder.go b/builder.go index 7bc97d6..d7a89f0 100644 --- a/builder.go +++ b/builder.go @@ -140,7 +140,7 @@ func (sdb *StateDiffBuilder) WriteStateDiffObject(args Args, params Params, outp func (sdb *StateDiffBuilder) BuildStateDiff(iterPairs []IterPair, params Params, output sdtypes.StateNodeSink, ipldOutput sdtypes.IPLDSink, logger log.Logger, prefixPath []byte) error { - logger.Debug("statediff BEGIN BuildStateDiff") + logger.Trace("statediff BEGIN BuildStateDiff") defer metrics.ReportAndUpdateDuration("statediff END BuildStateDiff", time.Now(), logger, metrics.IndexerMetrics.BuildStateDiffTimer) // collect a slice of all the nodes that were touched and exist at B (B-A) // a map of their leafkey to all the accounts that were touched and exist at B @@ -195,7 +195,7 @@ func (sdb *StateDiffBuilder) BuildStateDiff(iterPairs []IterPair, params Params, // and a slice of the paths for all of the nodes included in both func (sdb *StateDiffBuilder) createdAndUpdatedState(a, b trie.NodeIterator, watchedAddressesLeafPaths [][]byte, output sdtypes.IPLDSink, logger log.Logger, prefixPath []byte) (sdtypes.AccountMap, error) { - logger.Debug("statediff BEGIN createdAndUpdatedState") + logger.Trace("statediff BEGIN createdAndUpdatedState") defer metrics.ReportAndUpdateDuration("statediff END createdAndUpdatedState", time.Now(), logger, metrics.IndexerMetrics.CreatedAndUpdatedStateTimer) diffAccountsAtB := make(sdtypes.AccountMap) @@ -280,7 +280,7 @@ func (sdb *StateDiffBuilder) processStateValueNode(it trie.NodeIterator, parentB // and a mapping of their leafkeys to all the accounts that exist in a different state at A than B func (sdb *StateDiffBuilder) deletedOrUpdatedState(a, b trie.NodeIterator, diffAccountsAtB sdtypes.AccountMap, watchedAddressesLeafPaths [][]byte, output sdtypes.StateNodeSink, logger log.Logger, prefixPath []byte) (sdtypes.AccountMap, error) { - logger.Debug("statediff BEGIN deletedOrUpdatedState") + logger.Trace("statediff BEGIN deletedOrUpdatedState") defer metrics.ReportAndUpdateDuration("statediff END deletedOrUpdatedState", time.Now(), logger, metrics.IndexerMetrics.DeletedOrUpdatedStateTimer) diffAccountAtA := make(sdtypes.AccountMap) @@ -339,7 +339,7 @@ func (sdb *StateDiffBuilder) deletedOrUpdatedState(a, b trie.NodeIterator, diffA // those account maps to remove the accounts which were updated func (sdb *StateDiffBuilder) buildAccountUpdates(creations, deletions sdtypes.AccountMap, updatedKeys []string, output sdtypes.StateNodeSink, ipldOutput sdtypes.IPLDSink, logger log.Logger) error { - logger.Debug("statediff BEGIN buildAccountUpdates", + logger.Trace("statediff BEGIN buildAccountUpdates", "creations", len(creations), "deletions", len(deletions), "updated", len(updatedKeys)) defer metrics.ReportAndUpdateDuration("statediff END buildAccountUpdates ", time.Now(), logger, metrics.IndexerMetrics.BuildAccountUpdatesTimer) @@ -375,7 +375,7 @@ func (sdb *StateDiffBuilder) buildAccountUpdates(creations, deletions sdtypes.Ac // it also returns the code and codehash for created contract accounts func (sdb *StateDiffBuilder) buildAccountCreations(accounts sdtypes.AccountMap, output sdtypes.StateNodeSink, ipldOutput sdtypes.IPLDSink, logger log.Logger) error { - logger.Debug("statediff BEGIN buildAccountCreations") + logger.Trace("statediff BEGIN buildAccountCreations") defer metrics.ReportAndUpdateDuration("statediff END buildAccountCreations", time.Now(), logger, metrics.IndexerMetrics.BuildAccountCreationsTimer) for _, val := range accounts { diff --git a/indexer/database/file/csv_writer.go b/indexer/database/file/csv_writer.go index efcc55c..6c73ef7 100644 --- a/indexer/database/file/csv_writer.go +++ b/indexer/database/file/csv_writer.go @@ -130,7 +130,7 @@ func (tx fileWriters) flush() error { func NewCSVWriter(path string, watchedAddressesFilePath string) (*CSVWriter, error) { if err := os.MkdirAll(path, 0777); err != nil { - return nil, fmt.Errorf("unable to make MkdirAll for path: %s err: %s", path, err) + return nil, fmt.Errorf("unable to create directory '%s': %w", path, err) } writers, err := makeFileWriters(path, Tables) @@ -383,7 +383,7 @@ func loadWatchedAddressesRows(filePath string) ([][]string, error) { return [][]string{}, nil } - return nil, fmt.Errorf("error opening watched addresses file: %v", err) + return nil, fmt.Errorf("error opening watched addresses file: %w", err) } defer file.Close() @@ -399,7 +399,7 @@ func dumpWatchedAddressesRows(watchedAddressesWriter fileWriter, filteredRows [] file, err := os.Create(file.Name()) if err != nil { - return fmt.Errorf("error creating watched addresses file: %v", err) + return fmt.Errorf("error creating watched addresses file: %w", err) } watchedAddressesWriter.Writer = csv.NewWriter(file) diff --git a/mainnet_tests/builder_test.go b/mainnet_tests/builder_test.go index 8e25aed..e7e96f3 100644 --- a/mainnet_tests/builder_test.go +++ b/mainnet_tests/builder_test.go @@ -41,6 +41,10 @@ import ( sdtypes "github.com/cerc-io/plugeth-statediff/types" ) +func init() { + test_helpers.SilenceLogs() +} + var ( db ethdb.Database genesisBlock, block0, block1, block2, block3 *types.Block diff --git a/scripts/integration-setup.sh b/scripts/integration-setup.sh index b54aa87..4409a78 100755 --- a/scripts/integration-setup.sh +++ b/scripts/integration-setup.sh @@ -26,11 +26,6 @@ $laconic_so --quiet deploy \ --env-file $CONFIG_DIR/stack.env \ --cluster "$cluster" up & -# debug geth -until [[ -n "$(docker ps -q --filter='name=test-fixturenet-eth-geth-1-1')" ]]; do sleep 1; done - -docker logs test-fixturenet-eth-geth-1-1 -f - set +x # Output vars if we are running on Github diff --git a/service_test.go b/service_test.go index 62bc4f8..0fa95bb 100644 --- a/service_test.go +++ b/service_test.go @@ -31,20 +31,17 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - geth_log "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" statediff "github.com/cerc-io/plugeth-statediff" + "github.com/cerc-io/plugeth-statediff/test_helpers" "github.com/cerc-io/plugeth-statediff/test_helpers/mocks" sdtypes "github.com/cerc-io/plugeth-statediff/types" - // "github.com/cerc-io/plugeth-statediff/utils/log" ) func init() { - // The geth sync logs are noisy, silence them - geth_log.Root().SetHandler(geth_log.DiscardHandler()) - // log.TestLogger.SetLevel(2) + test_helpers.SilenceLogs() } func TestServiceLoop(t *testing.T) { diff --git a/test_helpers/util.go b/test_helpers/util.go new file mode 100644 index 0000000..30c7530 --- /dev/null +++ b/test_helpers/util.go @@ -0,0 +1,13 @@ +package test_helpers + +import ( + geth_log "github.com/ethereum/go-ethereum/log" + + "github.com/cerc-io/plugeth-statediff/utils/log" +) + +// The geth sync logs are noisy, it can be useful to silence them +func SilenceLogs() { + geth_log.Root().SetHandler(geth_log.DiscardHandler()) + log.TestLogger.SetLevel(2) +} diff --git a/utils/log/log.go b/utils/log/log.go index e113bbf..2cdeb82 100644 --- a/utils/log/log.go +++ b/utils/log/log.go @@ -1,7 +1,6 @@ package log import ( - // geth_log "github.com/ethereum/go-ethereum/log" "github.com/inconshreveable/log15" "github.com/openrelayxyz/plugeth-utils/core" ) @@ -28,10 +27,6 @@ func Crit(m string, a ...interface{}) { DefaultLogger.Crit(m, a...) } func Error(m string, a ...interface{}) { DefaultLogger.Error(m, a...) } func SetDefaultLogger(l core.Logger) { - // gethlogger, ok := l.(geth_log.Logger) - // if !ok { - // panic("not a geth Logger") - // } DefaultLogger = l }