-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix removing voting power during expiry #218
Changes from all commits
9c5beca
dbd16e4
8e30303
7dae2e6
65bcd08
f7c0cee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,17 +187,19 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre | |
// and set start height and end height | ||
var startHeight, endHeight uint32 | ||
if parsedMsg.StakingTxProofOfInclusion != nil { | ||
inclusionHeight, err := ms.VerifyInclusionProofAndGetHeight( | ||
timeInfo, err := ms.VerifyInclusionProofAndGetHeight( | ||
ctx, | ||
btcutil.NewTx(parsedMsg.StakingTx.Transaction), | ||
btccParams.BtcConfirmationDepth, | ||
uint32(parsedMsg.StakingTime), | ||
paramsValidationResult.MinUnbondingTime, | ||
parsedMsg.StakingTxProofOfInclusion) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid inclusion proof: %w", err) | ||
} | ||
|
||
startHeight = inclusionHeight | ||
endHeight = startHeight + uint32(parsedMsg.StakingTime) | ||
startHeight = timeInfo.startHeight | ||
endHeight = timeInfo.endHeight | ||
} else { | ||
// NOTE: here we consume more gas to protect Babylon chain and covenant members against spamming | ||
// i.e creating delegation that will never reach BTC | ||
|
@@ -234,7 +236,7 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre | |
} | ||
|
||
// add this BTC delegation, and emit corresponding events | ||
if err := ms.AddBTCDelegation(ctx, newBTCDel); err != nil { | ||
if err := ms.AddBTCDelegation(ctx, newBTCDel, paramsValidationResult.MinUnbondingTime); err != nil { | ||
panic(fmt.Errorf("failed to add BTC delegation that has passed verification: %w", err)) | ||
} | ||
Comment on lines
238
to
241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh it's a bit cleaner to not have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree it is a bit cleaner, but imo it is not that much cleaner to be worth two additional database calls 😅 |
||
|
||
|
@@ -280,10 +282,17 @@ func (ms msgServer) AddBTCDelegationInclusionProof( | |
if err != nil { | ||
return nil, err | ||
} | ||
inclusionHeight, err := ms.VerifyInclusionProofAndGetHeight( | ||
|
||
btccParams := ms.btccKeeper.GetParams(ctx) | ||
|
||
minUnbondingTime := types.MinimumUnbondingTime(params, &btccParams) | ||
|
||
timeInfo, err := ms.VerifyInclusionProofAndGetHeight( | ||
ctx, | ||
btcutil.NewTx(stakingTx), | ||
btccParams.BtcConfirmationDepth, | ||
btcDel.StakingTime, | ||
minUnbondingTime, | ||
parsedInclusionProof, | ||
) | ||
|
||
|
@@ -292,8 +301,8 @@ func (ms msgServer) AddBTCDelegationInclusionProof( | |
} | ||
|
||
// 6. set start height and end height and save it to db | ||
btcDel.StartHeight = inclusionHeight | ||
btcDel.EndHeight = btcDel.StartHeight + btcDel.StakingTime | ||
btcDel.StartHeight = timeInfo.startHeight | ||
btcDel.EndHeight = timeInfo.endHeight | ||
ms.setBTCDelegation(ctx, btcDel) | ||
|
||
// 7. emit events | ||
|
@@ -324,8 +333,9 @@ func (ms msgServer) AddBTCDelegationInclusionProof( | |
StakingTxHash: req.StakingTxHash, | ||
NewState: types.BTCDelegationStatus_UNBONDED, | ||
}) | ||
wValue := ms.btccKeeper.GetParams(ctx).CheckpointFinalizationTimeout | ||
ms.addPowerDistUpdateEvent(ctx, btcDel.EndHeight-wValue, unbondedEvent) | ||
|
||
// NOTE: we should have verified that EndHeight > btcTip.Height + max(w, min_unbonding_time) | ||
ms.addPowerDistUpdateEvent(ctx, btcDel.EndHeight-minUnbondingTime, unbondedEvent) | ||
|
||
// at this point, the BTC delegation inclusion proof is verified and is not duplicated | ||
// thus, we can safely consider this message as refundable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
as this object is unpacked to two uint32 later anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this may be a personal preference, but:
(uint32, uint32, error)
does not tell you much what thoseuint32
represent while in returned struct those numbers have proper namesstartHeight uint32
which makes life easier for the caller