Skip to content

Commit d7e22cc

Browse files
committed
fixed dust limits, biggest utxo of all outputs and not of taproot outputs was used
1 parent 9db3e9b commit d7e22cc

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

blindbit.example.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tweaks_full_with_dust_filter = 0
4444

4545
# This index applies cut-through and dust filtering.
4646
# Beware that it will be stored in addition to any full index (with or without dust) if activated.
47-
# It has more storage requirments than the simple indices.
47+
# It has more storage requirements than the simple indices.
4848
# Currently still requires tweaks_only=1.
4949
# default: 0
5050
tweaks_cut_through_with_dust_filter = 0

src/common/types/tweakindex_dust.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func (t TweakData) Tweak() [33]byte {
3535
}
3636

3737
func PairFactoryTweakIndexDust() Pair {
38-
var filter Pair = &TweakIndexDust{}
39-
return filter
38+
var pair Pair = &TweakIndexDust{}
39+
return pair
4040
}
4141

4242
const lengthDataTweakIndexDust = TweakDataLength + 8

src/core/cleanup.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func markSpentUTXOsAndTweaks(utxos []types.UTXO) error {
3737
if len(utxos) == 0 {
3838
if common.Chain == common.Mainnet {
3939
// no warnings on other chains as it is very likely to not have any taproot outputs for several blocks on end
40-
common.WarningLogger.Println("no utxos to mark as spent")
40+
common.DebugLogger.Println("no utxos to mark as spent")
4141
}
4242
return nil
4343
}
@@ -87,13 +87,26 @@ func markSpentUTXOsAndTweaks(utxos []types.UTXO) error {
8787
common.ErrorLogger.Println(err)
8888
return err
8989
} else if err != nil && errors.Is(err, dblevel.NoEntryErr{}) {
90-
// if no UTXOs are left for a certain blockHash-txid combination we can remove the tweak
90+
// this case should not even occur at this stage as utxos are not deleted before this query and are only marked as spent
91+
common.DebugLogger.Printf("txid: %x\n", utxo.Txid)
92+
common.DebugLogger.Println("no UTXOs were found for transaction")
93+
continue
94+
}
95+
var canBeRemoved = true
96+
for _, utxo := range remainingUTXOs {
97+
if !utxo.Spent {
98+
canBeRemoved = false
99+
break
100+
}
101+
}
102+
if canBeRemoved {
91103
tweaksToDelete = append(tweaksToDelete, types.Tweak{
92104
// we only need those Fields to serialise the key
93105
BlockHash: utxo.BlockHash,
94106
Txid: utxo.Txid,
95107
})
96108
continue
109+
97110
}
98111
var newBiggest *uint64
99112
newBiggest, err = types.FindBiggestRemainingUTXO(utxo, remainingUTXOs)

src/core/tweak.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"encoding/hex"
99
"errors"
1010
"fmt"
11-
"github.com/btcsuite/btcd/btcec/v2"
1211
"math/big"
1312
"sort"
1413
"sync"
14+
15+
"github.com/btcsuite/btcd/btcec/v2"
1516
)
1617

1718
func ComputeTweaksForBlock(block *types.Block) ([]types.Tweak, error) {
@@ -311,14 +312,19 @@ func FindBiggestOutputFromTx(tx types.Transaction) (uint64, error) {
311312
var biggest uint64
312313

313314
for _, output := range tx.Vout {
315+
if output.ScriptPubKey.Type != "witness_v1_taproot" {
316+
continue
317+
}
314318
valueOutput := common.ConvertFloatBTCtoSats(output.Value)
315319
if valueOutput > biggest {
316320
biggest = valueOutput
317321
}
318322
}
319323

320324
if biggest == 0 {
321-
common.WarningLogger.Printf("Highest value was 0 txid: %s", tx.Txid)
325+
common.DebugLogger.Printf("%+v\n", tx)
326+
common.ErrorLogger.Printf("Highest value was 0 txid: %s", tx.Txid)
327+
// panic("highest value was 0") // This should not happen, but we don't kill the program
322328
}
323329

324330
return biggest, nil

src/main.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ func main() {
133133
common.ErrorLogger.Fatalln(err)
134134
return
135135
}
136+
137+
// so we can start fetching data while not fully synced. Requires headers to be synced to avoid grave errors.
138+
go server.RunServer(&server.ApiHandler{})
139+
136140
// todo buggy for sync catchup from 0, needs to be 1 or higher
137141
err = core.SyncChain()
138142
if err != nil {
139143
common.ErrorLogger.Fatalln(err)
140144
return
141145
}
142-
common.InfoLogger.Printf("Sync took: %s", time.Now().Sub(startSync).String())
146+
common.InfoLogger.Printf("Sync took: %s", time.Since(startSync).String())
143147
go core.CheckForNewBlockRoutine()
144148

145149
// only call this if you need to reindex. It doesn't delete anything but takes a couple of minutes to finish
@@ -149,15 +153,12 @@ func main() {
149153
// return
150154
//}
151155

152-
go server.RunServer(&server.ApiHandler{})
153156
}()
154157

155158
for {
156-
select {
157-
case <-interrupt:
158-
common.InfoLogger.Println("Program interrupted")
159-
return
160-
}
159+
<-interrupt
160+
common.InfoLogger.Println("Program interrupted")
161+
return
161162
}
162163
}
163164

0 commit comments

Comments
 (0)