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

refact: use specific hash_with_index instead of the generic one #13

Closed garyyu closed 4 years ago

garyyu commented 4 years ago

Regarding to the following designed behaviour:

    // Among all 3 types: Output, OutputI, and OutputII, we define same Hash
    // for all of them:
    // 1. Only the OutputIdentifier is used for Hash.
    // 2. All 3 types (Output, OutputI, OutputII) have same Hash result.

The benefit of this design is for the convenience of hash compare between all these types of OutputX and Input, but the consequence is the Output MMR will be same even if the detail of the OutputX are different! That definitely is NOT what we want.

Since the MMR hash always use the hash_with_index, we just need to remove the universal hash_with_index implementation which was:

impl<T: DefaultHashable> PMMRIndexHashable for T {
    fn hash_with_index(&self, index: u64) -> Hash {
        (index, self).hash()
    }
}

And use the full data of Output / OutputI / OutputII for the specific hash_with_index function implementation.

This is a consensus breaking change and we have to re-generate a new Genesis again, I will do it in next PR soon.