-
Notifications
You must be signed in to change notification settings - Fork 362
protocol/bc: add SpendCommitment type #665
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
Conversation
|
👀 |
bobg
left a comment
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.
protocol/bc/txhashes.go
Outdated
| ExpirationMS uint64 | ||
| } | ||
| VMContexts []*VMContext // one per old-style Input | ||
| SpentOutputIDs []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.
Do the entries in this list correspond 1:1 with the inputs of the oldtx? (And for inputs that aren't spends, are those entries the zero hash?) Please add a comment saying so.
| // to avoid a circular dependency between the bc and tx packages. | ||
| var BlockHeaderHashFunc func(*BlockHeader) Hash | ||
|
|
||
| var OutputHash func(*SpendCommitment) (Hash, 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.
Please godoc this var.
| }) | ||
| } | ||
|
|
||
| func (sc *SpendCommitment) Hash(suffix []byte, assetVersion uint64) (spendhash 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.
Am I correct in thinking that we don't expect this to get used? That it's only for the !SerPrevout case?
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.
correct
protocol/tx/map.go
Outdated
| for i, inp := range tx.Inputs { | ||
| if oldSp, ok := inp.TypedInput.(*bc.SpendInput); ok { | ||
| var oldSpID bc.Hash | ||
| oldSpID, err = ComputeOutputID(&oldSp.SpendCommitment) |
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.
In the absence of distinguishing types for outputIDs and IDs of other kinds of entry, please observe a convention of putting "out" somewhere in the varname when it holds an outputID. As it is, oldSpID looks like it could be the ID of a spend entry.
| }, program{VMVersion: sc.VMVersion, Code: sc.ControlProgram}, sc.RefDataHash, 0) | ||
|
|
||
| h = entryID(o) | ||
| return h, 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.
Specifying nil here will override the setting of err that happens in the defer above. A bare return should do the trick.
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.
I think the defer actually takes precedence:
https://play.golang.org/p/yHPkJUHgkn
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.
The defer executes after the return statement, so that you can modify the returned values even when they've been supplied directly to return.
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.
Oh of course - if recover() returns a value then we're in a panic and normal control flow from the entryID call to the return call didn't happen. Duh, sorry.
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.
That's also true, but note that defer runs after return even when we're not in a panic. Along the lines of @erykwalder's example: https://play.golang.org/p/_qBWbRSA2x
protocol/tx/map.go
Outdated
| if oldSp, ok := inp.TypedInput.(*bc.SpendInput); ok { | ||
| var oldSpID bc.Hash | ||
| oldSpID, err = ComputeOutputID(&oldSp.SpendCommitment) | ||
| var spendOutputID bc.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.
nit: spentOutputID would be better
|
LGTM (with one tiny nit) but please wait for other 👀 to take a look too |
|
👀 |
| ALTER TABLE account_utxos | ||
| ADD COLUMN source_id bytea NOT NULL, | ||
| ADD COLUMN source_pos bigint NOT NULL, | ||
| ADD COLUMN ref_data_hash bytea NOT NULL; |
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 expect customers to completely drop the database and recreate it before attempting to run a 1.1.1 binary right? I think that's a fine assumption when dealing with a blockchain reset.
Once landed, we should double check that the migration has the same name and hash on the 1.1.1 branch and main so that Cores updating from 1.1.1 to 1.2.0 do not try to run this migration again.
|
It looks like the base branch for this PR is |
Yep, there's a base-branch pull-down menu when you click the Edit button next to the PR title. |
Spend TxInputs need to contain all of the data necessary to reconstruct output ids in order to spend them. Performing the hashing during validation gives us cryptographic integrity that the spent output data is correct. In order to preserve this data, the mapping process was updated to return additional information which is stored in the account_utxos table. This data is then populated in a SpendCommitment type on the TxInput structs. 1.1-stable version of #665 Closes #677
Spend TxInputs need to contain all of the data necessary to reconstruct output ids in order to spend them. Performing the hashing during validation gives us cryptographic integrity that the spent output data is correct. In order to preserve this data, the mapping process was updated to return additional information which is stored in the account_utxos table. This data is then populated in a SpendCommitment type on the TxInput structs.
Spend TxInputs need to contain all of the data necessary to reconstruct
output ids in order to spend them. Performing the hashing during
validation gives us cryptographic integrity that the spent output data
is correct.
In order to preserve this data, the mapping process was updated to
return additional information which is stored in the account_utxos
table. This data is then populated in a SpendCommitment type on the
TxInput structs.
Fixes #648