blockchain: Correct invalid assertion.
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.
This commit is contained in:
parent
01cb59c67d
commit
9f0e66ee3f
2 changed files with 4 additions and 3 deletions
|
@ -298,7 +298,7 @@ func decodeSpentTxOut(serialized []byte, stxo *spentTxOut, txVersion int32) (int
|
||||||
// it. This should never happen unless there is database
|
// it. This should never happen unless there is database
|
||||||
// corruption or this function is being called without the
|
// corruption or this function is being called without the
|
||||||
// proper state.
|
// proper state.
|
||||||
if txVersion == 0 {
|
if txVersion == -1 {
|
||||||
return offset, AssertError("decodeSpentTxOut called " +
|
return offset, AssertError("decodeSpentTxOut called " +
|
||||||
"without a containing tx version when the " +
|
"without a containing tx version when the " +
|
||||||
"serialized stxo that does not encode the " +
|
"serialized stxo that does not encode the " +
|
||||||
|
@ -382,7 +382,7 @@ func deserializeSpendJournalEntry(serialized []byte, txns []*wire.MsgTx, view *U
|
||||||
// to detect this case and pull the tx version from the
|
// to detect this case and pull the tx version from the
|
||||||
// entry that contains the version information as just
|
// entry that contains the version information as just
|
||||||
// described.
|
// described.
|
||||||
var txVersion int32
|
txVersion := int32(-1)
|
||||||
originHash := &txIn.PreviousOutPoint.Hash
|
originHash := &txIn.PreviousOutPoint.Hash
|
||||||
entry := view.LookupEntry(originHash)
|
entry := view.LookupEntry(originHash)
|
||||||
if entry != nil {
|
if entry != nil {
|
||||||
|
|
|
@ -194,8 +194,9 @@ func TestStxoDecodeErrors(t *testing.T) {
|
||||||
bytesRead: 2,
|
bytesRead: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no serialized tx version and passed 0",
|
name: "no serialized tx version and passed -1",
|
||||||
stxo: spentTxOut{},
|
stxo: spentTxOut{},
|
||||||
|
txVersion: -1,
|
||||||
serialized: hexToBytes("003205"),
|
serialized: hexToBytes("003205"),
|
||||||
errType: AssertError(""),
|
errType: AssertError(""),
|
||||||
bytesRead: 1,
|
bytesRead: 1,
|
||||||
|
|
Loading…
Reference in a new issue