Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateEpoch(e Epoch) error
- func ValidateJamTime(t time.Time) error
- func ValidateTimeslot(ts Timeslot) error
- type Epoch
- type JamTime
- func (jt JamTime) Add(d time.Duration) (JamTime, error)
- func (jt JamTime) After(u JamTime) bool
- func (jt JamTime) Before(u JamTime) bool
- func (jt JamTime) Equal(u JamTime) bool
- func (jt JamTime) IsInFutureTimeSlot() bool
- func (jt JamTime) IsInSameEpoch(other JamTime) bool
- func (jt JamTime) IsZero() bool
- func (jt JamTime) MarshalJSON() ([]byte, error)
- func (jt JamTime) Sub(u JamTime) time.Duration
- func (jt JamTime) ToEpoch() Epoch
- func (jt JamTime) ToEpochAndTimeslot() (Epoch, Timeslot)
- func (jt JamTime) ToTime() time.Time
- func (jt JamTime) ToTimeslot() Timeslot
- func (jt *JamTime) UnmarshalJSON(data []byte) error
- type Timeslot
- func (ts Timeslot) IsFirstTimeslotInEpoch() bool
- func (ts Timeslot) IsInFuture() bool
- func (ts Timeslot) IsLastCoreRotation() bool
- func (ts Timeslot) IsLastTimeslotInEpoch() bool
- func (ts Timeslot) IsTicketSubmissionPeriod() bool
- func (ts Timeslot) IsWinningTicketMarkerPeriod(previous Timeslot) bool
- func (ts Timeslot) NextTimeslot() (Timeslot, error)
- func (ts Timeslot) PreviousTimeslot() (Timeslot, error)
- func (ts Timeslot) TimeslotEnd() (JamTime, error)
- func (ts Timeslot) TimeslotInEpoch() uint32
- func (ts Timeslot) TimeslotStart() JamTime
- func (ts Timeslot) ToEpoch() Epoch
Constants ¶
const ( // MinEpoch represents the first epoch in the JAM protocol. // It corresponds to the epoch containing the JAM Epoch start time // (12:00pm on January 1, 2024 UTC). MinEpoch Epoch = 0 // MaxEpoch represents the last possible epoch in the JAM protocol. // It is calculated as the maximum value of Epoch (uint32) divided by // TimeslotsPerEpoch. This ensures that the last epoch can contain // a full complement of timeslots without overflowing. MaxEpoch Epoch = ^Epoch(0) / TimeslotsPerEpoch // TimeslotsPerEpoch defines the number of timeslots in each epoch. // In the JAM protocol, each epoch consists of exactly 600 timeslots, // as specified in the JAM Graypaper. (E) TimeslotsPerEpoch = 600 // EpochDuration defines the total duration of each epoch. // It is calculated by multiplying TimeslotsPerEpoch by TimeslotDuration, // resulting in a duration of 1 hour per epoch. EpochDuration = TimeslotsPerEpoch * TimeslotDuration // The number of slots into an epoch at which ticket-submission ends. TicketSubmissionTimeSlots = 500 // R = 10: The rotation period of validator-core assignments, in timeslots. ValidatorRotationPeriod = Timeslot(10) SlotPeriodInSeconds = 6 // P = 6: The slot period, in seconds )
const ( // MinTimeslot represents the first timeslot in the JAM protocol. // It corresponds to the beginning of the JAM Epoch (12:00pm on January 1, 2025 UTC). MinTimeslot Timeslot = 0 // MaxTimeslot represents the last possible timeslot in the JAM protocol. // It is set to the maximum value of a uint32 (2^32 - 1), which allows // the protocol to represent time up to mid-August 2840. MaxTimeslot Timeslot = ^Timeslot(0) // TimeslotDuration defines the length of each timeslot in the JAM protocol. // Each timeslot is exactly 6 seconds long, as specified in the JAM Graypaper. // This constant duration is used for conversions between timeslots and actual time. TimeslotDuration = SlotPeriodInSeconds * time.Second // The period in timeslots after which an unreferenced preimage may be expunged. // D = L + 4,800 where L = 14,400 (maximum age of lookup anchor) PreimageExpulsionPeriod = 19_200 // D ≡ L + 4_800 = 19_200 (equation B.3 v0.6.6) )
Variables ¶
var ( // ErrBeforeJamEpoch is returned when attempting to create or manipulate a // JamTime that represents a moment before the JAM Epoch (1200 UTC on January 1, 2024). // This error indicates that the given time is outside the valid range for // the JAM protocol. ErrBeforeJamEpoch = errors.New("time is before JAM Epoch") // ErrAfterMaxJamTime is returned when attempting to create or manipulate a // JamTime that represents a moment after the maximum representable time in the // JAM protocol (typically around mid-August 2840). This error indicates that // the given time exceeds the maximum value that can be represented within the // protocol's time range. ErrAfterMaxJamTime = errors.New("time is after maximum representable JAM time") // ErrMinEpochReached is returned when attempting to get the previous epoch // from the minimum possible epoch value. ErrMinEpochReached = errors.New("minimum epoch reached") // ErrMaxEpochReached is returned when attempting to get the next epoch // from the maximum possible epoch value. ErrMaxEpochReached = errors.New("maximum epoch reached") // ErrEpochExceedsMaxJamTime is returned when an epoch value exceeds the maximum // representable time in the JAM system, typically during epoch calculations // or conversions. ErrEpochExceedsMaxJamTime = errors.New("epoch is after maximum representable JAM time") // ErrMinTimeslotReached is returned when attempting to get the previous timeslot // from the minimum possible timeslot value. ErrMinTimeslotReached = errors.New("minimum timeslot reached") // ErrMaxTimeslotReached is returned when attempting to get the next timeslot // from the maximum possible timeslot value. ErrMaxTimeslotReached = errors.New("maximum timeslot reached") // ErrTimeslotExceedsEpochLength is returned when a timeslot number is greater than // or equal to the number of timeslots in an epoch. This typically occurs when // converting between epochs and timeslots or when validating timeslot values. ErrTimeslotExceedsEpochLength = errors.New("timeslot number exceeds epoch length") )
JamEpoch represents the start of the JAM Common Era 2025-01-01 12:00:00
var MaxRepresentableJamTime = time.Date(2841, time.August, 15, 23, 59, 59, 999999999, time.UTC)
MaxRepresentableJamTime is the latest date and time that can be represented in the JAM protocol. It corresponds to the end of the last timeslot in the last epoch (2^32 - 1 timeslots after the JAM Epoch). This time is set to 23:59:59.999999999 UTC on August 15, 2840, as specified in the JAM Graypaper. Any attempt to represent a time beyond this will result in an error.
Functions ¶
func ValidateEpoch ¶
ValidateEpoch checks if a given Epoch is within the valid range
func ValidateJamTime ¶
ValidateJamTime checks if a given time.Time is within the valid range for JamTime Returns nil if valid and non-nil err if the given time.Time is outside the valid range for JamTime
func ValidateTimeslot ¶
ValidateTimeslot checks if a given Timeslot is within the valid range
Types ¶
type Epoch ¶
type Epoch uint32
Epoch represents a JAM Epoch
func (Epoch) EpochStart ¶
EpochStart returns the JamTime at the start of the epoch
func (Epoch) PreviousEpoch ¶
PreviousEpoch returns the previous epoch
type JamTime ¶
type JamTime struct {
Seconds uint64
// contains filtered or unexported fields
}
JamTime represents a time in the JAM Common Era
func EpochAndTimeslotToJamTime ¶
EpochAndTimeslotToJamTime converts an Epoch and a timeslot within that epoch to JamTime
func FromSeconds ¶
FromSeconds creates a JamTime from the number of seconds since the JAM Epoch
func FromTimeslot ¶
FromTimeslot creates a JamTime from a Timeslot (start of the timeslot)
func (JamTime) IsInFutureTimeSlot ¶
IsInFutureTimeSlot checks if a given JamTime is in a future timeslot
func (JamTime) IsInSameEpoch ¶
IsInSameEpoch checks if two JamTimes are in the same epoch
func (JamTime) IsZero ¶
IsZero reports whether jt represents the zero time instant, IsZero is true when the date and time equal to 2025-01-01 12:00:00
func (JamTime) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (JamTime) ToEpochAndTimeslot ¶
ToEpochAndTimeslot converts a JamTime to its Epoch and timeslot within that epoch
func (JamTime) ToTimeslot ¶
ToTimeslot converts a JamTime to its corresponding Timeslot
func (*JamTime) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface
type Timeslot ¶
type Timeslot uint32
Timeslot represents a 6-second window in JAM time
func (Timeslot) IsFirstTimeslotInEpoch ¶
IsFirstTimeslotInEpoch checks if the timeslot is the first in its epoch
func (Timeslot) IsInFuture ¶
IsInFutureTimeslot checks if a given Timeslot is in the future
func (Timeslot) IsLastCoreRotation ¶
IsLastCoreRotation checks if the timeslot is within the last core rotation of the epoch
func (Timeslot) IsLastTimeslotInEpoch ¶
IsLastTimeslotInEpoch checks if the timeslot is the last in its epoch
func (Timeslot) IsTicketSubmissionPeriod ¶
IsTicketSubmissionPeriod checks if tickets can still be submitted in the given Timeslot
func (Timeslot) IsWinningTicketMarkerPeriod ¶
IsWinningTicketMarkerPeriod checks if it's the first available Timeslot after the ticket submission lottery ends and where the winning ticket marker can be generated.
func (Timeslot) NextTimeslot ¶
NextTimeslot returns the next timeslot
func (Timeslot) PreviousTimeslot ¶
PreviousTimeslot returns the previous timeslot
func (Timeslot) TimeslotEnd ¶
TimeslotEnd returns the JamTime at the end of the timeslot
func (Timeslot) TimeslotInEpoch ¶
TimeslotInEpoch returns the timeslot number within the epoch (0-599)
func (Timeslot) TimeslotStart ¶
TimeslotStart returns the JamTime at the start of the timeslot