Add RepostedCount, EffectiveAmount prefix rows #51

Merged
moodyjon merged 3 commits from schema_catchup2 into master 2022-08-26 15:24:40 +02:00
4 changed files with 29 additions and 29 deletions
Showing only changes of commit 2c9be1d8a8 - Show all commits

View file

@ -519,13 +519,13 @@ func (db *ReadOnlyDBColumnFamily) GetDBState() (*prefixes.DBStateValue, error) {
return value, nil return value, nil
} }
func (db *ReadOnlyDBColumnFamily) EffectiveAmountNameIter(normalizedName string) <-chan *prefixes.PrefixRowKV { func (db *ReadOnlyDBColumnFamily) BidOrderNameIter(normalizedName string) <-chan *prefixes.PrefixRowKV {
handle, err := db.EnsureHandle(prefixes.EffectiveAmount) handle, err := db.EnsureHandle(prefixes.BidOrder)
if err != nil { if err != nil {
return nil return nil
} }
key := prefixes.NewEffectiveAmountKey(normalizedName) key := prefixes.NewBidOrderKey(normalizedName)
var rawKeyPrefix []byte = nil var rawKeyPrefix []byte = nil
rawKeyPrefix = key.PartialPack(1) rawKeyPrefix = key.PartialPack(1)
options := NewIterateOptions().WithCfHandle(handle).WithPrefix(rawKeyPrefix) options := NewIterateOptions().WithCfHandle(handle).WithPrefix(rawKeyPrefix)

View file

@ -281,15 +281,15 @@ func (db *ReadOnlyDBColumnFamily) ResolveParsedUrl(parsed *PathSegment) (*Resolv
// Resolve by amount ordering // Resolve by amount ordering
log.Warn("resolving by amount ordering") log.Warn("resolving by amount ordering")
ch := db.EffectiveAmountNameIter(normalizedName) ch := db.BidOrderNameIter(normalizedName)
var i = 0 var i = 0
for kv := range ch { for kv := range ch {
if i+1 < amountOrder { if i+1 < amountOrder {
i++ i++
continue continue
} }
key := kv.Key.(*prefixes.EffectiveAmountKey) key := kv.Key.(*prefixes.BidOrderKey)
claimVal := kv.Value.(*prefixes.EffectiveAmountValue) claimVal := kv.Value.(*prefixes.BidOrderValue)
claimTxo, err := db.GetCachedClaimTxo(claimVal.ClaimHash, true) claimTxo, err := db.GetCachedClaimTxo(claimVal.ClaimHash, true)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -32,7 +32,7 @@ const (
ChannelToClaim = 'J' ChannelToClaim = 'J'
ClaimShortIdPrefix = 'F' ClaimShortIdPrefix = 'F'
EffectiveAmount = 'D' BidOrder = 'D'
ClaimExpiration = 'O' ClaimExpiration = 'O'
ClaimTakeover = 'P' ClaimTakeover = 'P'
@ -83,7 +83,7 @@ func GetPrefixes() [][]byte {
{ClaimToChannel}, {ClaimToChannel},
{ChannelToClaim}, {ChannelToClaim},
{ClaimShortIdPrefix}, {ClaimShortIdPrefix},
{EffectiveAmount}, {BidOrder},
{ClaimExpiration}, {ClaimExpiration},
{ClaimTakeover}, {ClaimTakeover},
{PendingActivation}, {PendingActivation},
@ -2665,7 +2665,7 @@ func ActiveAmountValueUnpack(value []byte) *ActiveAmountValue {
type OnesComplementEffectiveAmount uint64 type OnesComplementEffectiveAmount uint64
type EffectiveAmountKey struct { type BidOrderKey struct {
Prefix []byte `struct:"[1]byte" json:"prefix"` Prefix []byte `struct:"[1]byte" json:"prefix"`
LengthEncodedNormalizedName // fields NormalizedNameLen, NormalizedName LengthEncodedNormalizedName // fields NormalizedNameLen, NormalizedName
EffectiveAmount OnesComplementEffectiveAmount `json:"effective_amount"` EffectiveAmount OnesComplementEffectiveAmount `json:"effective_amount"`
@ -2673,18 +2673,18 @@ type EffectiveAmountKey struct {
Position uint16 `json:"position"` Position uint16 `json:"position"`
} }
type EffectiveAmountValue struct { type BidOrderValue struct {
ClaimHash []byte `struct:"[20]byte" json:"claim_hash"` ClaimHash []byte `struct:"[20]byte" json:"claim_hash"`
} }
func NewEffectiveAmountKey(normalizedName string) *EffectiveAmountKey { func NewBidOrderKey(normalizedName string) *BidOrderKey {
return &EffectiveAmountKey{ return &BidOrderKey{
Prefix: []byte{EffectiveAmount}, Prefix: []byte{BidOrder},
LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(normalizedName), LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(normalizedName),
} }
} }
func (k *EffectiveAmountKey) PackKey() []byte { func (k *BidOrderKey) PackKey() []byte {
prefixLen := 1 prefixLen := 1
// 2 byte length field, plus number of bytes in name // 2 byte length field, plus number of bytes in name
nameLen := len(k.NormalizedName) nameLen := len(k.NormalizedName)
@ -2703,7 +2703,7 @@ func (k *EffectiveAmountKey) PackKey() []byte {
return key return key
} }
func (v *EffectiveAmountValue) PackValue() []byte { func (v *BidOrderValue) PackValue() []byte {
// b'>20s' // b'>20s'
value := make([]byte, 20) value := make([]byte, 20)
copy(value, v.ClaimHash[:20]) copy(value, v.ClaimHash[:20])
@ -2711,11 +2711,11 @@ func (v *EffectiveAmountValue) PackValue() []byte {
return value return value
} }
func (kv *EffectiveAmountKey) NumFields() int { func (kv *BidOrderKey) NumFields() int {
return 4 return 4
} }
func (k *EffectiveAmountKey) PartialPack(fields int) []byte { func (k *BidOrderKey) PartialPack(fields int) []byte {
// Limit fields between 0 and number of fields, we always at least need // Limit fields between 0 and number of fields, we always at least need
// the prefix, and we never need to iterate past the number of fields. // the prefix, and we never need to iterate past the number of fields.
nameLen := len(k.NormalizedName) nameLen := len(k.NormalizedName)
@ -2763,10 +2763,10 @@ func (k *EffectiveAmountKey) PartialPack(fields int) []byte {
return key return key
} }
func EffectiveAmountKeyUnpack(key []byte) *EffectiveAmountKey { func BidOrderKeyUnpack(key []byte) *BidOrderKey {
prefixLen := 1 prefixLen := 1
nameLen := binary.BigEndian.Uint16(key[prefixLen:]) nameLen := binary.BigEndian.Uint16(key[prefixLen:])
return &EffectiveAmountKey{ return &BidOrderKey{
Prefix: key[:prefixLen], Prefix: key[:prefixLen],
LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(string(key[prefixLen+2 : prefixLen+2+int(nameLen)])), LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(string(key[prefixLen+2 : prefixLen+2+int(nameLen)])),
EffectiveAmount: OnesComplementEffectiveAmount(OnesCompTwiddle64 - binary.BigEndian.Uint64(key[prefixLen+2+int(nameLen):])), EffectiveAmount: OnesComplementEffectiveAmount(OnesCompTwiddle64 - binary.BigEndian.Uint64(key[prefixLen+2+int(nameLen):])),
@ -2775,8 +2775,8 @@ func EffectiveAmountKeyUnpack(key []byte) *EffectiveAmountKey {
} }
} }
func EffectiveAmountValueUnpack(value []byte) *EffectiveAmountValue { func BidOrderValueUnpack(value []byte) *BidOrderValue {
return &EffectiveAmountValue{ return &BidOrderValue{
ClaimHash: value[:20], ClaimHash: value[:20],
} }
} }
@ -3651,18 +3651,18 @@ var prefixRegistry = map[byte]prefixMeta{
return ClaimShortIDValueUnpack(buf) return ClaimShortIDValueUnpack(buf)
}, },
}, },
EffectiveAmount: { BidOrder: {
newKey: func() interface{} { newKey: func() interface{} {
return &EffectiveAmountKey{Prefix: []byte{EffectiveAmount}} return &BidOrderKey{Prefix: []byte{BidOrder}}
}, },
newValue: func() interface{} { newValue: func() interface{} {
return &EffectiveAmountValue{} return &BidOrderValue{}
}, },
newKeyUnpack: func(buf []byte) interface{} { newKeyUnpack: func(buf []byte) interface{} {
return EffectiveAmountKeyUnpack(buf) return BidOrderKeyUnpack(buf)
}, },
newValueUnpack: func(buf []byte) interface{} { newValueUnpack: func(buf []byte) interface{} {
return EffectiveAmountValueUnpack(buf) return BidOrderValueUnpack(buf)
}, },
}, },
ClaimExpiration: { ClaimExpiration: {

View file

@ -311,9 +311,9 @@ func TestActiveAmount(t *testing.T) {
testGeneric(filePath, prefixes.ActiveAmount, 5)(t) testGeneric(filePath, prefixes.ActiveAmount, 5)(t)
} }
func TestEffectiveAmount(t *testing.T) { func TestBidOrder(t *testing.T) {
filePath := fmt.Sprintf("../../testdata/%c.csv", prefixes.EffectiveAmount) filePath := fmt.Sprintf("../../testdata/%c.csv", prefixes.BidOrder)
testGeneric(filePath, prefixes.EffectiveAmount, 4)(t) testGeneric(filePath, prefixes.BidOrder, 4)(t)
} }
func TestRepost(t *testing.T) { func TestRepost(t *testing.T) {