jamtime

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

View Source
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")
)
View Source
var JamEpoch = time.Date(2025, time.January, 1, 12, 0, 0, 0, time.UTC)

JamEpoch represents the start of the JAM Common Era 2025-01-01 12:00:00

View Source
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

func ValidateEpoch(e Epoch) error

ValidateEpoch checks if a given Epoch is within the valid range

func ValidateJamTime

func ValidateJamTime(t time.Time) error

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

func ValidateTimeslot(ts Timeslot) error

ValidateTimeslot checks if a given Timeslot is within the valid range

Types

type Epoch

type Epoch uint32

Epoch represents a JAM Epoch

func CurrentEpoch

func CurrentEpoch() Epoch

CurrentEpoch returns the current epoch

func (Epoch) EpochEnd

func (e Epoch) EpochEnd() (JamTime, error)

EpochEnd returns the JamTime at the end of the epoch

func (Epoch) EpochStart

func (e Epoch) EpochStart() JamTime

EpochStart returns the JamTime at the start of the epoch

func (Epoch) NextEpoch

func (e Epoch) NextEpoch() (Epoch, error)

NextEpoch returns the next epoch

func (Epoch) PreviousEpoch

func (e Epoch) PreviousEpoch() (Epoch, error)

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

func EpochAndTimeslotToJamTime(e Epoch, timeslot Timeslot) (JamTime, error)

EpochAndTimeslotToJamTime converts an Epoch and a timeslot within that epoch to JamTime

func FromEpoch

func FromEpoch(e Epoch) JamTime

FromEpoch creates a JamTime from an Epoch (start of the epoch)

func FromSeconds

func FromSeconds(seconds uint64) JamTime

FromSeconds creates a JamTime from the number of seconds since the JAM Epoch

func FromTime

func FromTime(t time.Time) (JamTime, error)

FromTime converts a standard time.Time to JamTime

func FromTimeslot

func FromTimeslot(ts Timeslot) JamTime

FromTimeslot creates a JamTime from a Timeslot (start of the timeslot)

func Now

func Now() JamTime

Now returns the current time as a JamTime

func (JamTime) Add

func (jt JamTime) Add(d time.Duration) (JamTime, error)

Add returns the time jt+d

func (JamTime) After

func (jt JamTime) After(u JamTime) bool

After reports whether the time instant jt is after u

func (JamTime) Before

func (jt JamTime) Before(u JamTime) bool

Before reports whether the time instant jt is before u

func (JamTime) Equal

func (jt JamTime) Equal(u JamTime) bool

Equal reports whether jt and u represent the same time instant

func (JamTime) IsInFutureTimeSlot

func (jt JamTime) IsInFutureTimeSlot() bool

IsInFutureTimeSlot checks if a given JamTime is in a future timeslot

func (JamTime) IsInSameEpoch

func (jt JamTime) IsInSameEpoch(other JamTime) bool

IsInSameEpoch checks if two JamTimes are in the same epoch

func (JamTime) IsZero

func (jt JamTime) IsZero() bool

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

func (jt JamTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (JamTime) Sub

func (jt JamTime) Sub(u JamTime) time.Duration

Sub returns the duration jt-u

func (JamTime) ToEpoch

func (jt JamTime) ToEpoch() Epoch

ToEpoch converts a JamTime to its corresponding Epoch

func (JamTime) ToEpochAndTimeslot

func (jt JamTime) ToEpochAndTimeslot() (Epoch, Timeslot)

ToEpochAndTimeslot converts a JamTime to its Epoch and timeslot within that epoch

func (JamTime) ToTime

func (jt JamTime) ToTime() time.Time

ToTime converts a JamTime to a standard time.Time

func (JamTime) ToTimeslot

func (jt JamTime) ToTimeslot() Timeslot

ToTimeslot converts a JamTime to its corresponding Timeslot

func (*JamTime) UnmarshalJSON

func (jt *JamTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type Timeslot

type Timeslot uint32

Timeslot represents a 6-second window in JAM time

func CurrentTimeslot

func CurrentTimeslot() Timeslot

CurrentTimeslot returns the current timeslot

func (Timeslot) IsFirstTimeslotInEpoch

func (ts Timeslot) IsFirstTimeslotInEpoch() bool

IsFirstTimeslotInEpoch checks if the timeslot is the first in its epoch

func (Timeslot) IsInFuture

func (ts Timeslot) IsInFuture() bool

IsInFutureTimeslot checks if a given Timeslot is in the future

func (Timeslot) IsLastCoreRotation

func (ts Timeslot) IsLastCoreRotation() bool

IsLastCoreRotation checks if the timeslot is within the last core rotation of the epoch

func (Timeslot) IsLastTimeslotInEpoch

func (ts Timeslot) IsLastTimeslotInEpoch() bool

IsLastTimeslotInEpoch checks if the timeslot is the last in its epoch

func (Timeslot) IsTicketSubmissionPeriod

func (ts Timeslot) IsTicketSubmissionPeriod() bool

IsTicketSubmissionPeriod checks if tickets can still be submitted in the given Timeslot

func (Timeslot) IsWinningTicketMarkerPeriod

func (ts Timeslot) IsWinningTicketMarkerPeriod(previous Timeslot) bool

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

func (ts Timeslot) NextTimeslot() (Timeslot, error)

NextTimeslot returns the next timeslot

func (Timeslot) PreviousTimeslot

func (ts Timeslot) PreviousTimeslot() (Timeslot, error)

PreviousTimeslot returns the previous timeslot

func (Timeslot) TimeslotEnd

func (ts Timeslot) TimeslotEnd() (JamTime, error)

TimeslotEnd returns the JamTime at the end of the timeslot

func (Timeslot) TimeslotInEpoch

func (ts Timeslot) TimeslotInEpoch() uint32

TimeslotInEpoch returns the timeslot number within the epoch (0-599)

func (Timeslot) TimeslotStart

func (ts Timeslot) TimeslotStart() JamTime

TimeslotStart returns the JamTime at the start of the timeslot

func (Timeslot) ToEpoch

func (ts Timeslot) ToEpoch() Epoch

ToEpoch converts a Timeslot to its corresponding Epoch

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL