Skip to content
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
10 changes: 9 additions & 1 deletion database/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ func (d *Database) SetEpoch(
txn *Txn,
) error {
if txn == nil {
err := d.metadata.SetEpoch(slot, epoch, nonce, era, slotLength, lengthInSlots, nil)
err := d.metadata.SetEpoch(
slot,
epoch,
nonce,
era,
slotLength,
lengthInSlots,
nil,
)
if err != nil {
return err
}
Expand Down
72 changes: 72 additions & 0 deletions database/pparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2025 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 database

import (
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
)

func (d *Database) GetPParams(
epoch uint64,
decodeFunc func([]byte) (lcommon.ProtocolParameters, error),
txn *Txn,
) (lcommon.ProtocolParameters, error) {
var ret lcommon.ProtocolParameters
var err error
if txn == nil {
pparams, ppErr := d.metadata.GetPParams(epoch, nil)
if err != nil {
return ret, ppErr
}
if len(pparams) == 0 {
return ret, nil
}
// pparams is ordered, so grab the first
tmpPParams := pparams[0]
ret, err = decodeFunc(tmpPParams.Cbor)
} else {
pparams, ppErr := d.metadata.GetPParams(epoch, txn.Metadata())
if err != nil {
return ret, ppErr
}
if len(pparams) == 0 {
return ret, nil
}
// pparams is ordered, so grab the first
tmpPParams := pparams[0]
ret, err = decodeFunc(tmpPParams.Cbor)
}
return ret, err
}

func (d *Database) SetPParams(
params []byte,
slot, epoch uint64,
era uint,
txn *Txn,
) error {
if txn == nil {
err := d.metadata.SetPParams(params, slot, epoch, era, nil)
if err != nil {
return err
}
} else {
err := d.metadata.SetPParams(params, slot, epoch, era, txn.Metadata())
if err != nil {
return err
}
}
return nil
}
9 changes: 8 additions & 1 deletion database/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ func (d *Database) NewUtxo(
if err != nil {
return err
}
return d.metadata.SetUtxo(txId, outputIdx, slot, paymentKey, stakeKey, txn.Metadata())
return d.metadata.SetUtxo(
txId,
outputIdx,
slot,
paymentKey,
stakeKey,
txn.Metadata(),
)
}

func (d *Database) UtxoByRef(
Expand Down
6 changes: 5 additions & 1 deletion state/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ func (ls *LedgerState) handleEventChainsyncBlockHeader(e ChainsyncEvent) error {
ls.chainsyncBlockfetchBusy = false
ls.chainsyncBlockfetchWaiting = false
// Reset buffer
ls.chainsyncBlockEvents = slices.Delete(ls.chainsyncBlockEvents, 0, len(ls.chainsyncBlockEvents))
ls.chainsyncBlockEvents = slices.Delete(
ls.chainsyncBlockEvents,
0,
len(ls.chainsyncBlockEvents),
)
ls.config.Logger.Warn(
fmt.Sprintf(
"blockfetch operation timed out after %s",
Expand Down
27 changes: 10 additions & 17 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ func (ls *LedgerState) transitionToEra(
if err != nil {
return err
}
err = txn.DB().Metadata().SetPParams(
err = txn.DB().SetPParams(
pparamsCbor,
addedSlot,
startEpoch,
nextEraId,
txn.Metadata(),
txn,
)
if err != nil {
return err
Expand Down Expand Up @@ -379,17 +379,17 @@ func (ls *LedgerState) applyPParamUpdates(
"pparams",
fmt.Sprintf("%#v", ls.currentPParams),
)
// Write pparams update to DB
pparamsCbor, err := cbor.Encode(&ls.currentPParams)
if err != nil {
return err
}
// Write pparams update to DB
err = txn.DB().Metadata().SetPParams(
err = txn.DB().SetPParams(
pparamsCbor,
addedSlot,
uint64(currentEpoch+1),
ls.currentEra.Id,
txn.Metadata(),
txn,
)
if err != nil {
return err
Expand Down Expand Up @@ -447,22 +447,15 @@ func (ls *LedgerState) removeBlock(
}

func (ls *LedgerState) loadPParams() error {
pparams, err := ls.db.Metadata().GetPParams(ls.currentEpoch.EpochId, nil)
if err != nil {
return err
}
if len(pparams) == 0 {
return nil
}
// pparams is ordered, so grab the first
tmpPParams := pparams[0]
currentPParams, err := ls.currentEra.DecodePParamsFunc(
tmpPParams.Cbor,
pparams, err := ls.db.GetPParams(
ls.currentEpoch.EpochId,
ls.currentEra.DecodePParamsFunc,
nil,
)
if err != nil {
return err
}
ls.currentPParams = currentPParams
ls.currentPParams = pparams
return nil
}

Expand Down
Loading