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: Multiple GSRPC version support #347

Merged
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
31 changes: 24 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package app
import (
"context"
"fmt"
substrateCheckMetadataModeEnabledSignature "github.com/sygmaprotocol/go-substrate-rpc-client/v4/signature"
substrateCheckMetadataModeEnabledClient "github.com/sygmaprotocol/sygma-core/chains/substrate/client"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -50,7 +52,9 @@ import (
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor/monitored"
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor/transaction"
substrateClient "github.com/sygmaprotocol/sygma-core/chains/substrate/client"
"github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
connection "github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
connectionCheckMetadataModeEnabled "github.com/sygmaprotocol/sygma-core/chains/substrate/connection"

coreSubstrateListener "github.com/sygmaprotocol/sygma-core/chains/substrate/listener"

"github.com/ChainSafe/sygma-relayer/comm/elector"
Expand Down Expand Up @@ -255,17 +259,30 @@ func Run() error {
panic(err)
}

conn, err := connection.NewSubstrateConnection(config.GeneralChainConfig.Endpoint)
keyPair, err := signature.KeyringPairFromSecret(config.GeneralChainConfig.Key, config.SubstrateNetwork)
if err != nil {
panic(err)
}
keyPair, err := signature.KeyringPairFromSecret(config.GeneralChainConfig.Key, config.SubstrateNetwork)

conn, err := connection.NewSubstrateConnection(config.GeneralChainConfig.Endpoint)
if err != nil {
panic(err)
}

substrateClient := substrateClient.NewSubstrateClient(conn, &keyPair, config.ChainID, config.Tip)
bridgePallet := substratePallet.NewPallet(substrateClient)
subClient := substrateClient.NewSubstrateClient(conn, &keyPair, config.ChainID, config.Tip)
bridgePallet := substratePallet.NewPallet(subClient, nil, false)

// Temporarily differ the substrate chain with CheckMetadataModeEnabled chain and non-CheckMetadataModeEnabled
// chain by the endpoint name without touching the chain configure.
// This will only stay in this temporary feature branch
isCheckMetadataModeEnabled := strings.Contains(config.GeneralChainConfig.Endpoint, "tangle")
if isCheckMetadataModeEnabled {
connCheckMetadataModeEnabled, err := connectionCheckMetadataModeEnabled.NewCheckMetadataModeEnabledConnection(config.GeneralChainConfig.Endpoint)
if err != nil {
panic(err)
}
subCheckMetadataModeEnabledClient := substrateCheckMetadataModeEnabledClient.NewSubstrateCheckMetadataModeEnabledClient(connCheckMetadataModeEnabled, (*substrateCheckMetadataModeEnabledSignature.KeyringPair)(&keyPair), config.ChainID, config.Tip)
bridgePallet = substratePallet.NewPallet(nil, subCheckMetadataModeEnabledClient, true)
}

log.Info().Str("domain", config.String()).Msgf("Registering substrate domain")

Expand All @@ -288,7 +305,7 @@ func Run() error {
panic(err)
}
if startBlock == nil {
head, err := substrateClient.LatestBlock()
head, err := subClient.LatestBlock()
if err != nil {
panic(err)
}
Expand Down
47 changes: 38 additions & 9 deletions chains/substrate/pallet/pallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,25 @@ type BridgeProposal struct {
}

type Pallet struct {
*client.SubstrateClient
c *client.SubstrateClient
m *client.SubstrateCheckMetadataModeEnabledClient
isCheckMetadataModeEnabled bool
}

func (p *Pallet) TrackExtrinsic(extHash types.Hash, sub *author.ExtrinsicStatusSubscription) error {
//TODO implement me
return nil
}

func NewPallet(
client *client.SubstrateClient,
checkMetadataModeEnabledClient *client.SubstrateCheckMetadataModeEnabledClient,
isCheckMetadataModeEnabled bool,
) *Pallet {
return &Pallet{
client,
checkMetadataModeEnabledClient,
isCheckMetadataModeEnabled,
}
}

Expand All @@ -53,15 +64,27 @@ func (p *Pallet) ExecuteProposals(
})
}

return p.Transact(
"SygmaBridge.execute_proposal",
bridgeProposals,
signature,
)
if p.isCheckMetadataModeEnabled {
mpetrun5 marked this conversation as resolved.
Show resolved Hide resolved
hash, _, err := p.m.Transact(
"SygmaBridge.execute_proposal",
bridgeProposals,
signature,
)
return types.Hash(hash), nil, err
} else {
return p.c.Transact(
"SygmaBridge.execute_proposal",
bridgeProposals,
signature,
)
}
}

func (p *Pallet) ProposalsHash(proposals []*transfer.TransferProposal) ([]byte, error) {
return chains.ProposalsHash(proposals, p.ChainID.Int64(), verifyingContract, bridgeVersion)
if !p.isCheckMetadataModeEnabled {
return chains.ProposalsHash(proposals, p.c.ChainID.Int64(), verifyingContract, bridgeVersion)
}
return chains.ProposalsHash(proposals, p.m.ChainID.Int64(), verifyingContract, bridgeVersion)
}

