Skip to content

Commit ce1d08a

Browse files
authored
Merge pull request #863 from rsksmart/feature/FLY-807
Feature/FLY-807 - Emergency pause functionality
2 parents 25d118e + 662d4e5 commit ce1d08a

File tree

70 files changed

+2310
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2310
-79
lines changed

.mockery.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ packages:
4040
DefaultCredentialsProvider:
4141
github.com/rsksmart/liquidity-provider-server/internal/adapters/entrypoints/rest/handlers:
4242
interfaces:
43+
ResignUseCase:
44+
AcceptQuoteUseCase:
4345
GetAssetsReportUseCase:
4446
PeginStatusUseCase:
4547
PegoutStatusUseCase:
@@ -64,6 +66,7 @@ packages:
6466
PegConfiguration:
6567
github.com/rsksmart/liquidity-provider-server/internal/entities/blockchain:
6668
interfaces:
69+
Pausable:
6770
BitcoinWallet:
6871
RootstockRpcServer:
6972
PeginContract:

internal/adapters/dataproviders/rootstock/bindings.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ type RskBridgeBinding interface {
4646
FilterBatchPegoutCreated(opts *bind.FilterOpts, btcTxHash [][32]byte) (*bindings.RskBridgeBatchPegoutCreatedIterator, error)
4747
}
4848

49+
type PausableBinding interface {
50+
PauseStatus(opts *bind.CallOpts) (struct {
51+
IsPaused bool
52+
Reason string
53+
Since uint64
54+
}, error)
55+
}
56+
4957
type PegoutBinding interface {
58+
PausableBinding
5059
HashPegOutQuote(opts *bind.CallOpts, quote bindings.QuotesPegOutQuote) ([32]byte, error)
5160
RefundPegOut(opts *bind.TransactOpts, quoteHash [32]byte, btcTx []byte, btcBlockHeaderHash [32]byte, partialMerkleTree *big.Int, merkleBranchHashes [][32]byte) (*types.Transaction, error)
5261
FilterPegOutDeposit(opts *bind.FilterOpts, quoteHash [][32]byte, sender []common.Address, timestamp []*big.Int) (*bindings.IPegOutPegOutDepositIterator, error)
@@ -63,6 +72,7 @@ type PegoutContractAdapter interface {
6372
}
6473

6574
type PeginBinding interface {
75+
PausableBinding
6676
HashPegInQuote(opts *bind.CallOpts, quote bindings.QuotesPegInQuote) ([32]byte, error)
6777
RegisterPegIn(opts *bind.TransactOpts, quote bindings.QuotesPegInQuote, signature []byte, btcRawTransaction []byte, partialMerkleTree []byte, height *big.Int) (*types.Transaction, error)
6878
CallForUser(opts *bind.TransactOpts, quote bindings.QuotesPegInQuote) (*types.Transaction, error)
@@ -76,6 +86,7 @@ type PeginContractAdapter interface {
7686
}
7787

7888
type DiscoveryBinding interface {
89+
PausableBinding
7990
IsOperational(opts *bind.CallOpts, providerType uint8, addr common.Address) (bool, error)
8091
GetProviders(opts *bind.CallOpts) ([]bindings.FlyoverLiquidityProvider, error)
8192
GetProvider(opts *bind.CallOpts, providerAddress common.Address) (bindings.FlyoverLiquidityProvider, error)
@@ -86,6 +97,7 @@ type DiscoveryBinding interface {
8697
}
8798

8899
type CollateralManagementBinding interface {
100+
PausableBinding
89101
FilterPenalized(opts *bind.FilterOpts, liquidityProvider []common.Address, punisher []common.Address, quoteHash [][32]byte) (*bindings.ICollateralManagementPenalizedIterator, error)
90102
Resign(opts *bind.TransactOpts) (*types.Transaction, error)
91103
GetPegInCollateral(opts *bind.CallOpts, addr common.Address) (*big.Int, error)

internal/adapters/dataproviders/rootstock/bindings/flyover_contracts.go

Lines changed: 589 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/adapters/dataproviders/rootstock/collateral_management_contract.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,12 @@ func (collateral *collateralManagementContractImpl) GetPenalizedEvents(ctx conte
240240
}
241241
return result, nil
242242
}
243+
244+
func (collateral *collateralManagementContractImpl) PausedStatus() (blockchain.PauseStatus, error) {
245+
opts := new(bind.CallOpts)
246+
return rskRetry(
247+
collateral.retryParams.Retries,
248+
collateral.retryParams.Sleep,
249+
func() (blockchain.PauseStatus, error) { return collateral.contract.PauseStatus(opts) },
250+
)
251+
}

internal/adapters/dataproviders/rootstock/collateral_management_contract_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/rsksmart/liquidity-provider-server/internal/adapters/dataproviders/rootstock"
99
"github.com/rsksmart/liquidity-provider-server/internal/adapters/dataproviders/rootstock/bindings"
1010
"github.com/rsksmart/liquidity-provider-server/internal/entities"
11+
"github.com/rsksmart/liquidity-provider-server/internal/entities/blockchain"
1112
"github.com/rsksmart/liquidity-provider-server/internal/entities/penalization"
1213
"github.com/rsksmart/liquidity-provider-server/test"
1314
"github.com/rsksmart/liquidity-provider-server/test/mocks"
@@ -364,3 +365,29 @@ func TestLiquidityBridgeContractImpl_GetPunishmentEvents(t *testing.T) {
364365
iteratorMock.AssertExpectations(t)
365366
})
366367
}
368+
369+
func TestCollateralManagementContractImpl_PausedStatus(t *testing.T) {
370+
contractBinding := new(mocks.CollateralManagementAdapterMock)
371+
contract := rootstock.NewCollateralManagementContractImpl(dummyClient, test.AnyRskAddress, test.AnyAddress, contractBinding, nil, rootstock.RetryParams{}, time.Duration(1), Abis)
372+
t.Run("should return pause status result", func(t *testing.T) {
373+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
374+
IsPaused bool
375+
Reason string
376+
Since uint64
377+
}{IsPaused: true, Reason: "test", Since: 123}, nil).Once()
378+
result, err := contract.PausedStatus()
379+
require.NoError(t, err)
380+
assert.Equal(t, blockchain.PauseStatus{IsPaused: true, Reason: "test", Since: 123}, result)
381+
})
382+
t.Run("should handle error checking pause status", func(t *testing.T) {
383+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
384+
IsPaused bool
385+
Reason string
386+
Since uint64
387+
}{}, assert.AnError).Once()
388+
result, err := contract.PausedStatus()
389+
require.Error(t, err)
390+
assert.Empty(t, result)
391+
})
392+
contractBinding.AssertExpectations(t)
393+
}

