Skip to content

Commit

Permalink
fix tests and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Dec 13, 2024
1 parent 0ba7ce7 commit 743e9fb
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 245 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ generate:
mockery --dir=storage --name=TransactionIndexer --output=storage/mocks
mockery --dir=storage --name=TraceIndexer --output=storage/mocks
mockery --all --dir=services/ingestion --output=services/ingestion/mocks
mockery --dir=models --name=Engine --output=models/mocks

.PHONY: ci
ci: check-tidy test e2e-test
Expand Down
2 changes: 2 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"strings"
"time"

"github.com/onflow/go-ethereum/core"

"github.com/onflow/flow-go/module/component"
"github.com/onflow/flow-go/module/irrecoverable"

Expand Down
20 changes: 11 additions & 9 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/onflow/flow-evm-gateway/api"
"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-go-sdk/crypto"
"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/evm"
Expand All @@ -34,7 +33,6 @@ import (
errs "github.com/onflow/flow-evm-gateway/models/errors"
"github.com/onflow/flow-evm-gateway/services/ingestion"
"github.com/onflow/flow-evm-gateway/services/replayer"
"github.com/onflow/flow-evm-gateway/services/signer"
pebble2 "github.com/onflow/flow-evm-gateway/storage/pebble"
)

Expand Down Expand Up @@ -92,8 +90,8 @@ type EVMGatewayNodeBuilder struct {
Client *requester.CrossSporkClient
Storages *Storages
// Signer is used for signing flow transactions
Signer crypto.Signer
Publishers *Publishers
Keystore *requester.KeyStoreComponent
}

