Skip to content

Commit

Permalink
SIN Executor Config Chain ID restructure (#2198)
Browse files Browse the repository at this point in the history
* Refactor config to use slice for chains and add ChainID field; adjust executor logic accordingly

* [goreleaser]
  • Loading branch information
aureliusbtc authored Mar 3, 2024
1 parent 55e655e commit 8130cc0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 3 additions & 1 deletion sin-executor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// Config is the config for the Synapse module.
type Config struct {
// Chains is a map of chain IDs to execution service contract addresses.
Chains map[int]ChainConfig `yaml:"chains"`
Chains []ChainConfig `yaml:"chains"`
// OmnirpcURL is the URL of the Omni RPC.
OmnirpcURL string `yaml:"omnirpc_url"`
// Database is the database config.
Expand All @@ -21,6 +21,8 @@ type Config struct {
}

type ChainConfig struct {
// ChainID is the chain ID.
ChainID int `yaml:"id"`
// ExecutionService is the address of the execution service contract.
ExecutionService string `yaml:"execution_service"`
// Client is the address of the interchain client contract.
Expand Down
17 changes: 9 additions & 8 deletions sin-executor/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package executor
import (
"context"
"fmt"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/sin-executor/contracts/executionservice"
"math/big"
"time"

"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/sin-executor/contracts/executionservice"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -60,10 +61,10 @@ func NewExecutor(ctx context.Context, handler metrics.Handler, cfg config.Config
executor.chainListeners = make(map[int]listener.ContractListener)
executor.clientContracts = make(map[int]*interchainclient.InterchainClientRef)

for chainID, chainCfg := range cfg.Chains {
for _, chainCfg := range cfg.Chains {
executionService := common.HexToAddress(chainCfg.ExecutionService)
interchainClient := common.HexToAddress(chainCfg.Client)
chainClient, err := executor.client.GetChainClient(ctx, chainID)
chainClient, err := executor.client.GetChainClient(ctx, chainCfg.ChainID)
if err != nil {
return nil, fmt.Errorf("could not get chain client: %w", err)
}
Expand All @@ -72,9 +73,9 @@ func NewExecutor(ctx context.Context, handler metrics.Handler, cfg config.Config
if err != nil {
return nil, fmt.Errorf("could not get chain listener: %w", err)
}
executor.chainListeners[chainID] = chainListener
executor.chainListeners[chainCfg.ChainID] = chainListener

executor.clientContracts[chainID], err = interchainclient.NewInterchainClientRef(interchainClient, chainClient)
executor.clientContracts[chainCfg.ChainID], err = interchainclient.NewInterchainClientRef(interchainClient, chainClient)
if err != nil {
return nil, fmt.Errorf("could not get synapse module ref: %w", err)
}
Expand Down Expand Up @@ -226,8 +227,8 @@ func (e *Executor) startChainIndexers(ctx context.Context) error {
g, ctx := errgroup.WithContext(ctx)

// TODO: good chance we wanna prepare these chain listeners up front and then listen later.
for chainID := range e.cfg.Chains {
chainID := chainID // capture func litera
for _, chain := range e.cfg.Chains {
chainID := chain.ChainID // capture func litera

g.Go(func() error {
err := e.runChainIndexer(ctx, chainID)
Expand Down
15 changes: 9 additions & 6 deletions sin-executor/executor/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package executor_test
import (
"context"
"errors"
"math/big"
"sync"
"testing"

"github.com/Flaque/filet"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -22,9 +26,6 @@ import (
"github.com/synapsecns/sanguine/sin-executor/contracts/interchainclient"
"github.com/synapsecns/sanguine/sin-executor/executor"
"github.com/synapsecns/sanguine/sin-executor/testutil"
"math/big"
"sync"
"testing"
)

// InterchainSuite is a test suite for the interchain package.
Expand Down Expand Up @@ -135,12 +136,14 @@ func (i *InterchainSuite) makeExecutor() {
destOwner, execServiceDest := i.deployManager.GetExecutionService(i.GetTestContext(), i.destChain)

cfg := config.Config{
Chains: map[int]config.ChainConfig{
1: {
Chains: []config.ChainConfig{
{
ChainID: 1,
ExecutionService: execServiceOrigin.Address().String(),
Client: i.originModule.Address().String(),
},
2: {
{
ChainID: 2,
ExecutionService: execServiceDest.Address().String(),
Client: i.destModule.Address().String(),
},
Expand Down

0 comments on commit 8130cc0

Please sign in to comment.