As noted, there is a pending range check to perform. SQLite by default does not support uint64 values (and neither other DBs like Postgres), allowing only int64 values. For both fields, if we try to store math.MaxUint64 we'll get the following SQL error:
uint64 values with high bit set are not supported
I'm not 100% sure who is to blame here (gorm, SQLite), but this means that in the future, if we have either a BlockHeight or a Timestamp greater than math.MaxInt64 then we'll get an error.
Possible actions:
Do nothing since we can guess that such high values will not show up in the near future.
Add a check to prevent inserting these values in the DB. This is not that different from 1 but at least we control what to do on errors
Change the DB schema to store these values, ex. store them as text. Curiously we get the same error on BlockHeight despite technically using text as a type which makes things a bit confusing. Either way, changing the schema would mean a breaking change which we want to avoid at least for the time being.
Current Behavior
Partially solves https://github.com/NethermindEth/near-sffl/issues/239 by introducing additional bounds checks to the checkpoint messages fetching. It also adds additional tests for parameter deserializing.
New Behavior
Ensures that ranges
from - to
are valid, that isfrom < to
is always satisfied.Breaking Changes
Certain queries that would previously return an empty result set now return an error message indicating that the range provided is invalid.
Observations
There is quite a complicated issue with the storage of
BlockNumber
andTimestamp
as defined here:https://github.com/NethermindEth/near-sffl/blob/18544a6716cb6fe0cb91f928ba1f476cc7bcaa5f/core/types/fields.go#L14-L15
These types are used in
StateRootUpdateMessage
https://github.com/NethermindEth/near-sffl/blob/18544a6716cb6fe0cb91f928ba1f476cc7bcaa5f/core/types/messages/state_root_update.go#L18-L19
This message type then gets converted to a specific model when interacting with the DB:
https://github.com/NethermindEth/near-sffl/blob/18544a6716cb6fe0cb91f928ba1f476cc7bcaa5f/aggregator/database/models/state_root_update.go#L12-L13
As noted, there is a pending range check to perform. SQLite by default does not support
uint64
values (and neither other DBs like Postgres), allowing onlyint64
values. For both fields, if we try to storemath.MaxUint64
we'll get the following SQL error:I'm not 100% sure who is to blame here (gorm, SQLite), but this means that in the future, if we have either a
BlockHeight
or aTimestamp
greater thanmath.MaxInt64
then we'll get an error.Possible actions:
text
. Curiously we get the same error onBlockHeight
despite technically usingtext
as a type which makes things a bit confusing. Either way, changing the schema would mean a breaking change which we want to avoid at least for the time being.