Skip to content

Commit

Permalink
blockchain: Correct invalid assertion.
Browse files Browse the repository at this point in the history
This corrects the assertion in the decodeSpentTxOut function so it does
not improperly cause a panic when unwinding transactions during a reorg
under certain circumstances.  In particular, the provided transaction
version that is passed when a stxo entry does not exist is now -1 in
order to properly distinguish it from the zero value.

It also updates the tests accordingly.

This was discovered by the reorg on testnet from block
00000000000018c58c2d2816f03dac327d975a18af6edf1a369df67ecddaf816 to
0000000000001c1161a367156465cc6226e9f862d9c585f94db5779fdf5455ff.
  • Loading branch information
davecgh committed Jul 1, 2017
1 parent 01cb59c commit 9f0e66e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func decodeSpentTxOut(serialized []byte, stxo *spentTxOut, txVersion int32) (int
// it. This should never happen unless there is database
// corruption or this function is being called without the
// proper state.
if txVersion == 0 {
if txVersion == -1 {
return offset, AssertError("decodeSpentTxOut called " +
"without a containing tx version when the " +
"serialized stxo that does not encode the " +
Expand Down Expand Up @@ -382,7 +382,7 @@ func deserializeSpendJournalEntry(serialized []byte, txns []*wire.MsgTx, view *U
// to detect this case and pull the tx version from the
// entry that contains the version information as just
// described.
var txVersion int32
txVersion := int32(-1)
originHash := &txIn.PreviousOutPoint.Hash
entry := view.LookupEntry(originHash)
if entry != nil {
Expand Down
3 changes: 2 additions & 1 deletion blockchain/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ func TestStxoDecodeErrors(t *testing.T) {
bytesRead: 2,
},
{
name: "no serialized tx version and passed 0",
name: "no serialized tx version and passed -1",
stxo: spentTxOut{},
txVersion: -1,
serialized: hexToBytes("003205"),
errType: AssertError(""),
bytesRead: 1,
Expand Down

0 comments on commit 9f0e66e

Please sign in to comment.