func (fnb *EVMGatewayNodeBuilder) Build() (cmd.Node, error) {
Expand Down Expand Up @@ -209,7 +207,7 @@ func (fnb *EVMGatewayNodeBuilder) Initialize() error {
func (fnb *EVMGatewayNodeBuilder) LoadComponentsAndModules() {
fnb.initPublishers()

fnb.Component("Transaction Signer", fnb.initSigner)
fnb.Component("Key Store", fnb.initKeyStore)
fnb.Component("API Server", fnb.apiServerComponent)
fnb.Component("Event Ingestion Engine", fnb.eventIngestionEngineComponent)
fnb.Component("Metrics Server", fnb.metricsServerComponent)
Expand Down Expand Up @@ -238,6 +236,7 @@ func (fnb *EVMGatewayNodeBuilder) apiServerComponent(cfg config.Config) (module.
fnb.Client,
fnb.Publishers.Transaction,
log,
cfg,
)

blocksProvider := replayer.NewBlocksProvider(
Expand All @@ -251,11 +250,11 @@ func (fnb *EVMGatewayNodeBuilder) apiServerComponent(cfg config.Config) (module.
blocksProvider,
fnb.Client,
cfg,
fnb.Signer,
log,
fnb.Storages.Blocks,
txPool,
fnb.Metrics,
fnb.Keystore.KeyStore,
)
if err != nil {
return nil, fmt.Errorf("failed to create EVM requester: %w", err)
Expand Down Expand Up @@ -393,6 +392,7 @@ func (fnb *EVMGatewayNodeBuilder) eventIngestionEngineComponent(cfg config.Confi
fnb.Logger,
fnb.Client,
chainID,
fnb.Keystore,
latestCadenceHeight,
)

Expand Down Expand Up @@ -542,10 +542,12 @@ func (fnb *EVMGatewayNodeBuilder) initStorage() error {

return nil
}
func (fnb *EVMGatewayNodeBuilder) initSigner(config config.Config) (module.ReadyDoneAware, error) {
sig := signer.NewSigner(fnb.Logger, config)
fnb.Signer = sig
return sig, nil
func (fnb *EVMGatewayNodeBuilder) initKeyStore(cfg config.Config) (module.ReadyDoneAware, error) {
keystore := requester.NewKeyStoreComponent(fnb.Logger, cfg, fnb.Client)

fnb.Keystore = keystore

return keystore, nil
}

func (fnb *EVMGatewayNodeBuilder) initPublishers() {
Expand Down
40 changes: 0 additions & 40 deletions bootstrap/utils.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/run/cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package run

import (
"encoding/json"
"fmt"
"math/big"
"os"
Expand Down
91 changes: 0 additions & 91 deletions models/mocks/Engine.go

This file was deleted.

9 changes: 7 additions & 2 deletions services/ingestion/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func TestSerialBlockIngestion(t *testing.T) {
return eventsChan
})

blocksPublisher := models.NewPublisher[*models.Block](zerolog.Nop())
blocksPublisher.Start(ictx)
logsPublisher := models.NewPublisher[[]*gethTypes.Log](zerolog.Nop())
logsPublisher.Start(ictx)

engine := NewEventIngestionEngine(
subscriber,
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
Expand All @@ -78,8 +83,8 @@ func TestSerialBlockIngestion(t *testing.T) {
receipts,
transactions,
traces,
models.NewPublisher[*models.Block](zerolog.Nop()),
models.NewPublisher[[]*gethTypes.Log](zerolog.Nop()),
blocksPublisher,
logsPublisher,
zerolog.Nop(),
metrics.NopCollector,
defaultReplayerConfig(),
Expand Down
125 changes: 125 additions & 0 deletions services/requester/key_store_component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package requester

import (
"context"
"fmt"

"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-go-sdk/access"
"github.com/onflow/flow-go-sdk/crypto"
"github.com/onflow/flow-go/module/component"
"github.com/onflow/flow-go/module/irrecoverable"
"github.com/rs/zerolog"
)

type KeyStoreComponent struct {
*KeyStore

log zerolog.Logger
config config.Config
client access.Client
startupCompleted chan struct{}
}

var _ component.Component = (*KeyStoreComponent)(nil)

func NewKeyStoreComponent(log zerolog.Logger, config config.Config, client access.Client) *KeyStoreComponent {
ks := &KeyStoreComponent{
log: log,
config: config,
client: client,
startupCompleted: make(chan struct{}),
}

return ks
}

func (k *KeyStoreComponent) Start(ctx irrecoverable.SignalerContext) {
defer close(k.startupCompleted)

k.log.Info().Msg("starting key store component")

accountKeys := make([]*AccountKey, 0)
account, err := k.client.GetAccount(ctx, k.config.COAAddress)
if err != nil {
ctx.Throw(fmt.Errorf(
"failed to get signer info account for address: %s, with: %w",
k.config.COAAddress,
err,
))

return
}
signer, err := createSigner(ctx, k.config, k.log)

if err != nil {
ctx.Throw(err)

return
}
for _, key := range account.Keys {
accountKeys = append(accountKeys, &AccountKey{
AccountKey: *key,
Address: k.config.COAAddress,
Signer: signer,
})
}

k.KeyStore = NewKeyStore(accountKeys)

}

func (k *KeyStoreComponent) Ready() <-chan struct{} {
ready := make(chan struct{})

go func() {
<-k.startupCompleted
close(ready)
}()

return ready
}

func (k *KeyStoreComponent) Done() <-chan struct{} {
done := make(chan struct{})

go func() {
<-k.startupCompleted

// This is where we would close the KMS client connection,
// but it currently does not have a close method

close(done)
}()

return done
}

// createSigner creates the signer based on either a single coa key being
// provided and using a simple in-memory signer, or a Cloud KMS key being
// provided and using a Cloud KMS signer.
func createSigner(
ctx context.Context,
config config.Config,
logger zerolog.Logger,
) (crypto.Signer, error) {
var signer crypto.Signer
var err error
switch {
case config.COAKey != nil:
signer, err = crypto.NewInMemorySigner(config.COAKey, crypto.SHA3_256)
case config.COACloudKMSKey != nil:
signer, err = NewKMSKeySigner(
ctx,
*config.COACloudKMSKey,
logger,
)
default:
return nil, fmt.Errorf("must provide either single COA / Cloud KMS key")
}
if err != nil {
return nil, fmt.Errorf("failed to create a COA signer: %w", err)
}

return signer, nil
}
Loading

0 comments on commit 743e9fb

Please sign in to comment.