internal/adapters/dataproviders/rootstock/discovery_contract.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ func (discovery *discoveryContractImpl) IsOperational(providerType liquidity_pro
212212
})
213213
}
214214

215+
func (discovery *discoveryContractImpl) PausedStatus() (blockchain.PauseStatus, error) {
216+
opts := new(bind.CallOpts)
217+
return rskRetry(
218+
discovery.retryParams.Retries,
219+
discovery.retryParams.Sleep,
220+
func() (blockchain.PauseStatus, error) { return discovery.contract.PauseStatus(opts) },
221+
)
222+
}
223+
215224
func (discovery *discoveryContractImpl) toContractProviderType(providerType liquidity_provider.ProviderType) (uint8, error) {
216225
if !providerType.IsValid() {
217226
return 0, liquidity_provider.InvalidProviderTypeError

internal/adapters/dataproviders/rootstock/discovery_contract_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,29 @@ func TestDiscoveryContractImpl_IsOperational(t *testing.T) {
435435
})
436436
})
437437
}
438+
439+
func TestDiscoveryContractImpl_PausedStatus(t *testing.T) {
440+
contractBinding := &mocks.DiscoveryBindingMock{}
441+
discovery := rootstock.NewDiscoveryContractImpl(dummyClient, test.AnyAddress, contractBinding, nil, rootstock.RetryParams{}, time.Duration(1), Abis)
442+
t.Run("should return pause status result", func(t *testing.T) {
443+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
444+
IsPaused bool
445+
Reason string
446+
Since uint64
447+
}{IsPaused: true, Reason: "test", Since: 123}, nil).Once()
448+
result, err := discovery.PausedStatus()
449+
require.NoError(t, err)
450+
assert.Equal(t, blockchain.PauseStatus{IsPaused: true, Reason: "test", Since: 123}, result)
451+
})
452+
t.Run("should handle error checking pause status", func(t *testing.T) {
453+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
454+
IsPaused bool
455+
Reason string
456+
Since uint64
457+
}{}, assert.AnError).Once()
458+
result, err := discovery.PausedStatus()
459+
require.Error(t, err)
460+
assert.Empty(t, result)
461+
})
462+
contractBinding.AssertExpectations(t)
463+
}

