mirror of
https://github.com/logos-messaging/go-rln.git
synced 2026-01-07 23:43:11 +00:00
fix: epoch calculation
This commit is contained in:
parent
9bd071c7fb
commit
429ea1c12a
11
rln/types.go
11
rln/types.go
@ -191,6 +191,8 @@ func init() {
|
|||||||
// the root is created locally, using createMembershipList proc from waku_rln_relay_utils module, and the result is hardcoded in here
|
// the root is created locally, using createMembershipList proc from waku_rln_relay_utils module, and the result is hardcoded in here
|
||||||
const STATIC_GROUP_MERKLE_ROOT = "a1877a553eff12e1b21632a0545a916a5c5b8060ad7cc6c69956741134397b2d"
|
const STATIC_GROUP_MERKLE_ROOT = "a1877a553eff12e1b21632a0545a916a5c5b8060ad7cc6c69956741134397b2d"
|
||||||
|
|
||||||
|
const EPOCH_UNIT_SECONDS = uint64(10) // the rln-relay epoch length in seconds
|
||||||
|
|
||||||
type Epoch [32]byte
|
type Epoch [32]byte
|
||||||
|
|
||||||
func BytesToEpoch(b []byte) Epoch {
|
func BytesToEpoch(b []byte) Epoch {
|
||||||
@ -209,15 +211,14 @@ func (e Epoch) Uint64() uint64 {
|
|||||||
return binary.LittleEndian.Uint64(e[:])
|
return binary.LittleEndian.Uint64(e[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalcEpoch gets time `t` as `float64` with subseconds resolution in the fractional part
|
// CalcEpoch returns the corresponding rln `Epoch` value for a time.Time
|
||||||
// and returns its corresponding rln `Epoch` value
|
|
||||||
func CalcEpoch(t time.Time) Epoch {
|
func CalcEpoch(t time.Time) Epoch {
|
||||||
return ToEpoch(uint64(t.Unix()))
|
return ToEpoch(uint64(t.Unix()) / EPOCH_UNIT_SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentEpoch gets the current rln Epoch time
|
// GetCurrentEpoch gets the current rln Epoch time
|
||||||
func GetCurrentEpoch() Epoch {
|
func GetCurrentEpoch() Epoch {
|
||||||
return ToEpoch(uint64(time.Now().Unix()))
|
return CalcEpoch(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diff returns the difference between the two rln `Epoch`s `e1` and `e2`
|
// Diff returns the difference between the two rln `Epoch`s `e1` and `e2`
|
||||||
@ -228,5 +229,5 @@ func Diff(e1, e2 Epoch) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e Epoch) Time() time.Time {
|
func (e Epoch) Time() time.Time {
|
||||||
return time.Unix(int64(e.Uint64()), 0)
|
return time.Unix(int64(e.Uint64()*EPOCH_UNIT_SECONDS), 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user