Skip to content

Commit

Permalink
Send newHeads event only if store succeded for sure
Browse files Browse the repository at this point in the history
and the block is available for users to query via RPC
  • Loading branch information
omerfirmak committed Oct 11, 2023
1 parent 3c32f49 commit 3e5c10b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (b *Blockchain) SetL1Head(update *core.L1Head) error {
func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommitments,
stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class,
) error {
return b.database.Update(func(txn db.Transaction) error {
err := b.database.Update(func(txn db.Transaction) error {
if err := verifyBlock(txn, block); err != nil {
return err
}
Expand All @@ -330,7 +330,6 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
if err := StoreBlockHeader(txn, block.Header); err != nil {
return err
}
b.newHeads.Send(block.Header)

for i, tx := range block.Transactions {
if err := storeTransactionAndReceipt(txn, block.Number, uint64(i), tx,
Expand All @@ -356,6 +355,10 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
heightBin := core.MarshalBlockNumber(block.Number)
return txn.Set(db.ChainHeight.Key(), heightBin)
})
if err == nil {
b.newHeads.Send(block.Header)
}
return err
}

// VerifyBlock assumes the block has already been sanity-checked.
Expand Down

0 comments on commit 3e5c10b

Please sign in to comment.