-
Notifications
You must be signed in to change notification settings - Fork 324
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
[rewarding] move claim address check to LoadProto() and SanityCheck() #4304
Conversation
Quality Gate failedFailed conditions |
#4277 added a new field |
if err != nil { | ||
log.L().Debug("Invalid claim to address", zap.Error(err)) | ||
return p.settleUserAction(ctx, sm, uint64(iotextypes.ReceiptStatus_Failure), si, nil) | ||
} |
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.
this address check can (and should) be done before Handle()
in the action's LoadProto()
and SanityCheck()
, this is consistent with other actions like candidate register
6da2e90
to
041292a
Compare
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.
lgtm, except the comment below
if claimTo == "" { | ||
claimTo = protocol.MustGetActionCtx(ctx).Caller.String() | ||
addr := protocol.MustGetActionCtx(ctx).Caller | ||
if protocol.MustGetFeatureCtx(ctx).AddClaimRewardAddress && act.Address() != nil { |
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.
shall we reject an action if !protocol.MustGetFeatureCtx(ctx).AddClaimRewardAddress && act.Address() != nil
?
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.
can check it when validating
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.
added
action/claimreward.go
Outdated
@@ -217,8 +232,16 @@ func NewClaimFromRewardingFundFromABIBinary(data []byte) (*ClaimFromRewardingFun | |||
if ac.data, ok = paramsMap["data"].([]byte); !ok { | |||
return nil, errDecodeFailure | |||
} | |||
if ac.address, ok = paramsMap["address"].(string); !ok { | |||
var s string | |||
if s, ok = paramsMap["address"].(string); !ok { |
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.
should keep backword compatibility, allowing without address param
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.
add a 2nd commit to keep both v1 and v2 ABI
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, |
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.
need to keep the current (v1) ABI for backward compatibility
"4d26d0736ebd9e69bd5994f3730b05a2d48c810b3bb54818be65d02004cf4ff4", | ||
"04830579b50e01602c2015c24e72fbc48bca1cca1e601b119ca73abe2e0b5bd61fcb7874567e091030d6b644f927445d80e00b3f9ca0c566c21c30615e94c343da", | ||
"8d38efe45794d7fceea10b2262c23c12245959db", | ||
}, |
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.
this is test with v1 ABI, fixed and restored
the original #4277 shouldn't have broken this
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.
reverse order if doesn't hurt, because data
is useless for now
action/claimreward.go
Outdated
return nil, err | ||
} | ||
return append(_claimRewardingMethodV1.ID, data...), nil | ||
} | ||
var addr string | ||
if c.address != nil { |
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.
delete
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.
fixed
action/claimreward.go
Outdated
var ( | ||
act *ClaimFromRewardingFund | ||
err error | ||
) | ||
if act, err = newClaimFromRewardingFundFromABIv2(data); err == nil { | ||
return act, nil | ||
} | ||
if err != errWrongMethodSig { | ||
// data is v2-encoded, but got error when decoding | ||
return nil, err | ||
} |
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.
if len(data) >= 4 {
switch {
case bytes.Equal(_claimRewardingMethodV2.ID[:], data[:4]):
....
case bytes.Equal(_claimRewardingMethodV1.ID[:], data[:4]):
....
}
}
return nil, errDecodeFailure
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.
fixed
Description
#4277 added a
claimTo
field to receive claim reward, so other EOA can help claim reward on another's behalf.move the address check from inside
protocol.Handle
to the action'sLoadProto()
andSanityCheck()
, which is consistent with other action's behaviorFixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: