Skip to content

Commit 77de2f7

Browse files
committed
refactor: use ledger block on verify block
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 84c0c51 commit 77de2f7

File tree

9 files changed

+512
-315
lines changed

9 files changed

+512
-315
lines changed

cbor/encode.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func Encode(data any) ([]byte, error) {
3939
return buf.Bytes(), err
4040
}
4141

42+
// EncMode returns an encoder mode with the custom tag set configured
43+
func EncMode() (_cbor.EncMode, error) {
44+
opts := _cbor.EncOptions{
45+
Sort: _cbor.SortCoreDeterministic,
46+
}
47+
return opts.EncModeWithTags(customTagSet)
48+
}
49+
4250
var (
4351
encodeGenericTypeCache = map[reflect.Type]reflect.Type{}
4452
encodeGenericTypeCacheMutex sync.RWMutex
@@ -132,3 +140,30 @@ func (i IndefLengthByteString) MarshalCBOR() ([]byte, error) {
132140
)
133141
return ret, nil
134142
}
143+
144+
type IndefLengthMap map[any]any
145+
146+
func (i IndefLengthMap) MarshalCBOR() ([]byte, error) {
147+
ret := []byte{
148+
// Start indefinite-length map
149+
0xbf,
150+
}
151+
for key, value := range map[any]any(i) {
152+
keyData, err := Encode(key)
153+
if err != nil {
154+
return nil, err
155+
}
156+
ret = append(ret, keyData...)
157+
valueData, err := Encode(value)
158+
if err != nil {
159+
return nil, err
160+
}
161+
ret = append(ret, valueData...)
162+
}
163+
ret = append(
164+
ret,
165+
// End indefinite length map
166+
byte(0xff),
167+
)
168+
return ret, nil
169+
}

connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121

2222
ouroboros "github.com/blinklabs-io/gouroboros"
23-
"github.com/blinklabs-io/ouroboros-mock"
23+
ouroboros_mock "github.com/blinklabs-io/ouroboros-mock"
2424
"go.uber.org/goleak"
2525
)
2626

ledger/common/rewards.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ func calculatePoolShare(
394394
stakeRatio := float64(poolStake) / float64(snapshot.TotalActiveStake)
395395

396396
// Calculate saturation (capped at 1.0)
397-
saturation := math.Min(stakeRatio/0.05, 1.0) // TODO: consider wiring a param or helper for consistency with CalculatePoolSaturation
397+
saturation := math.Min(
398+
stakeRatio/0.05,
399+
1.0,
400+
) // TODO: consider wiring a param or helper for consistency with CalculatePoolSaturation
398401

399402
// Calculate pool reward share using leader stake influence formula
400403
// R_pool = (stake_ratio * performance * (1 - margin)) / (1 + a0 * saturation)

0 commit comments

Comments
 (0)