Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate epoch length from pparams #211

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions state/eras/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var AllegraEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateAllegra,
PParamsUpdateFunc: PParamsUpdateAllegra,
HardForkFunc: HardForkAllegra,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsAllegra(data []byte) (any, error) {
Expand Down
1 change: 1 addition & 0 deletions state/eras/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var AlonzoEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateAlonzo,
PParamsUpdateFunc: PParamsUpdateAlonzo,
HardForkFunc: HardForkAlonzo,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsAlonzo(data []byte) (any, error) {
Expand Down
1 change: 1 addition & 0 deletions state/eras/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var BabbageEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateBabbage,
PParamsUpdateFunc: PParamsUpdateBabbage,
HardForkFunc: HardForkBabbage,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsBabbage(data []byte) (any, error) {
Expand Down
20 changes: 17 additions & 3 deletions state/eras/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@

package eras

import "github.com/blinklabs-io/gouroboros/ledger/byron"
import (
"github.com/blinklabs-io/gouroboros/ledger/byron"
"github.com/blinklabs-io/node/config/cardano"
)

var ByronEraDesc = EraDesc{
Id: byron.EraIdByron,
Name: byron.EraNameByron,
Id: byron.EraIdByron,
Name: byron.EraNameByron,
EpochLengthFunc: EpochLengthByron,
}

func EpochLengthByron(nodeConfig *cardano.CardanoNodeConfig) (uint, uint, error) {
byronGenesis, err := nodeConfig.ByronGenesis()
if err != nil {
return 0, 0, err
}
return uint(byronGenesis.BlockVersionData.SlotDuration),
uint(byronGenesis.ProtocolConsts.K * 10),
nil
}
1 change: 1 addition & 0 deletions state/eras/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var ConwayEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateConway,
PParamsUpdateFunc: PParamsUpdateConway,
HardForkFunc: HardForkConway,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsConway(data []byte) (any, error) {
Expand Down
1 change: 1 addition & 0 deletions state/eras/eras.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type EraDesc struct {
DecodePParamsUpdateFunc func([]byte) (any, error)
PParamsUpdateFunc func(any, any) (any, error)
HardForkFunc func(*cardano.CardanoNodeConfig, any) (any, error)
EpochLengthFunc func(*cardano.CardanoNodeConfig) (uint, uint, error)
}

var Eras = []EraDesc{
Expand Down
1 change: 1 addition & 0 deletions state/eras/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var MaryEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateMary,
PParamsUpdateFunc: PParamsUpdateMary,
HardForkFunc: HardForkMary,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsMary(data []byte) (any, error) {
Expand Down
11 changes: 11 additions & 0 deletions state/eras/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var ShelleyEraDesc = EraDesc{
DecodePParamsUpdateFunc: DecodePParamsUpdateShelley,
PParamsUpdateFunc: PParamsUpdateShelley,
HardForkFunc: HardForkShelley,
EpochLengthFunc: EpochLengthShelley,
}

func DecodePParamsShelley(data []byte) (any, error) {
Expand Down Expand Up @@ -80,3 +81,13 @@ func HardForkShelley(
ret.UpdateFromGenesis(shelleyGenesis)
return ret, nil
}

func EpochLengthShelley(nodeConfig *cardano.CardanoNodeConfig) (uint, uint, error) {
shelleyGenesis, err := nodeConfig.ShelleyGenesis()
if err != nil {
return 0, 0, err
}
return uint(shelleyGenesis.SlotLength * 1000),
uint(shelleyGenesis.EpochLength),
nil
}
10 changes: 5 additions & 5 deletions state/models/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type Epoch struct {
ID uint `gorm:"primarykey"`
// NOTE: we would normally use this as the primary key, but GORM doesn't
// like a primary key value of 0
EpochId uint `gorm:"uniqueIndex"`
EraId uint8
StartSlot uint64
SlotLengthInSeconds uint
LengthInSlots uint
EpochId uint `gorm:"uniqueIndex"`
EraId uint
StartSlot uint64
SlotLength uint
LengthInSlots uint
}

func (Epoch) TableName() string {
Expand Down
48 changes: 0 additions & 48 deletions state/models/era.go

This file was deleted.

1 change: 0 additions & 1 deletion state/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package models
var MigrateModels = []any{
&Block{},
&Epoch{},
&Era{},
&PoolRegistration{},
&PoolRegistrationOwner{},
&PoolRegistrationRelay{},
Expand Down
Loading