Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: make the relayer save the relayed signatures to store #431

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 18 additions & 55 deletions cmd/qgb/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import (
"strings"
"time"

"github.com/libp2p/go-libp2p/core/host"

evm2 "github.com/celestiaorg/orchestrator-relayer/cmd/qgb/keys/evm"
"github.com/celestiaorg/orchestrator-relayer/store"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
dssync "github.com/ipfs/go-datastore/sync"

"github.com/libp2p/go-libp2p/core/host"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
Expand Down Expand Up @@ -115,67 +111,34 @@ func CreateDHTAndWaitForPeers(
return dht, nil
}

func prettyPrintHost(h host.Host) {
fmt.Printf("ID: %s\n", h.ID().String())
fmt.Println("Listen addresses:")
for _, addr := range h.Addrs() {
fmt.Printf("\t%s\n", addr.String())
}
}

// InitBase initializes the base components for the orchestrator and relayer.
func InitBase(
ctx context.Context,
logger tmlog.Logger,
tendermintRPC, celesGRPC, home, evmAccAddress, evmPassphrase, p2pNickname, p2pListenAddr, bootstrappers string,
) (*rpc.TmQuerier, *rpc.AppQuerier, *p2p.Querier, *helpers.Retrier, *keystore.KeyStore, *accounts.Account, []func() error, error) {
func OpenStore(logger tmlog.Logger, home string, openOptions store.OpenOptions) (*store.Store, []func() error, error) {
stopFuncs := make([]func() error, 0)

tmQuerier, appQuerier, stops, err := NewTmAndAppQuerier(logger, tendermintRPC, celesGRPC)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return nil, nil, nil, nil, nil, nil, stopFuncs, err
}

// checking if the provided home is already initiated
isInit := store.IsInit(logger, home, store.InitOptions{NeedDataStore: true, NeedEVMKeyStore: true, NeedP2PKeyStore: true})
isInit := store.IsInit(logger, home, store.InitOptions{
NeedDataStore: openOptions.HasDataStore,
NeedEVMKeyStore: openOptions.HasEVMKeyStore,
NeedP2PKeyStore: openOptions.HasP2PKeyStore,
NeedSignatureStore: openOptions.HasSignatureStore,
})
if !isInit {
return nil, nil, nil, nil, nil, nil, stopFuncs, store.ErrNotInited
return nil, stopFuncs, store.ErrNotInited
}

// creating the data store
openOptions := store.OpenOptions{
HasDataStore: true,
BadgerOptions: store.DefaultBadgerOptions(home),
HasEVMKeyStore: true,
HasP2PKeyStore: true,
}
s, err := store.OpenStore(logger, home, openOptions)
if err != nil {
return nil, nil, nil, nil, nil, nil, stopFuncs, err
return nil, stopFuncs, err
}
stopFuncs = append(stopFuncs, func() error { return s.Close(logger, openOptions) })

logger.Info("loading EVM account", "address", evmAccAddress)

acc, err := evm2.GetAccountFromStoreAndUnlockIt(s.EVMKeyStore, evmAccAddress, evmPassphrase)
if err != nil {
return nil, nil, nil, nil, nil, nil, stopFuncs, err
}
stopFuncs = append(stopFuncs, func() error { return s.EVMKeyStore.Lock(acc.Address) })

// creating the data store
dataStore := dssync.MutexWrap(s.DataStore)
return s, stopFuncs, nil
}

dht, err := CreateDHTAndWaitForPeers(ctx, logger, s.P2PKeyStore, p2pNickname, p2pListenAddr, bootstrappers, dataStore)
if err != nil {
return nil, nil, nil, nil, nil, nil, stopFuncs, err
func prettyPrintHost(h host.Host) {
fmt.Printf("ID: %s\n", h.ID().String())
fmt.Println("Listen addresses:")
for _, addr := range h.Addrs() {
fmt.Printf("\t%s\n", addr.String())
}
stopFuncs = append(stopFuncs, func() error { return dht.Close() })

// creating the p2p querier
p2pQuerier := p2p.NewQuerier(dht, logger)
retrier := helpers.NewRetrier(logger, 6, time.Minute)

return tmQuerier, appQuerier, p2pQuerier, retrier, s.EVMKeyStore, &acc, stopFuncs, nil
}
65 changes: 48 additions & 17 deletions cmd/qgb/orchestrator/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package orchestrator
import (
"context"
"os"
"time"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/common"
evm2 "github.com/celestiaorg/orchestrator-relayer/cmd/qgb/keys/evm"
"github.com/celestiaorg/orchestrator-relayer/p2p"
dssync "github.com/ipfs/go-datastore/sync"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/keys"
"github.com/celestiaorg/orchestrator-relayer/store"

Expand Down Expand Up @@ -50,18 +55,47 @@ func Start() *cobra.Command {
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()

tmQuerier, appQuerier, p2pQuerier, retrier, evmKeyStore, acc, stopFuncs, err := common.InitBase(
ctx,
logger,
config.coreRPC,
config.coreGRPC,
config.Home,
config.evmAccAddress,
config.EVMPassphrase,
config.p2pNickname,
config.p2pListenAddr,
config.bootstrappers,
)
stopFuncs := make([]func() error, 0)

tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
}

s, stops, err := common.OpenStore(logger, config.Home, store.OpenOptions{
HasDataStore: true,
BadgerOptions: store.DefaultBadgerOptions(config.Home),
HasSignatureStore: false,
HasEVMKeyStore: true,
HasP2PKeyStore: true,
})
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
}

logger.Info("loading EVM account", "address", config.evmAccAddress)

acc, err := evm2.GetAccountFromStoreAndUnlockIt(s.EVMKeyStore, config.evmAccAddress, config.EVMPassphrase)
stopFuncs = append(stopFuncs, func() error { return s.EVMKeyStore.Lock(acc.Address) })
if err != nil {
return err
}

// creating the data store
dataStore := dssync.MutexWrap(s.DataStore)

dht, err := common.CreateDHTAndWaitForPeers(ctx, logger, s.P2PKeyStore, config.p2pNickname, config.p2pListenAddr, config.bootstrappers, dataStore)
if err != nil {
return err
}
stopFuncs = append(stopFuncs, func() error { return dht.Close() })

// creating the p2p querier
p2pQuerier := p2p.NewQuerier(dht, logger)
retrier := helpers.NewRetrier(logger, 6, time.Minute)

defer func() {
for _, f := range stopFuncs {
err := f()
Expand All @@ -70,9 +104,6 @@ func Start() *cobra.Command {
}
}
}()
if err != nil {
return err
}

// creating the broadcaster
broadcaster := orchestrator.NewBroadcaster(p2pQuerier.QgbDHT)
Expand All @@ -88,8 +119,8 @@ func Start() *cobra.Command {
p2pQuerier,
broadcaster,
retrier,
evmKeyStore,
acc,
s.EVMKeyStore,
&acc,
)
if err != nil {
return err
Expand Down
73 changes: 53 additions & 20 deletions cmd/qgb/relayer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package relayer
import (
"context"
"os"
"time"

evm2 "github.com/celestiaorg/orchestrator-relayer/cmd/qgb/keys/evm"
"github.com/celestiaorg/orchestrator-relayer/p2p"
dssync "github.com/ipfs/go-datastore/sync"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/common"
"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/keys"
Expand Down Expand Up @@ -50,9 +55,10 @@ func Init() *cobra.Command {
logger := tmlog.NewTMLogger(os.Stdout)

initOptions := store.InitOptions{
NeedDataStore: true,
NeedEVMKeyStore: true,
NeedP2PKeyStore: true,
NeedDataStore: true,
NeedEVMKeyStore: true,
NeedP2PKeyStore: true,
NeedSignatureStore: true,
}
isInit := store.IsInit(logger, config.home, initOptions)
if isInit {
Expand Down Expand Up @@ -88,18 +94,47 @@ func Start() *cobra.Command {
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()

tmQuerier, appQuerier, p2pQuerier, retrier, evmKeystore, acc, stopFuncs, err := common.InitBase(
ctx,
logger,
config.coreRPC,
config.coreGRPC,
config.Home,
config.evmAccAddress,
config.EVMPassphrase,
config.p2pNickname,
config.p2pListenAddr,
config.bootstrappers,
)
stopFuncs := make([]func() error, 0)

tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
}

s, stops, err := common.OpenStore(logger, config.Home, store.OpenOptions{
HasDataStore: true,
BadgerOptions: store.DefaultBadgerOptions(config.Home),
HasSignatureStore: true,
HasEVMKeyStore: true,
HasP2PKeyStore: true,
})
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
}

logger.Info("loading EVM account", "address", config.evmAccAddress)

acc, err := evm2.GetAccountFromStoreAndUnlockIt(s.EVMKeyStore, config.evmAccAddress, config.EVMPassphrase)
stopFuncs = append(stopFuncs, func() error { return s.EVMKeyStore.Lock(acc.Address) })
if err != nil {
return err
}

// creating the data store
dataStore := dssync.MutexWrap(s.DataStore)

dht, err := common.CreateDHTAndWaitForPeers(ctx, logger, s.P2PKeyStore, config.p2pNickname, config.p2pListenAddr, config.bootstrappers, dataStore)
if err != nil {
return err
}
stopFuncs = append(stopFuncs, func() error { return dht.Close() })

// creating the p2p querier
p2pQuerier := p2p.NewQuerier(dht, logger)
retrier := helpers.NewRetrier(logger, 6, time.Minute)

defer func() {
for _, f := range stopFuncs {
err := f()
Expand All @@ -108,9 +143,6 @@ func Start() *cobra.Command {
}
}
}()
if err != nil {
return err
}

// connecting to a QGB contract
ethClient, err := ethclient.Dial(config.evmRPC)
Expand All @@ -126,8 +158,8 @@ func Start() *cobra.Command {
evmClient := evm.NewClient(
logger,
qgbWrapper,
evmKeystore,
acc,
s.EVMKeyStore,
&acc,
config.evmRPC,
config.evmGasLimit,
)
Expand All @@ -139,6 +171,7 @@ func Start() *cobra.Command {
evmClient,
logger,
retrier,
s.SignatureStore,
)

// Listen for and trap any OS signal to graceful shutdown and exit
Expand Down
Loading