Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple destination domains #40

Merged
merged 2 commits into from
Jan 27, 2024
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
20 changes: 14 additions & 6 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Start(cmd *cobra.Command, args []string) {
go c.StartListener(cmd.Context(), Logger, processingQueue)

if _, ok := registeredDomains[c.Domain()]; ok {
Logger.Error("Duplicate domain found", "domain", c.Domain())
Logger.Error("Duplicate domain found", "domain", c.Domain(), "name:", c.Name())
os.Exit(1)
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func StartProcessor(
for _, msg := range tx.Msgs {

// if a filter's condition is met, mark as filtered
if filterDisabledCCTPRoutes(cfg, logger, msg) ||
if FilterDisabledCCTPRoutes(cfg, logger, msg) ||
filterInvalidDestinationCallers(registeredDomains, logger, msg) {
msg.Status = types.Filtered
}
Expand Down Expand Up @@ -155,14 +155,22 @@ func StartProcessor(
}

// filterDisabledCCTPRoutes returns true if we haven't enabled relaying from a source domain to a destination domain
func filterDisabledCCTPRoutes(cfg *types.Config, logger log.Logger, msg *types.MessageState) bool {
func FilterDisabledCCTPRoutes(cfg *types.Config, logger log.Logger, msg *types.MessageState) bool {
val, ok := cfg.EnabledRoutes[msg.SourceDomain]
result := !(ok && val == msg.DestDomain)
if result {
if !ok {
logger.Info(fmt.Sprintf("Filtered tx %s because relaying from %d to %d is not enabled",
msg.SourceTxHash, msg.SourceDomain, msg.DestDomain))
return !ok
}
for _, dd := range val {
if dd == msg.DestDomain {
return false
}
}
return result
logger.Info(fmt.Sprintf("Filtered tx %s because relaying from %d to %d is not enabled",
msg.SourceTxHash, msg.SourceDomain, msg.DestDomain))
return true

}

// filterInvalidDestinationCallers returns true if the minter is not the destination caller for the specified domain
Expand Down
53 changes: 46 additions & 7 deletions cmd/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var sequenceMap *types.SequenceMap

func setupTest(t *testing.T) map[types.Domain]types.Chain {
var err error
cfg, err = cmd.Parse("../.ignore/unit_tests.yaml")
cfg, err = cmd.Parse("../.ignore/testnet.yaml")
require.NoError(t, err, "Error parsing config")

logger = log.NewLogger(os.Stdout, log.LevelOption(zerolog.DebugLevel))
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestProcessNewLog(t *testing.T) {
// created message -> check attestation -> mark as attested -> mark as complete -> remove from state
func TestProcessCreatedLog(t *testing.T) {
registeredDomains := setupTest(t)
cfg.EnabledRoutes[0] = 5 // skip mint
cfg.EnabledRoutes[0] = []types.Domain{5} // skip mint

go cmd.StartProcessor(context.TODO(), cfg, logger, registeredDomains, processingQueue, sequenceMap)

Expand Down Expand Up @@ -120,7 +120,7 @@ func TestProcessDisabledCctpRoute(t *testing.T) {
expectedState := &types.TxState{
TxHash: "123",
Msgs: []*types.MessageState{
&types.MessageState{
{
SourceTxHash: "123",
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestProcessInvalidDestinationCaller(t *testing.T) {
expectedState := &types.TxState{
TxHash: "123",
Msgs: []*types.MessageState{
&types.MessageState{
{
SourceTxHash: "123",
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestProcessNonBurnMessageWhenDisabled(t *testing.T) {
expectedState := &types.TxState{
TxHash: "123",
Msgs: []*types.MessageState{
&types.MessageState{
{
SourceTxHash: "123",
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
Expand Down Expand Up @@ -213,15 +213,15 @@ func TestBatchTx(t *testing.T) {
expectedState := &types.TxState{
TxHash: "123",
Msgs: []*types.MessageState{
&types.MessageState{
{
SourceTxHash: "123",
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
SourceDomain: 0,
DestDomain: 4,
MsgSentBytes: []byte("mock bytes 1"), // different message sent bytes
},
&types.MessageState{
{
SourceTxHash: "123", // same source tx hash
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
Expand All @@ -239,3 +239,42 @@ func TestBatchTx(t *testing.T) {
require.True(t, ok)
require.Equal(t, 2, len(actualState.Msgs))
}

// we want to filter out the transaction if the route is not enalbed
func TestFilterDisabledCCTPRoutes(t *testing.T) {

logger = log.NewLogger(os.Stdout, log.LevelOption(zerolog.DebugLevel))

var msgState types.MessageState

cfg := types.Config{
EnabledRoutes: map[types.Domain][]types.Domain{
0: {1, 2},
},
}

// test enabled dest domain
msgState = types.MessageState{
SourceDomain: types.Domain(0),
DestDomain: types.Domain(1),
}
filterTx := cmd.FilterDisabledCCTPRoutes(&cfg, logger, &msgState)
require.False(t, filterTx)

// test NOT enabled dest domain
msgState = types.MessageState{
SourceDomain: types.Domain(0),
DestDomain: types.Domain(3),
}
filterTx = cmd.FilterDisabledCCTPRoutes(&cfg, logger, &msgState)
require.True(t, filterTx)

// test NOT enabled source domain
msgState = types.MessageState{
SourceDomain: types.Domain(3),
DestDomain: types.Domain(1),
}
filterTx = cmd.FilterDisabledCCTPRoutes(&cfg, logger, &msgState)
require.True(t, filterTx)

}
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestConfig(t *testing.T) {
file, err := cmd.Parse("../config/sample.yaml")
file, err := cmd.Parse("../config/sample-config.yaml")
require.NoError(t, err, "Error parsing config")

// assert noble chainConfig correctly parsed
Expand Down
4 changes: 2 additions & 2 deletions config/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ chains:

# source domain id -> destination domain id
enabled-routes:
0: 4 # ethereum to noble
4: 0 # noble to ethereum
0: [4] # ethereum to noble
4: [0] # noble to ethereum

circle:
attestation-base-url: "https://iris-api-sandbox.circle.com/attestations/"
Expand Down
1 change: 1 addition & 0 deletions ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func NewChain(
return &Ethereum{
name: name,
chainID: chainID,
domain: domain,
rpcURL: rpcURL,
wsURL: wsURL,
messageTransmitterAddress: messageTransmitterAddress,
Expand Down
4 changes: 2 additions & 2 deletions ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _ types.ChainConfig = (*ChainConfig)(nil)
type ChainConfig struct {
RPC string `yaml:"rpc"`
WS string `yaml:"ws"`
domain types.Domain
Domain types.Domain
ChainID int64 `yaml:"chain-id"`
MessageTransmitter string `yaml:"message-transmitter"`

Expand All @@ -26,7 +26,7 @@ type ChainConfig struct {
func (c *ChainConfig) Chain(name string) (types.Chain, error) {
return NewChain(
name,
c.domain,
c.Domain,
c.ChainID,
c.RPC,
c.WS,
Expand Down
2 changes: 1 addition & 1 deletion integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func setupTestIntegration() func() {
}

nobleCfg = cfg.Chains["noble"].(*noble.ChainConfig)
ethCfg = cfg.Chains["ethereum"].(*ethereum.ChainConfig)
ethCfg = cfg.Chains["sepolia"].(*ethereum.ChainConfig)

sequenceMap = types.NewSequenceMap()

Expand Down
4 changes: 2 additions & 2 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

type Config struct {
Chains map[string]ChainConfig `yaml:"chains"`
EnabledRoutes map[Domain]Domain `yaml:"enabled-routes"`
EnabledRoutes map[Domain][]Domain `yaml:"enabled-routes"`
Circle struct {
AttestationBaseUrl string `yaml:"attestation-base-url"`
FetchRetries int `yaml:"fetch-retries"`
Expand All @@ -16,7 +16,7 @@ type Config struct {

type ConfigWrapper struct {
Chains map[string]map[string]any `yaml:"chains"`
EnabledRoutes map[Domain]Domain `yaml:"enabled-routes"`
EnabledRoutes map[Domain][]Domain `yaml:"enabled-routes"`
Circle struct {
AttestationBaseUrl string `yaml:"attestation-base-url"`
FetchRetries int `yaml:"fetch-retries"`
Expand Down
Loading