Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/client: Redeem #1302

Merged
merged 4 commits into from Dec 7, 2021
Merged

eth/client: Redeem #1302

merged 4 commits into from Dec 7, 2021

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Nov 17, 2021

Part of #1154

@chappjc chappjc added the ETH label Nov 23, 2021
@chappjc chappjc added this to the 0.5 milestone Nov 28, 2021
@martonp martonp force-pushed the ethRedeem branch 3 times, most recently from 06ecb03 to 8533e90 Compare December 3, 2021 09:56
@martonp martonp marked this pull request as ready for review December 3, 2021 09:56
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

The live test TestContract/testRedeem is not passing.

--- FAIL: TestRedeem (9.37s)
    nodeclient_harness_test.go:953: ok before locktime: unexpected balance change: want 10999999818286 got 10999999757732, diff = 60554

if n.redeemErr != nil {
return nil, n.redeemErr
}
/*baseTx := &types.DynamicFeeTx{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to leave these comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.. I'll take them out of initiate also.

Comment on lines +420 to +405
// redeem redeems a swap contract. Any on-chain failure, such as this secret not
// matching the hash, will not cause this to error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such as this secret not matching the hash

We should check this in Redeem though.

Comment on lines 337 to +340
FeeSuggestion uint64
// AssetVersion is the swap protocol version, which may indicate a specific
// contract or form of contract.
AssetVersion uint32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good for now. Can rethink in or after #1320.

Side note: It may be possible we don't need the FromVersion and ToVersion added to the OrderMetaData in #1301 after all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure I'll clean it out in 1320, merging with this solution now

client/asset/eth/eth.go Outdated Show resolved Hide resolved
@martonp
Copy link
Contributor Author

martonp commented Dec 3, 2021

I got that too but it went away after another run.. I think it has to do with the issue with a fresh harness.

}
outputCoin := eth.createAmountCoin(redeemedValue)
fundsRequired := dexeth.RedeemGas(len(form.Redemptions), form.AssetVersion) * form.FeeSuggestion

Copy link
Member

@chappjc chappjc Dec 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we should be calling the free public view isRedeemable, I believe. The next step is to broadcast any number of secrets, which can be used to immediately redeem assets on another chain, so the txn better not fail on execution on a remote node.
The call is free, so we should do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was the whole point haha, I've updated it

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem like the first round of simnet tests always fails recently... #1327

Comment on lines +705 to +715
if err != nil {
return fail(fmt.Errorf("Redeem: redeem error: %w", err))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a failure here unlock the coins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A success should unlock the coins as well. It's actually not so easy to handle the failure, since failure will actually consume some gas as well.. and if it keeps failing then we may use more gas than we had locked in the first place. Anyways, I have a TODO in there regarding this and there will be another PR regarding locking/unlocking funds for redemption, so this can be handled there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error is a communication error I don't think the fee would be lost. I'm not sure if their could be another reason for a failure here. If the redeem fails on-chain I don't think there will be an error.

A TODO is fine for now imo. Will be easier to diagnose when we start actually trading with eth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right, on chain error doesn't fail there. In that case we don't need to unlock funds for failure since it will be retried anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a communication error though with the internal geth node and the tx is never sent over the wire. I think that's the only type of error possible, but not sure. In that case the redeem gas stays locked. Doesn't it? I could be wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these locked? I see fundsRequired saved to t.metaData.RedemptionFeesPaid in trade.go, but I don't see any locking or unlocking.

Copy link
Member

@chappjc chappjc Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1289 (comment)
EDIT: bad link initially. Goes to a discussion with @martonp on that PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok. Thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can figure it out there then.

@@ -145,6 +145,7 @@ type ethFetcher interface {
initiate(ctx context.Context, contracts []*asset.Contract, maxFeeRate uint64, contractVer uint32) (*types.Transaction, error)
shutdown()
syncProgress() ethereum.SyncProgress
isRedeemable(secretHash, secret [32]byte, contractVer uint32) (bool, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good for me, but I have a suspicious that redeem can call the contractor method of isRedeemable internally.

@chappjc chappjc merged commit c4df8a9 into decred:master Dec 7, 2021
@martonp martonp deleted the ethRedeem branch December 20, 2022 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants