-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: protocol params tracking from genesis configs (#200)
* split ledger config into separate type * basic era tracking * per-era functions for decoding and upgrading pparams * persist active pparams in DB
- Loading branch information
Showing
17 changed files
with
597 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/allegra" | ||
"github.com/blinklabs-io/gouroboros/ledger/shelley" | ||
"github.com/blinklabs-io/node/config/cardano" | ||
) | ||
|
||
var AllegraEraDesc = EraDesc{ | ||
Id: allegra.EraIdAllegra, | ||
Name: allegra.EraNameAllegra, | ||
DecodePParamsFunc: DecodePParamsAllegra, | ||
HardForkFunc: HardForkAllegra, | ||
} | ||
|
||
func DecodePParamsAllegra(data []byte) (any, error) { | ||
var ret allegra.AllegraProtocolParameters | ||
if _, err := cbor.Decode(data, &ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
func HardForkAllegra(nodeConfig *cardano.CardanoNodeConfig, prevPParams any) (any, error) { | ||
shelleyPParams, ok := prevPParams.(shelley.ShelleyProtocolParameters) | ||
if !ok { | ||
return nil, fmt.Errorf("previous PParams (%T) are not expected type", prevPParams) | ||
} | ||
ret := allegra.UpgradePParams(shelleyPParams) | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/alonzo" | ||
"github.com/blinklabs-io/gouroboros/ledger/mary" | ||
"github.com/blinklabs-io/node/config/cardano" | ||
) | ||
|
||
var AlonzoEraDesc = EraDesc{ | ||
Id: alonzo.EraIdAlonzo, | ||
Name: alonzo.EraNameAlonzo, | ||
DecodePParamsFunc: DecodePParamsAlonzo, | ||
HardForkFunc: HardForkAlonzo, | ||
} | ||
|
||
func DecodePParamsAlonzo(data []byte) (any, error) { | ||
var ret alonzo.AlonzoProtocolParameters | ||
if _, err := cbor.Decode(data, &ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
func HardForkAlonzo(nodeConfig *cardano.CardanoNodeConfig, prevPParams any) (any, error) { | ||
maryPParams, ok := prevPParams.(mary.MaryProtocolParameters) | ||
if !ok { | ||
return nil, fmt.Errorf("previous PParams (%T) are not expected type", prevPParams) | ||
} | ||
ret := alonzo.UpgradePParams(maryPParams) | ||
alonzoGenesis, err := nodeConfig.AlonzoGenesis() | ||
if err != nil { | ||
return nil, err | ||
} | ||
ret.UpdateFromGenesis(alonzoGenesis) | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/alonzo" | ||
"github.com/blinklabs-io/gouroboros/ledger/babbage" | ||
"github.com/blinklabs-io/node/config/cardano" | ||
) | ||
|
||
var BabbageEraDesc = EraDesc{ | ||
Id: babbage.EraIdBabbage, | ||
Name: babbage.EraNameBabbage, | ||
DecodePParamsFunc: DecodePParamsBabbage, | ||
HardForkFunc: HardForkBabbage, | ||
} | ||
|
||
func DecodePParamsBabbage(data []byte) (any, error) { | ||
var ret babbage.BabbageProtocolParameters | ||
if _, err := cbor.Decode(data, &ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
func HardForkBabbage(nodeConfig *cardano.CardanoNodeConfig, prevPParams any) (any, error) { | ||
alonzoPParams, ok := prevPParams.(alonzo.AlonzoProtocolParameters) | ||
if !ok { | ||
return nil, fmt.Errorf("previous PParams (%T) are not expected type", prevPParams) | ||
} | ||
ret := babbage.UpgradePParams(alonzoPParams) | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import "github.com/blinklabs-io/gouroboros/ledger/byron" | ||
|
||
var ByronEraDesc = EraDesc{ | ||
Id: byron.EraIdByron, | ||
Name: byron.EraNameByron, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/babbage" | ||
"github.com/blinklabs-io/gouroboros/ledger/conway" | ||
"github.com/blinklabs-io/node/config/cardano" | ||
) | ||
|
||
var ConwayEraDesc = EraDesc{ | ||
Id: conway.EraIdConway, | ||
Name: conway.EraNameConway, | ||
DecodePParamsFunc: DecodePParamsConway, | ||
HardForkFunc: HardForkConway, | ||
} | ||
|
||
func DecodePParamsConway(data []byte) (any, error) { | ||
var ret conway.ConwayProtocolParameters | ||
if _, err := cbor.Decode(data, &ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
func HardForkConway(nodeConfig *cardano.CardanoNodeConfig, prevPParams any) (any, error) { | ||
babbagePParams, ok := prevPParams.(babbage.BabbageProtocolParameters) | ||
if !ok { | ||
return nil, fmt.Errorf("previous PParams (%T) are not expected type", prevPParams) | ||
} | ||
ret := conway.UpgradePParams(babbagePParams) | ||
conwayGenesis, err := nodeConfig.ConwayGenesis() | ||
if err != nil { | ||
return nil, err | ||
} | ||
ret.UpdateFromGenesis(conwayGenesis) | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import "github.com/blinklabs-io/node/config/cardano" | ||
|
||
type EraDesc struct { | ||
Id uint | ||
Name string | ||
DecodePParamsFunc func([]byte) (any, error) | ||
HardForkFunc func(*cardano.CardanoNodeConfig, any) (any, error) | ||
} | ||
|
||
var Eras = []EraDesc{ | ||
ByronEraDesc, | ||
ShelleyEraDesc, | ||
AllegraEraDesc, | ||
MaryEraDesc, | ||
AlonzoEraDesc, | ||
BabbageEraDesc, | ||
ConwayEraDesc, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package eras | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/allegra" | ||
"github.com/blinklabs-io/gouroboros/ledger/mary" | ||
"github.com/blinklabs-io/node/config/cardano" | ||
) | ||
|
||
var MaryEraDesc = EraDesc{ | ||
Id: mary.EraIdMary, | ||
Name: mary.EraNameMary, | ||
DecodePParamsFunc: DecodePParamsMary, | ||
HardForkFunc: HardForkMary, | ||
} | ||
|
||
func DecodePParamsMary(data []byte) (any, error) { | ||
var ret mary.MaryProtocolParameters | ||
if _, err := cbor.Decode(data, &ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
func HardForkMary(nodeConfig *cardano.CardanoNodeConfig, prevPParams any) (any, error) { | ||
allegraPParams, ok := prevPParams.(allegra.AllegraProtocolParameters) | ||
if !ok { | ||
return nil, fmt.Errorf("previous PParams (%T) are not expected type", prevPParams) | ||
} | ||
ret := mary.UpgradePParams(allegraPParams) | ||
return ret, nil | ||
} |
Oops, something went wrong.