Skip to content

Commit

Permalink
Merge branch 'main' into feat/499/member-nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikelle authored Dec 10, 2024
2 parents 7fd9e7e + fb7cba9 commit 29dd768
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 865 deletions.
12 changes: 6 additions & 6 deletions bridge/standard/cmd/relayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ var (
},
})

optionL1RPCUrl = altsrc.NewStringFlag(&cli.StringFlag{
Name: "l1-rpc-url",
Usage: "URL for L1 RPC",
EnvVars: []string{"STANDARD_BRIDGE_RELAYER_L1_RPC_URL"},
optionL1RPCUrls = altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
Name: "l1-rpc-urls",
Usage: "URLs for L1 RPC",
EnvVars: []string{"STANDARD_BRIDGE_RELAYER_L1_RPC_URLS"},
Required: true,
})

Expand Down Expand Up @@ -158,7 +158,7 @@ func main() {
optionLogFmt,
optionLogLevel,
optionLogTags,
optionL1RPCUrl,
optionL1RPCUrls,
optionSettlementRPCUrl,
optionL1ContractAddr,
optionSettlementContractAddr,
Expand Down Expand Up @@ -219,7 +219,7 @@ func start(c *cli.Context) error {
Logger: logger,
HTTPPort: c.Int(optionHTTPPort.Name),
Signer: signer,
L1RPCURL: c.String(optionL1RPCUrl.Name),
L1RPCURLs: c.StringSlice(optionL1RPCUrls.Name),
L1GatewayContractAddr: common.HexToAddress(c.String(optionL1ContractAddr.Name)),
SettlementRPCURL: c.String(optionSettlementRPCUrl.Name),
SettlementContractAddr: common.HexToAddress(c.String(optionSettlementContractAddr.Name)),
Expand Down
3 changes: 3 additions & 0 deletions bridge/standard/pkg/gwcontract/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type GatewayTransactor interface {
_recipient common.Address,
_amount *big.Int,
_counterpartyIdx *big.Int,
_finalizationFee *big.Int,
) (*types.Transaction, error)
}

Expand Down Expand Up @@ -71,6 +72,7 @@ func (g *Gateway[EventType]) FinalizeTransfer(
recipient common.Address,
amount *big.Int,
counterpartyIdx *big.Int,
finalizationFee *big.Int,
) error {
switch settled, err := g.store.IsSettled(ctx, counterpartyIdx); {
case err != nil:
Expand All @@ -92,6 +94,7 @@ func (g *Gateway[EventType]) FinalizeTransfer(
recipient,
amount,
counterpartyIdx,
finalizationFee,
)
if err != nil {
g.logger.Error(
Expand Down
32 changes: 20 additions & 12 deletions bridge/standard/pkg/gwcontract/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (t *testGatewayTransactor) FinalizeTransfer(
recipient common.Address,
amount *big.Int,
counterpartyIdx *big.Int,
finalizationFee *big.Int,
) (*types.Transaction, error) {
newNonce := t.nonce
t.nonce++
Expand Down Expand Up @@ -143,22 +144,25 @@ func TestGateway(t *testing.T) {

transfers := []*l1gateway.L1gatewayTransferInitiated{
{
Sender: common.HexToAddress("0x1234"),
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(100),
TransferIdx: big.NewInt(1),
Sender: common.HexToAddress("0x1234"),
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(100),
TransferIdx: big.NewInt(1),
CounterpartyFinalizationFee: big.NewInt(10),
},
{
Sender: common.HexToAddress("0x5678"),
Recipient: common.HexToAddress("0x1234"),
Amount: big.NewInt(200),
TransferIdx: big.NewInt(2),
Sender: common.HexToAddress("0x5678"),
Recipient: common.HexToAddress("0x1234"),
Amount: big.NewInt(200),
TransferIdx: big.NewInt(2),
CounterpartyFinalizationFee: big.NewInt(20),
},
{
Sender: common.HexToAddress("0x1234"),
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(300),
TransferIdx: big.NewInt(3),
Sender: common.HexToAddress("0x1234"),
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(300),
TransferIdx: big.NewInt(3),
CounterpartyFinalizationFee: big.NewInt(30),
},
}

Expand Down Expand Up @@ -208,6 +212,7 @@ func TestGateway(t *testing.T) {
transfer.Recipient,
transfer.Amount,
transfer.TransferIdx,
transfer.CounterpartyFinalizationFee,
); err != nil {
t.Fatal(err)
}
Expand All @@ -229,6 +234,7 @@ func TestGateway(t *testing.T) {
transfers[0].Recipient,
transfers[0].Amount,
transfers[0].TransferIdx,
transfers[0].CounterpartyFinalizationFee,
); err != nil {
t.Fatal(err)
}
Expand All @@ -241,6 +247,7 @@ func TestGateway(t *testing.T) {
common.HexToAddress("0x1234"),
big.NewInt(100),
big.NewInt(4),
big.NewInt(10),
); err == nil {
t.Fatal("expected error")
}
Expand All @@ -254,6 +261,7 @@ func publishTransfer(
event := brABI.Events["TransferInitiated"]
buf, err := event.Inputs.NonIndexed().Pack(
transfer.Amount,
transfer.CounterpartyFinalizationFee,
)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions bridge/standard/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Options struct {
Logger *slog.Logger
HTTPPort int
Signer keysigner.KeySigner
L1RPCURL string
L1RPCURLs []string
L1GatewayContractAddr common.Address
SettlementRPCURL string
SettlementContractAddr common.Address
Expand Down Expand Up @@ -100,7 +100,7 @@ func NewNode(opts *Options) (*Node, error) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

client, err := ethclient.DialContext(ctx, opts.L1RPCURL)
client, err := ethclient.DialContext(ctx, opts.L1RPCURLs[0])
if err != nil {
return nil, fmt.Errorf("failed to connect to the Ethereum node: %w", err)
}
Expand All @@ -125,7 +125,7 @@ func NewNode(opts *Options) (*Node, error) {
ctx,
"l1",
opts.Logger,
opts.L1RPCURL,
opts.L1RPCURLs,
opts.Signer,
opts.L1GatewayContractAddr,
l1Store,
Expand All @@ -139,7 +139,7 @@ func NewNode(opts *Options) (*Node, error) {
ctx,
"settlement",
opts.Logger,
opts.SettlementRPCURL,
[]string{opts.SettlementRPCURL},
opts.Signer,
opts.SettlementContractAddr,
settlementStore,
Expand Down Expand Up @@ -243,12 +243,12 @@ func (n *Node) createGatewayContract(
ctx context.Context,
component string,
logger *slog.Logger,
rpcURL string,
rpcURLs []string,
signer keysigner.KeySigner,
contractAddr common.Address,
st *store.Store,
) error {
client, err := ethclient.Dial(rpcURL)
client, err := ethclient.Dial(rpcURLs[0])
if err != nil {
return fmt.Errorf("failed to connect to the Ethereum node: %w", err)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (n *Node) createGatewayContract(

wrappedClient, err := ethwrapper.NewClient(
logger.With("component", fmt.Sprintf("%s/ethwrapper", component)),
[]string{rpcURL},
rpcURLs,
opts...,
)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions bridge/standard/pkg/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

type L1Gateway interface {
Subscribe(ctx context.Context) (<-chan *l1gateway.L1gatewayTransferInitiated, <-chan error)
FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int) error
FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int, finalizationFee *big.Int) error
}

type SettlementGateway interface {
Subscribe(ctx context.Context) (<-chan *settlementgateway.SettlementgatewayTransferInitiated, <-chan error)
FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int) error
FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int, finalizationFee *big.Int) error
}

type Relayer struct {
Expand Down Expand Up @@ -72,6 +72,7 @@ func (r *Relayer) Start(ctx context.Context) <-chan struct{} {
upd.Recipient,
upd.Amount,
upd.TransferIdx,
upd.CounterpartyFinalizationFee,
)
if err != nil {
r.logger.Error(
Expand Down Expand Up @@ -104,6 +105,7 @@ func (r *Relayer) Start(ctx context.Context) <-chan struct{} {
upd.Recipient,
upd.Amount,
upd.TransferIdx,
upd.CounterpartyFinalizationFee,
)
if err != nil {
r.logger.Error(
Expand Down
67 changes: 38 additions & 29 deletions bridge/standard/pkg/relayer/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
)

type Transfer struct {
Recipient common.Address
Amount *big.Int
TransferIdx *big.Int
Recipient common.Address
Amount *big.Int
TransferIdx *big.Int
FinalizationFee *big.Int
}

type testL1Gateway struct {
Expand All @@ -33,12 +34,13 @@ func (t *testL1Gateway) Subscribe(ctx context.Context) (<-chan *l1gateway.L1gate
return t.initiated, t.err
}

func (t *testL1Gateway) FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int) error {
func (t *testL1Gateway) FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int, finalizationFee *big.Int) error {
t.mu.Lock()
t.finalized = append(t.finalized, Transfer{
Recipient: recipient,
Amount: amount,
TransferIdx: transferIdx,
Recipient: recipient,
Amount: amount,
TransferIdx: transferIdx,
FinalizationFee: finalizationFee,
})
t.mu.Unlock()
return nil
Expand All @@ -55,12 +57,13 @@ func (t *testSettlementGateway) Subscribe(ctx context.Context) (<-chan *settleme
return t.initiated, t.err
}

func (t *testSettlementGateway) FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int) error {
func (t *testSettlementGateway) FinalizeTransfer(ctx context.Context, recipient common.Address, amount *big.Int, transferIdx *big.Int, finalizationFee *big.Int) error {
t.mu.Lock()
t.finalized = append(t.finalized, Transfer{
Recipient: recipient,
Amount: amount,
TransferIdx: transferIdx,
Recipient: recipient,
Amount: amount,
TransferIdx: transferIdx,
FinalizationFee: finalizationFee,
})
t.mu.Unlock()
return nil
Expand All @@ -83,32 +86,37 @@ func TestRelayer(t *testing.T) {

expTransfers := []Transfer{
{
Recipient: common.HexToAddress("0x1234"),
Amount: big.NewInt(100),
TransferIdx: big.NewInt(1),
Recipient: common.HexToAddress("0x1234"),
Amount: big.NewInt(100),
TransferIdx: big.NewInt(1),
FinalizationFee: big.NewInt(10),
},
{
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(200),
TransferIdx: big.NewInt(2),
Recipient: common.HexToAddress("0x5678"),
Amount: big.NewInt(200),
TransferIdx: big.NewInt(2),
FinalizationFee: big.NewInt(20),
},
{
Recipient: common.HexToAddress("0x9abc"),
Amount: big.NewInt(300),
TransferIdx: big.NewInt(3),
Recipient: common.HexToAddress("0x9abc"),
Amount: big.NewInt(300),
TransferIdx: big.NewInt(3),
FinalizationFee: big.NewInt(30),
},
{
Recipient: common.HexToAddress("0xdef0"),
Amount: big.NewInt(400),
TransferIdx: big.NewInt(4),
Recipient: common.HexToAddress("0xdef0"),
Amount: big.NewInt(400),
TransferIdx: big.NewInt(4),
FinalizationFee: big.NewInt(40),
},
}

for _, transfer := range expTransfers {
l1Gateway.initiated <- &l1gateway.L1gatewayTransferInitiated{
Recipient: transfer.Recipient,
Amount: transfer.Amount,
TransferIdx: transfer.TransferIdx,
Recipient: transfer.Recipient,
Amount: transfer.Amount,
TransferIdx: transfer.TransferIdx,
CounterpartyFinalizationFee: transfer.FinalizationFee,
}
}

Expand All @@ -135,9 +143,10 @@ func TestRelayer(t *testing.T) {

for _, transfer := range expTransfers {
settlementGateway.initiated <- &settlementgateway.SettlementgatewayTransferInitiated{
Recipient: transfer.Recipient,
Amount: transfer.Amount,
TransferIdx: transfer.TransferIdx,
Recipient: transfer.Recipient,
Amount: transfer.Amount,
TransferIdx: transfer.TransferIdx,
CounterpartyFinalizationFee: transfer.FinalizationFee,
}
}

Expand Down
Loading

0 comments on commit 29dd768

Please sign in to comment.