Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Change liveness window storage method #2562
Currently we store the liveness window per validator as a single bit array. On every block, we read and set to the liveness window bit array for every validator. On the current testnet, the liveness window is 10000 blocks (source: https://github.com/cosmos/cosmos-sdk/blob/master/x/slashing/params.go#L70). This is at least
This means that
I propose instead separating more of the bit array into separate leaves. I propose that in state, per validator, we split the bit array into separate bit arrays of 4096 bits. Now staking would need a get operation that would obtain the correct thing from the store, and then get the right index. This is relatively simple though, since note that every element in the bit_array has all bits the same, except the last 12 bits. So just index the bitarray in the IAVL tree by
There should be no issues with rebalancing, since the keys will all be created at once for each bonded validator.
Sure. If everything has an index, and is broken up into
I don't think this is minor in the short term. At 35k blocks per window, that means there are 35 thousand state entries. We currently amino decode a length prefixed bool per entry. I'm unsure how length prefixing works on bools, so lets assume this is just 1 byte. The IAVL leaf for it is 32 bytes. This means at 100 validators, there are
We can generalize this by making a hash-based tree friendly bitarray type that takes a prefix, so the API within slashing would be as a normal bit array.