diff --git a/go.work.sum b/go.work.sum index 6994b8e4..066e4ec2 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1395,6 +1395,7 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= diff --git a/integration-tests/contract/keys_rotation_test.go b/integration-tests/contract/keys_rotation_test.go index 781df731..f39fce8f 100644 --- a/integration-tests/contract/keys_rotation_test.go +++ b/integration-tests/contract/keys_rotation_test.go @@ -302,3 +302,40 @@ func TestKeysRotationWithRecovery(t *testing.T) { require.NoError(t, err) require.Equal(t, xrplToCoreumXRPLTokenTransferEvidence.Amount.String(), coreumRecipientBalance.Balance.Amount.String()) } + +func TestKeysRotationWithProhibitedAddresses(t *testing.T) { + t.Parallel() + + ctx, chains := integrationtests.NewTestingContext(t) + + initialRelayers := genRelayers(ctx, t, chains, 1) + owner, contractClient := integrationtests.DeployAndInstantiateContract( + ctx, + t, + chains, + initialRelayers, + uint32(len(initialRelayers)), + 20, + defaultTrustSetLimitAmount, + xrpl.GenPrivKeyTxSigner().Account().String(), + uint32(10), + ) + // recover tickets to be able to create operations from coreum to XRPL + recoverTickets(ctx, t, contractClient, owner, initialRelayers, 100) + + prohibitedXRPLAddresses, err := contractClient.GetProhibitedXRPLAddresses(ctx) + require.NoError(t, err) + + // keys rotation + for i := 0; i < len(prohibitedXRPLAddresses); i++ { + newRelayers := genRelayers(ctx, t, chains, 2) + // set one address from prohibited list + newRelayers[0].XRPLAddress = prohibitedXRPLAddresses[i] + _, err = contractClient.RotateKeys(ctx, + owner, + newRelayers, + 1, + ) + require.True(t, coreum.IsProhibitedAddressError(err), err) + } +} diff --git a/integration-tests/go.mod b/integration-tests/go.mod index fa09bf9f..2ca19929 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -20,7 +20,7 @@ replace ( ) require ( - github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543 + github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0 github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28 github.com/CoreumFoundation/coreumbridge-xrpl/relayer v1.0.0 github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 05a47548..a96a90d1 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -212,8 +212,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= -github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543 h1:BEegqwAFIRfym2hfqiBbRUTi28jK/u8Bn/1cwtK+ldI= -github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0= +github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0 h1:1PSfqh5NFBxCUJnZlPdQxx7BAdlqfQEjPm8MgvPZDJo= +github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0= github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28 h1:Xey8FAt4XtmlQsOQvHu45KjFOWU/TE8pOx54aLvgMPk= github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28/go.mod h1:m17GEOObKO0uMNRSeitPFjjne55MSbzFeTlAONaMGkI= github.com/CosmWasm/wasmd v0.44.0 h1:2sbcoCAvfjCs1O0SWt53xULKjkV06dbSFthEViIC6Zg= diff --git a/integration-tests/xrpl/scanner_test.go b/integration-tests/xrpl/scanner_test.go index ae49a58e..a56949ab 100644 --- a/integration-tests/xrpl/scanner_test.go +++ b/integration-tests/xrpl/scanner_test.go @@ -197,10 +197,10 @@ func validateTxsHashesInChannel( case <-scanCtx.Done(): return scanCtx.Err() case tx := <-txsCh: - // validate that we have all sent hashed and no duplicated + // validate that we have all sent hashes hash := strings.ToUpper(tx.GetHash().String()) if _, found := expectedHashes[hash]; !found { - return errors.Errorf("not found expected tx hash:%s", hash) + continue } delete(expectedHashes, hash) diff --git a/relayer/client/bridge.go b/relayer/client/bridge.go index 3ee8bcdc..77204bef 100644 --- a/relayer/client/bridge.go +++ b/relayer/client/bridge.go @@ -140,6 +140,7 @@ type ContractClient interface { operationID uint32, ) (*sdk.TxResponse, error) GetPendingOperations(ctx context.Context) ([]coreum.Operation, error) + GetTransactionEvidences(ctx context.Context) ([]coreum.TransactionEvidence, error) } // XRPLRPCClient is XRPL RPC client interface. @@ -1058,6 +1059,12 @@ func (b *BridgeClient) GetPendingOperations(ctx context.Context) ([]coreum.Opera return b.contractClient.GetPendingOperations(ctx) } +// GetTransactionEvidences returns a list of not confirmed transaction evidences. +func (b *BridgeClient) GetTransactionEvidences(ctx context.Context) ([]coreum.TransactionEvidence, error) { + b.log.Info(ctx, "Getting transaction evidences") + return b.contractClient.GetTransactionEvidences(ctx) +} + func (b *BridgeClient) validateXRPLBridgeAccountBalance( ctx context.Context, xrplBridgeAccount rippledata.Account, diff --git a/relayer/cmd/cli/cli.go b/relayer/cmd/cli/cli.go index 83b7a002..6b7d209b 100644 --- a/relayer/cmd/cli/cli.go +++ b/relayer/cmd/cli/cli.go @@ -213,6 +213,7 @@ type BridgeClient interface { operationID uint32, ) error GetPendingOperations(ctx context.Context) ([]coreum.Operation, error) + GetTransactionEvidences(ctx context.Context) ([]coreum.TransactionEvidence, error) } // BridgeClientProvider is function which returns the BridgeClient from the input cmd. diff --git a/relayer/cmd/cli/cli_mocks_test.go b/relayer/cmd/cli/cli_mocks_test.go index 3517a97e..d10a8446 100644 --- a/relayer/cmd/cli/cli_mocks_test.go +++ b/relayer/cmd/cli/cli_mocks_test.go @@ -218,6 +218,21 @@ func (mr *MockBridgeClientMockRecorder) GetProhibitedXRPLAddresses(arg0 interfac return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProhibitedXRPLAddresses", reflect.TypeOf((*MockBridgeClient)(nil).GetProhibitedXRPLAddresses), arg0) } +// GetTransactionEvidences mocks base method. +func (m *MockBridgeClient) GetTransactionEvidences(arg0 context.Context) ([]coreum.TransactionEvidence, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTransactionEvidences", arg0) + ret0, _ := ret[0].([]coreum.TransactionEvidence) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTransactionEvidences indicates an expected call of GetTransactionEvidences. +func (mr *MockBridgeClientMockRecorder) GetTransactionEvidences(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionEvidences", reflect.TypeOf((*MockBridgeClient)(nil).GetTransactionEvidences), arg0) +} + // GetXRPLBalances mocks base method. func (m *MockBridgeClient) GetXRPLBalances(arg0 context.Context, arg1 data.Account) ([]data.Amount, error) { m.ctrl.T.Helper() diff --git a/relayer/cmd/cli/coreum_cli.go b/relayer/cmd/cli/coreum_cli.go index c83a193a..135046ec 100644 --- a/relayer/cmd/cli/coreum_cli.go +++ b/relayer/cmd/cli/coreum_cli.go @@ -70,6 +70,8 @@ func CoreumCmd(bcp BridgeClientProvider) (*cobra.Command, error) { coreumQueryCmd.AddCommand(RelayerFeesCmd(bcp)) coreumQueryCmd.AddCommand(PendingOperationsCmd(bcp)) coreumQueryCmd.AddCommand(ProhibitedXRPLAddressesCmd(bcp)) + coreumQueryCmd.AddCommand(TransactionEvidencesCmd(bcp)) + AddHomeFlag(coreumQueryCmd) keyringCoreumCmd, err := KeyringCmd(CoreumKeyringSuffix, constant.CoinType, @@ -917,7 +919,7 @@ func PendingOperationsCmd(bcp BridgeClientProvider) *cobra.Command { if err != nil { return err } - log.Info(ctx, "Got pending operations", zap.Any("pendingOperations", pendingOperations)) + log.Info(ctx, "Got pending operations", zap.Any("operations", pendingOperations)) return nil }), @@ -945,13 +947,38 @@ $ prohibited-xrpl-addresses %s components.Log.Info( ctx, "Got prohibited XRPL addresses", - zap.Any("prohibitedXRPLAddresses", prohibitedXRPLAddresses), + zap.Any("addresses", prohibitedXRPLAddresses), ) return nil }), } } +// TransactionEvidencesCmd prints the not confirmed transaction evidences. +func TransactionEvidencesCmd(bcp BridgeClientProvider) *cobra.Command { + return &cobra.Command{ + Use: "transaction-evidences", + Short: "Print not confirmed transaction evidences.", + RunE: runBridgeCmd(bcp, + func(cmd *cobra.Command, args []string, components runner.Components, bridgeClient BridgeClient) error { + ctx := cmd.Context() + + transactionEvidences, err := bridgeClient.GetTransactionEvidences(ctx) + if err != nil { + return err + } + + log, err := GetCLILogger() + if err != nil { + return err + } + log.Info(ctx, "Got transaction evidences", zap.Any("evidences", transactionEvidences)) + + return nil + }), + } +} + // CoreumTxPreRun is Coreum transaction CMD pre-run function. func CoreumTxPreRun(bcp BridgeClientProvider) func(cmd *cobra.Command, args []string) error { return runBridgeCmd(bcp, diff --git a/relayer/cmd/cli/coreum_cli_test.go b/relayer/cmd/cli/coreum_cli_test.go index 451f8b14..799d75e3 100644 --- a/relayer/cmd/cli/coreum_cli_test.go +++ b/relayer/cmd/cli/coreum_cli_test.go @@ -1212,6 +1212,16 @@ func TestProhibitedXRPLAddressesCmd(t *testing.T) { executeQueryCmd(t, cli.ProhibitedXRPLAddressesCmd(mockBridgeClientProvider(bridgeClientMock)), initConfig(t)...) } +func TestTransactionEvidencesCmd(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + bridgeClientMock := NewMockBridgeClient(ctrl) + + bridgeClientMock.EXPECT().GetTransactionEvidences(gomock.Any()).Return([]coreum.TransactionEvidence{}, nil) + executeQueryCmd(t, cli.TransactionEvidencesCmd(mockBridgeClientProvider(bridgeClientMock)), initConfig(t)...) +} + func executeCoreumTxCmd(t *testing.T, bcp cli.BridgeClientProvider, cmd *cobra.Command, args ...string) { cli.AddCoreumTxFlags(cmd) cmd.PreRunE = cli.CoreumTxPreRun(bcp) diff --git a/relayer/go.mod b/relayer/go.mod index 1e600c0b..b3c3cd47 100644 --- a/relayer/go.mod +++ b/relayer/go.mod @@ -20,7 +20,7 @@ replace ( require ( cosmossdk.io/math v1.2.0 - github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543 + github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0 github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28 github.com/CosmWasm/wasmd v0.44.0 github.com/cosmos/cosmos-sdk v0.47.8 diff --git a/relayer/go.sum b/relayer/go.sum index b15ee372..51c15ac1 100644 --- a/relayer/go.sum +++ b/relayer/go.sum @@ -212,8 +212,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= -github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543 h1:BEegqwAFIRfym2hfqiBbRUTi28jK/u8Bn/1cwtK+ldI= -github.com/CoreumFoundation/coreum-tools v0.4.1-0.20231219065050-077b204f5543/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0= +github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0 h1:1PSfqh5NFBxCUJnZlPdQxx7BAdlqfQEjPm8MgvPZDJo= +github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240306133015-8a9ec4eb1bf0/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0= github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28 h1:Xey8FAt4XtmlQsOQvHu45KjFOWU/TE8pOx54aLvgMPk= github.com/CoreumFoundation/coreum/v4 v4.0.0-20240220134751-03b0f19e9a28/go.mod h1:m17GEOObKO0uMNRSeitPFjjne55MSbzFeTlAONaMGkI= github.com/CosmWasm/wasmd v0.44.0 h1:2sbcoCAvfjCs1O0SWt53xULKjkV06dbSFthEViIC6Zg= diff --git a/relayer/xrpl/rpc.go b/relayer/xrpl/rpc.go index 1385e5de..a09b62c3 100644 --- a/relayer/xrpl/rpc.go +++ b/relayer/xrpl/rpc.go @@ -339,7 +339,7 @@ func (c *RPCClient) AccountTx( MinLedger: minLedger, MaxLedger: maxLedger, Binary: false, - Forward: false, + Forward: true, Limit: c.cfg.PageLimit, Marker: marker, } diff --git a/relayer/xrpl/scanner.go b/relayer/xrpl/scanner.go index 5799d38c..95ba5d66 100644 --- a/relayer/xrpl/scanner.go +++ b/relayer/xrpl/scanner.go @@ -199,6 +199,7 @@ func (s *AccountScanner) scanTransactions( lastLedger = prevProcessedLedger prevProcessedLedger = int64(tx.LedgerSequence) } + indexRegistryFunc(float64(prevProcessedLedger)) if tx == nil { continue } @@ -209,9 +210,6 @@ func (s *AccountScanner) scanTransactions( } } } - if prevProcessedLedger != 0 { - indexRegistryFunc(float64(prevProcessedLedger)) - } if len(accountTxResult.Marker) == 0 { lastLedger = prevProcessedLedger break