From 76d71caef246acfc8b338fc0dbe62ffbe255c3ad Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Thu, 27 Mar 2025 15:19:07 -0400 Subject: [PATCH] fix(state): use ls.db to get database instead of txn methods Signed-off-by: Chris Gianelloni --- state/certs.go | 10 +++++----- state/chainsync.go | 14 +++++++------- state/state.go | 8 ++++---- state/view.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/state/certs.go b/state/certs.go index 4d9e7808..5e58356f 100644 --- a/state/certs.go +++ b/state/certs.go @@ -37,7 +37,7 @@ func (ls *LedgerState) processTransactionCertificates( } switch cert := tmpCert.(type) { case *lcommon.PoolRegistrationCertificate: - err := txn.DB().SetPoolRegistration( + err := ls.db.SetPoolRegistration( cert, blockPoint.Slot, certDeposit, @@ -47,7 +47,7 @@ func (ls *LedgerState) processTransactionCertificates( return err } case *lcommon.PoolRetirementCertificate: - err := txn.DB().SetPoolRetirement( + err := ls.db.SetPoolRetirement( cert, blockPoint.Slot, txn, @@ -56,7 +56,7 @@ func (ls *LedgerState) processTransactionCertificates( return err } case *lcommon.StakeDelegationCertificate: - err := txn.DB().SetStakeDelegation( + err := ls.db.SetStakeDelegation( cert, blockPoint.Slot, txn, @@ -65,7 +65,7 @@ func (ls *LedgerState) processTransactionCertificates( return err } case *lcommon.StakeDeregistrationCertificate: - err := txn.DB().SetStakeDeregistration( + err := ls.db.SetStakeDeregistration( cert, blockPoint.Slot, txn, @@ -74,7 +74,7 @@ func (ls *LedgerState) processTransactionCertificates( return err } case *lcommon.StakeRegistrationCertificate: - err := txn.DB().SetStakeRegistration( + err := ls.db.SetStakeRegistration( cert, blockPoint.Slot, certDeposit, diff --git a/state/chainsync.go b/state/chainsync.go index ab97b437..8cd1f8fa 100644 --- a/state/chainsync.go +++ b/state/chainsync.go @@ -321,7 +321,7 @@ func (ls *LedgerState) processGenesisBlock( ) tmpNonce = genesisHashBytes } - err = txn.DB().SetEpoch( + err = ls.db.SetEpoch( 0, 0, tmpNonce, @@ -333,7 +333,7 @@ func (ls *LedgerState) processGenesisBlock( if err != nil { return err } - newEpoch, err := txn.DB().GetEpochLatest(txn) + newEpoch, err := ls.db.GetEpochLatest(txn) if err != nil { return err } @@ -355,7 +355,7 @@ func (ls *LedgerState) processGenesisBlock( if err != nil { return err } - err = txn.DB().NewUtxo( + err = ls.db.NewUtxo( utxo.Id.Id().Bytes(), utxo.Id.Index(), 0, @@ -456,7 +456,7 @@ func (ls *LedgerState) processEpochRollover( if err != nil { return err } - err = txn.DB().SetEpoch( + err = ls.db.SetEpoch( epochStartSlot, ls.currentEpoch.EpochId+1, tmpNonce, @@ -468,7 +468,7 @@ func (ls *LedgerState) processEpochRollover( if err != nil { return err } - newEpoch, err := txn.DB().GetEpochLatest(txn) + newEpoch, err := ls.db.GetEpochLatest(txn) if err != nil { return err } @@ -602,7 +602,7 @@ func (ls *LedgerState) processTransaction( // Process produced UTxOs for _, produced := range tx.Produced() { outAddr := produced.Output.Address() - err := txn.DB().NewUtxo( + err := ls.db.NewUtxo( produced.Id.Id().Bytes(), produced.Id.Index(), point.Slot, @@ -619,7 +619,7 @@ func (ls *LedgerState) processTransaction( // Protocol parameter updates if updateEpoch, paramUpdates := tx.ProtocolParameterUpdates(); updateEpoch > 0 { for genesisHash, update := range paramUpdates { - err := txn.DB().Metadata().SetPParamUpdate( + err := ls.db.Metadata().SetPParamUpdate( genesisHash.Bytes(), update.Cbor(), point.Slot, diff --git a/state/state.go b/state/state.go index bd0d8ac4..281fa2b1 100644 --- a/state/state.go +++ b/state/state.go @@ -329,7 +329,7 @@ func (ls *LedgerState) transitionToEra( if err != nil { return err } - err = txn.DB().SetPParams( + err = ls.db.SetPParams( pparamsCbor, addedSlot, startEpoch, @@ -350,7 +350,7 @@ func (ls *LedgerState) applyPParamUpdates( addedSlot uint64, ) error { // Check for pparam updates that apply at the end of the epoch - pparamUpdates, err := txn.DB(). + pparamUpdates, err := ls.db. Metadata(). GetPParamUpdates(currentEpoch, txn.Metadata()) if err != nil { @@ -386,7 +386,7 @@ func (ls *LedgerState) applyPParamUpdates( if err != nil { return err } - err = txn.DB().SetPParams( + err = ls.db.SetPParams( pparamsCbor, addedSlot, uint64(currentEpoch+1), @@ -409,7 +409,7 @@ func (ls *LedgerState) consumeUtxo( utxoId ledger.TransactionInput, slot uint64, ) error { - return txn.DB().UtxoConsume( + return ls.db.UtxoConsume( utxoId, slot, txn, diff --git a/state/view.go b/state/view.go index 2aeea21f..1593d866 100644 --- a/state/view.go +++ b/state/view.go @@ -62,12 +62,12 @@ func (lv *LedgerView) PoolRegistration( pkh []byte, ) ([]lcommon.PoolRegistrationCertificate, error) { poolKeyHash := lcommon.PoolKeyHash(lcommon.NewBlake2b224(pkh)) - return lv.txn.DB().GetPoolRegistrations(poolKeyHash, lv.txn) + return lv.ls.db.GetPoolRegistrations(poolKeyHash, lv.txn) } func (lv *LedgerView) StakeRegistration( stakingKey []byte, ) ([]lcommon.StakeRegistrationCertificate, error) { // stakingKey = lcommon.NewBlake2b224(stakingKey) - return lv.txn.DB().GetStakeRegistrations(stakingKey, lv.txn) + return lv.ls.db.GetStakeRegistrations(stakingKey, lv.txn) }