Skip to content

Commit

Permalink
Merge branch 'main' into petera/add-indexer-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik authored Oct 2, 2024
2 parents 0f3bfdb + 4798d65 commit 94f727f
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @sideninja @peterargue @m-Peter
* @janezpodhostnik @peterargue @m-Peter @zhangchiqing @ramtinms
4 changes: 4 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[linters]
enable = [
"goimports",
]
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ WORKDIR /flow-evm-gateway
RUN apt-get update && apt-get install ca-certificates -y

COPY --from=app-builder /app/bin /flow-evm-gateway/app
COPY --from=app-builder /app/previewnet-keys.json /flow-evm-gateway/previewnet-keys.json
COPY --from=app-builder /app/migration-keys.json /flow-evm-gateway/migration-keys.json

EXPOSE 8545

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ The application can be configured using the following flags at runtime:
| `ws-enabled` | `false` | Enable websocket connections |
| `access-node-grpc-host` | `localhost:3569` | Host to the flow access node gRPC API |
| `access-node-spork-hosts` | `""` | Previous spork AN hosts, defined as a comma-separated list (e.g. `"host-1.com,host2.com"`) |
| `evm-network-id` | `testnet ` | EVM network ID (options: `testnet`, `mainnet`) |
| `flow-network-id` | `flow-emulator` | Flow network ID (options: `flow-emulator`, `flow-testnet`, `flow-mainnet`) |
| `coinbase` | `""` | Coinbase address to use for fee collection |
| `init-cadence-height` | `0` | Cadence block height to start indexing; avoid using on a new network |
Expand All @@ -204,7 +203,6 @@ The application can be configured using the following flags at runtime:
| `wallet-api-key` | `""` | ECDSA private key for wallet APIs (local/testing use only) |
| `filter-expiry` | `5m` | Expiry time for idle filters |
| `traces-gcp-bucket` | `""` | GCP bucket name for transaction traces |
| `prometheus-config-file-path`| `./metrics/prometheus.yml` | Path to the Prometheus configuration file |
| `index-only` | `false` | Run in index-only mode, allowing state queries and indexing but no transaction sending |
| `profiler-enabled` | `false` | Enable the pprof profiler server |
| `profiler-host` | `localhost` | Host for the pprof profiler |
Expand Down
23 changes: 14 additions & 9 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type Bootstrap struct {

func New(config *config.Config) (*Bootstrap, error) {
logger := zerolog.New(config.LogWriter).
With().Timestamp().Logger().Level(config.LogLevel)
With().Timestamp().Str("version", api.Version).
Logger().Level(config.LogLevel)

client, err := setupCrossSporkClient(config, logger)
if err != nil {
Expand Down Expand Up @@ -136,7 +137,7 @@ func (b *Bootstrap) StartEventIngestion(ctx context.Context) error {
b.collector,
)

startEngine(ctx, b.events, l)
StartEngine(ctx, b.events, l)
return nil
}

Expand All @@ -160,7 +161,7 @@ func (b *Bootstrap) StartTraceDownloader(ctx context.Context) error {
b.collector,
)

startEngine(ctx, b.traces, l)
StartEngine(ctx, b.traces, l)
return nil
}

Expand Down Expand Up @@ -373,23 +374,27 @@ func (b *Bootstrap) StopProfilerServer() {
}
}

// startEngine starts provided engine and panics if there are startup errors.
func startEngine(
// StartEngine starts provided engine and panics if there are startup errors.
func StartEngine(
ctx context.Context,
engine models.Engine,
logger zerolog.Logger,
) {
logger.Info().Msg("starting engine")
l := logger.With().Type("engine", engine).Logger()

l.Info().Msg("starting engine")
start := time.Now()
go func() {
err := engine.Run(ctx)
if err != nil {
logger.Error().Err(err).Msg("engine failed to run")
panic(err)
l.Fatal().Err(err).Msg("engine failed to run")
}
}()

<-engine.Ready()
logger.Info().Msg("engine started successfully")
l.Info().
Dur("duration", time.Since(start)).
Msg("engine started successfully")
}

// setupCrossSporkClient sets up a cross-spork AN client.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/onflow/go-ethereum v1.14.7
github.com/prometheus/client_golang v1.18.0
github.com/rs/cors v1.8.0
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.33.0
github.com/samber/slog-zerolog v1.0.0
github.com/sethvargo/go-limiter v1.0.0
github.com/sethvargo/go-retry v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1988,8 +1988,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.0 h1:P2KMzcFwrPoSjkF1WLRPsp3UMLyql8L4v9hQpVeK5so=
github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
22 changes: 0 additions & 22 deletions migration-keys.json

This file was deleted.

6 changes: 3 additions & 3 deletions models/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func NewEngineStatus() *EngineStatus {
}
}