internal/adapters/dataproviders/rootstock/pegin_contract.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ func (peginContract *peginContractImpl) RegisterPegin(params blockchain.Register
240240
return transactionReceipt, nil
241241
}
242242

243+
func (peginContract *peginContractImpl) PausedStatus() (blockchain.PauseStatus, error) {
244+
opts := new(bind.CallOpts)
245+
return rskRetry(
246+
peginContract.retryParams.Retries,
247+
peginContract.retryParams.Sleep,
248+
func() (blockchain.PauseStatus, error) { return peginContract.contract.PauseStatus(opts) },
249+
)
250+
}
251+
243252
// parsePeginQuote parses a quote.PeginQuote into a bindings.QuotesPegInQuote. All BTC address fields support all address types
244253
// except for FedBtcAddress which must be a P2SH address.
245254
func parsePeginQuote(peginQuote quote.PeginQuote) (bindings.QuotesPegInQuote, error) {

internal/adapters/dataproviders/rootstock/pegin_contract_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,29 @@ func TestPeginContractImpl_RegisterPegin_ErrorHandling(t *testing.T) {
425425
assert.Empty(t, result)
426426
})
427427
}
428+
429+
func TestPeginContractImpl_PausedStatus(t *testing.T) {
430+
contractBinding := &mocks.PeginContractAdapterMock{}
431+
contract := rootstock.NewPeginContractImpl(dummyClient, test.AnyAddress, contractBinding, nil, rootstock.RetryParams{}, time.Duration(1), Abis)
432+
t.Run("should return pause status result", func(t *testing.T) {
433+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
434+
IsPaused bool
435+
Reason string
436+
Since uint64
437+
}{IsPaused: true, Reason: "test", Since: 123}, nil).Once()
438+
result, err := contract.PausedStatus()
439+
require.NoError(t, err)
440+
assert.Equal(t, blockchain.PauseStatus{IsPaused: true, Reason: "test", Since: 123}, result)
441+
})
442+
t.Run("should handle error checking pause status", func(t *testing.T) {
443+
contractBinding.EXPECT().PauseStatus(mock.Anything).Return(struct {
444+
IsPaused bool
445+
Reason string
446+
Since uint64
447+
}{}, assert.AnError).Once()
448+
result, err := contract.PausedStatus()
449+
require.Error(t, err)
450+
assert.Empty(t, result)
451+
})
452+
contractBinding.AssertExpectations(t)
453+
}

internal/adapters/dataproviders/rootstock/pegout_contract.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ func (pegoutContract *pegoutContractImpl) GetDepositEvents(ctx context.Context,
280280
return result, nil
281281
}
282282

283+
func (pegoutContract *pegoutContractImpl) PausedStatus() (blockchain.PauseStatus, error) {
284+
opts := new(bind.CallOpts)
285+
return rskRetry(
286+
pegoutContract.retryParams.Retries,
287+
pegoutContract.retryParams.Sleep,
288+
func() (blockchain.PauseStatus, error) { return pegoutContract.contract.PauseStatus(opts) },
289+
)
290+
}
291+
283292
// parsePegoutQuote parses a quote.PegoutQuote into a bindings.QuotesPegOutQuote. All BTC address fields support all address types.
284293
func parsePegoutQuote(pegoutQuote quote.PegoutQuote) (bindings.QuotesPegOutQuote, error) {
285294
var parsedQuote bindings.QuotesPegOutQuote

0 commit comments

Comments
 (0)