Duniter Squid crash for out of range integer

Parameters of ĞDev network are:

// in /runtime/gdev/src/parameters.rs

// 0.002_381_440 = 0.0488^2
pub const SquareMoneyGrowthRate: Perbill = Perbill::from_parts(2_381_440);

# in /resources/gdev.yaml

# Time between 2 UDs, in milliseconds. 4 hours.
ud_creation_period: 14400000
# Time between 2 UD reevaluations, in milliseconds. 24 hours.
ud_reeval_period: 86400000

ĞDev network 800 was launched on 5th february (ĞDev Runtime 800 -- new network - #13 by cgeek).

This means that in 259 days (~ 9 months), we had 1554 universal dividends. But this UDs were reevaluated every day instead of every 6 month. Even with decreasing member count, this exponential growth lead to a UD value of 2163069901 which is too high for 32 bits integer type.

julia code for simulation
# ud count between reevals
udcountbetweenreevals(udreevalperiod=86_400_000, udcreationperiod=14_400_000) = udreevalperiod/udcreationperiod
# growth factor depending on params
factor(csquare=0.002_381_440, udcountbetweenreevals=udcountbetweenreevals()) = csquare/udcountbetweenreevals
# ud formula
udtplusone(udt, monetarymass, membercount; factor=factor()) = udt + Int(floor(factor * monetarymass / membercount))

monetarymass = [9_173_584_257] # in cents
membercount = [8000]
uds = [1000] # 10 ĞD in cents

# simulation step (each ud reeval)
function step(factor=factor(), udcountbetweenreevals=udcountbetweenreevals())
    udt = uds[end]
    membercountt = membercount[end]
    monetarymasst = monetarymass[end]
    # do not change member count
    # push!(membercount, membercountt)
    # update monetary mass
    push!(monetarymass, monetarymasst + udt * membercountt * udcountbetweenreevals)
    push!(uds, udtplusone(udt, monetarymasst, membercountt, factor=factor))
end

for i in 1:280
    step()
end

plot(uds, legend=false)
plot!([0,300],[2^31, 2^31])

image

I confirm that with these values and 8000 fixed member count, its normal to reach this size within ~270 days (270 reevals).

The problem is that with this growth rate, ĞDev would reach 64 bit limit within ~ 730 days.

Conclusion

  • i’ll use BigInt in squid for ud amount too
  • but for next test network, we should increase the reeval period a lot