Skip to content

Commit 8cde350

Browse files
authored
Merge pull request #5 from setavenger/dev
small adjustments
2 parents 93e0a1b + 0d84a7a commit 8cde350

File tree

4 files changed

+9
-82
lines changed

4 files changed

+9
-82
lines changed

src/common/vars.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ var (
3333
// SyncHeadersMaxPerCall how many headers will maximally be requested in one batched RPC call
3434
SyncHeadersMaxPerCall uint32 = 10_000
3535
// MaxParallelRequests sets how many RPC calls will be made in parallel to the Node
36-
MaxParallelRequests uint16 = 24
36+
MaxParallelRequests uint16 = 2
3737
// MaxParallelTweakComputations number of parallel processes which will be spawned in order to compute the tweaks for a given block
38-
MaxParallelTweakComputations = 1
38+
MaxParallelTweakComputations = 2
3939
// PruneFrequency every x blocks the data will be checked and pruned
4040
// possible routines: -remove utxos for 100% spent transaction
4141
PruneFrequency = 72

src/core/cleanup.go

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,6 @@ import (
77
"errors"
88
)
99

10-
/*
11-
todo needs a routine that cleans up the tweak data if no more utxos exist for a tx.
12-
The routine will then remove the corresponding tweak data from the db for every txid without light utxos.
13-
In an optimal implementation this should not be needed though.
14-
*/
15-
16-
func removeSpentUTXOsAndTweaks(utxos []types.UTXO) error {
17-
// First delete the old UTXOs
18-
err := dblevel.DeleteBatchUTXOs(utxos)
19-
if err != nil {
20-
common.ErrorLogger.Println(err)
21-
return err
22-
}
23-
24-
// Now begin process to find the tweaks that need to be deleted
25-
26-
// we only need to check for one utxo per txid, so we reduce the number of utxos -> fewer lookups in DB
27-
var cleanUTXOs []types.UTXO
28-
includedTxids := make(map[string]bool)
29-
30-
for _, utxo := range utxos {
31-
if _, exists := includedTxids[utxo.Txid]; !exists {
32-
cleanUTXOs = append(cleanUTXOs, utxo)
33-
includedTxids[utxo.Txid] = true
34-
}
35-
}
36-
37-
var tweaksToDelete []types.Tweak
38-
var tweaksToOverwrite []types.Tweak
39-
40-
for _, utxo := range cleanUTXOs {
41-
var remainingUTXOs []types.UTXO
42-
remainingUTXOs, err = dblevel.FetchByBlockHashAndTxidUTXOs(utxo.BlockHash, utxo.Txid)
43-
if err != nil && !errors.Is(err, dblevel.NoEntryErr{}) {
44-
common.ErrorLogger.Println(err)
45-
return err
46-
} else if err != nil && errors.Is(err, dblevel.NoEntryErr{}) {
47-
// if no UTXOs are left for a certain blockHash-txid combination we can remove the tweak
48-
tweaksToDelete = append(tweaksToDelete, types.Tweak{
49-
// we only need those Fields to serialise the key
50-
BlockHash: utxo.BlockHash,
51-
Txid: utxo.Txid,
52-
})
53-
continue
54-
}
55-
var newBiggest *uint64
56-
newBiggest, err = types.FindBiggestRemainingUTXO(utxo, remainingUTXOs)
57-
if err != nil {
58-
common.ErrorLogger.Println(err)
59-
return err
60-
}
61-
if newBiggest != nil {
62-
// find the biggest UTXO for the tx and overwrite if necessary
63-
tweaksToOverwrite = append(tweaksToOverwrite, types.Tweak{
64-
BlockHash: utxo.BlockHash,
65-
BlockHeight: 0,
66-
Txid: utxo.Txid,
67-
Data: [33]byte{},
68-
HighestValue: *newBiggest,
69-
})
70-
}
71-
}
72-
73-
err = dblevel.DeleteBatchTweaks(tweaksToDelete)
74-
if err != nil {
75-
common.ErrorLogger.Println(err)
76-
return err
77-
}
78-
79-
err = dblevel.OverWriteTweaks(tweaksToOverwrite)
80-
if err != nil {
81-
common.ErrorLogger.Println(err)
82-
return err
83-
}
84-
85-
return err
86-
}
87-
8810
func overwriteUTXOsWithLookUp(utxos []types.UTXO) error {
8911
var utxosToOverwrite []types.UTXO
9012

src/db/dblevel/utxo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dblevel
33
import (
44
"SilentPaymentAppBackend/src/common"
55
"SilentPaymentAppBackend/src/common/types"
6+
"errors"
67
)
78

89
func InsertUTXOs(utxos []types.UTXO) error {
@@ -55,6 +56,10 @@ func FetchByBlockHashAndTxidUTXOs(blockHash, txid string) ([]types.UTXO, error)
5556
//common.InfoLogger.Println("Fetching UTXOs")
5657
pairs, err := retrieveManyByBlockHashAndTxid(UTXOsDB, blockHash, txid, types.PairFactoryUTXO)
5758
if err != nil {
59+
if errors.Is(err, NoEntryErr{}) {
60+
// don't print if it's a no entry error
61+
return nil, err
62+
}
5863
common.ErrorLogger.Println(err)
5964
return nil, err
6065
}

src/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func init() {
4141
log.Fatal(err)
4242
}
4343

44-
file, err := os.OpenFile(fmt.Sprintf("%s/logs/logs-%s.txt", common.BaseDirectory, time.Now()), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
44+
file, err := os.OpenFile(fmt.Sprintf("%s/logs.log", common.BaseDirectory), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
4545
if err != nil {
4646
log.Fatal(err)
4747
}
48-
fileDebug, err := os.OpenFile(fmt.Sprintf("%s/logs/logs-debug-%s.txt", common.BaseDirectory, time.Now()), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
48+
fileDebug, err := os.OpenFile(fmt.Sprintf("%s/logs-debug.log", common.BaseDirectory), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
4949
if err != nil {
5050
log.Fatal(err)
5151
}

0 commit comments

Comments
 (0)