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

Parachain Relayer V2 #1321

Open
wants to merge 23 commits into
base: vincent/v2
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion contracts/src/v2/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface IGatewayV2 {
) external payable;

// Check if an inbound message was previously accepted and dispatched
function v2_isDispatched(uint64 nonce) external returns (bool);
function v2_isDispatched(uint64 nonce) external view returns (bool);

/// @dev Check whether a token is registered
function isTokenRegistered(address token) external view returns (bool);
Expand Down
49 changes: 49 additions & 0 deletions contracts/test/GatewayV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,53 @@ contract GatewayV2Test is Test {
// Agent balance should be 0.5 + 0.5
assertEq(token.balanceOf(assetHubAgent), 1 ether);
}

function testEncodeDecodeMessageV2() public {
UnlockNativeTokenParams memory params = UnlockNativeTokenParams({
token: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
recipient: 0xEDa338E4dC46038493b885327842fD3E301CaB39,
amount: 1_000_000
});
bytes memory encoded = abi.encode(params);
CommandV2[] memory commands = new CommandV2[](1);
commands[0] = CommandV2({
kind: CommandKind.UnlockNativeToken,
gas: 100_000,
payload: encoded
});
InboundMessageV2 memory message = InboundMessageV2({
origin: bytes32(uint256(1000)),
nonce: 1,
commands: commands
});
bytes memory rawBytes = abi.encode(message);

//From OutboundQueueV2
bytes memory data = abi.encodePacked(
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000186a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eda338e4dc46038493b885327842fd3e301cab3900000000000000000000000000000000000000000000000000000000000f4240"
);
assertEq(data, rawBytes);
InboundMessageV2 memory result = abi.decode(data, (InboundMessageV2));
assertEq(result.nonce, 1);
assertEq(result.commands.length, 1);
}

function testSubmitRegisterPNA() public {
//From Relayer V2
bytes memory data = abi.encodePacked(
hex"000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002e0d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000124f800000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000209441dceeeffa7e032eedaccf9b7632e60e86711551a82ffbbb0dda8afd9e4ef7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000020776e6401010101010101010101010101010101010101010101010101010101010000000000000000000000000000000000000000000000000000000000000020776e640101010101010101010101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000357fd8184830ac484da672bb9741f2b506f8503a1ac7e1cc48a47e1e0658ff382000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004bb47b15c3d292b996aa030ac4daa69f9ba4d07bba2846ad786fa9203cd7bba0e00000000000000000000000000000000000000000000000000000000000006200000000000000000000000000000000000000000000000000000000000000435620015748e29b5ddf1606eaa103b741d1b42cb5b6494e00e723415d50a8737f9000000000000000000000000000000000000000000000000000000000000001de0ab0b550176ac143add9e5dad46bf60f3ff09e6910ddcd8cbd0bd95d9af99c458e9af973605f8977d29a97331322ae8b7df3ee387660f4f78c391a8910b06c400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000006617572610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000008b1cb3111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004525053520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000021f2fa13b3689581ab90e8be6189a6a182bc5f18e67b0cd4d634780d57eda5e7abc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002100f97fc21a954ee5ce488329357e198fe1842be336d835186429d0d63b50ae6a43000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005617572610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000040deba90c498fc585fab36e1c5e916453b5bf9b1db0053740f456c8bb3cd319818bae31266b4091b569265cc091096c3759f0a37ab3c3ff47c49db45179454588c0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002c50ec1a82811ddd645332a2ba5b83d54e4b139cb6cccd8c243fe70ff46ee99107c8edcedf83c0365d02f0f0e81db16f5d26af633b1649447ae6227eb25f2d4d1000000000000000000000000000000000000000000000000000000000000000b4f279cd0d31616f60fbca046ca14d27d8c54183783356e2fde772b3af1ff640dec888d3366c7531cd23f04f924269472d18864602b96b8df7256bd5e13860bc455731c01ace46fb597458f801b25e372e783f539d5b1c4a2e0c1a821fe5338e3ca7022028de5b7152ca06f8f2c9665f08f9352e39863a626c356f01ffa8a56d0a468414d1d507347b97e913fa7ea12775f986069d3fb6a67536e17558485623d17e94f9962a75ef8b0653f508f4374e3ac17c983014d1155c1940a1f0b6facfd7c7665562546908af6e378cae444aa7cc88768e03607261892617aae0bbffe3409335c9382edbf4177711abc4d7918354a70a8c7fba91e8048b303ec2d2d3f23350f3eed8dc9af2607a0642499f364aedebfc250fb5658250702f131c5e866a02e21d45bc6f83c95b520aa8cee188cc3680179d112cc78227897faa8264f8b758bc8264207401f3a9fbc051fcf4f9083b3591c95de65c00175b88eefcc96723f"
);
InboundMessageV2 memory message = abi.decode(data, (InboundMessageV2));
assertEq(message.nonce, 0);
assertEq(message.commands.length, 1);
hoax(relayer, 1 ether);
vm.expectEmit(true, false, false, false);
emit IGatewayBase.ForeignTokenRegistered(
bytes32(0x9441dceeeffa7e032eedaccf9b7632e60e86711551a82ffbbb0dda8afd9e4ef7),
address(0x7ff9C67c93D9f7318219faacB5c619a773AFeF6A)
);
IGatewayV2(address(gateway)).v2_submit(
message, proof, makeMockProof(), relayerRewardAddress
);
}
}
5 changes: 5 additions & 0 deletions relayer/chain/parachain/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sync"
"time"

