-
Notifications
You must be signed in to change notification settings - Fork 493
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
cleanup: replace crypto.HashObj(Transaction) with Transaction.ID() #3958
Changes from 2 commits
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 |
---|---|---|
|
@@ -161,6 +161,7 @@ type TxGroup struct { | |
// together, sequentially, in a block in order for the group to be | ||
// valid. Each hash in the list is a hash of a transaction with | ||
// the `Group` field omitted. | ||
// These are all `Txid` which is equivalent to `crypto.Digest` | ||
TxGroupHashes []crypto.Digest `codec:"txlist,allocbound=config.MaxTxGroupSize"` | ||
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. would it make sense to make this |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,19 +269,20 @@ func SignedTxns(txns ...*Txn) []transactions.SignedTxn { | |
txgroup := transactions.TxGroup{ | ||
TxGroupHashes: make([]crypto.Digest, len(txns)), | ||
} | ||
stxns := make([]transactions.SignedTxn, len(txns)) | ||
for i, txn := range txns { | ||
txn.Group = crypto.Digest{} | ||
txgroup.TxGroupHashes[i] = crypto.HashObj(txn.Txn()) | ||
stxns[i] = txn.SignedTxn() | ||
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. Why flip the order? (pulling txn.SignedTxn() up to happen before the ID stuff) I guess I don't understand this change 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. I get the impression that the intent was to get things ready so that once the group was calculated it could be put into the txn objects and the stxn objects, saving a loop. I think that would work. But this change doesn't save a loop, because of the loop used to initialize stxns. I think that loop could be removed, and the initialization done in the final loop (at what would now be line 282.5). Then you would indeed have the benefit of having eliminated a loop. 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. Fewer copies. The local |
||
} | ||
for i, txn := range stxns { | ||
txn.Txn.Group = crypto.Digest{} | ||
txgroup.TxGroupHashes[i] = crypto.Digest(txn.ID()) | ||
} | ||
group := crypto.HashObj(txgroup) | ||
for _, txn := range txns { | ||
for i, txn := range txns { | ||
txn.Group = group | ||
stxns[i].Txn.Group = group | ||
} | ||
|
||
stxns := make([]transactions.SignedTxn, len(txns)) | ||
for i, txn := range txns { | ||
stxns[i] = txn.SignedTxn() | ||
} | ||
return stxns | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -752,7 +752,7 @@ func (c *Client) GroupID(txgroup []transactions.Transaction) (gid crypto.Digest, | |
return | ||
} | ||
|
||
group.TxGroupHashes = append(group.TxGroupHashes, crypto.HashObj(tx)) | ||
group.TxGroupHashes = append(group.TxGroupHashes, crypto.Digest((tx.ID()))) | ||
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. Is there an extra set of parens here? |
||
} | ||
|
||
return crypto.HashObj(group), 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.
could you please add a test into
transaction_test.go
checkingtx.ID() == crypto.HashObj(tx)
? In code I see they are the same but this is not enforced.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.
agreed, would be good to put that assertion in this PR