Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tbc: add an external blockheader insert for headers only mode #414

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions database/tbcd/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,9 @@ func (l *ldb) BlockHeadersInsert(ctx context.Context, bhs *wire.MsgHeaders, batc
}
defer hhDiscard()

// blocks
blocksDB := l.rawPool[level.BlocksDB]

// retrieve best/canonical block header
bbh, err := bhsTx.Get([]byte(bhsCanonicalTipKey), nil)
if err != nil {
Expand Down Expand Up @@ -1111,12 +1114,23 @@ func (l *ldb) BlockHeadersInsert(ctx context.Context, bhs *wire.MsgHeaders, batc

// Store height_hash for future reference
hhKey := heightHashToKey(height, bhash[:])
hhBatch.Put(hhKey, []byte{}) // XXX nil?
ok, err := hhTx.Has(hhKey, nil)
if err != nil {
return tbcd.ITInvalid, nil, nil, 0,
fmt.Errorf("height hash has: %w", err)
} else if !ok {
hhBatch.Put(hhKey, []byte{})
}

// Insert a synthesized height_hash key that serves as an index
// to see which blocks are missing.
// XXX should we always insert or should we verify prior to insert?
bmBatch.Put(hhKey, []byte{})
ok, err = blocksDB.Has(hhKey)
if err != nil {
return tbcd.ITInvalid, nil, nil, 0,
fmt.Errorf("blocks has: %w", err)
} else if !ok {
bmBatch.Put(hhKey, []byte{})
}

// XXX reason about pre encoding. Due to the caller code being
// heavily reentrant the odds are not good that encoding would
Expand Down
4 changes: 4 additions & 0 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,10 @@ func (s *Server) BlockInsert(ctx context.Context, blk *wire.MsgBlock) (int64, er
return s.db.BlockInsert(ctx, btcutil.NewBlock(blk))
}

func (s *Server) BlockHeadersInsert(ctx context.Context, headers *wire.MsgHeaders) (tbcd.InsertType, *tbcd.BlockHeader, *tbcd.BlockHeader, int, error) {
return s.db.BlockHeadersInsert(ctx, headers, nil)
}

func (s *Server) handleBlock(ctx context.Context, p *rawpeer.RawPeer, msg *wire.MsgBlock, raw []byte) error {
log.Tracef("handleBlock (%v)", p)
defer log.Tracef("handleBlock exit (%v)", p)
Expand Down
Loading