Skip to content

Conversation

@erykwalder
Copy link
Contributor

@erykwalder erykwalder commented Mar 2, 2017

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

@bobg
Copy link
Contributor

bobg commented Mar 2, 2017

👀

Copy link
Contributor

@bobg bobg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice work, thanks for doing it. I only have a few small comments, and one request: will you cherrypick (and adapt) 210dc19 to help use feel sure we're fixing what we expect to be fixing?

Oh, also mention in the PR description that this fixes #648

ExpirationMS uint64
}
VMContexts []*VMContext // one per old-style Input
SpentOutputIDs []Hash
Copy link
Contributor

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)
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

for i, inp := range tx.Inputs {
if oldSp, ok := inp.TypedInput.(*bc.SpendInput); ok {
var oldSpID bc.Hash
oldSpID, err = ComputeOutputID(&oldSp.SpendCommitment)
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

if oldSp, ok := inp.TypedInput.(*bc.SpendInput); ok {
var oldSpID bc.Hash
oldSpID, err = ComputeOutputID(&oldSp.SpendCommitment)
var spendOutputID bc.Hash
Copy link
Contributor

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

@bobg
Copy link
Contributor

bobg commented Mar 2, 2017

LGTM (with one tiny nit) but please wait for other 👀 to take a look too

@kr
Copy link
Contributor

kr commented Mar 2, 2017

👀

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;
Copy link
Contributor

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.

@kr
Copy link
Contributor

kr commented Mar 2, 2017

It looks like the base branch for this PR is main. It's more important right now to be preparing a fix for the 1.1.x branch. Check out docs/internal/package-tags-branches.md and #670. Maybe also wait until the fallout from #670 is cleaned up before landing this? (And we might have to open a new PR anyway. Is there a way to change the base branch of an open PR?)

@bobg
Copy link
Contributor

bobg commented Mar 2, 2017

Is there a way to change the base branch of an open PR?

Yep, there's a base-branch pull-down menu when you click the Edit button next to the PR title.

@erykwalder erykwalder changed the base branch from main to 1.1-stable March 2, 2017 21:37
@erykwalder erykwalder changed the base branch from 1.1-stable to main March 2, 2017 21:41
iampogo pushed a commit that referenced this pull request Mar 2, 2017
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
@bobg bobg added PTAL and removed PTAL labels Mar 3, 2017
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.
@iampogo iampogo merged commit 28f6f9b into main Mar 3, 2017
@iampogo iampogo deleted the spent-output branch March 3, 2017 17:51
jeffomatic added a commit that referenced this pull request Mar 6, 2017
This accounts for updates affecting validation-critical hashing
in #665 (#677 in 1.1-stable).
iampogo pushed a commit that referenced this pull request Mar 6, 2017
This accounts for updates affecting validation-critical hashing
in #665 (#677 in 1.1-stable).
iampogo pushed a commit that referenced this pull request Mar 6, 2017
This accounts for updates affecting validation-critical hashing
in #665 (#677 in 1.1-stable).

Closes #703
jeffomatic added a commit that referenced this pull request Mar 6, 2017
This accounts for updates affecting validation-critical hashing
in #665 (#677 in 1.1-stable).

This is a 1.1-stable backport of #703.
iampogo pushed a commit that referenced this pull request Mar 6, 2017
This accounts for updates affecting validation-critical hashing
in #665 (#677 in 1.1-stable).

This is a 1.1-stable backport of #703.

Closes #704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants