gottstech / gotts

A blockchain for non-collateralized stable-coins, follow MimbleWimble protocol but with explicit amount.
https://gotts.tech
Apache License 2.0
49 stars 4 forks source link

Spent output still has the output position height index info in the database #24

Closed garyyu closed 4 years ago

garyyu commented 4 years ago

When querying a spent output, the unwrap() here will panic:

chain/src/txhashset/utxo_view.rs

    /// Find the complete input/s info, use chain database data according to inputs
    pub fn get_complete_inputs(
        &self,
        inputs: &Vec<Input>,
    ) -> Result<HashMap<Commitment, OutputEx>, Error> {
        let mut complete_inputs: HashMap<Commitment, OutputEx> = HashMap::new();
        for input in inputs {
            if let Ok(ofph) = self.batch.get_output_pos_height(&input.commitment()) {
                let output = match ofph.features {
                    OutputFeatures::Plain | OutputFeatures::Coinbase => self
                        .output_i_pmmr
                        .get_data(ofph.position)
                        .unwrap()        <<<< panic here
                        .into_output(),
                    OutputFeatures::SigLocked => self
                        .output_ii_pmmr
                        .get_data(ofph.position)
                        .unwrap()        <<<< or panic here
                        .into_output(),
                };
                ...

The only possible reason is that I could have forgot cleaning the output position height index when an output is spent. The original PR is here.

To be checked and confirmed.

garyyu commented 4 years ago

"fix" by #25, remove the unwrap and use ? instead.

leave a todo item here to clean the index garbage.