Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sygmaprotocol/sygma-core into tcar/…
Browse files Browse the repository at this point in the history
…refactor-depositHandler

Signed-off-by: tcar <[email protected]>
  • Loading branch information
tcar121293 committed Oct 24, 2023
2 parents ca91e82 + 62219e0 commit 82c2902
Show file tree
Hide file tree
Showing 43 changed files with 1,081 additions and 625 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Create Sygma core release

on:
push:
branches:
- main
jobs:
release-please:
name: release
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:

- uses: actions/checkout@v2
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: go
package-name: release-please-action
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false},{"type":"revert","hidden":true}]'
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ genmocks:
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 -destination=chains/evm/eventhandlers/mock/eventhandlers.go -source=./chains/evm/eventhandlers/event-handler.go -package mock
mockgen -source=./relayer/message/handler.go -destination=./mock/message.go -package mock
mockgen -source=./chains/evm/listener/listener.go -destination=./mock/evmListener.go -package mock
mockgen -destination=./mock/substrateListener.go -package mock github.com/sygmaprotocol/sygma-core/chains/substrate/listener ChainConnection
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ When implementing a change:
7. Title the PR in a meaningful way and describe the rationale and the thought process in the PR description.
8. Write clean, thoughtful, and detailed [commit messages](https://chris.beams.io/posts/git-commit/).

If change entails an update that needs to be documented, please submit a PR to [chainbridge-docs](https://github.com/ChainSafe/chainbridge-docs/tree/develop/docs) repo.


### Submiting a PR

Expand Down
40 changes: 24 additions & 16 deletions chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,44 @@ import (
"context"
"math/big"

"github.com/ChainSafe/sygma-core/store"
"github.com/ChainSafe/sygma-core/types"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"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
4 changes: 2 additions & 2 deletions chains/evm/client/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"math/big"
"testing"

"github.com/ChainSafe/sygma-core/chains/evm/client"
"github.com/ChainSafe/sygma-core/crypto/secp256k1"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/suite"
"github.com/sygmaprotocol/sygma-core/chains/evm/client"
"github.com/sygmaprotocol/sygma-core/crypto/secp256k1"
)

type UtilsTestSuite struct {
Expand Down
4 changes: 2 additions & 2 deletions chains/evm/contracts/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"

"github.com/ChainSafe/sygma-core/chains/evm/client"
"github.com/ChainSafe/sygma-core/chains/evm/transactor"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/chains/evm/client"
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor"
)

const DefaultDeployGasLimit = 6000000
Expand Down
4 changes: 2 additions & 2 deletions chains/evm/contracts/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"strings"
"testing"

"github.com/ChainSafe/sygma-core/chains/evm/transactor"
"github.com/ChainSafe/sygma-core/mock"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor"
"github.com/sygmaprotocol/sygma-core/mock"
"go.uber.org/mock/gomock"
)

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

This file was deleted.

17 changes: 10 additions & 7 deletions chains/evm/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"math/big"
"time"

"github.com/ChainSafe/sygma-core/store"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
Expand All @@ -26,13 +24,17 @@ type BlockDeltaMeter interface {
TrackBlockDelta(domainID uint8, head *big.Int, current *big.Int)
}

type BlockStorer interface {
StoreBlock(block *big.Int, domainID uint8) error
}

type EVMListener struct {
client ChainClient
eventHandlers []EventHandler
metrics BlockDeltaMeter
blockstore BlockStorer

domainID uint8
blockstore *store.BlockStore
blockRetryInterval time.Duration
blockConfirmations *big.Int
blockInterval *big.Int
Expand All @@ -45,7 +47,7 @@ type EVMListener struct {
func NewEVMListener(
client ChainClient,
eventHandlers []EventHandler,
blockstore *store.BlockStore,
blockstore BlockStorer,
metrics BlockDeltaMeter,
domainID uint8,
blockRetryInterval time.Duration,
Expand All @@ -69,14 +71,15 @@ func NewEVMListener(
// configured for the listener.
func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int) {
endBlock := big.NewInt(0)
loop:
for {
select {
case <-ctx.Done():
return
default:
head, err := l.client.LatestBlock()
if err != nil {
l.log.Error().Err(err).Msg("Unable to get latest block")
l.log.Warn().Err(err).Msg("Unable to get latest block")
time.Sleep(l.blockRetryInterval)
continue
}
Expand All @@ -97,8 +100,8 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int) {
for _, handler := range l.eventHandlers {
err := handler.HandleEvents(startBlock, new(big.Int).Sub(endBlock, big.NewInt(1)))
if err != nil {
l.log.Error().Err(err).Msgf("Unable to handle events")
continue
l.log.Warn().Err(err).Msgf("Unable to handle events")
continue loop
}
}

Expand Down
Loading

0 comments on commit 82c2902

Please sign in to comment.