func (e *EngineStatus) IsReady() <-chan struct{} {
func (e *EngineStatus) Ready() <-chan struct{} {
return e.ready
}

func (e *EngineStatus) IsStopped() <-chan struct{} {
func (e *EngineStatus) Stopped() <-chan struct{} {
return e.stop
}

func (e *EngineStatus) IsDone() <-chan struct{} {
func (e *EngineStatus) Done() <-chan struct{} {
return e.done
}

Expand Down
3 changes: 2 additions & 1 deletion models/sequential_height_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package models

import (
"github.com/stretchr/testify/require"
"math"
"testing"

"github.com/stretchr/testify/require"
)

func TestSequentialHeight(t *testing.T) {
Expand Down
22 changes: 0 additions & 22 deletions previewnet-keys.json

This file was deleted.

19 changes: 5 additions & 14 deletions services/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var _ models.Engine = &Engine{}
// it will just overwrite the current indexed data. Idempotency is an important
// requirement of the implementation of this engine.
type Engine struct {
*models.EngineStatus

subscriber EventSubscriber
store *pebble.Storage
blocks storage.BlockIndexer
Expand All @@ -39,7 +41,6 @@ type Engine struct {
accounts storage.AccountIndexer
log zerolog.Logger
evmLastHeight *models.SequentialHeight
status *models.EngineStatus
blocksPublisher *models.Publisher
logsPublisher *models.Publisher
collector metrics.Collector
Expand All @@ -60,31 +61,21 @@ func NewEventIngestionEngine(
log = log.With().Str("component", "ingestion").Logger()

return &Engine{
EngineStatus: models.NewEngineStatus(),

subscriber: subscriber,
store: store,
blocks: blocks,
receipts: receipts,
transactions: transactions,
accounts: accounts,
log: log,
status: models.NewEngineStatus(),
blocksPublisher: blocksPublisher,
logsPublisher: logsPublisher,
collector: collector,
}
}

// Ready signals when the engine has started.
func (e *Engine) Ready() <-chan struct{} {
return e.status.IsReady()
}

// Done signals when the engine has stopped.
func (e *Engine) Done() <-chan struct{} {
// return e.status.IsDone()
return nil
}

// Stop the engine.
func (e *Engine) Stop() {
// todo
Expand Down Expand Up @@ -113,7 +104,7 @@ func (e *Engine) Run(ctx context.Context) error {

e.log.Info().Uint64("start-cadence-height", latestCadence).Msg("starting ingestion")

e.status.MarkReady()
e.MarkReady()

for events := range e.subscriber.Subscribe(ctx, latestCadence) {
if events.Err != nil {
Expand Down
5 changes: 3 additions & 2 deletions services/requester/rotation_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package requester

import (
"fmt"
"sync"
"testing"

"github.com/onflow/flow-go-sdk/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"sync"
"testing"
)

func Test_KeyRotation(t *testing.T) {
Expand Down
20 changes: 8 additions & 12 deletions services/traces/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ var _ models.Engine = &Engine{}
// listens for new transaction events and then downloads and index the
// traces from the transaction execution.
type Engine struct {
*models.EngineStatus

logger zerolog.Logger
status *models.EngineStatus
blocksPublisher *models.Publisher
blocks storage.BlockIndexer
traces storage.TraceIndexer
Expand All @@ -46,7 +47,8 @@ func NewTracesIngestionEngine(
collector metrics.Collector,
) *Engine {
return &Engine{
status: models.NewEngineStatus(),
EngineStatus: models.NewEngineStatus(),

logger: logger.With().Str("component", "trace-ingestion").Logger(),
blocksPublisher: blocksPublisher,
blocks: blocks,
Expand All @@ -56,11 +58,13 @@ func NewTracesIngestionEngine(
}
}

// Run the engine.
// TODO: use the context to stop the engine.
func (e *Engine) Run(ctx context.Context) error {
// subscribe to new blocks
e.blocksPublisher.Subscribe(e)

e.status.MarkReady()
e.MarkReady()
return nil
}

Expand Down Expand Up @@ -148,13 +152,5 @@ func (e *Engine) Error() <-chan error {
}

func (e *Engine) Stop() {
e.status.MarkStopped()
}

func (e *Engine) Done() <-chan struct{} {
return e.status.IsDone()
}

func (e *Engine) Ready() <-chan struct{} {
return e.status.IsReady()
e.MarkStopped()
}
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/onflow/flow-go v0.37.10
github.com/onflow/flow-go-sdk v1.0.0-preview.56
github.com/onflow/go-ethereum v1.14.7
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
)

Expand Down
4 changes: 2 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2264,8 +2264,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.0 h1:P2KMzcFwrPoSjkF1WLRPsp3UMLyql8L4v9hQpVeK5so=
github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down

0 comments on commit 94f727f

Please sign in to comment.