Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
302620b
unfinished refactoring, trying to get rid of common
setavenger May 31, 2025
02e3b3e
Major refactoring and libsecp256k1 bindings
setavenger Jun 8, 2025
5fae0f9
Hex strings to byte slices/arrays
setavenger Jun 28, 2025
cdd0433
gRPC support ready
setavenger Aug 14, 2025
3f605f7
Cleanup; no more errors for empty db results
setavenger Aug 14, 2025
461903d
Simple benchmarking tool
setavenger Aug 14, 2025
bff8629
Added a v1 <> v2 compare test
setavenger Aug 14, 2025
d85caf9
Fixed imports and docker
setavenger Aug 14, 2025
7c805b3
Merge branch 'dev'
setavenger Aug 14, 2025
6c0ffcc
Merge branch 'dev'
setavenger Aug 14, 2025
c3ce6c7
Cleanup and bug fixes
setavenger Aug 16, 2025
b84af27
benchmarking: make a dummy run to preload data
setavenger Aug 16, 2025
1a6af5a
Some beginnings
setavenger Aug 17, 2025
76cc603
somewhat working; need to fix db writes
setavenger Aug 18, 2025
513ae94
Some good improvements but might need to switch
setavenger Aug 18, 2025
929917d
PebbleDB support
setavenger Aug 19, 2025
0e49016
Bug fix and Small adjustments for smoother sync
setavenger Aug 19, 2025
14caf7c
PebbleDB performance boost; not done
setavenger Aug 20, 2025
b8c1640
Somewhat useable, works on some v2 endpoints
setavenger Aug 20, 2025
6350abd
Fixed go-bip352 imports
setavenger Aug 20, 2025
86192ad
Bug fixes, cleanup and more
setavenger Aug 21, 2025
cfb43f9
Bug fixes, and cleanup
setavenger Aug 21, 2025
990db64
small changes, wordings comments and logs
setavenger Aug 21, 2025
0231d90
created tx anlayzer
setavenger May 1, 2025
060adb0
Fixed incorrect tweaks, tx-analyzer cli for debugs
setavenger Aug 22, 2025
3d78127
Some cleanup
setavenger Aug 22, 2025
7deb6d6
Added utxos for db operations and gRPC endpoints
setavenger Aug 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions blindbit.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ log_level = "debug"

# 0.0.0.0:8000 to expose outside of localhost
# default: "127.0.0.1:8000"
host = "127.0.0.1:8000"
http_host = "127.0.0.1:8000"

# defines where the gRPC host is exposed
# default: "" gRPC is not exposed by default
grpc_host = "127.0.0.1:8001"

# Defines on which chain the wallet runs. Allowed values: main, testnet, signet, regtest.
# default: signet
chain = "signet"

# bitcoin core rpc endpoint
# default: http://127.0.0.1:8332
# also used for rest api
rpc_endpoint = "http://127.0.0.1:18443"
core_rpc_endpoint = "http://127.0.0.1:18443"

# bitcoin core rest endpoint
# note: requires bitcoin core PR #32540 (already merged to master but in a release yet)
# default: ""
core_rest_endpoint = "http://127.0.01:38332"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing . between 01


# required, unless rpc_user and rpc_pass are set
cookie_path = ""
Expand Down
31 changes: 13 additions & 18 deletions cmd/blindbit-oracle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func init() {
return
}

config.SetDirectories() // todo a proper set settings function which does it all would be good to avoid several small function calls
// todo: a proper set settings function which does it all
// avoid several small function calls
config.SetDirectories()

