Skip to content

Commit 0a488cc

Browse files
authored
Adjustments to the wallet proposal generator (#3788)
Refs: threshold-network/tbtc-v2#781 Depends on: threshold-network/tbtc-v2#788 (the `client-build-test-publish` job will become green once 788 is merged and a new `tbtc-v2@development` package with `RedemptionWatchtower` artifact will be published to npm) The optimistic redemption upgrade introduces a veto mechanism (threshold-network/tbtc-v2#788) that enforces a processing delay on each redemption request. The exact delay value depends on the number of objections raised against the given redemption request. The `WalletProposalValidator` contract has been modified to include validation of that delay factor. The first change ed9c4ae introduces the same for the redemption proposal generator. This ensures the generator issues proposals that conform to the on-chain validation rules and coordination windows are not being wasted. By the way, we are taking an opportunity to optimize the deposit sweep proposal generation. The `WalletProposalValidator` contract enforces the minimum age of a deposit that can become part of the proposal. The proposal generator was missing this check and was often producing invalid proposals that were violating the on-chain minimum deposit age rule. We fix that in 55be487.
2 parents 65a105d + dcdcdec commit 0a488cc

21 files changed

+10602
-43
lines changed

pkg/chain/ethereum/tbtc.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type TbtcChain struct {
4949
walletRegistry *ecdsacontract.WalletRegistry
5050
sortitionPool *ecdsacontract.EcdsaSortitionPool
5151
walletProposalValidator *tbtccontract.WalletProposalValidator
52+
redemptionWatchtower *tbtccontract.RedemptionWatchtower
5253
}
5354

5455
// NewTbtcChain construct a new instance of the TBTC-specific Ethereum
@@ -194,13 +195,48 @@ func newTbtcChain(
194195
)
195196
}
196197

198+
redemptionWatchtowerAddress, err := bridge.GetRedemptionWatchtower()
199+
if err != nil {
200+
return nil, fmt.Errorf(
201+
"failed to get RedemptionWatchtower address from Bridge: [%v]",
202+
err,
203+
)
204+
}
205+
206+
// The RedemptionWatchtower contract is an additional component
207+
// that implements the redemption veto mechanism. It is optional
208+
// and may not be present in the system. This code must be able
209+
// to handle the case when the RedemptionWatchtower contract is
210+
// not set.
211+
var redemptionWatchtower *tbtccontract.RedemptionWatchtower
212+
if redemptionWatchtowerAddress != [20]byte{} {
213+
redemptionWatchtower, err =
214+
tbtccontract.NewRedemptionWatchtower(
215+
redemptionWatchtowerAddress,
216+
baseChain.chainID,
217+
baseChain.key,
218+
baseChain.client,
219+
baseChain.nonceManager,
220+
baseChain.miningWaiter,
221+
baseChain.blockCounter,
222+
baseChain.transactionMutex,
223+
)
224+
if err != nil {
225+
return nil, fmt.Errorf(
226+
"failed to attach to RedemptionWatchtower contract: [%v]",
227+
err,
228+
)
229+
}
230+
}
231+
197232
return &TbtcChain{
198233
baseChain: baseChain,
199234
bridge: bridge,
200235
maintainerProxy: maintainerProxy,
201236
walletRegistry: walletRegistry,
202237
sortitionPool: sortitionPool,
203238
walletProposalValidator: walletProposalValidator,
239+
redemptionWatchtower: redemptionWatchtower,
204240
}, nil
205241
}
206242

@@ -2040,3 +2076,28 @@ func (tc *TbtcChain) ValidateMovingFundsProposal(
20402076

20412077
return nil
20422078
}
2079+
2080+
func (tc *TbtcChain) GetRedemptionDelay(
2081+
walletPublicKeyHash [20]byte,
2082+
redeemerOutputScript bitcoin.Script,
2083+
) (time.Duration, error) {
2084+
if tc.redemptionWatchtower == nil {
2085+
return 0, nil
2086+
}
2087+
2088+
redemptionKey, err := tc.BuildRedemptionKey(walletPublicKeyHash, redeemerOutputScript)
2089+
if err != nil {
2090+
return 0, fmt.Errorf("cannot build redemption key: [%v]", err)
2091+
}
2092+
2093+
delay, err := tc.redemptionWatchtower.GetRedemptionDelay(redemptionKey)
2094+
if err != nil {
2095+
return 0, fmt.Errorf("cannot get redemption delay: [%v]", err)
2096+
}
2097+
2098+
return time.Duration(delay) * time.Second, nil
2099+
}
2100+
2101+
func (tc *TbtcChain) GetDepositMinAge() (uint32, error) {
2102+
return tc.walletProposalValidator.DEPOSITMINAGE()
2103+
}

pkg/chain/ethereum/tbtc/gen/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
npm_package_name=@keep-network/tbtc-v2
22

33
# Contracts for which the bindings should be generated.
4-
required_contracts := Bridge MaintainerProxy LightRelay LightRelayMaintainerProxy WalletProposalValidator
4+
required_contracts := Bridge MaintainerProxy LightRelay LightRelayMaintainerProxy WalletProposalValidator RedemptionWatchtower
55

66
# There is a bug in the currently used abigen version (v1.10.19) that makes it
77
# re-declaring structs used by multiple contracts

pkg/chain/ethereum/tbtc/gen/_address/RedemptionWatchtower

Whitespace-only changes.

pkg/chain/ethereum/tbtc/gen/abi/Bridge.go

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

pkg/chain/ethereum/tbtc/gen/abi/RedemptionWatchtower.go

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

pkg/chain/ethereum/tbtc/gen/cmd/Bridge.go

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

0 commit comments

Comments
 (0)