Skip to content

Commit

Permalink
feat: full gravity multichain support (#397)
Browse files Browse the repository at this point in the history
* WIP

* Merge resolution

* chore: refactor Paloma client

* fix: send gravity_nonce in claims

* chore: redirect Paloma dep to feature branch
  • Loading branch information
byte-bandit authored Jun 11, 2024
1 parent 4916400 commit 29813e9
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 96 deletions.
2 changes: 1 addition & 1 deletion chain/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type PalomaClienter interface {
QueryGetEVMValsetByID(ctx context.Context, id uint64, chainID string) (*types.Valset, error)
SendBatchSendToEVMClaim(ctx context.Context, claim gravitytypes.MsgBatchSendToEthClaim) error
SendSendToPalomaClaim(ctx context.Context, claim gravitytypes.MsgSendToPalomaClaim) error
QueryGetLastEventNonce(ctx context.Context, orchestrator string) (uint64, error)
QueryLastObservedGravityNonceByAddr(ctx context.Context, chainReferenceID string, orchestrator string) (uint64, error)
QueryBatchRequestByNonce(ctx context.Context, nonce uint64, contract string) (gravitytypes.OutgoingTxBatch, error)
QueryGetLatestPublishedSnapshot(ctx context.Context, chainReferenceID string) (*valset.Snapshot, error)
}
Expand Down
34 changes: 24 additions & 10 deletions chain/evm/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (t *compass) GetBatchSendEvents(ctx context.Context, orchestrator string) (
filter, err := ethfilter.Factory().
WithFromBlockNumberProvider(t.evm.FindCurrentBlockNumber).
WithFromBlockNumberSafetyMargin(1).
WithTopics([]common.Hash{crypto.Keccak256Hash([]byte("BatchSendEvent(address,uint256,uint256)"))}).
WithTopics([]common.Hash{crypto.Keccak256Hash([]byte("BatchSendEvent(address,uint256,uint256,uint256)"))}).
WithAddresses(t.smartContractAddr).
Filter(ctx)
if err != nil {
Expand All @@ -701,7 +701,7 @@ func (t *compass) GetBatchSendEvents(ctx context.Context, orchestrator string) (
return nil, err
}

lastEventNonce, err := t.paloma.QueryGetLastEventNonce(ctx, orchestrator)
lastGravityNonce, err := t.paloma.QueryLastObservedGravityNonceByAddr(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
return nil, err
}
Expand All @@ -722,13 +722,18 @@ func (t *compass) GetBatchSendEvents(ctx context.Context, orchestrator string) (
return nil, fmt.Errorf("invalid batch nonce")
}

eventNonce, ok := event[2].(*big.Int)
gravityNonce, ok := event[2].(*big.Int)
if !ok {
return nil, fmt.Errorf("invalid gravity nonce")
}

eventNonce, ok := event[3].(*big.Int)
if !ok {
return nil, fmt.Errorf("invalid event nonce")
}

if eventNonce.Uint64() <= lastEventNonce {
liblog.WithContext(ctx).WithField("last-event-nonce", lastEventNonce).WithField("event-nonce", eventNonce.Uint64()).Info("Skipping already observed event...")
if gravityNonce.Uint64() <= lastGravityNonce {
liblog.WithContext(ctx).WithField("last-event-nonce", lastGravityNonce).WithField("gravity-nonce", gravityNonce.Uint64()).Info("Skipping already observed event...")
continue
}

Expand All @@ -737,6 +742,7 @@ func (t *compass) GetBatchSendEvents(ctx context.Context, orchestrator string) (
EventNonce: eventNonce.Uint64(),
BatchNonce: batchNonce.Uint64(),
TokenContract: tokenContract.String(),
GravityNonce: gravityNonce.Uint64(),
})
}

Expand All @@ -749,7 +755,7 @@ func (t *compass) GetSendToPalomaEvents(ctx context.Context, orchestrator string
filter, err := ethfilter.Factory().
WithFromBlockNumberProvider(t.evm.FindCurrentBlockNumber).
WithFromBlockNumberSafetyMargin(1).
WithTopics([]common.Hash{crypto.Keccak256Hash([]byte("SendToPalomaEvent(address,address,string,uint256,uint256)"))}).
WithTopics([]common.Hash{crypto.Keccak256Hash([]byte("SendToPalomaEvent(address,address,string,uint256,uint256,uint256)"))}).
WithAddresses(t.smartContractAddr).
Filter(ctx)
if err != nil {
Expand All @@ -771,7 +777,7 @@ func (t *compass) GetSendToPalomaEvents(ctx context.Context, orchestrator string
return nil, err
}

lastEventNonce, err := t.paloma.QueryGetLastEventNonce(ctx, orchestrator)
lastGravityNonce, err := t.paloma.QueryLastObservedGravityNonceByAddr(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -802,13 +808,18 @@ func (t *compass) GetSendToPalomaEvents(ctx context.Context, orchestrator string
return nil, fmt.Errorf("invalid amount")
}

eventNonce, ok := event[4].(*big.Int)
gravityNonce, ok := event[4].(*big.Int)
if !ok {
return nil, fmt.Errorf("invalid paloma nonce")
}

eventNonce, ok := event[5].(*big.Int)
if !ok {
return nil, fmt.Errorf("invalid event nonce")
}

if eventNonce.Uint64() <= lastEventNonce {
liblog.WithContext(ctx).WithField("last-event-nonce", lastEventNonce).WithField("event-nonce", eventNonce.Uint64()).Info("Skipping already observed event...")
if gravityNonce.Uint64() <= lastGravityNonce {
liblog.WithContext(ctx).WithField("last-event-nonce", lastGravityNonce).WithField("gravity-nonce", gravityNonce.Uint64()).Info("Skipping already observed event...")
continue
}

Expand All @@ -819,6 +830,7 @@ func (t *compass) GetSendToPalomaEvents(ctx context.Context, orchestrator string
EthereumSender: ethSender.String(),
PalomaReceiver: palomaReceiver,
TokenContract: tokenContract.String(),
GravityNonce: gravityNonce.Uint64(),
})
}

Expand Down Expand Up @@ -858,6 +870,7 @@ func (t compass) submitBatchSendToEVMClaim(ctx context.Context, event chain.Batc
TokenContract: event.TokenContract,
ChainReferenceId: t.ChainReferenceID,
Orchestrator: orchestrator,
GravityNonce: event.GravityNonce,
}
return t.paloma.SendBatchSendToEVMClaim(ctx, msg)
}
Expand All @@ -872,6 +885,7 @@ func (t compass) submitSendToPalomaClaim(ctx context.Context, event chain.SendTo
PalomaReceiver: event.PalomaReceiver,
ChainReferenceId: t.ChainReferenceID,
Orchestrator: orchestrator,
GravityNonce: event.GravityNonce,
}
return t.paloma.SendSendToPalomaClaim(ctx, msg)
}
Expand Down
26 changes: 13 additions & 13 deletions chain/evm/mock_ethClientConn_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/evm/mock_ethClientToFilterLogs_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions chain/evm/mock_ethClienter_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/evm/mock_mevClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/evm/mocks/CompassBinding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions chain/evm/mocks/PalomaClienter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 29813e9

Please sign in to comment.