Skip to content

Commit

Permalink
update namespace to ppcd partially
Browse files Browse the repository at this point in the history
  • Loading branch information
ihavenoface committed Nov 15, 2023
1 parent 82e7953 commit efa4083
Show file tree
Hide file tree
Showing 35 changed files with 3,690 additions and 1,185 deletions.
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
test-cover:
name: Unit coverage
runs-on: ubuntu-latest
if: false
steps:
- name: Set up Go
uses: actions/setup-go@v2
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG := github.com/btcsuite/btcd
PKG := github.com/peercoin/ppcd

LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ recommended that `GOPATH` is set to a directory in your home directory such as

```bash
$ git clone https://github.com/peercoin/ppcd && cd ppcd
$ go build -o ppcd
$ go build
# run it using ./ppcd
```

Expand Down
2 changes: 1 addition & 1 deletion addrmgr/knownaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

"github.com/btcsuite/btcd/addrmgr"
"github.com/btcsuite/btcd/wire"
"github.com/peercoin/ppcd/addrmgr"
)

func TestChance(t *testing.T) {
Expand Down
641 changes: 641 additions & 0 deletions btcec/coverage.txt.bak

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion btcjson/cmdinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"reflect"
"testing"

"github.com/btcsuite/btcd/btcjson"
"github.com/peercoin/ppcd/btcjson"
)

// TestCmdMethod tests the CmdMethod function to ensure it retunrs the expected
Expand Down
2 changes: 1 addition & 1 deletion btcjson/cmdparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"reflect"
"testing"

"github.com/btcsuite/btcd/btcjson"
"github.com/peercoin/ppcd/btcjson"
)

// TestAssignField tests the assignField function handles supported combinations
Expand Down
2 changes: 1 addition & 1 deletion btcjson/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package btcjson_test
import (
"testing"

"github.com/btcsuite/btcd/btcjson"
"github.com/peercoin/ppcd/btcjson"
)

// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
Expand Down
2 changes: 1 addition & 1 deletion btcjson/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"reflect"
"testing"

"github.com/btcsuite/btcd/btcjson"
"github.com/peercoin/ppcd/btcjson"
)

// TestHelpReflectInternals ensures the various help functions which deal with
Expand Down
2 changes: 1 addition & 1 deletion btcjson/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"testing"

"github.com/btcsuite/btcd/btcjson"
"github.com/peercoin/ppcd/btcjson"
)

// TestUsageFlagStringer tests the stringized output for the UsageFlag type.
Expand Down
6 changes: 3 additions & 3 deletions btcutil/go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/btcsuite/btcd/btcutil

go 1.16
go 1.21.4

require (
github.com/aead/siphash v1.0.1
github.com/btcsuite/btcd v0.23.0
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btcd/btcec/v2 v2.1.3
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/crypto v0.14.0
)

replace github.com/btcsuite/btcd => ../
1 change: 1 addition & 0 deletions btcutil/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
Expand Down
10 changes: 4 additions & 6 deletions btcutil/psbt/go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
module github.com/btcsuite/btcd/btcutil/psbt

go 1.17
go 1.21.4

require (
github.com/btcsuite/btcd v0.23.0
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btcd/btcec/v2 v2.1.3
github.com/btcsuite/btcd/btcutil v1.1.0
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/davecgh/go-spew v1.1.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions btcutil/psbt/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
Expand All @@ -65,6 +66,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ=
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
2 changes: 1 addition & 1 deletion database/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"testing"

"github.com/btcsuite/btcd/database"
"github.com/peercoin/ppcd/database"
)

// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
Expand Down
2 changes: 1 addition & 1 deletion database/ffldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcd/database/internal/treap"
"github.com/btcsuite/btcd/database/treap"
"github.com/btcsuite/btcd/wire"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/comparer"
Expand Down
2 changes: 1 addition & 1 deletion database/ffldb/dbcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

"github.com/btcsuite/btcd/database/internal/treap"
"github.com/btcsuite/btcd/database/treap"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down
2 changes: 1 addition & 1 deletion database/ffldb/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcd/database/ffldb"
"github.com/peercoin/ppcd/database/ffldb"
)

// dbType is the database type name for this driver.
Expand Down
2 changes: 1 addition & 1 deletion database/ffldb/ldbtreapiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package ffldb

import (
"github.com/btcsuite/btcd/database/internal/treap"
"github.com/btcsuite/btcd/database/treap"
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/util"
)
Expand Down
39 changes: 39 additions & 0 deletions database/treap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
treap
=====

