Skip to content

Commit

Permalink
Merge branch 'main' into switch-organization
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Oct 18, 2023
2 parents fd2e282 + 0f397e3 commit 3d0cb77
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 578 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ genmocks:
mockgen -source=chains/evm/transactor/transact.go -destination=./mock/transact.go -package mock
mockgen -source=chains/evm/transactor/signAndSend/signAndSend.go -destination=./mock/signAndSend.go -package mock
mockgen -source=./store/store.go -destination=./mock/store.go -package mock
mockgen -source=./relayer/message/handler.go -destination=./mock/message.go -package mock
40 changes: 24 additions & 16 deletions chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,42 @@ import (

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/store"
"github.com/sygmaprotocol/sygma-core/types"
"github.com/sygmaprotocol/sygma-core/relayer/message"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
)

type EventListener interface {
ListenToEvents(ctx context.Context, startBlock *big.Int)
}

type ProposalExecutor interface {
Execute(messages []*types.Message) error
Execute(props []*proposal.Proposal) error
}

type MessageHandler interface {
HandleMessage(m *message.Message) (*proposal.Proposal, error)
}

// EVMChain is struct that aggregates all data required for
type EVMChain struct {
listener EventListener
executor ProposalExecutor
blockstore *store.BlockStore
listener EventListener
executor ProposalExecutor
messageHandler MessageHandler

domainID uint8
startBlock *big.Int

logger zerolog.Logger
}

func NewEVMChain(listener EventListener, executor ProposalExecutor, blockstore *store.BlockStore, domainID uint8, startBlock *big.Int) *EVMChain {
func NewEVMChain(listener EventListener, messageHandler MessageHandler, executor ProposalExecutor, domainID uint8, startBlock *big.Int) *EVMChain {
return &EVMChain{
listener: listener,
executor: executor,
blockstore: blockstore,
domainID: domainID,
startBlock: startBlock,
logger: log.With().Uint8("domainID", domainID).Logger(),
listener: listener,
executor: executor,
domainID: domainID,
startBlock: startBlock,
messageHandler: messageHandler,
logger: log.With().Uint8("domainID", domainID).Logger(),
}
}

Expand All @@ -51,10 +55,14 @@ func (c *EVMChain) PollEvents(ctx context.Context) {
go c.listener.ListenToEvents(ctx, c.startBlock)
}

func (c *EVMChain) Write(msgs []*types.Message) error {
err := c.executor.Execute(msgs)
func (c *EVMChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
return c.messageHandler.HandleMessage(m)
}

func (c *EVMChain) Write(props []*proposal.Proposal) error {
err := c.executor.Execute(props)
if err != nil {
c.logger.Err(err).Msgf("error writing messages %+v on network %d", msgs, c.DomainID())
c.logger.Err(err).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
return err
}

Expand Down
71 changes: 0 additions & 71 deletions chains/evm/executor/message-handler.go

This file was deleted.

44 changes: 24 additions & 20 deletions chains/substrate/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ import (

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/chains/substrate/client"
"github.com/sygmaprotocol/sygma-core/store"
"github.com/sygmaprotocol/sygma-core/types"
"github.com/sygmaprotocol/sygma-core/relayer/message"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
)

type BatchProposalExecutor interface {
Execute(msgs []*types.Message) error
type ProposalExecutor interface {
Execute(props []*proposal.Proposal) error
}

type SubstrateChain struct {
client *client.SubstrateClient
type MessageHandler interface {
HandleMessage(m *message.Message) (*proposal.Proposal, error)
}

listener EventListener
executor BatchProposalExecutor
type EventListener interface {
ListenToEvents(ctx context.Context, startBlock *big.Int)
}

blockstore *store.BlockStore
type SubstrateChain struct {
listener EventListener
messageHandler MessageHandler
executor ProposalExecutor

domainID uint8
startBlock *big.Int

logger zerolog.Logger
}

type EventListener interface {
ListenToEvents(ctx context.Context, startBlock *big.Int)
}

func NewSubstrateChain(client *client.SubstrateClient, listener EventListener, blockstore *store.BlockStore, executor BatchProposalExecutor, domainID uint8, startBlock *big.Int) *SubstrateChain {
func NewSubstrateChain(listener EventListener, messageHandler MessageHandler, executor ProposalExecutor, domainID uint8, startBlock *big.Int) *SubstrateChain {
return &SubstrateChain{
client: client,
listener: listener,
blockstore: blockstore,
executor: executor,
domainID: domainID,
startBlock: startBlock,
logger: log.With().Uint8("domainID", domainID).Logger()}
}

Expand All @@ -49,10 +49,14 @@ func (c *SubstrateChain) PollEvents(ctx context.Context) {
go c.listener.ListenToEvents(ctx, c.startBlock)
}

func (c *SubstrateChain) Write(msgs []*types.Message) error {
err := c.executor.Execute(msgs)
func (c *SubstrateChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
return c.messageHandler.HandleMessage(m)
}

func (c *SubstrateChain) Write(props []*proposal.Proposal) error {
err := c.executor.Execute(props)
if err != nil {
c.logger.Err(err).Msgf("error writing messages %+v on network %d", msgs, c.DomainID())
c.logger.Err(err).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
return err
}

Expand Down
61 changes: 0 additions & 61 deletions chains/substrate/executor/message-handler.go

This file was deleted.

Loading

0 comments on commit 3d0cb77

Please sign in to comment.