"github.com/snowfork/go-substrate-rpc-client/v4/rpc/author"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
Expand Down Expand Up @@ -48,6 +49,10 @@ func NewParachainWriter(
}

func (wr *ParachainWriter) Start(ctx context.Context, eg *errgroup.Group) error {
err := wr.conn.ConnectWithHeartBeat(ctx, 30*time.Second)
if err != nil {
return err
}
nonce, err := wr.queryAccountNonce()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion relayer/cmd/generate_beacon_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func getEthereumEvent(ctx context.Context, gatewayContract *contracts.Gateway, c
for event == nil {
log.Info("looking for Ethereum event")

iter, err := gatewayContract.FilterOutboundMessageAccepted(&opts, [][32]byte{channelID}, [][32]byte{})
iter, err := gatewayContract.FilterOutboundMessageAccepted(&opts)
if err != nil {
return nil, err
}
Expand Down
19 changes: 14 additions & 5 deletions relayer/cmd/run/parachain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/sirupsen/logrus"
"github.com/snowfork/snowbridge/relayer/chain/ethereum"
para "github.com/snowfork/snowbridge/relayer/chain/parachain"
"github.com/snowfork/snowbridge/relayer/relays/parachain"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
)

var (
configFile string
privateKey string
privateKeyFile string
privateKeyID string
configFile string
privateKey string
privateKeyFile string
privateKeyID string
parachainPrivateKey string
)

func Command() *cobra.Command {
Expand All @@ -42,6 +44,8 @@ func Command() *cobra.Command {
cmd.Flags().StringVar(&privateKeyFile, "ethereum.private-key-file", "", "The file from which to read the private key")
cmd.Flags().StringVar(&privateKeyID, "ethereum.private-key-id", "", "The secret id to lookup the private key in AWS Secrets Manager")

cmd.Flags().StringVar(&parachainPrivateKey, "substrate.private-key", "", "substrate private key")

return cmd
}

Expand Down Expand Up @@ -70,7 +74,12 @@ func run(_ *cobra.Command, _ []string) error {
return err
}

relay, err := parachain.NewRelay(&config, keypair)
keypair2, err := para.ResolvePrivateKey(parachainPrivateKey, "", "")
if err != nil {
return err
}

relay, err := parachain.NewRelay(&config, keypair, keypair2)
if err != nil {
return err
}
Expand Down
Loading
Loading