Skip to content

Commit

Permalink
Merge pull request #29 from smartcontractkit/chain-set
Browse files Browse the repository at this point in the history
support multiple chains via ChainSet
  • Loading branch information
jmank88 authored Jan 14, 2022
2 parents c411859 + e3109b8 commit 93492fc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
27 changes: 27 additions & 0 deletions pkg/terra/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package terra

import (
"github.com/smartcontractkit/chainlink-terra/pkg/terra/client"
"github.com/smartcontractkit/chainlink-terra/pkg/terra/config"
)

type ChainSet interface {
Service
Chain(id string) (Chain, error)
}

type Chain interface {
Service

ID() string
Config() config.ChainCfg
MsgEnqueuer() MsgEnqueuer
Reader() client.Reader
}

type Service interface {
Start() error
Close() error
Ready() error
Healthy() error
}
7 changes: 7 additions & 0 deletions pkg/terra/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

// ChainCfg is configuration parameters for a terra chain.
type ChainCfg struct {
FallbackGasPriceULuna string
GasLimitMultiplier float64
}
42 changes: 23 additions & 19 deletions pkg/terra/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terra

import (
"errors"
"github.com/smartcontractkit/chainlink-terra/pkg/terra/client"

cosmosSDK "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -33,9 +32,12 @@ type MsgEnqueuer interface {

// CL Core OCR2 job spec RelayConfig member for Terra
type RelayConfig struct {
ChainID string `json:"chainID"`
}

type OCR2Spec struct {
ChainID string

ID int32
IsBootstrap bool

Expand All @@ -45,39 +47,34 @@ type OCR2Spec struct {
}

type Relayer struct {
lggr Logger
msgEnqueuer MsgEnqueuer
chainReader client.Reader
chainID string
lggr Logger
chainSet ChainSet
}

// Note: constructed in core
func NewRelayer(lggr Logger, msgEnqueuer MsgEnqueuer, chainReader client.Reader, chainID string) *Relayer {
func NewRelayer(lggr Logger, chainSet ChainSet) *Relayer {
return &Relayer{
lggr: lggr,
msgEnqueuer: msgEnqueuer,
chainReader: chainReader,
chainID: chainID,
lggr: lggr,
chainSet: chainSet,
}
}

func (r *Relayer) Start() error {
return r.msgEnqueuer.Start()
return r.chainSet.Start()
}

// Close will close all open subservices
func (r *Relayer) Close() error {
return r.msgEnqueuer.Close()
return r.chainSet.Close()
}

func (r *Relayer) Ready() error {
// always ready
return nil
return r.chainSet.Ready()
}

// Healthy only if all subservices are healthy
func (r *Relayer) Healthy() error {
return nil
return r.chainSet.Healthy()
}

func (r *Relayer) NewOCR2Provider(externalJobID uuid.UUID, s interface{}) (relaytypes.OCR2Provider, error) {
Expand All @@ -86,6 +83,13 @@ func (r *Relayer) NewOCR2Provider(externalJobID uuid.UUID, s interface{}) (relay
return nil, errors.New("unsuccessful cast to 'terra.OCR2Spec'")
}

chain, err := r.chainSet.Chain(spec.ChainID)
if err != nil {
return nil, err
}
chainReader := chain.Reader()
msgEnqueuer := chain.MsgEnqueuer()

contractAddr, err := cosmosSDK.AccAddressFromBech32(spec.ContractID)
if err != nil {
return nil, err
Expand All @@ -95,8 +99,8 @@ func (r *Relayer) NewOCR2Provider(externalJobID uuid.UUID, s interface{}) (relay
return nil, err
}

tracker := NewContractTracker(contractAddr, externalJobID.String(), r.chainReader, r.lggr)
digester := NewOffchainConfigDigester(r.chainID, contractAddr)
tracker := NewContractTracker(contractAddr, externalJobID.String(), chainReader, r.lggr)
digester := NewOffchainConfigDigester(spec.ChainID, contractAddr)

if spec.IsBootstrap {
// Return early if bootstrap node (doesn't require the full OCR2 provider)
Expand All @@ -107,8 +111,8 @@ func (r *Relayer) NewOCR2Provider(externalJobID uuid.UUID, s interface{}) (relay
}

reportCodec := ReportCodec{}
transmitter := NewContractTransmitter(externalJobID.String(), contractAddr, senderAddr, r.msgEnqueuer, r.chainReader, r.lggr)
median := NewMedianContract(contractAddr, r.chainReader, r.lggr, transmitter)
transmitter := NewContractTransmitter(externalJobID.String(), contractAddr, senderAddr, msgEnqueuer, chainReader, r.lggr)
median := NewMedianContract(contractAddr, chainReader, r.lggr, transmitter)

return ocr2Provider{
digester: digester,
Expand Down

0 comments on commit 93492fc

Please sign in to comment.