-
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
[action] add address
and hash
field in SealedEnvelope
#3420
Conversation
action/sealedenvelope.go
Outdated
hv, err := sealed.calcHash() | ||
sealed.hash = &Hash256Result{hv, err} | ||
} | ||
return sealed.hash.Value() |
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.
return sealed.hash.Hash256, sealed.hash.error
would suffice
action/sealedenvelope.go
Outdated
error | ||
} | ||
|
||
func (h *Hash256Result) Value() (hash.Hash256, error) { |
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.
no need for this func, see comments below
action/sealedenvelope.go
Outdated
hash *Hash256Result | ||
} | ||
|
||
type Hash256Result struct { |
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.
hash256Result
, this is internal data struct
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.
Remove this struct
action/sealedenvelope_test.go
Outdated
@@ -165,6 +165,7 @@ func TestSealedEnvelope_Proto(t *testing.T) { | |||
{1, "d5dc789026c12cc69f1ea7997fbe0aa1bcc02e85176848c7b2ecf4da6b4560d0"}, | |||
} { | |||
se.encoding = v.enc | |||
req.NoError(se.LoadProto(se.Proto())) |
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 should not be needed?
se.Hash()
below will trigger the if hash == nil
code path and test its correctness
action/sealedenvelope_test.go
Outdated
@@ -35,7 +35,7 @@ func TestSealedEnvelope_Basic(t *testing.T) { | |||
{0, "322884fb04663019be6fb461d9453827487eafdd57b4de3bd89a7d77c9bf8395"}, | |||
{1, "80af7840d73772d3022d8bdc46278fb755352e5e9d5f2a1f12ee7ec4f1ea98e9"}, | |||
} { | |||
se, err := createSealedEnvelope(v.id) | |||
se, err := createSealedEnvelopeWithSignature(v.id, _signByte) |
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 not need this? see comments below
action/sealedenvelope_test.go
Outdated
se.signature = _validSig | ||
if err = se.LoadProto(se.Proto()); err != nil { | ||
return se, 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.
we don't need this? see comments below
action/sealedenvelope_test.go
Outdated
return se, err | ||
} | ||
|
||
func createSealedEnvelopeWithSignature(chainID uint32, sig []byte) (SealedEnvelope, error) { |
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.
we don't need to add this func? if there's a need (for test) about signature, just directly set the signature (as done in tests now)
action/sealedenvelope.go
Outdated
@@ -69,6 +93,13 @@ func (sealed *SealedEnvelope) Hash() (hash.Hash256, error) { | |||
// SrcPubkey returns the source public key | |||
func (sealed *SealedEnvelope) SrcPubkey() crypto.PublicKey { return sealed.srcPubkey } | |||
|
|||
func (sealed *SealedEnvelope) Address() address.Address { |
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 a comment like // Address() xxx
to satisfy go lint
you run make lint
local to make sure no lint error
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.
SenderAddress
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.
change to SenderAddress
, it's a better/clear name
action/sealedenvelope.go
Outdated
@@ -69,6 +93,13 @@ func (sealed *SealedEnvelope) Hash() (hash.Hash256, error) { | |||
// SrcPubkey returns the source public key | |||
func (sealed *SealedEnvelope) SrcPubkey() crypto.PublicKey { return sealed.srcPubkey } | |||
|
|||
func (sealed *SealedEnvelope) Address() address.Address { |
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.
SenderAddress
action/sealedenvelope.go
Outdated
hashValue, err := sealed.calcHash() | ||
sealed.hash = &Hash256Result{hashValue, err} | ||
sealed.address = srcPub.Address() |
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
action/action_deserializer_test.go
Outdated
_ = se.Address() | ||
// after Hash() and Address() was invoked, the two value are equal | ||
NewWithT(t).Expect(validated).To(Equal(se)) | ||
}) |
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.
revert these, we don't want to introduce a new testing style, pls only do minimum necessary changes to make existing test pass
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.
as we discussed, please revert unnecessary changes, only need these 3 lines to make the test pass
_, err = se.Hash()
r.NoError(err)
se.SenderAddress()
// after Hash() and Address() was invoked, the two value are equal
action/const.go
Outdated
|
||
// vars | ||
var ( | ||
ErrAddress = errors.New("invalid address") | ||
ErrAddress = errors.New("invalid srcAddress") |
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.
revert, not necessary
action/const.go
Outdated
return errors.Errorf("unknown encoding type %d", enc) | ||
} | ||
) | ||
|
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.
not very necessary, seems an overkill
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.
as we discussed, we don't really need this
action/sealedenvelope.go
Outdated
} | ||
|
||
// calcHash returns the hash value of SealedEnvelope | ||
func (sealed *SealedEnvelope) calcHash() (hash.Hash256, error) { |
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.
keep this, it is clear to have an internal func (which might be used)
action/sealedenvelope.go
Outdated
return nil | ||
sealed.encoding = pbAct.GetEncoding() | ||
_, err = sealed.Hash() | ||
return 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.
revert, like we discussed, there's no need to change loadProto
at all
action/sealedenvelope_test.go
Outdated
tsf2, ok2 := validated.Envelope.Action().(*Transfer) | ||
NewWithT(t).Expect(tsf1).To(Equal(tsf2)) | ||
NewWithT(t).Expect(ok1 && ok2).To(BeTrue()) | ||
}) |
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.
no need to change these test files
action/sealedenvelope.go
Outdated
hv, err := sealed.calcHash() | ||
sealed.hash = &Hash256Result{hv, err} | ||
if sealed.hash != hash.ZeroHash256 || sealed.hashErr != nil { | ||
return sealed.hash, sealed.hashErr |
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.
just like the 1st commit
if sealed.hash == hash.ZeroHash256 && sealed.hashErr == nil {
sealed.hash, sealed.hashErr = sealed.calcHash()
}
return sealed.hash, sealed.hashErr
action/sealedenvelope.go
Outdated
} | ||
return rlpSignedHash(tx, sealed.evmNetworkID, sealed.Signature()) | ||
sealed.evmNetworkID = config.EVMNetworkID() |
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.
why do this? the correct place to set evmNetworkID
is in LoadProto()
action/sealedenvelope.go
Outdated
} | ||
return sealed.hash, sealed.hashErr |
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.
as we discussed, please revert unnecessary changes, and make this an internal func calcHash()
action/sealedenvelope_test.go
Outdated
se.encoding = v.encoding | ||
se.signature = v.sig | ||
req.Equal(se2.LoadProto(se.Proto()).Error(), v.err.Error()) | ||
}) |
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.
as we discussed, please revert unnecessary changes, do minimum changes to make the test pass
action/sealedenvelope.go
Outdated
return sealed.hash, sealed.hashErr | ||
} | ||
|
||
func (sealed *SealedEnvelope) calcHash() { |
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.
one final comment:
func (sealed *SealedEnvelope) calcHash() (hash.Hash256, error)
then don't need to change this func at all, in the above, just
sealed.hash, sealed.hashErr = calcHash()
b10ff27
to
c41afb2
Compare
cd34ff4
to
c7a4bfe
Compare
Codecov Report
@@ Coverage Diff @@
## master #3420 +/- ##
=======================================
Coverage 75.16% 75.16%
=======================================
Files 236 236
Lines 22070 22083 +13
=======================================
+ Hits 16589 16599 +10
- Misses 4591 4595 +4
+ Partials 890 889 -1
Continue to review full report at Codecov.
|
action/const.go
Outdated
@@ -6,7 +6,9 @@ | |||
|
|||
package action | |||
|
|||
import "github.com/pkg/errors" | |||
import ( |
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.
revert
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.
reverted
@@ -5,12 +5,13 @@ import ( | |||
|
|||
"github.com/iotexproject/go-pkgs/crypto" | |||
"github.com/iotexproject/go-pkgs/hash" | |||
"github.com/iotexproject/iotex-address/address" |
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.
revert
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.
reverted
action/sealedenvelope.go
Outdated
@@ -22,6 +23,9 @@ type SealedEnvelope struct { | |||
evmNetworkID uint32 | |||
srcPubkey crypto.PublicKey | |||
signature []byte | |||
srcAddress address.Address | |||
hash hash.Hash256 | |||
hashErr error |
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.
remove
se.signature = _validSig | ||
se.hash = hash.ZeroHash256 | ||
se.Hash() |
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.
any validation for the return values?
se1, err := (&Deserializer{}).ActionToSealedEnvelope(se.Proto()) | ||
se1.Hash() |
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.
same here
actpool/actpool_test.go
Outdated
_, err = validated[i].Hash() | ||
require.NoError(err) | ||
} | ||
require.Equal(validated, acts) |
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.
asserting hash
* remove ActionsByBlock() in coreService
Description
Fixes #2989
Type of change
Please delete options that are not relevant.
Test Configuration:
Checklist: