Skip to content

Commit

Permalink
client/asset/eth: reduce redeem conf count to 3
Browse files Browse the repository at this point in the history
Post-Merge, reorgs are very difficult:

> even single-block reorgs are extremely difficult, because an
> attacker controlling only a few validators has no way to beat the
> honest majority of thousands of attesters.

from https://www.paradigm.xyz/2021/07/ethereum-reorgs-after-the-merge#post-merge-ethereum-with-proof-of-stake
  • Loading branch information
chappjc committed Feb 16, 2023
1 parent 02323e6 commit a9fdf04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ func (w *TokenWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Rede
}

const (
txConfsNeededToConfirm = 10
txConfsNeededToConfirm = 3
blocksToWaitBeforeCoinNotFound = 10
blocksToWaitBeforeCheckingIfReplaced = 10
)
Expand Down
43 changes: 22 additions & 21 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3752,10 +3752,10 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
blockSubmitted: 9,
},
},
bestBlock: 13,
bestBlock: 11, // tx.height + txConfsNeededToConfirm - 2
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 4,
Req: 10,
Confs: txConfsNeededToConfirm - 1,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(3, 200, redeem0Data),
},
baseFee: dexeth.GweiToWei(100),
Expand Down Expand Up @@ -3784,10 +3784,10 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
},
},
expectedMonitoredTxs: map[common.Hash]*monitoredTx{},
bestBlock: 19,
bestBlock: 12, // tx.height + txConfsNeededToConfirm
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 10,
Req: 10,
Confs: txConfsNeededToConfirm,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(3, 200, redeem0Data),
},
receipt: &types.Receipt{
Expand Down Expand Up @@ -3835,7 +3835,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 19,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0Data),
},
redeemTx: toEthTx(4, 123, redeem0Data),
Expand Down Expand Up @@ -3901,14 +3901,14 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0Data),
},
redeemTx: toEthTx(4, 123, redeem0Data),
baseFee: dexeth.GweiToWei(100),
},
{
name: "not in monitored txs, found by geth, < 10 confirmations",
name: "not in monitored txs, found by geth, < 3 confirmations",
coinID: toEthTxCoinID(3, 200, redeem0Data),
redemption: assetRedemption(secretHashes[0], secrets[0]),
getTxResMap: map[common.Hash]*txData{
Expand All @@ -3925,11 +3925,11 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
},
},
monitoredTxs: map[common.Hash]*monitoredTx{},
bestBlock: 13,
bestBlock: 11,

expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 4,
Req: 10,
Confs: 2,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(3, 200, redeem0Data),
},
baseFee: dexeth.GweiToWei(100),
Expand Down Expand Up @@ -3967,7 +3967,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0and1Data),
},
expectedResubmittedRedemptions: []*asset.Redemption{
Expand Down Expand Up @@ -4010,7 +4010,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0Data),
},
expectedResubmittedRedemptions: []*asset.Redemption{
Expand Down Expand Up @@ -4061,7 +4061,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 22,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 2,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(5, 200, redeem0Data),
},
baseFee: dexeth.GweiToWei(100),
Expand All @@ -4083,10 +4083,10 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
State: dexeth.SSRedeemed,
},
},
bestBlock: 13,
bestBlock: 3, // txConfsNeededToConfirm + tx.height + 1
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 10,
Req: 10,
Confs: txConfsNeededToConfirm,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(3, 200, redeem0Data),
},
baseFee: dexeth.GweiToWei(100),
Expand Down Expand Up @@ -4128,7 +4128,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0Data),
},
expectedResubmittedRedemptions: []*asset.Redemption{
Expand Down Expand Up @@ -4175,7 +4175,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(4, 123, redeem0Data),
},
expectedResubmittedRedemptions: []*asset.Redemption{
Expand Down Expand Up @@ -4217,7 +4217,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
bestBlock: 13,
expectedResult: &asset.ConfirmRedemptionStatus{
Confs: 0,
Req: 10,
Req: txConfsNeededToConfirm,
CoinID: toEthTxCoinID(3, 200, redeem0Data),
},
expectSentSignedTransaction: toEthTx(3, 200, redeem0Data),
Expand Down Expand Up @@ -4255,6 +4255,7 @@ func testConfirmRedemption(t *testing.T, assetID uint32) {
}

for _, test := range tests {
fmt.Printf("###### %s ###### \n", test.name)
node.getTxResMap = make(map[common.Hash]*tGetTxRes)
for hash, txData := range test.getTxResMap {
node.getTxResMap[hash] = &tGetTxRes{
Expand Down

0 comments on commit a9fdf04

Please sign in to comment.