From c90bab14d6ede00f18cbd91133c68023de7c6ac0 Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Fri, 22 Aug 2025 10:44:20 -0400 Subject: [PATCH 1/6] remove runtime --- cmd/blindbit-oracle/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/blindbit-oracle/main.go b/cmd/blindbit-oracle/main.go index e021a3a..31aff8c 100644 --- a/cmd/blindbit-oracle/main.go +++ b/cmd/blindbit-oracle/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "path" - "runtime" "os" "os/signal" From 349413829501ffb01797c5161c6cecf9c462a2e8 Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Sat, 23 Aug 2025 12:11:51 -0400 Subject: [PATCH 2/6] address the outpoint index issue causing duplicate tweaks for a block --- internal/core/tweak.go | 23 +++++++---------------- internal/indexer/compute.go | 7 ++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/internal/core/tweak.go b/internal/core/tweak.go index 1eba2ac..d1e9537 100644 --- a/internal/core/tweak.go +++ b/internal/core/tweak.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "encoding/hex" "errors" - "fmt" "sort" "strings" "sync" @@ -283,20 +282,16 @@ func ComputeTweakPerTx(tx types.Transaction) (*types.Tweak, error) { logging.L.Err(err).Msg("error computing tweak per tx") return nil, err } - fmt.Printf("txid: %x\n", txidBytes) - fmt.Printf("summed Key: %x\n", summedKey[:]) hash, err := ComputeInputHash(tx, summedKey) if err != nil { logging.L.Debug().Str("txid", tx.Txid).Msg("error computing tweak per tx") logging.L.Err(err).Msg("error computing tweak per tx") return nil, err } - fmt.Printf("Input hash: %x\n", hash[:]) golibsecp256k1.PubKeyTweakMul(summedKey, &hash) tweakBytes := summedKey - fmt.Printf("Tweak: %x\n", tweakBytes[:]) highestValue, err := FindBiggestOutputFromTx(tx) if err != nil { @@ -485,7 +480,6 @@ func ComputeInputHash(tx types.Transaction, sumPublicKeys *[33]byte) ([32]byte, return [32]byte{}, err } - fmt.Printf("smallestOutpoint: %x\n", smallestOutpoint) // Concatenate outpointL and A var buffer bytes.Buffer @@ -520,18 +514,15 @@ func findSmallestOutpoint(tx types.Transaction) ([]byte, error) { } reversedTxid := utils.ReverseBytes(txidBytes) - // Serialize the Vout as little-endian bytes - voutBytes := new(bytes.Buffer) - err = binary.Write(voutBytes, binary.LittleEndian, vin.Vout) - if err != nil { - logging.L.Err(err).Msg("error serializing vout") - return nil, err - } - // Concatenate reversed Txid and Vout bytes - outpoint := append(reversedTxid, voutBytes.Bytes()...) + // Serialize outpoint: 32 bytes txid + 4 bytes vout + var outpoint [36]byte + copy(outpoint[:32], reversedTxid) + + // Encode vout as 4-byte little-endian + binary.LittleEndian.PutUint32(outpoint[32:36], vin.Vout) // Add the serialized outpoint to the slice - outpoints = append(outpoints, outpoint) + outpoints = append(outpoints, outpoint[:]) } // Sort the slice of outpoints to find the lexicographically smallest one diff --git a/internal/indexer/compute.go b/internal/indexer/compute.go index dd01236..88033d0 100644 --- a/internal/indexer/compute.go +++ b/internal/indexer/compute.go @@ -86,11 +86,8 @@ func findSmallestOutpoint(tx *Transaction) ([]byte, error) { var outpoint [36]byte copy(outpoint[:32], in.txIn.PreviousOutPoint.Hash[:]) - // using a helper slice for vout/index as not sure on the exact copy and slicing behaviour of underlying AppendUint32 - var index [4]byte - - indexBytes := binary.LittleEndian.AppendUint32(index[:], in.txIn.PreviousOutPoint.Index) - copy(outpoint[32:], indexBytes) + // Encode vout as 4-byte little-endian + binary.LittleEndian.PutUint32(outpoint[32:36], in.txIn.PreviousOutPoint.Index) // Add the serialized outpoint to the slice outpoints = append(outpoints, outpoint) From 76129fd6622ee9250360a36c0bd20dee3f96664a Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Sat, 23 Aug 2025 15:12:52 -0400 Subject: [PATCH 3/6] add logging configuration to file --- cmd/blindbit-oracle/main.go | 14 ++++++++++++++ internal/config/config.go | 3 +++ 2 files changed, 17 insertions(+) diff --git a/cmd/blindbit-oracle/main.go b/cmd/blindbit-oracle/main.go index 31aff8c..355b288 100644 --- a/cmd/blindbit-oracle/main.go +++ b/cmd/blindbit-oracle/main.go @@ -6,6 +6,7 @@ import ( "flag" "fmt" "path" + "path/filepath" "os" "os/signal" @@ -99,6 +100,19 @@ func init() { if config.RpcPass == "" { logging.L.Fatal().Msg("rpc pass not set") // todo use cookie file to circumvent this requirement } + + if config.LogsPath != "" { + logFile := filepath.Join(config.LogsPath, "blindbit.log") + err := os.Mkdir(config.LogsPath, 0750) + if err != nil && !errors.Is(err, os.ErrExist) { + logging.L.Fatal().Err(err).Msg("error creating log directory") + } else { + logging.L.Info().Msgf("writing logs to %s", logFile) + if err := logging.SetLogOutput(logFile); err != nil { + logging.L.Warn().Err(err).Msg("Failed to initialize file logging, continuing with console-only") + } + } + } } func main() { diff --git a/internal/config/config.go b/internal/config/config.go index 12b80a9..241da1f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -33,6 +33,7 @@ func LoadConfigs(pathToConfig string) { viper.SetDefault("tweaks_full_with_dust_filter", false) viper.SetDefault("tweaks_cut_through_with_dust_filter", false) viper.SetDefault("log_level", "info") + viper.SetDefault("log_path", "") // Bind viper keys to environment variables (optional, for backup) viper.AutomaticEnv() viper.BindEnv("http_host", "HTTP_HOST") @@ -58,6 +59,8 @@ func LoadConfigs(pathToConfig string) { HTTPHost = viper.GetString("http_host") GRPCHost = viper.GetString("grpc_host") LogLevel = viper.GetString("log_level") + LogsPath = viper.GetString("log_path") + // Performance MaxParallelRequests = viper.GetUint16("max_parallel_requests") MaxParallelTweakComputations = viper.GetInt("max_parallel_tweak_computations") From f6bb3d5323beaaf1cdf93ef750216cdf4aa5dbdb Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Sat, 23 Aug 2025 17:05:03 -0400 Subject: [PATCH 4/6] push more work to blindbit-lib --- cmd/blindbit-oracle/main.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cmd/blindbit-oracle/main.go b/cmd/blindbit-oracle/main.go index 355b288..196f03b 100644 --- a/cmd/blindbit-oracle/main.go +++ b/cmd/blindbit-oracle/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "path" - "path/filepath" "os" "os/signal" @@ -102,15 +101,9 @@ func init() { } if config.LogsPath != "" { - logFile := filepath.Join(config.LogsPath, "blindbit.log") - err := os.Mkdir(config.LogsPath, 0750) - if err != nil && !errors.Is(err, os.ErrExist) { - logging.L.Fatal().Err(err).Msg("error creating log directory") - } else { - logging.L.Info().Msgf("writing logs to %s", logFile) - if err := logging.SetLogOutput(logFile); err != nil { - logging.L.Warn().Err(err).Msg("Failed to initialize file logging, continuing with console-only") - } + if err := logging.SetLogOutput(config.LogsPath, "blindbit.log"); err != nil { + logging.L.Warn().Err(err).Msg("Failed to initialize file logging") + defer logging.Close() } } } From 2dd62b8809f1ed504e23f1a1e07a03b6e6e367cd Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Sat, 23 Aug 2025 17:18:32 -0400 Subject: [PATCH 5/6] add method to disable console log --- blindbit.example.toml | 2 ++ cmd/blindbit-oracle/main.go | 1 + internal/config/config.go | 2 ++ internal/config/vars.go | 1 + 4 files changed, 6 insertions(+) diff --git a/blindbit.example.toml b/blindbit.example.toml index e89e8f6..745fbab 100644 --- a/blindbit.example.toml +++ b/blindbit.example.toml @@ -1,5 +1,7 @@ # possible values: trace, debug, info, warn, error log_level = "debug" +# log_path = "" +# log_to_console = true # 0.0.0.0:8000 to expose outside of localhost # default: "127.0.0.1:8000" diff --git a/cmd/blindbit-oracle/main.go b/cmd/blindbit-oracle/main.go index 196f03b..9eaf405 100644 --- a/cmd/blindbit-oracle/main.go +++ b/cmd/blindbit-oracle/main.go @@ -106,6 +106,7 @@ func init() { defer logging.Close() } } + logging.SetConsoleLogging(config.LogToConsole) } func main() { diff --git a/internal/config/config.go b/internal/config/config.go index 241da1f..fb29433 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -34,6 +34,7 @@ func LoadConfigs(pathToConfig string) { viper.SetDefault("tweaks_cut_through_with_dust_filter", false) viper.SetDefault("log_level", "info") viper.SetDefault("log_path", "") + viper.SetDefault("log_to_console", true) // Bind viper keys to environment variables (optional, for backup) viper.AutomaticEnv() viper.BindEnv("http_host", "HTTP_HOST") @@ -60,6 +61,7 @@ func LoadConfigs(pathToConfig string) { GRPCHost = viper.GetString("grpc_host") LogLevel = viper.GetString("log_level") LogsPath = viper.GetString("log_path") + LogToConsole = viper.GetBool("log_to_console") // Performance MaxParallelRequests = viper.GetUint16("max_parallel_requests") diff --git a/internal/config/vars.go b/internal/config/vars.go index 223b8d8..a030fe8 100644 --- a/internal/config/vars.go +++ b/internal/config/vars.go @@ -37,6 +37,7 @@ var ( BaseDirectory = "" DBPath = "" LogsPath = "" + LogToConsole = true HTTPHost = "127.0.0.1:8000" GRPCHost = "" // default value is empty (deactivated) From 576998e9959496e469aa5b1012848bdc336a76d2 Mon Sep 17 00:00:00 2001 From: macgyver13 <4712150+macgyver13@users.noreply.github.com> Date: Mon, 25 Aug 2025 08:38:43 -0400 Subject: [PATCH 6/6] reverse print removal --- internal/core/tweak.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/core/tweak.go b/internal/core/tweak.go index d1e9537..e83a078 100644 --- a/internal/core/tweak.go +++ b/internal/core/tweak.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "encoding/hex" "errors" + "fmt" "sort" "strings" "sync" @@ -282,16 +283,20 @@ func ComputeTweakPerTx(tx types.Transaction) (*types.Tweak, error) { logging.L.Err(err).Msg("error computing tweak per tx") return nil, err } + fmt.Printf("txid: %x\n", txidBytes) + fmt.Printf("summed Key: %x\n", summedKey[:]) hash, err := ComputeInputHash(tx, summedKey) if err != nil { logging.L.Debug().Str("txid", tx.Txid).Msg("error computing tweak per tx") logging.L.Err(err).Msg("error computing tweak per tx") return nil, err } + fmt.Printf("Input hash: %x\n", hash[:]) golibsecp256k1.PubKeyTweakMul(summedKey, &hash) tweakBytes := summedKey + fmt.Printf("Tweak: %x\n", tweakBytes[:]) highestValue, err := FindBiggestOutputFromTx(tx) if err != nil { @@ -480,6 +485,7 @@ func ComputeInputHash(tx types.Transaction, sumPublicKeys *[33]byte) ([32]byte, return [32]byte{}, err } + fmt.Printf("smallestOutpoint: %x\n", smallestOutpoint) // Concatenate outpointL and A var buffer bytes.Buffer