func (p *Pallet) IsProposalExecuted(prop *transfer.TransferProposal) (bool, error) {
Expand All @@ -71,10 +94,16 @@ func (p *Pallet) IsProposalExecuted(prop *transfer.TransferProposal) (bool, erro
Str("resourceID", hexutil.Encode(prop.Data.ResourceId[:])).
Msg("Getting is proposal executed")
var res bool
err := p.Conn.Call(&res, "sygma_isProposalExecuted", prop.Data.DepositNonce, prop.Source)
if !p.isCheckMetadataModeEnabled {
err := p.c.Conn.Call(&res, "sygma_isProposalExecuted", prop.Data.DepositNonce, prop.Source)
if err != nil {
return false, err
}
return res, nil
}
err := p.m.Conn.Call(&res, "sygma_isProposalExecuted", prop.Data.DepositNonce, prop.Source)
if err != nil {
return false, err
}

return res, nil
}
28 changes: 22 additions & 6 deletions example/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ package app
import (
"context"
"fmt"
substrateCheckMetadataModeEnabledSignature "github.com/sygmaprotocol/go-substrate-rpc-client/v4/signature"
substrateCheckMetadataModeEnabledClient "github.com/sygmaprotocol/sygma-core/chains/substrate/client"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
Expand All @@ -23,7 +26,8 @@ import (
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor/transaction"
coreSubstrate "github.com/sygmaprotocol/sygma-core/chains/substrate"
substrateClient "github.com/sygmaprotocol/sygma-core/chains/substrate/client"
"github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
connection "github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
connectionCheckMetadataModeEnabled "github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
coreSubstrateListener "github.com/sygmaprotocol/sygma-core/chains/substrate/listener"
"github.com/sygmaprotocol/sygma-core/crypto/secp256k1"
"github.com/sygmaprotocol/sygma-core/observability"
Expand Down Expand Up @@ -212,21 +216,33 @@ func Run() error {
panic(err)
}

conn, err := connection.NewSubstrateConnection(config.GeneralChainConfig.Endpoint)
keyPair, err := signature.KeyringPairFromSecret(config.GeneralChainConfig.Key, config.SubstrateNetwork)
if err != nil {
panic(err)
}

keyPair, err := signature.KeyringPairFromSecret(config.GeneralChainConfig.Key, config.SubstrateNetwork)
conn, err := connection.NewSubstrateConnection(config.GeneralChainConfig.Endpoint)
if err != nil {
panic(err)
}
subClient := substrateClient.NewSubstrateClient(conn, &keyPair, config.ChainID, config.Tip)
bridgePallet := substratePallet.NewPallet(subClient, nil, false)

// Temporarily differ the substrate chain with CheckMetadataModeEnabled chain and non-CheckMetadataModeEnabled
// chain by the endpoint name without touching the chain configure.
// This will only stay in this temporary feature branch
isCheckMetadataModeEnabled := strings.Contains(config.GeneralChainConfig.Endpoint, "tangle")
if isCheckMetadataModeEnabled {
connCheckMetadataModeEnabled, err := connectionCheckMetadataModeEnabled.NewCheckMetadataModeEnabledConnection(config.GeneralChainConfig.Endpoint)
if err != nil {
panic(err)
}
subCheckMetadataModeEnabledClient := substrateCheckMetadataModeEnabledClient.NewSubstrateCheckMetadataModeEnabledClient(connCheckMetadataModeEnabled, (*substrateCheckMetadataModeEnabledSignature.KeyringPair)(&keyPair), config.ChainID, config.Tip)
bridgePallet = substratePallet.NewPallet(nil, subCheckMetadataModeEnabledClient, true)
}

log.Info().Str("domain", config.String()).Msgf("Registering substrate domain")

substrateClient := substrateClient.NewSubstrateClient(conn, &keyPair, config.ChainID, config.Tip)
bridgePallet := substratePallet.NewPallet(substrateClient)

l := log.With().Str("chain", fmt.Sprintf("%v", config.GeneralChainConfig.Name)).Uint8("domainID", *config.GeneralChainConfig.Id)
depositHandler := substrateListener.NewSubstrateDepositHandler()
depositHandler.RegisterDepositHandler(transfer.FungibleTransfer, substrateListener.FungibleTransferHandler)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.8.4
github.com/sygmaprotocol/sygma-core v0.0.0-20240710140025-258996be150b
github.com/sygmaprotocol/go-substrate-rpc-client/v4 v4.2.2-0.20240813185906-0395c914c6f8
github.com/sygmaprotocol/sygma-core v0.0.0-20240813191424-fff897579766
github.com/taurusgroup/multi-party-sig v0.6.0-alpha-2021-09-21.0.20230619131919-9c7c6ffd7217
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,12 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/sygmaprotocol/go-substrate-rpc-client/v4 v4.2.2-0.20240813185906-0395c914c6f8 h1:I1yWp/SlL96ZirqU6qhwvW1Mpmw7SnaAu+RfwBXYX/g=
github.com/sygmaprotocol/go-substrate-rpc-client/v4 v4.2.2-0.20240813185906-0395c914c6f8/go.mod h1:UMezfYq6Blh0C7RPTfNwtbVmNOSfu6mwoiu2F8kWUTI=
github.com/sygmaprotocol/multi-party-sig v0.0.0-20240523153754-9377ba09c35e h1:IzidTxe1CT6O5qy2gK9NQO/hrC+2wjDGzCxCF+kjCKU=
github.com/sygmaprotocol/multi-party-sig v0.0.0-20240523153754-9377ba09c35e/go.mod h1:roZI3gaKCo15PUSB4LdJpTLTjq8TFsJiOH5kpcN1HpQ=
github.com/sygmaprotocol/sygma-core v0.0.0-20240710140025-258996be150b h1:gaXOurg/0X/iKS7uED0RLTieilJymQUNoyXOTwI1710=
github.com/sygmaprotocol/sygma-core v0.0.0-20240710140025-258996be150b/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc=
github.com/sygmaprotocol/sygma-core v0.0.0-20240813191424-fff897579766 h1:ER6BmCv6BbEPOpyzmz4MipkKFjsfxNw8v1SlkFoOi2A=
github.com/sygmaprotocol/sygma-core v0.0.0-20240813191424-fff897579766/go.mod h1:lQqFgR6Pz5aRe1D0U4b8PBRE8z3pmkXNQkXa1FBLTrg=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
Expand Down
Loading