From f5520656e5446d7a0c79f04023d4553287747e0a Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Thu, 10 Mar 2022 16:12:08 +0000 Subject: [PATCH] cleanup --- db/db.go | 18 +++++++++++++----- server/server.go | 8 ++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/db/db.go b/db/db.go index e8d4e84..778c610 100644 --- a/db/db.go +++ b/db/db.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/hex" "fmt" - "math" "os" "sort" "time" @@ -23,6 +22,7 @@ import ( // const ( + // Blochchain height / expiration constants NOriginalClaimExpirationTime = 262974 NExtendedClaimExpirationTime = 2102400 NExtendedClaimExpirationForkHeight = 400155 @@ -33,6 +33,8 @@ const ( NAllClaimsInMerkleForkHeight = 658310 // targeting 30 Oct 2019 ProportionalDelayFactor = 32 MaxTakeoverDelay = 4032 + // Initial size constants + InitialTxCountSize = 1200000 ) // @@ -265,14 +267,21 @@ func BisectRight(arr []interface{}, val uint32) uint32 { // Iterators / db construction functions // +func intMin(a, b int) int { + if a < b { + return a + } + return b +} + func (o *IterOptions) StopIteration(key []byte) bool { if key == nil { return false } // TODO: Look at not doing floating point conversions for this - maxLenStop := int(math.Min(float64(len(key)), float64(len(o.Stop)))) - maxLenStart := int(math.Min(float64(len(key)), float64(len(o.Start)))) + maxLenStop := intMin(len(key), len(o.Stop)) + maxLenStart := intMin(len(key), len(o.Start)) if o.Stop != nil && (bytes.HasPrefix(key, o.Stop) || bytes.Compare(o.Stop, key[:maxLenStop]) < 0) { return true @@ -771,8 +780,7 @@ func InitTxCounts(db *ReadOnlyDBColumnFamily) error { return err } - //TODO: figure out a reasonable default and make it a constant - db.TxCounts = db_stack.NewSliceBackedStack(1200000) + db.TxCounts = db_stack.NewSliceBackedStack(InitialTxCountSize) options := NewIterateOptions().WithPrefix([]byte{prefixes.TxCount}).WithCfHandle(handle) options = options.WithIncludeKey(false).WithIncludeValue(true).WithIncludeStop(true) diff --git a/server/server.go b/server/server.go index d02051c..744f666 100644 --- a/server/server.go +++ b/server/server.go @@ -488,9 +488,9 @@ func (s *Server) Resolve(ctx context.Context, args *pb.StringValue) (*pb.Outputs return &pb.Outputs{ Txos: txos, ExtraTxos: extraTxos, - Total: 1, - Offset: 0, - Blocked: nil, - BlockedTotal: 0, + Total: uint32(len(txos) + len(extraTxos)), + Offset: 0, //TODO + Blocked: nil, //TODO + BlockedTotal: 0, //TODO }, nil }