Skip to content

Commit

Permalink
Added WriteBlock helper in core to write the Block to db
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Mar 13, 2023
1 parent 1a9703e commit 441b91e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/bodydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func (bc *BodyDb) Append(batch ethdb.Batch, block *types.Block, newInboundEtxs t
return logs, nil
}

// WriteBlock write the block to the bodydb database
func (bc *BodyDb) WriteBlock(block *types.Block) {
rawdb.WriteBlock(bc.db, block)
}

// HasBlock checks if a block is fully present in the database or not.
func (bc *BodyDb) HasBlock(hash common.Hash, number uint64) bool {
if bc.blockCache.Contains(hash) {
Expand Down
7 changes: 6 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
c.futureHeaders.Remove(block.Hash())

// Resume the downloader if paused
c.sl.downloaderWaitFeed.Send(false)
c.sl.downloaderWaitFeed.Send(false)

// If we have a dom, send the dom any pending ETXs which will become
// referencable by this block. When this block is referenced in the dom's
Expand Down Expand Up @@ -200,6 +200,11 @@ func (c *Core) Stop() {
// Slice methods //
//---------------//

// WriteBlock write the block to the bodydb database
func (c *Core) WriteBlock(block *types.Block) {
c.sl.WriteBlock(block)
}

func (c *Core) Append(header *types.Header, domPendingHeader *types.Header, domTerminus common.Hash, td *big.Int, domOrigin bool, reorg bool, newInboundEtxs types.Transactions) ([]types.Transactions, error) {
newPendingEtxs, err := c.sl.Append(header, domPendingHeader, domTerminus, td, domOrigin, reorg, newInboundEtxs)
// If dom tries to append the block and sub is not in sync.
Expand Down
4 changes: 4 additions & 0 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ func (hc *HeaderChain) GetHorizon() uint64 {
return header.NumberU64()
}

func (hc *HeaderChain) WriteBlock(block *types.Block) {
hc.bc.WriteBlock(block)
}

// GetTd retrieves a block's total difficulty in the canonical chain from the
// database by hash and number, caching it if found.
func (hc *HeaderChain) GetTd(hash common.Hash, number uint64) *big.Int {
Expand Down
4 changes: 4 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,7 @@ func (sl *Slice) SubscribeDownloaderWait(ch chan<- bool) event.Subscription {
func (sl *Slice) SubscribeMissingBody(ch chan<- *types.Header) event.Subscription {
return sl.scope.Track(sl.missingBodyFeed.Subscribe(ch))
}

func (sl *Slice) WriteBlock(block *types.Block) {
sl.hc.WriteBlock(block)
}

0 comments on commit 441b91e

Please sign in to comment.