diff --git a/internal/test/ledger/ledger.go b/internal/test/ledger/ledger.go index c9f14ce2..2915945c 100644 --- a/internal/test/ledger/ledger.go +++ b/internal/test/ledger/ledger.go @@ -63,20 +63,17 @@ func (ls MockLedgerState) StakeRegistration( return ret, nil } -func (ls MockLedgerState) PoolRegistration( +func (ls MockLedgerState) PoolCurrentState( poolKeyHash []byte, -) ([]common.PoolRegistrationCertificate, error) { - ret := []common.PoolRegistrationCertificate{} +) (*common.PoolRegistrationCertificate, *uint64, error) { for _, cert := range ls.MockPoolRegistration { - if string( - common.Blake2b224(cert.Operator).Bytes(), - ) == string( - poolKeyHash, - ) { - ret = append(ret, cert) + if string(common.Blake2b224(cert.Operator).Bytes()) == string(poolKeyHash) { + // pretend latest registration is current; no retirement support in mock + c := cert + return &c, nil, nil } } - return ret, nil + return nil, nil, nil } func (ls MockLedgerState) SlotToTime(slot uint64) (time.Time, error) { diff --git a/ledger/alonzo/rules.go b/ledger/alonzo/rules.go index e3a3d3d2..5419f3d1 100644 --- a/ledger/alonzo/rules.go +++ b/ledger/alonzo/rules.go @@ -289,11 +289,11 @@ func UtxoValidateValueNotConservedUtxo( for _, cert := range tx.Certificates() { switch tmpCert := cert.(type) { case *common.PoolRegistrationCertificate: - certs, err := ls.PoolRegistration(common.Blake2b224(tmpCert.Operator).Bytes()) + reg, _, err := ls.PoolCurrentState(common.Blake2b224(tmpCert.Operator).Bytes()) if err != nil { return err } - if len(certs) == 0 { + if reg == nil { producedValue += uint64(tmpPparams.PoolDeposit) } case *common.StakeRegistrationCertificate: diff --git a/ledger/babbage/rules.go b/ledger/babbage/rules.go index b771ef02..2aa6e7ac 100644 --- a/ledger/babbage/rules.go +++ b/ledger/babbage/rules.go @@ -275,11 +275,11 @@ func UtxoValidateValueNotConservedUtxo( for _, cert := range tx.Certificates() { switch tmpCert := cert.(type) { case *common.PoolRegistrationCertificate: - certs, err := ls.PoolRegistration(common.Blake2b224(tmpCert.Operator).Bytes()) + reg, _, err := ls.PoolCurrentState(common.Blake2b224(tmpCert.Operator).Bytes()) if err != nil { return err } - if len(certs) == 0 { + if reg == nil { producedValue += uint64(tmpPparams.PoolDeposit) } case *common.StakeRegistrationCertificate: diff --git a/ledger/common/state.go b/ledger/common/state.go index 8c9410f0..ec562d6b 100644 --- a/ledger/common/state.go +++ b/ledger/common/state.go @@ -28,7 +28,14 @@ type UtxoState interface { // CertState defines the interface for querying the certificate state type CertState interface { StakeRegistration([]byte) ([]StakeRegistrationCertificate, error) - PoolRegistration([]byte) ([]PoolRegistrationCertificate, error) +} + +// PoolState defines the interface for querying the current pool state +type PoolState interface { + // PoolCurrentState returns the latest active registration certificate for the given pool key hash. + // It also returns the epoch of a pending retirement certificate, if one exists. + // If the pool is not registered, the registration certificate will be nil. + PoolCurrentState([]byte) (*PoolRegistrationCertificate, *uint64, error) } // LedgerState defines the interface for querying the ledger @@ -36,6 +43,7 @@ type LedgerState interface { UtxoState CertState SlotState + PoolState NetworkId() uint } diff --git a/ledger/conway/rules.go b/ledger/conway/rules.go index b247b9c4..cfce8a33 100644 --- a/ledger/conway/rules.go +++ b/ledger/conway/rules.go @@ -272,11 +272,11 @@ func UtxoValidateValueNotConservedUtxo( for _, cert := range tx.Certificates() { switch tmpCert := cert.(type) { case *common.PoolRegistrationCertificate: - certs, err := ls.PoolRegistration(common.Blake2b224(tmpCert.Operator).Bytes()) + reg, _, err := ls.PoolCurrentState(common.Blake2b224(tmpCert.Operator).Bytes()) if err != nil { return err } - if len(certs) == 0 { + if reg == nil { producedValue += uint64(tmpPparams.PoolDeposit) } case *common.RegistrationCertificate: diff --git a/ledger/shelley/rules.go b/ledger/shelley/rules.go index 372a4e87..e0263d37 100644 --- a/ledger/shelley/rules.go +++ b/ledger/shelley/rules.go @@ -196,11 +196,11 @@ func UtxoValidateValueNotConservedUtxo( for _, cert := range tx.Certificates() { switch tmpCert := cert.(type) { case *common.PoolRegistrationCertificate: - certs, err := ls.PoolRegistration(common.Blake2b224(tmpCert.Operator).Bytes()) + reg, _, err := ls.PoolCurrentState(common.Blake2b224(tmpCert.Operator).Bytes()) if err != nil { return err } - if len(certs) == 0 { + if reg == nil { producedValue += uint64(tmpPparams.PoolDeposit) } case *common.StakeRegistrationCertificate: