Skip to content

Commit

Permalink
Merge pull request #206 from kcalvinalvin/2024-10-22-update-utreexo-lib
Browse files Browse the repository at this point in the history
main, wire: update utreexo lib
  • Loading branch information
kcalvinalvin authored Oct 23, 2024
2 parents 75c934c + c1bc268 commit 8ea6726
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.20", "1.21"]
go: ["1.21"]
rust:
- version: stable
clippy: true
Expand All @@ -36,7 +36,7 @@ jobs:
run: make all

- name: Install Linters
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0

- name: Test
run: make test
4 changes: 2 additions & 2 deletions blockchain/utreexoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func (b *BlockChain) VerifyUData(ud *wire.UData, txIns []*wire.TxIn, remember bo
str += fmt.Sprintf("%s\n", txIn.PreviousOutPoint.String())
}

return fmt.Errorf(str)
return fmt.Errorf("%v", str)
}

// Make a slice of hashes from LeafDatas. These are the hash commitments
Expand Down Expand Up @@ -954,7 +954,7 @@ func (b *BlockChain) VerifyUData(ud *wire.UData, txIns []*wire.TxIn, remember bo
ud.LeafDatas[i].String(), hex.EncodeToString(leafHash[:]))
}
str += fmt.Sprintf("err: %s", err.Error())
return fmt.Errorf(str)
return fmt.Errorf("%v", str)
}

if remember {
Expand Down
2 changes: 1 addition & 1 deletion btcjson/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) str
w.Init(&formatted, 0, 4, 1, ' ', 0)
for i, text := range results {
if i == len(results)-1 {
fmt.Fprintf(w, text)
fmt.Fprint(w, text)
} else {
fmt.Fprintln(w, text)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/utreexo/utreexo v0.1.5
github.com/utreexo/utreexo v0.2.1
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd
)
Expand All @@ -31,4 +31,4 @@ require (
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

go 1.18
go 1.21
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ github.com/utreexo/utreexo v0.1.4 h1:jygjZscJEzab7woP7aB6YWUKjhsV5Mrbjj873inhwR8
github.com/utreexo/utreexo v0.1.4/go.mod h1:RT9JpZADhLr2YJVBgp48tmUxVeAHaAbOSr6p6nAEJpI=
github.com/utreexo/utreexo v0.1.5 h1:nnG2VvwDYPkXCSRicV15eAbh2vvTp/g4Pot3vlseGdQ=
github.com/utreexo/utreexo v0.1.5/go.mod h1:RT9JpZADhLr2YJVBgp48tmUxVeAHaAbOSr6p6nAEJpI=
github.com/utreexo/utreexo v0.2.1 h1:xycdaHK+HhDZO5MY6Clq7YeXEDguzar1GrAYqIJ1gvs=
github.com/utreexo/utreexo v0.2.1/go.mod h1:xIu3cTtT0jNdntc1qJhVyQV/RX03Sk9gFD3UAzALvuU=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
6 changes: 3 additions & 3 deletions goclean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ set -ex
go test -short -race -tags="rpctest" -tags="bdkwallet" ./...

# Automatic checks
golangci-lint run --deadline=10m --disable-all \
golangci-lint run --disable-all \
--enable=gofmt \
--enable=vet \
--enable=govet \
--enable=gosimple \
--enable=unconvert \
--skip-dirs=bdkwallet/bdkgo # these are generated files
--exclude-dirs=bdkwallet/bdkgo # these are generated files
33 changes: 22 additions & 11 deletions wire/batchproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,41 @@ func BatchProofDeserialize(r io.Reader) (*utreexo.Proof, error) {
return nil, err
}

targets := make([]uint64, targetCount)
for i := range targets {
target, err := ReadVarInt(r, 0)
if err != nil {
return nil, err
}
proof := new(utreexo.Proof)

targets[i] = target
if targetCount > 0 {
targets := make([]uint64, 0, targetCount)
for i := 0; i < int(targetCount); i++ {
target, err := ReadVarInt(r, 0)
if err != nil {
return nil, err
}

targets = append(targets, target)
}
proof.Targets = targets
}

proofCount, err := ReadVarInt(r, 0)
if err != nil {
return nil, err
}
if proofCount == 0 {
return proof, nil
}

proofs := make([]utreexo.Hash, proofCount)
for i := range proofs {
_, err = io.ReadFull(r, proofs[i][:])
proofs := make([]utreexo.Hash, 0, proofCount)
for i := 0; i < int(proofCount); i++ {
var hash utreexo.Hash
_, err = io.ReadFull(r, hash[:])
if err != nil {
return nil, err
}
proofs = append(proofs, hash)
}
proof.Proof = proofs

return &utreexo.Proof{Targets: targets, Proof: proofs}, nil
return proof, nil
}

// BatchProofToString converts a batchproof into a human-readable string. Note
Expand Down
4 changes: 2 additions & 2 deletions wire/batchproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestBatchProofSerializeSize(t *testing.T) {
if BatchProofSerializeSize(&test.bp) != test.size {
err := fmt.Errorf("TestBatchProofSerializeSize \"%s\": expected size of %d but got %d",
test.name, test.size, BatchProofSerializeSize(&test.bp))
t.Errorf(err.Error())
t.Error(err)
}

var buf bytes.Buffer
Expand All @@ -149,7 +149,7 @@ func TestBatchProofSerializeSize(t *testing.T) {
if test.size != len(buf.Bytes()) {
err := fmt.Errorf("TestBatchProofSerializeSize \"%s\": serialized bytes len of %d but serialize size of %d",
test.name, len(buf.Bytes()), BatchProofSerializeSize(&test.bp))
t.Errorf(err.Error())
t.Error(err)
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions wire/udata.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,21 @@ func (ud *UData) Deserialize(r io.Reader) error {
if err != nil {
return err
}
if udCount == 0 {
return nil
}

ud.LeafDatas = make([]LeafData, udCount)
for i := range ud.LeafDatas {
err = ud.LeafDatas[i].Deserialize(r)
ud.LeafDatas = make([]LeafData, 0, udCount)
for i := 0; i < int(udCount); i++ {
ld := LeafData{}
err = ld.Deserialize(r)
if err != nil {
str := fmt.Sprintf("targetCount:%d, Stxos[%d], err:%s\n",
len(ud.AccProof.Targets), i, err.Error())
returnErr := messageError("Deserialize stxos", str)
return returnErr
}
ud.LeafDatas = append(ud.LeafDatas, ld)
}

return nil
Expand Down

0 comments on commit 8ea6726

Please sign in to comment.