err := os.Mkdir(config.BaseDirectory, 0750)
if err != nil && !errors.Is(err, os.ErrExist) {
logging.L.Fatal().Err(err).Msg("error creating base directory")
Expand All @@ -75,9 +78,6 @@ func init() {
logging.L.Fatal().Err(err).Msg("error creating db path")
}

// open levelDB connections
// openLevelDBConnections()

if config.CookiePath != "" {
data, err := os.ReadFile(config.CookiePath)
if err != nil {
Expand Down Expand Up @@ -147,24 +147,19 @@ func main() {

// index builder
go func() {
// err = database.DropIndexesForIBD(context.Background(), db)
// if err != nil {
// logging.L.Err(err).Msg("failed to drop indexes")
// errChan <- err
// }

builder := indexer.NewBuilder(store)
// builder := indexer.NewBuilder(db)

// ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
// defer cancel()
// do initial sync then move towards steady state sync
err = builder.InitialSyncToTip(ctx)
if err != nil {
logging.L.Err(err).Msg("failed initial sync")
errChan <- err
return
}

_ = ctx
_ = builder
// do continous scans
err = builder.ContinuousSync(ctx)

// err = builder.SyncBlocks(ctx, 1, 265_963)
// err = builder.SyncBlocks(ctx, 251_000, 265_000)
// err = builder.SyncBlocks(ctx, 230_000, 265_000)
if err != nil {
logging.L.Err(err).Msg("error indexing blocks")
errChan <- err
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func LoadConfigs(pathToConfig string) {
viper.BindEnv("http_host", "HTTP_HOST")
viper.BindEnv("grpc_host", "GRPC_HOST")
viper.BindEnv("chain", "CHAIN")
viper.BindEnv("rpc_endpoint", "RPC_ENDPOINT")
viper.BindEnv("core_rpc_endpoint", "CORE_RPC_ENDPOINT")
viper.BindEnv("core_rest_endpoint", "CORE_REST_ENDPOINT")
viper.BindEnv("cookie_path", "COOKIE_PATH")
viper.BindEnv("rpc_pass", "RPC_PASS")
viper.BindEnv("rpc_user", "RPC_USER")
Expand Down
9 changes: 5 additions & 4 deletions internal/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ var (
)

var (
RpcEndpoint = "http://127.0.0.1:8332" // default local node
CookiePath = ""
RpcUser = ""
RpcPass = ""
RpcEndpoint = "http://127.0.0.1:8332" // default local node
RestEndpoint = "" // default local node
CookiePath = ""
RpcUser = ""
RpcPass = ""

BaseDirectory = ""
DBPath = ""
Expand Down
4 changes: 2 additions & 2 deletions internal/database/dbpebble/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func (s *Store) GetChainTip() ([]byte, uint32, error) {
}
defer it.Close()
if !it.Last() {
// means literally zero blockhashes are in the db
return nil, 0, errors.New("no chain tip found")
// edge case empty db we are at 0 height
return nil, 0, nil
}
heightBytes := it.Key()
blockhash := it.Value()
Expand Down
38 changes: 36 additions & 2 deletions internal/database/dbpebble/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func (s *Store) collectAndWrite(block *database.DBBlock) error {
logging.L.Err(err).Msg("failed to write Batch")
return err
}
logging.L.Warn().Dur("write_batch_duration", time.Since(writeBatchStart)).Msg("batch_write_bench")
logging.L.Warn().
Dur("write_batch_duration", time.Since(writeBatchStart)).
Msg("batch_write_bench")
err = s.dbBatch.Close()
if err != nil {
logging.L.Err(err).Msg("failed to close db batch")
Expand All @@ -83,6 +85,31 @@ func (s *Store) collectAndWrite(block *database.DBBlock) error {
return nil
}

func (s *Store) FlushBatch() error {
s.batchSync.Lock()
defer s.batchSync.Unlock()

err := s.dbBatch.Commit(pebble.NoSync)
if err != nil {
logging.L.Err(err).Msg("failed to write Batch")
return err
}
return nil
}

// don't use yet until api design is clear for this concept
func (s *Store) commitBatch() error {
s.batchSync.Lock()
defer s.batchSync.Unlock()

err := s.dbBatch.Commit(pebble.NoSync)
if err != nil {
logging.L.Err(err).Msg("failed to write Batch")
return err
}
return nil
}

func attachBlcokToBatch(batch *pebble.Batch, block *database.DBBlock) error {
blockHash := block.Hash[:]
txs := block.Txs
Expand All @@ -103,7 +130,14 @@ func attachBlcokToBatch(batch *pebble.Batch, block *database.DBBlock) error {
}

// block → txs + transaction records
for i, t := range txs {
for i := range txs {

t := txs[i]
if t == nil {
// we skip nil txs here to so that we have exact positions.
// todo: should we keep it like this?
continue
}
// bt
if err := b.Set(KeyBlockTx(blockHash, uint32(i)), t.Txid, nil); err != nil {
logging.L.Err(err).Msg("insert failed")
Expand Down
1 change: 1 addition & 0 deletions internal/database/specifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DB interface {
GetChainTip() ([]byte, uint32, error)
GetBlockHashByHeight(height uint32) ([]byte, error)
ApplyBlock(*DBBlock) error
FlushBatch() error
TweaksForBlockAll([]byte) ([]TweakRow, error)
TweaksForBlockCutThrough([]byte, uint32) ([]TweakRow, error)
}
Expand Down
Loading