Skip to content

Commit

Permalink
relayer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Dec 9, 2024
1 parent 38adb17 commit f09a651
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
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
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

0 comments on commit f09a651

Please sign in to comment.