[![Build Status](https://github.com/btcsuite/btcd/workflows/Build%20and%20Test/badge.svg)](https://github.com/btcsuite/btcd/actions)
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://pkg.go.dev/github.com/btcsuite/btcd/database/internal/treap?status.png)](https://pkg.go.dev/github.com/btcsuite/btcd/database/internal/treap)

Package treap implements a treap data structure that is used to hold ordered
key/value pairs using a combination of binary search tree and heap semantics.
It is a self-organizing and randomized data structure that doesn't require
complex operations to maintain balance. Search, insert, and delete
operations are all O(log n). Both mutable and immutable variants are provided.

The mutable variant is typically faster since it is able to simply update the
treap when modifications are made. However, a mutable treap is not safe for
concurrent access without careful use of locking by the caller and care must be
taken when iterating since it can change out from under the iterator.

The immutable variant works by creating a new version of the treap for all
mutations by replacing modified nodes with new nodes that have updated values
while sharing all unmodified nodes with the previous version. This is extremely
useful in concurrent applications since the caller only has to atomically
replace the treap pointer with the newly returned version after performing any
mutations. All readers can simply use their existing pointer as a snapshot
since the treap it points to is immutable. This effectively provides O(1)
snapshot capability with efficient memory usage characteristics since the old
nodes only remain allocated until there are no longer any references to them.

Package treap is licensed under the copyfree ISC license.

## Usage

This package is only used internally in the database code and as such is not
available for use outside of it.

## License

Package treap is licensed under the [copyfree](http://copyfree.org) ISC
License.
136 changes: 136 additions & 0 deletions database/treap/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (c) 2015-2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package treap

import (
"math/rand"
"time"
)

const (
// staticDepth is the size of the static array to use for keeping track
// of the parent stack during treap iteration. Since a treap has a very
// high probability that the tree height is logarithmic, it is
// exceedingly unlikely that the parent stack will ever exceed this size
// even for extremely large numbers of items.
staticDepth = 128

// nodeFieldsSize is the size the fields of each node takes excluding
// the contents of the key and value. It assumes 64-bit pointers so
// technically it is smaller on 32-bit platforms, but overestimating the
// size in that case is acceptable since it avoids the need to import
// unsafe. It consists of 24-bytes for each key and value + 8 bytes for
// each of the priority, left, and right fields (24*2 + 8*3).
nodeFieldsSize = 72
)

var (
// emptySlice is used for keys that have no value associated with them
// so callers can distinguish between a key that does not exist and one
// that has no value associated with it.
emptySlice = make([]byte, 0)
)

// treapNode represents a node in the treap.
type treapNode struct {
key []byte
value []byte
priority int
left *treapNode
right *treapNode
}

// nodeSize returns the number of bytes the specified node occupies including
// the struct fields and the contents of the key and value.
func nodeSize(node *treapNode) uint64 {
return nodeFieldsSize + uint64(len(node.key)+len(node.value))
}

// newTreapNode returns a new node from the given key, value, and priority. The
// node is not initially linked to any others.
func newTreapNode(key, value []byte, priority int) *treapNode {
return &treapNode{key: key, value: value, priority: priority}
}

// parentStack represents a stack of parent treap nodes that are used during
// iteration. It consists of a static array for holding the parents and a
// dynamic overflow slice. It is extremely unlikely the overflow will ever be
// hit during normal operation, however, since a treap's height is
// probabilistic, the overflow case needs to be handled properly. This approach
// is used because it is much more efficient for the majority case than
// dynamically allocating heap space every time the treap is iterated.
type parentStack struct {
index int
items [staticDepth]*treapNode
overflow []*treapNode
}

// Len returns the current number of items in the stack.
func (s *parentStack) Len() int {
return s.index
}

// At returns the item n number of items from the top of the stack, where 0 is
// the topmost item, without removing it. It returns nil if n exceeds the
// number of items on the stack.
func (s *parentStack) At(n int) *treapNode {
index := s.index - n - 1
if index < 0 {
return nil
}

if index < staticDepth {
return s.items[index]
}

return s.overflow[index-staticDepth]
}

// Pop removes the top item from the stack. It returns nil if the stack is
// empty.
func (s *parentStack) Pop() *treapNode {
if s.index == 0 {
return nil
}

s.index--
if s.index < staticDepth {
node := s.items[s.index]
s.items[s.index] = nil
return node
}

node := s.overflow[s.index-staticDepth]
s.overflow[s.index-staticDepth] = nil
return node
}

// Push pushes the passed item onto the top of the stack.
func (s *parentStack) Push(node *treapNode) {
if s.index < staticDepth {
s.items[s.index] = node
s.index++
return
}

// This approach is used over append because reslicing the slice to pop
// the item causes the compiler to make unneeded allocations. Also,
// since the max number of items is related to the tree depth which
// requires expontentially more items to increase, only increase the cap
// one item at a time. This is more intelligent than the generic append
// expansion algorithm which often doubles the cap.
index := s.index - staticDepth
if index+1 > cap(s.overflow) {
overflow := make([]*treapNode, index+1)
copy(overflow, s.overflow)
s.overflow = overflow
}
s.overflow[index] = node
s.index++
}

func init() {
rand.Seed(time.Now().UnixNano())
}
Loading

0 comments on commit efa4083

Please sign in to comment.