diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 3b4f5b276..f1cf536ac 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -436,15 +436,12 @@ func (bc *Blockchain) storeBlock(block *block.Block) error { if err != nil { return fmt.Errorf("could not find previous TX: %s", prevHash) } + unspent, err := cache.GetUnspentCoinStateOrNew(prevHash) + if err != nil { + return err + } for _, input := range inputs { - unspent, err := cache.GetUnspentCoinStateOrNew(input.PrevHash) - if err != nil { - return err - } unspent.states[input.PrevIndex] = state.CoinSpent - if err = cache.PutUnspentCoinState(input.PrevHash, unspent); err != nil { - return err - } prevTXOutput := prevTX.Outputs[input.PrevIndex] account, err := cache.GetAccountStateOrNew(prevTXOutput.ScriptHash) if err != nil { @@ -482,6 +479,9 @@ func (bc *Blockchain) storeBlock(block *block.Block) error { return err } } + if err = cache.PutUnspentCoinState(prevHash, unspent); err != nil { + return err + } } // Process the underlying type of the TX.