Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 58 additions & 99 deletions pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1597,25 +1597,18 @@ func (tc *TbtcChain) BuildRedemptionKey(
return buildRedemptionKey(walletPublicKeyHash, redeemerOutputScript)
}

func (tc *TbtcChain) GetDepositParameters() (
dustThreshold uint64,
treasuryFeeDivisor uint64,
txMaxFee uint64,
revealAheadPeriod uint32,
err error,
) {
parameters, callErr := tc.bridge.DepositParameters()
if callErr != nil {
err = callErr
return
func (tc *TbtcChain) GetDepositParameters() (tbtc.DepositParameters, error) {
parameters, err := tc.bridge.DepositParameters()
if err != nil {
return tbtc.DepositParameters{}, err
}

dustThreshold = parameters.DepositDustThreshold
treasuryFeeDivisor = parameters.DepositTreasuryFeeDivisor
txMaxFee = parameters.DepositTxMaxFee
revealAheadPeriod = parameters.DepositRevealAheadPeriod

return
return tbtc.DepositParameters{
DustThreshold: parameters.DepositDustThreshold,
TreasuryFeeDivisor: parameters.DepositTreasuryFeeDivisor,
TxMaxFee: parameters.DepositTxMaxFee,
RevealAheadPeriod: parameters.DepositRevealAheadPeriod,
}, nil
}

func (tc *TbtcChain) GetPendingRedemptionRequest(
Expand Down Expand Up @@ -1783,58 +1776,38 @@ func (tc *TbtcChain) SubmitDepositSweepProofWithReimbursement(
return err
}

func (tc *TbtcChain) GetRedemptionParameters() (
dustThreshold uint64,
treasuryFeeDivisor uint64,
txMaxFee uint64,
txMaxTotalFee uint64,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
err error,
) {
parameters, callErr := tc.bridge.RedemptionParameters()
if callErr != nil {
err = callErr
return
}

dustThreshold = parameters.RedemptionDustThreshold
treasuryFeeDivisor = parameters.RedemptionTreasuryFeeDivisor
txMaxFee = parameters.RedemptionTxMaxFee
txMaxTotalFee = parameters.RedemptionTxMaxTotalFee
timeout = parameters.RedemptionTimeout
timeoutSlashingAmount = parameters.RedemptionTimeoutSlashingAmount
timeoutNotifierRewardMultiplier = parameters.RedemptionTimeoutNotifierRewardMultiplier

return
}

func (tc *TbtcChain) GetWalletParameters() (
creationPeriod uint32,
creationMinBtcBalance uint64,
creationMaxBtcBalance uint64,
closureMinBtcBalance uint64,
maxAge uint32,
maxBtcTransfer uint64,
closingPeriod uint32,
err error,
) {
parameters, callErr := tc.bridge.WalletParameters()
if callErr != nil {
err = callErr
return
func (tc *TbtcChain) GetRedemptionParameters() (tbtc.RedemptionParameters, error) {
parameters, err := tc.bridge.RedemptionParameters()
if err != nil {
return tbtc.RedemptionParameters{}, err
}

creationPeriod = parameters.WalletCreationPeriod
creationMinBtcBalance = parameters.WalletCreationMinBtcBalance
creationMaxBtcBalance = parameters.WalletCreationMaxBtcBalance
closureMinBtcBalance = parameters.WalletClosureMinBtcBalance
maxAge = parameters.WalletMaxAge
maxBtcTransfer = parameters.WalletMaxBtcTransfer
closingPeriod = parameters.WalletClosingPeriod
return tbtc.RedemptionParameters{
DustThreshold: parameters.RedemptionDustThreshold,
TreasuryFeeDivisor: parameters.RedemptionTreasuryFeeDivisor,
TxMaxFee: parameters.RedemptionTxMaxFee,
TxMaxTotalFee: parameters.RedemptionTxMaxTotalFee,
Timeout: parameters.RedemptionTimeout,
TimeoutSlashingAmount: parameters.RedemptionTimeoutSlashingAmount,
TimeoutNotifierRewardMultiplier: parameters.RedemptionTimeoutNotifierRewardMultiplier,
}, nil
}

func (tc *TbtcChain) GetWalletParameters() (tbtc.WalletParameters, error) {
parameters, err := tc.bridge.WalletParameters()
if err != nil {
return tbtc.WalletParameters{}, err
}

return
return tbtc.WalletParameters{
CreationPeriod: parameters.WalletCreationPeriod,
CreationMinBtcBalance: parameters.WalletCreationMinBtcBalance,
CreationMaxBtcBalance: parameters.WalletCreationMaxBtcBalance,
ClosureMinBtcBalance: parameters.WalletClosureMinBtcBalance,
MaxAge: parameters.WalletMaxAge,
MaxBtcTransfer: parameters.WalletMaxBtcTransfer,
ClosingPeriod: parameters.WalletClosingPeriod,
}, nil
}

func (tc *TbtcChain) GetLiveWalletsCount() (uint32, error) {
Expand Down Expand Up @@ -2280,39 +2253,25 @@ func (tc *TbtcChain) ValidateHeartbeatProposal(
return nil
}

func (tc *TbtcChain) GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
) {
parameters, callErr := tc.bridge.MovingFundsParameters()
if callErr != nil {
err = callErr
return
}

txMaxTotalFee = parameters.MovingFundsTxMaxTotalFee
dustThreshold = parameters.MovingFundsDustThreshold
timeoutResetDelay = parameters.MovingFundsTimeoutResetDelay
timeout = parameters.MovingFundsTimeout
timeoutSlashingAmount = parameters.MovingFundsTimeoutSlashingAmount
timeoutNotifierRewardMultiplier = parameters.MovingFundsTimeoutNotifierRewardMultiplier
commitmentGasOffset = parameters.MovingFundsCommitmentGasOffset
sweepTxMaxTotalFee = parameters.MovedFundsSweepTxMaxTotalFee
sweepTimeout = parameters.MovedFundsSweepTimeout
sweepTimeoutSlashingAmount = parameters.MovedFundsSweepTimeoutSlashingAmount
sweepTimeoutNotifierRewardMultiplier = parameters.MovedFundsSweepTimeoutNotifierRewardMultiplier

return
func (tc *TbtcChain) GetMovingFundsParameters() (tbtc.MovingFundsParameters, error) {
parameters, err := tc.bridge.MovingFundsParameters()
if err != nil {
return tbtc.MovingFundsParameters{}, err
}

return tbtc.MovingFundsParameters{
TxMaxTotalFee: parameters.MovingFundsTxMaxTotalFee,
DustThreshold: parameters.MovingFundsDustThreshold,
TimeoutResetDelay: parameters.MovingFundsTimeoutResetDelay,
Timeout: parameters.MovingFundsTimeout,
TimeoutSlashingAmount: parameters.MovingFundsTimeoutSlashingAmount,
TimeoutNotifierRewardMultiplier: parameters.MovingFundsTimeoutNotifierRewardMultiplier,
CommitmentGasOffset: parameters.MovingFundsCommitmentGasOffset,
SweepTxMaxTotalFee: parameters.MovedFundsSweepTxMaxTotalFee,
SweepTimeout: parameters.MovedFundsSweepTimeout,
SweepTimeoutSlashingAmount: parameters.MovedFundsSweepTimeoutSlashingAmount,
SweepTimeoutNotifierRewardMultiplier: parameters.MovedFundsSweepTimeoutNotifierRewardMultiplier,
}, nil
}

func (tc *TbtcChain) GetMovedFundsSweepRequest(
Expand Down
15 changes: 1 addition & 14 deletions pkg/tbtc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,7 @@ type BridgeChain interface {

// GetMovingFundsParameters gets the current value of parameters relevant
// for the moving funds process.
GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
)
GetMovingFundsParameters() (MovingFundsParameters, error)

// PastMovingFundsCommitmentSubmittedEvents fetches past moving funds
// commitment submitted events according to the provided filter or
Expand Down
68 changes: 15 additions & 53 deletions pkg/tbtc/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ const (
stakingProvider = chain.Address("0x1111111111111111111111111111111111111111")
)

type movingFundsParameters = struct {
txMaxTotalFee uint64
dustThreshold uint64
timeoutResetDelay uint32
timeout uint32
timeoutSlashingAmount *big.Int
timeoutNotifierRewardMultiplier uint32
commitmentGasOffset uint16
sweepTxMaxTotalFee uint64
sweepTimeout uint32
sweepTimeoutSlashingAmount *big.Int
sweepTimeoutNotifierRewardMultiplier uint32
}

type localChain struct {
dkgResultSubmissionHandlersMutex sync.Mutex
dkgResultSubmissionHandlers map[int]func(submission *DKGResultSubmittedEvent)
Expand Down Expand Up @@ -109,7 +95,7 @@ type localChain struct {
depositRequests map[[32]byte]*DepositChainRequest

movingFundsParametersMutex sync.Mutex
movingFundsParameters movingFundsParameters
movingFundsParameters MovingFundsParameters

eligibleStakesMutex sync.Mutex
eligibleStakes map[chain.Address]*big.Int
Expand Down Expand Up @@ -1303,35 +1289,11 @@ func buildMovedFundsSweepProposalValidationKey(
return sha256.Sum256(buffer.Bytes()), nil
}

func (lc *localChain) GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
) {
func (lc *localChain) GetMovingFundsParameters() (MovingFundsParameters, error) {
lc.movingFundsParametersMutex.Lock()
defer lc.movingFundsParametersMutex.Unlock()

return lc.movingFundsParameters.txMaxTotalFee,
lc.movingFundsParameters.dustThreshold,
lc.movingFundsParameters.timeoutResetDelay,
lc.movingFundsParameters.timeout,
lc.movingFundsParameters.timeoutSlashingAmount,
lc.movingFundsParameters.timeoutNotifierRewardMultiplier,
lc.movingFundsParameters.commitmentGasOffset,
lc.movingFundsParameters.sweepTxMaxTotalFee,
lc.movingFundsParameters.sweepTimeout,
lc.movingFundsParameters.sweepTimeoutSlashingAmount,
lc.movingFundsParameters.sweepTimeoutNotifierRewardMultiplier,
nil
return lc.movingFundsParameters, nil
}

func (lc *localChain) SetMovingFundsParameters(
Expand All @@ -1350,18 +1312,18 @@ func (lc *localChain) SetMovingFundsParameters(
lc.movingFundsParametersMutex.Lock()
defer lc.movingFundsParametersMutex.Unlock()

lc.movingFundsParameters = movingFundsParameters{
txMaxTotalFee: txMaxTotalFee,
dustThreshold: dustThreshold,
timeoutResetDelay: timeoutResetDelay,
timeout: timeout,
timeoutSlashingAmount: timeoutSlashingAmount,
timeoutNotifierRewardMultiplier: timeoutNotifierRewardMultiplier,
commitmentGasOffset: commitmentGasOffset,
sweepTxMaxTotalFee: sweepTxMaxTotalFee,
sweepTimeout: sweepTimeout,
sweepTimeoutSlashingAmount: sweepTimeoutSlashingAmount,
sweepTimeoutNotifierRewardMultiplier: sweepTimeoutNotifierRewardMultiplier,
lc.movingFundsParameters = MovingFundsParameters{
TxMaxTotalFee: txMaxTotalFee,
DustThreshold: dustThreshold,
TimeoutResetDelay: timeoutResetDelay,
Timeout: timeout,
TimeoutSlashingAmount: timeoutSlashingAmount,
TimeoutNotifierRewardMultiplier: timeoutNotifierRewardMultiplier,
CommitmentGasOffset: commitmentGasOffset,
SweepTxMaxTotalFee: sweepTxMaxTotalFee,
SweepTimeout: sweepTimeout,
SweepTimeoutSlashingAmount: sweepTimeoutSlashingAmount,
SweepTimeoutNotifierRewardMultiplier: sweepTimeoutNotifierRewardMultiplier,
}
}

Expand Down
50 changes: 5 additions & 45 deletions pkg/tbtc/moving_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,7 @@ func ValidateMovingFundsProposal(

GetWallet(walletPublicKeyHash [20]byte) (*WalletChainData, error)

GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
)
GetMovingFundsParameters() (MovingFundsParameters, error)

PastMovingFundsCommitmentSubmittedEvents(
filter *MovingFundsCommitmentSubmittedEventFilter,
Expand Down Expand Up @@ -385,20 +372,7 @@ func ValidateMovingFundsSafetyMargin(

GetWallet(walletPublicKeyHash [20]byte) (*WalletChainData, error)

GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
)
GetMovingFundsParameters() (MovingFundsParameters, error)

PastMovingFundsCommitmentSubmittedEvents(
filter *MovingFundsCommitmentSubmittedEventFilter,
Expand Down Expand Up @@ -432,13 +406,12 @@ func ValidateMovingFundsSafetyMargin(
// As the moving funds procedure is time constrained, we must ensure the
// safety margin does not exceed half of the moving funds timeout parameter.
// This should give the wallet enough time to complete moving funds.
_, _, _, movingFundsTimeout, _, _, _, _, _, _, _, err :=
chain.GetMovingFundsParameters()
movingFundsParameters, err := chain.GetMovingFundsParameters()
if err != nil {
return fmt.Errorf("cannot get moving funds parameters: [%w]", err)
}

maxAllowedSafetyMargin := time.Duration(movingFundsTimeout/2) * time.Second
maxAllowedSafetyMargin := time.Duration(movingFundsParameters.Timeout/2) * time.Second

if safetyMargin > maxAllowedSafetyMargin {
safetyMargin = maxAllowedSafetyMargin
Expand Down Expand Up @@ -476,20 +449,7 @@ func isWalletPendingMovingFundsTarget(

GetWallet(walletPublicKeyHash [20]byte) (*WalletChainData, error)

GetMovingFundsParameters() (
txMaxTotalFee uint64,
dustThreshold uint64,
timeoutResetDelay uint32,
timeout uint32,
timeoutSlashingAmount *big.Int,
timeoutNotifierRewardMultiplier uint32,
commitmentGasOffset uint16,
sweepTxMaxTotalFee uint64,
sweepTimeout uint32,
sweepTimeoutSlashingAmount *big.Int,
sweepTimeoutNotifierRewardMultiplier uint32,
err error,
)
GetMovingFundsParameters() (MovingFundsParameters, error)

PastMovingFundsCommitmentSubmittedEvents(
filter *MovingFundsCommitmentSubmittedEventFilter,
Expand Down
Loading
Loading