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

feat: enable messages both ways #11

Merged
merged 38 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
32f81c1
Update README
mpetrun5 Sep 28, 2023
721f49b
Rename chainbridge-core module to sygma-core
mpetrun5 Sep 28, 2023
e42d14a
Remove all extra code
mpetrun5 Sep 29, 2023
68615e7
Remove test setup temporarily
mpetrun5 Sep 29, 2023
4a18032
Move package from calls to separate folders
mpetrun5 Sep 29, 2023
33256d4
Fix imports
mpetrun5 Sep 29, 2023
c1372a0
Move to proposal to relayer package
mpetrun5 Sep 29, 2023
6107e75
Fix all naming conflicts in code
mpetrun5 Sep 29, 2023
ccada0b
Move generic types to types package
mpetrun5 Sep 29, 2023
73f7311
Move msg channel to be a global message sending tool
mpetrun5 Sep 29, 2023
15ca617
Add evm config module
mpetrun5 Sep 29, 2023
01c27b9
Remove config module from core library
mpetrun5 Sep 29, 2023
9ad8df7
Move keyring to crypto module
mpetrun5 Sep 29, 2023
f16fd6b
Move modules related to transactions to transactor module
mpetrun5 Sep 29, 2023
9a0f09e
Fix tests and mocks
mpetrun5 Oct 2, 2023
f2f2fbc
Add additional github actions
mpetrun5 Oct 2, 2023
9180b16
Fix linter
mpetrun5 Oct 2, 2023
f9be6f9
Replace mockgen lib
mpetrun5 Oct 2, 2023
14105b6
Backport substrate chain from relayer
mpetrun5 Oct 2, 2023
43ae2e1
Fix dependecies
mpetrun5 Oct 2, 2023
614cac2
Bump go-ethereum
mpetrun5 Oct 2, 2023
176eaa8
Update import
mpetrun5 Oct 2, 2023
47f26ec
Remove keystore and sr25519 support
mpetrun5 Oct 2, 2023
7b14fc0
Hardcode random ethereum private key
mpetrun5 Oct 2, 2023
68efd2c
Rename message handler in tests
mpetrun5 Oct 2, 2023
2b9ebb3
Merge branch 'main' into add-substrate-code
mpetrun5 Oct 4, 2023
3526c83
Regenerate mocks
mpetrun5 Oct 4, 2023
d9a4739
Bump critical dependency
mpetrun5 Oct 4, 2023
84293fe
Refactor chain so it receives messages instead of expecting to write
mpetrun5 Oct 4, 2023
8685cb7
Make chain receive one message at a time
mpetrun5 Oct 5, 2023
54701a9
Remove deposit specific metrics
mpetrun5 Oct 5, 2023
d2f42b1
Create generic message handler for both networks
mpetrun5 Oct 5, 2023
7224501
Update godocs
mpetrun5 Oct 5, 2023
14f8ce3
Implement generic message handler
mpetrun5 Oct 5, 2023
c1a8fd9
Merge branch 'main' into mpetrun5/enable-messages-both-ways
mpetrun5 Oct 5, 2023
f9531ca
Remove extra substrate message handler
mpetrun5 Oct 5, 2023
2f9f117
Fix linter error
mpetrun5 Oct 5, 2023
d34b1f8
Update relayer/relayer.go
MakMuftic Oct 18, 2023
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
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 @@ -7,8 +7,8 @@ import (
"context"
"math/big"

"github.com/ChainSafe/sygma-core/store"
"github.com/ChainSafe/sygma-core/types"
"github.com/ChainSafe/sygma-core/relayer/message"
"github.com/ChainSafe/sygma-core/relayer/proposal"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
Expand All @@ -18,29 +18,33 @@ type EventListener interface {
}

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 @@ -4,41 +4,41 @@ import (
"context"
"math/big"

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

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
Loading