Skip to content

Commit 700a9da

Browse files
authored
feat: Allegra era 'Utxo' validation rules (#885)
Fixes #876 Signed-off-by: Aurora Gaffney <[email protected]>
1 parent e585ccb commit 700a9da

File tree

5 files changed

+967
-10
lines changed

5 files changed

+967
-10
lines changed

ledger/allegra/errors.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package allegra
16+
17+
import (
18+
"fmt"
19+
)
20+
21+
type OutsideValidityIntervalUtxoError struct {
22+
ValidityIntervalStart uint64
23+
Slot uint64
24+
}
25+
26+
func (e OutsideValidityIntervalUtxoError) Error() string {
27+
return fmt.Sprintf(
28+
"outside validity interval: start %d, slot %d",
29+
e.ValidityIntervalStart,
30+
e.Slot,
31+
)
32+
}

ledger/allegra/rules.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package allegra
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/blinklabs-io/gouroboros/ledger/common"
21+
"github.com/blinklabs-io/gouroboros/ledger/shelley"
22+
)
23+
24+
var UtxoValidationRules = []common.UtxoValidationRuleFunc{
25+
UtxoValidateOutsideValidityIntervalUtxo,
26+
UtxoValidateInputSetEmptyUtxo,
27+
UtxoValidateFeeTooSmallUtxo,
28+
UtxoValidateBadInputsUtxo,
29+
UtxoValidateWrongNetwork,
30+
UtxoValidateWrongNetworkWithdrawal,
31+
UtxoValidateValueNotConservedUtxo,
32+
UtxoValidateOutputTooSmallUtxo,
33+
UtxoValidateOutputBootAddrAttrsTooBig,
34+
UtxoValidateMaxTxSizeUtxo,
35+
}
36+
37+
// UtxoValidateOutsideValidityIntervalUtxo ensures that the current tip slot has reached the specified validity interval
38+
func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, _ common.LedgerState, _ common.ProtocolParameters) error {
39+
validityIntervalStart := tx.ValidityIntervalStart()
40+
if validityIntervalStart == 0 || slot >= validityIntervalStart {
41+
return nil
42+
}
43+
return OutsideValidityIntervalUtxoError{
44+
ValidityIntervalStart: validityIntervalStart,
45+
Slot: slot,
46+
}
47+
}
48+
49+
func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
50+
return shelley.UtxoValidateInputSetEmptyUtxo(tx, slot, ls, pp)
51+
}
52+
53+
func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
54+
tmpPparams, ok := pp.(*AllegraProtocolParameters)
55+
if !ok {
56+
return fmt.Errorf("pparams are not expected type")
57+
}
58+
return shelley.UtxoValidateFeeTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
59+
}
60+
61+
func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
62+
return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp)
63+
}
64+
65+
func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
66+
return shelley.UtxoValidateWrongNetwork(tx, slot, ls, pp)
67+
}
68+
69+
func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
70+
return shelley.UtxoValidateWrongNetworkWithdrawal(tx, slot, ls, pp)
71+
}
72+
73+
func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
74+
tmpPparams, ok := pp.(*AllegraProtocolParameters)
75+
if !ok {
76+
return fmt.Errorf("pparams are not expected type")
77+
}
78+
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
79+
}
80+
81+
func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
82+
tmpPparams, ok := pp.(*AllegraProtocolParameters)
83+
if !ok {
84+
return fmt.Errorf("pparams are not expected type")
85+
}
86+
return shelley.UtxoValidateOutputTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
87+
}
88+
89+
func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
90+
return shelley.UtxoValidateOutputBootAddrAttrsTooBig(tx, slot, ls, pp)
91+
}
92+
93+
func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
94+
tmpPparams, ok := pp.(*AllegraProtocolParameters)
95+
if !ok {
96+
return fmt.Errorf("pparams are not expected type")
97+
}
98+
return shelley.UtxoValidateMaxTxSizeUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
99+
}

0 commit comments

Comments
 (0)